/* ---------- Notes tool ----------
   Notes are organised Books → Pages → Content. The left sidebar pane "doubles":
   #notes-view holds a Books column + a Pages column side-by-side; the rich-text
   editor lives in the center content area (#notes-block). Self-contained
   (src/notes/notes.js, localStorage `marker.notes.v2`). */

/* Three tabs (Favorites / Projects / Notes) — let them share the header width
   equally so nothing overflows the 290px sidebar. */
.sidebar-tabs {
  flex: 1;
}
.sidebar-tabs .tab-btn {
  flex: 1;
  text-align: center;
  padding: 4px 8px;
}

/* When the Notes tab is active the right To-do panel is irrelevant — hide it, and
   WIDEN the sidebar so the Books | Pages columns fit; the editor takes the rest
   (animates via .layout's grid transition). ≤1080px already hides .todo. */
@media (min-width: 1081px) {
  .layout.notes-mode {
    --nbw: 290px; /* Books column = the normal sidebar width, FIXED */
    grid-template-columns: var(--nbw) 1fr;
  }
  .layout.notes-mode.notes-book-open {
    grid-template-columns: calc(var(--nbw) * 2) 1fr;
  }
  .layout.notes-mode .todo {
    display: none;
  }
}
@media (min-width: 761px) and (max-width: 1080px) {
  .layout.notes-mode {
    --nbw: 260px; /* matches the narrower sidebar at this width (misc.css) */
    grid-template-columns: var(--nbw) 1fr;
  }
  .layout.notes-mode.notes-book-open {
    grid-template-columns: calc(var(--nbw) * 2) 1fr;
  }
}

/* Keep the Bookmarks/Projects/Notes tabs at their normal (single-column) width —
   the widened sidebar must NOT stretch them across the Pages column. */
@media (min-width: 761px) {
  .layout.notes-mode .sidebar-tabs-wrap {
    max-width: var(--nbw, 290px);
  }
}

/* ----- Sidebar: Books | Pages two-column split ----- */
.notes-view {
  flex-direction: row !important; /* override .sidebar-view column */
  gap: 0;
}
.notes-col {
  display: flex;
  flex-direction: column;
  flex: 1 1 50%;
  min-width: 0;
  min-height: 0;
}
.notes-pages-col {
  border-left: 1px solid var(--border);
}
/* ≥761px: Books column keeps the FULL sidebar width; the Pages column lives in the
   extra space that appears when .notes-book-open widens the sidebar — the .layout
   grid transition makes it slide open left→right. Inner content is pinned to the
   final width so it slides instead of reflowing. */
