/* Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 16px; color: #1a1a1a; background: #ffffff; }
a { color: inherit; }

/* Layout */
.kb-layout { display: flex; height: 100dvh; overflow: hidden; }

/* Sidebar */
.kb-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #f1f0ee;
  border-right: 1px solid #e5e4e0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.kb-sidebar__header {
  padding: 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e5e4e0;
}
.kb-sidebar__logo { font-weight: 700; font-size: 15px; letter-spacing: -.3px; }
.kb-sidebar__nav { list-style: none; padding: 8px; }
.kb-sidebar__nav li { margin: 0; }
.kb-sidebar__item { list-style: none; }
.kb-sidebar__item--dragging { opacity: 0.4; }

.kb-sidebar__link {
  display: block;
  padding: 5px 16px;
  border-radius: 4px;
  font-size: 14px;
  text-decoration: none;
  color: #37352f;
  transition: background 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kb-sidebar__link:hover { background: #e8e7e3; }
.kb-sidebar__link--active { background: #e3e2de; font-weight: 500; }

/* Main content */
.kb-main { flex: 1; overflow-y: auto; padding: 48px 64px; }
.kb-main--empty { display: flex; align-items: center; justify-content: center; }
.kb-empty { color: #9b9a97; font-size: 14px; }

/* Page */
.kb-page { max-width: 720px; margin: 0 auto; }
/* Page options menu (fixed top-right) */
.kb-page-menu {
  position: fixed;
  top: 12px;
  right: 16px;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 2px;
}
.kb-page-menu__lock-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  color: #9b9a97;
  padding: 5px 8px;
  border-radius: 6px;
  letter-spacing: .3px;
  transition: background 0.1s, color 0.1s;
}
.kb-page-menu__lock-btn:hover { background: #e8e7e3; color: #37352f; }
.kb-page-menu__lock-btn--active { color: #e67e22; }
.kb-page-menu__lock-btn--active:hover { background: #fef3e8; color: #c0651a; }
.kb-page-menu__trigger {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: #9b9a97;
  padding: 4px 8px;
  border-radius: 6px;
  letter-spacing: 2px;
  line-height: 1;
  transition: background 0.1s, color 0.1s;
}
.kb-page-menu__trigger:hover { background: #e8e7e3; color: #37352f; }
.kb-page-menu__dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #fff;
  border: 1px solid #e5e4e0;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  padding: 4px;
  min-width: 160px;
}
.kb-page-menu__option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  color: #37352f;
  transition: background 0.1s;
}
.kb-page-menu__option svg { flex-shrink: 0; opacity: .7; }
.kb-page-menu__option:hover { background: #f1f0ee; }
.kb-page-menu__option--danger { color: #c0392b; }
.kb-page-menu__option--danger:hover { background: #fdf0ee; }

.kb-page__header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 32px; gap: 16px; }
.kb-page__title {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -.5px;
  color: #1a1a1a;
  cursor: text;
  line-height: 1.2;
  word-break: break-word;
  outline: none;
}
.kb-page__title:empty::before { content: "Untitled"; color: #c8c7c4; }
.kb-page__actions { display: flex; gap: 8px; flex-shrink: 0; padding-top: 10px; }

/* Buttons */
.kb-btn {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  text-decoration: none;
  background: #2d2d2d;
  color: #fff;
  transition: background 0.15s;
  white-space: nowrap;
}
.kb-btn:hover { background: #111; }
.kb-btn--ghost { background: transparent; color: #37352f; border: 1px solid #d8d7d4; }
.kb-btn--ghost:hover { background: #f1f0ee; }
.kb-btn--sm { padding: 4px 10px; font-size: 13px; }
.kb-btn--danger { background: transparent; color: #c0392b; border: 1px solid #e8c0bc; }
.kb-btn--danger:hover { background: #fdf0ee; }

/* Empty page prompt */
.kb-empty-page { position: relative; margin-top: 8px; }
.kb-empty-page__btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  color: #9b9a97;
  padding: 6px 2px;
  border-radius: 6px;
  transition: color 0.1s;
}
.kb-empty-page__btn:hover { color: #37352f; }
.kb-empty-page__picker {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: #fff;
  border: 1px solid #e5e4e0;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  padding: 4px;
  min-width: 160px;
  z-index: 100;
}

/* Blocks list */
.kb-blocks { display: flex; flex-direction: column; }

/* Individual block */
.kb-block {
  position: relative;
  display: flex;
  align-items: baseline;
  border-radius: 6px;
  padding: 2px 0;
  transition: background 0.1s;
}
.kb-block--image_gallery { align-items: flex-start; }
.kb-block--dragging { opacity: 0.4; }
.kb-block--dragging .kb-block__side-actions { opacity: 0 !important; }
.kb-page--locked .kb-block__side-actions { opacity: 0 !important; pointer-events: none; }
.kb-block { margin-bottom: 10px; }

.kb-drop-marker {
  height: 0;
  overflow: visible;
  pointer-events: none;
  position: relative;
  margin: 0;
}
.kb-drop-marker::before {
  content: '';
  display: block;
  position: absolute;
  inset-inline: 0;
  top: -5px;
  height: 3px;
  background: #3b82f6;
  border-radius: 2px;
}

/* Side actions — sit in the left margin, outside the page content area */
.kb-block__side-actions {
  flex-shrink: 0;
  width: 4rem;
  margin-left: -4rem;
  position: relative; /* dropdown anchor */
  display: flex;
  align-items: center;
  padding-right: 4px;
  opacity: 0;
  transition: opacity 0.1s;
  white-space: nowrap;
}
.kb-block:hover .kb-block__side-actions,
.kb-block__side-actions:has(.kb-block__actions-menu:not([hidden])),
.kb-block__side-actions:has(.kb-block__type-picker:not([hidden])) { opacity: 1; }

.kb-block__handle {
/*  letter-spacing: -3px;*/
}
.kb-block__handle,
.kb-block__add-btn {
  font-size: 20px;
  line-height: 1;
  color: #c8c7c4;
  background: none;
  border: none;
  cursor: pointer;
  user-select: none;
  padding: 4px 5px;
  border-radius: 4px;
  transition: background 0.1s, color 0.1s;
}
.kb-block__handle:hover,
.kb-block__add-btn:hover { background: #e8e7e3; color: #37352f; }

.kb-block__type-picker {
  position: absolute;
  left: 0;
  top: 0;
  background: #fff;
  border: 1px solid #e5e4e0;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  padding: 4px;
  min-width: 140px;
  z-index: 100;
}

.kb-block__actions-menu {
  position: absolute;
  left: 0;
  top: 0;
  background: #fff;
  border: 1px solid #e5e4e0;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  padding: 4px;
  min-width: 140px;
  z-index: 100;
}
.kb-display-submenu { position: relative; }
.kb-submenu-arrow { margin-left: auto; color: #b0b0a8; font-size: 14px; }

.kb-block__submenu {
  position: absolute;
  left: 100%;
  top: 0;
  background: #fff;
  border: 1px solid #e5e4e0;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  padding: 4px;
  min-width: 150px;
  z-index: 101;
}

.kb-check-icon {
  display: inline-block;
  width: 18px;
  flex-shrink: 0;
  font-size: 13px;
}

.kb-block__action-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 14px;
  color: #37352f;
  text-decoration: none;
  transition: background 0.1s;
}
.kb-block__action-option svg { flex-shrink: 0; opacity: .7; }
.kb-block__action-option:hover { background: #f1f0ee; }
.kb-block__action-option--danger { color: #c0392b; }
.kb-block__action-option--danger:hover { background: #fdf0ee; }
.kb-block__type-picker-divider { height: 1px; background: #e9e8e3; margin: 4px 8px; }

.kb-heading { outline: none; word-break: break-word; margin: 0; font-weight: 700; color: #1a1a1a; cursor: text; }
.kb-heading:empty::before { color: #c8c7c4; font-weight: 400; }
.kb-heading--heading1 { font-size: 2rem; letter-spacing: -.5px; line-height: 1.2; }
.kb-heading--heading1:empty::before { content: "Heading 1"; }
.kb-heading--heading2 { font-size: 1.6rem; letter-spacing: -.3px; line-height: 1.25; }
.kb-heading--heading2:empty::before { content: "Heading 2"; }
.kb-heading--heading3 { font-size: 1.3rem; letter-spacing: -.2px; line-height: 1.3; }
.kb-heading--heading3:empty::before { content: "Heading 3"; }
.kb-heading--heading4 { font-size: 1.1rem; line-height: 1.35; }
.kb-heading--heading4:empty::before { content: "Heading 4"; }

.kb-hr { border: none; border-top: 2px solid #e9e8e3; margin: 8px 0; }

.kb-block__frame { display: block; flex: 1; min-width: 0; }
.kb-block__content { min-width: 0; }


.kb-block__placeholder { color: #b3b1ab; font-style: italic; font-size: 15px; }
.kb-block__text-view { font-size: 15px; line-height: 1.6; }

/* Trix: disable file attachment */
.trix-button-group--file-tools { display: none !important; }

/* Block form */
.kb-block__form { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.kb-block__trix { font-size: 15px; }
.kb-block__form-actions { display: flex; gap: 8px; }

/* Image gallery */
.kb-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0;
}
.kb-gallery--edit { margin-bottom: 12px; }

.kb-gallery__item { display: flex; flex-direction: column; }

.kb-gallery--half-width {
  gap: 12px;
  padding: 4px 0;
}
.kb-gallery--half-width .kb-gallery__item { width: calc(50% - 6px); }
.kb-gallery--half-width .kb-gallery__thumb {
  width: 100%;
  height: auto;
  border-radius: 6px;
}

.kb-gallery--full-width {
  flex-direction: column;
  gap: 12px;
  padding: 4px 0;
}
.kb-gallery--full-width .kb-gallery__item { width: 100%; }
.kb-gallery--full-width .kb-gallery__thumb {
  width: 100%;
  height: auto;
  border-radius: 6px;
}

.kb-gallery__thumb-link { display: block; }
.kb-gallery__caption {
  font-size: 13px;
  color: #6b6b63;
  padding: 4px 2px 0;
  line-height: 1.4;
  display: none;
}

.kb-gallery__caption-input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 4px 6px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid #e1e1d8;
  border-radius: 4px;
  outline: none;
  background: #fff;
}
.kb-gallery__caption-input:focus { border-color: #3b82f6; }
.kb-gallery__thumb {
  display: block;
  height: 140px;
  width: auto;
  border-radius: 4px;
  transition: opacity 0.15s;
}

/* Gallery edit items */
.kb-gallery__edit-item { position: relative; display: inline-block; cursor: grab; }
.kb-gallery__edit-item:active { cursor: grabbing; }
.kb-gallery__edit-item--dragging { opacity: 0.4; }

.kb-gallery__drop-marker {
  display: inline-block;
  width: 3px;
  height: 100px;
  background: #3b82f6;
  border-radius: 2px;
  vertical-align: top;
  pointer-events: none;
  align-self: stretch;
}
.kb-gallery__edit-item .kb-gallery__thumb { height: 100px; width: auto; }
.kb-gallery__remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  text-decoration: none;
}
.kb-gallery__remove:hover { background: rgba(192,57,43,0.9); }


/* Dropzone */
.kb-dropzone {
  border: 2px dashed #d8d7d4;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 8px;
}
.kb-dropzone:hover, .kb-dropzone--over {
  border-color: #5e9af0;
  background: #f0f6ff;
}
.kb-dropzone__label { font-size: 14px; color: #9b9a97; pointer-events: none; }
.kb-dropzone__input { display: none; }
.kb-dropzone__preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  justify-content: center;
}
.kb-dropzone__preview-thumb {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
}


/* Page form */
.kb-page-form { max-width: 560px; margin: 0 auto; }
.kb-field { margin-bottom: 16px; }
.kb-page-title-input {
  width: 100%;
  font-size: 1.8rem;
  font-weight: 700;
  border: none;
  outline: none;
  background: transparent;
  color: #1a1a1a;
  letter-spacing: -.3px;
}
.kb-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d8d7d4;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}
.kb-input:focus { border-color: #5e9af0; }
.kb-errors { background: #fdf0ee; border: 1px solid #e8c0bc; border-radius: 6px; padding: 12px 16px; margin-bottom: 16px; font-size: 14px; color: #c0392b; }