@media (min-width: 761px) {
  .notes-books-col {
    flex: 0 0 var(--nbw, 290px);
  }
  .notes-pages-col {
    flex: 1 1 auto;
    overflow: hidden;
  }
  .notes-pages-col > * {
    width: calc(var(--nbw, 290px) - 1px);
    flex-shrink: 0;
  }
  .layout.notes-mode:not(.notes-book-open) .notes-pages-col {
    border-left-color: transparent;
  }
}
.notes-pages-head {
  flex-shrink: 0;
  padding: 0 12px 10px;
  display: flex;
  align-items: center;
  min-width: 0;
}
.notes-pages-book {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.notes-pages-book .npb-ico {
  flex-shrink: 0;
}

/* Create controls at the bottom of the Books column: a type selector (Book / Page /
   Section) sitting above the name-and-add row, so the whole thing mirrors the
   Bookmarks/Projects input + teal add-button pattern. (.sidebar-add gives the
   column layout + 8px gap between the selector and the add row.) */
.notes-type-select {
  display: flex;
  gap: 6px;
}
.notes-type-btn {
  flex: 1 1 0;
  min-width: 0;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 5px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    background var(--dur) var(--ease);
}
.notes-type-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.notes-type-btn:hover {
  color: var(--accent-text);
  border-color: var(--accent);
}
.notes-type-btn.is-active {
  color: var(--accent-text);
  border-style: solid;
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Lift the book header into the tab band so it sits at the very top (level with the
   tabs, filling the empty space beside them). The header is compact — a dashed rule
   sits right under it and the pages list starts immediately, filling from the top.
   ≤760px stacks, so skip the lift there. */
@media (min-width: 761px) {
  .layout.notes-mode .notes-pages-col {
    margin-top: -52px; /* = tab-bar height, so the header lines up with the tabs */
  }
  .layout.notes-mode .notes-pages-head {
    height: 52px; /* match the tab bar; keeps the header compact */
    padding: 9px 12px;
    border-bottom: 1px dashed var(--border-strong);
    margin-bottom: 6px;
  }
}
/* On phones the two columns stack inside the drawer instead of squeezing. */
@media (max-width: 760px) {
  .notes-view {
    flex-direction: column !important;
  }
  .notes-pages-col {
    border-left: 0;
    border-top: 1px solid var(--border);
  }
  /* no slide on the stacked drawer — the pane simply appears with an open book */
  .layout.notes-mode:not(.notes-book-open) .notes-pages-col {
    display: none;
  }
}

/* ----- Sidebar: notes list ----- */
.note-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  cursor: pointer;
  position: relative;
  transition: background var(--dur) var(--ease);
}
.note-row:hover {
  background: var(--surface-2);
}
.note-row.active {
  background: var(--accent-soft);
}
.note-row.active::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 70%;
  border-radius: var(--r-pill);
  background: var(--accent);
}
.note-row-title {
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 22px; /* room for the delete button */
}
.note-row.active .note-row-title {
  color: var(--accent-text);
}
.note-row-meta {
  display: flex;
  gap: 6px;
  min-width: 0;
  font-size: var(--fs-xs);
  color: var(--faint);
}
.note-row-time {
  flex-shrink: 0;
}
.note-row-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-row-del {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  color: var(--faint);
  opacity: 0;
  cursor: pointer;
  transition: opacity var(--dur) var(--ease), color var(--dur) var(--ease),
    background var(--dur) var(--ease);
}
.note-row:hover .note-row-del,
.note-row.active .note-row-del {
  opacity: 1;
}
.note-row-del:hover {
  color: var(--danger, #e5484d);
  background: var(--surface);
}
.note-row-del svg {
  width: 14px;
  height: 14px;
}

/* ----- Center: editor panel ----- */
.notes-block {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.note-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  padding: 6px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  flex-shrink: 0;
}
.nt-btn {
  height: 32px;
  min-width: 32px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: var(--r-md);
  color: var(--ink);
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nt-btn:hover {
  background: var(--surface-2);
}
.nt-btn.active {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.nt-btn svg {
  width: 16px;
  height: 16px;
}
.nt-glyph {
  font-size: 0.95rem;
  line-height: 1;
}
.nt-glyph.b {
  font-weight: 800;
}
.nt-glyph.i {
  font-style: italic;
  font-weight: 600;
}
.nt-glyph.s {
  text-decoration: line-through;
  font-weight: 600;
}
.nt-label {
  font-weight: 700;
  font-size: 0.8125rem;
}
.nt-caret {
  width: 9px;
  height: 6px;
  color: var(--faint);
}
.nt-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

/* dropdown menus (format / list / table) */
.nt-dd {
  position: relative;
}
.nt-menu {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  z-index: var(--z-flyout);
  min-width: 168px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-pop);
  padding: 4px;
}
.nt-menu[hidden] {
  display: none;
}
.nt-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  color: var(--ink);
  cursor: pointer;
}
.nt-menu-item:hover {
  background: var(--surface-2);
}

/* table size grid picker */
.nt-table-menu {
  min-width: auto;
}
.nt-grid-label {
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--muted);
  padding: 2px 0 6px;
}
.nt-grid {
  display: grid;
  grid-template-columns: repeat(6, 18px);
  gap: 3px;
  padding: 2px;
}
.nt-grid-cell {
  width: 18px;
  height: 18px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  cursor: pointer;
}
.nt-grid-cell.on {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* editor surface */
.note-editor-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
}
.note-editor-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 26px 32px;
  font-size: var(--fs-base);
  line-height: 1.7;
  color: var(--ink);
  outline: none;
}
.note-editor-body.is-empty::before {
  content: attr(data-placeholder);
  color: var(--faint);
  pointer-events: none;
}
.note-editor-body h1 {
  font-size: 1.6em;
  font-weight: 700;
  margin: 0.6em 0 0.3em;
  letter-spacing: -0.01em;
}
.note-editor-body h2 {
  font-size: 1.3em;
  font-weight: 700;
  margin: 0.6em 0 0.3em;
}
.note-editor-body h3 {
  font-size: 1.1em;
  font-weight: 700;
  margin: 0.6em 0 0.3em;
}
.note-editor-body p {
  margin: 0.4em 0;
}
.note-editor-body ul,
.note-editor-body ol {
  padding-left: 1.5em;
  margin: 0.4em 0;
}
.note-editor-body li {
  margin: 0.15em 0;
}
.note-editor-body a {
  color: var(--accent);
  text-decoration: underline;
}
.note-editor-body table {
  border-collapse: collapse;
  margin: 0.6em 0;
  width: auto;
}
.note-editor-body td,
.note-editor-body th {
  border: 1px solid var(--border-strong);
  padding: 6px 10px;
  min-width: 52px;
  vertical-align: top;
}

/* empty state (no note selected) */
.notes-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  gap: 4px;
  padding: 40px 20px;
}
.notes-empty svg {
  width: 40px;
  height: 40px;
  color: var(--faint);
  margin-bottom: 8px;
}
.notes-empty .empty-title {
  font-weight: 600;
  color: var(--ink);
}
.notes-empty .empty-sub {
  font-size: var(--fs-sm);
}
.notes-empty .btn {
  margin-top: 14px;
}

/* on mobile the editor stacks full-width like the other tabs */
@media (max-width: 760px) {
  .note-editor-body {
    padding: 18px 18px;
  }
}

/* ----- Page rows (Pages column) — one line: icon · title · last-edited date ----- */
.note-page-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border-radius: var(--r-md);
  cursor: pointer;
  position: relative;
  transition: background var(--dur) var(--ease);
}
.note-page-row:hover {
  background: var(--surface-2);
}
.note-page-row.active {
  background: var(--accent-soft);
}
.note-page-row.active::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 70%;
  border-radius: var(--r-pill);
  background: var(--accent);
}
.np-ico {
  flex-shrink: 0;
  width: 18px;
  text-align: center;
  font-size: 0.95em;
  line-height: 1.4;
}
.np-title {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-page-row.active .np-title {
  color: var(--accent-text);
}
.np-time {
  flex-shrink: 0;
  font-size: var(--fs-xs);
  color: var(--faint);
}

/* ----- Section divider (splits pages into groups) ----- */
.note-section {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 9px 5px;
  cursor: grab;
  position: relative;
}
.note-section::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.note-section-label {
  flex-shrink: 0;
  max-width: 78%;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-section.dragging {
  opacity: 0.4;
}
