/* Scaling Book Lab — the three-column shell and the two rails.
 * Structure only; the reading surface lives in app.css. */

/* `--topbar-h` is measured in main.ts, because the header's height moves with
 * font loading, safe-area insets and button wrapping. The fallback only has to
 * be sane for the first frame. */
:root { --topbar-h: 69px }

/* ── Shell ────────────────────────────────────────────────────────────────── */

/* Mobile first: one column, both rails off-canvas. */
.shell { display: block }
.shell__main { min-width: 0 }

/* Drawers open BELOW the header, not under it — the header sits above them in
   the stack, so a rail starting at top:0 would hide its own first row. */
.rail {
  position: fixed; top: var(--topbar-h); bottom: 0; z-index: 45;
  width: min(320px, 88vw); overflow-y: auto; overscroll-behavior: contain;
  background: var(--paper-raise);
  padding: var(--s5) var(--s4) calc(var(--s7) + env(safe-area-inset-bottom));
  transition: transform var(--slow) var(--ease);
  box-shadow: 0 0 40px rgb(0 0 0 / 0);
}
.rail--left { left: 0; border-right: var(--hair); transform: translateX(-102%) }
.rail--right { right: 0; border-left: var(--hair); transform: translateX(102%) }
.rail.is-open { transform: translateX(0); box-shadow: 0 0 40px rgb(0 0 0 / .16) }

.scrim {
  position: fixed; inset: var(--topbar-h) 0 0; z-index: 44;
  background: rgb(20 25 28 / .35); opacity: 0; pointer-events: none;
  transition: opacity var(--fast) var(--ease);
}
.scrim.is-on { opacity: 1; pointer-events: auto }

/*
 * Docking happens in two steps, not one. The reading column must never fall
 * below its measure (34rem ≈ 544px) plus breathing room — docking both rails at
 * 1080px left the middle column narrower than the text it holds, which is what
 * made figures overflow their column.
 *
 *   ≥ 1024px : outline docks, notes stays a drawer
 *   ≥ 1360px : notes docks too
 */
@media (min-width: 1024px) {
  .shell {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr);
    gap: var(--s4);
    align-items: start;
    max-width: 1560px; margin: 0 auto;
  }
  .rail--left {
    position: sticky; top: var(--topbar-h); bottom: auto; z-index: 1;
    transform: none; background: transparent; border-right: none;
    box-shadow: none; width: auto;
    max-height: calc(100vh - var(--topbar-h));
    padding: var(--s5) 0 var(--s7) var(--s4);
  }
  .railtoggle--left { display: none }
  .shell__main .page { margin: 0; max-width: none; padding-left: 0 }
}

/* Notes dock as soon as there is room, so the panel is visible rather than
   hidden behind a button on most laptop screens. */
@media (min-width: 1240px) {
  .shell { grid-template-columns: 210px minmax(0, 1fr) 288px }
  .rail--right {
    position: sticky; top: var(--topbar-h); bottom: auto; z-index: 1;
    transform: none; background: transparent; border-left: none;
    box-shadow: none; width: auto;
    max-height: calc(100vh - var(--topbar-h));
    padding: var(--s5) var(--s4) var(--s7) 0;
  }
  .railtoggle--right { display: none }
  .scrim { display: none }
}

/* The brand and Progress link crowd out the toggles on small phones. */
@media (max-width: 420px) {
  .topbar__progress { display: none }
}

/* ── Left rail: chapter switcher ──────────────────────────────────────────── */

/* The rail reads top-down: where you are, then where you can go. Tight
   leading and a divider keep it from looking like an empty column. */
.rail__switch { margin-bottom: var(--s4); padding-bottom: var(--s4); border-bottom: var(--hair) }
.rail__switch summary {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  cursor: pointer; list-style: none; min-height: 40px;
  padding: 0 var(--s3); border: var(--hair); border-radius: var(--r-sm);
  background: var(--paper); font-family: var(--font-ui); font-size: var(--t-small);
  transition: border-color var(--fast) var(--ease);
}
.rail__switch summary::-webkit-details-marker { display: none }
.rail__switch summary:hover { border-color: var(--ink-3) }
.rail__switchlabel { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.rail__chev { color: var(--ink-3); font-size: 11px; flex: none; transition: transform var(--fast) var(--ease) }
.rail__switch[open] .rail__chev { transform: rotate(180deg) }

.rail__chapters {
  margin-top: var(--s2); padding: var(--s2);
  border: var(--hair); border-radius: var(--r-sm); background: var(--paper);
  max-height: min(52vh, 460px); overflow-y: auto; overscroll-behavior: contain;
}
.rail__part {
  font-family: var(--font-mono); font-size: var(--t-micro);
  text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3);
  padding: var(--s3) var(--s2) var(--s1);
}
.rail__part:first-child { padding-top: var(--s1) }
.rail__chapter {
  display: flex; align-items: baseline; gap: var(--s2);
  padding: var(--s2); border-radius: var(--r-sm);
  font-family: var(--font-ui); font-size: var(--t-small);
  color: var(--ink); text-decoration: none; line-height: 1.35;
}
.rail__chapter:hover { background: var(--paper-sunk) }
.rail__chapter.is-current { background: var(--live-bg); color: var(--live); font-weight: 500 }
.rail__chapter.is-unwritten { color: var(--ink-3); cursor: default }
.rail__chapter.is-unwritten:hover { background: none }
.rail__num {
  font-family: var(--font-mono); font-size: var(--t-micro);
  color: var(--ink-3); flex: none; min-width: 1.5em;
}
.rail__done { margin-left: auto; color: var(--bound-cmp); font-size: 11px; flex: none }

/* ── Left rail: section outline ───────────────────────────────────────────── */

.rail__title {
  font-family: var(--font-mono); font-size: var(--t-micro);
  text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3);
  margin-bottom: var(--s3);
}
.rail__outline { display: flex; flex-direction: column; gap: 1px }
.rail__section {
  font-family: var(--font-ui); font-size: var(--t-small); line-height: 1.4;
  color: var(--ink-2); text-decoration: none;
  padding: var(--s2) var(--s3);
  border-left: 2px solid var(--rule);
  transition: color var(--fast) var(--ease), border-color var(--fast) var(--ease),
              background var(--fast) var(--ease);
}
.rail__section:hover { color: var(--ink); border-left-color: var(--ink-3); background: var(--paper-sunk) }
.rail__section.is-active {
  color: var(--live); border-left-color: var(--live); font-weight: 500;
}

.rail__empty {
  font-family: var(--font-ui); font-size: var(--t-small); color: var(--ink-3);
  line-height: 1.5;
}

/* ── Right rail: notes ────────────────────────────────────────────────────── */

.notes__head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: var(--s3);
}
/* The sync line: one dot, one sentence, one link. This is the whole report
   on where a chapter's notes live, so it sits directly under the title and
   never moves. */
.notes__sync {
  display: flex; align-items: baseline; gap: var(--s2);
  font-family: var(--font-ui); font-size: var(--t-micro);
  color: var(--ink-3); margin-bottom: var(--s3); min-height: 1.4em;
}
.notes__dot {
  flex: none; align-self: center;
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--rule-strong);
  transition: background var(--fast) var(--ease);
}
.notes__dot.is-synced   { background: var(--bound-cmp) }
.notes__dot.is-saving   { background: var(--bound-mix) }
.notes__dot.is-conflict { background: var(--bound-mem) }
.notes__dot.is-offline  { background: var(--rule-strong) }
.notes__syncmsg { flex: 1; min-width: 0; line-height: 1.45 }
.notes__page {
  flex: none; white-space: nowrap; color: var(--live); text-decoration: none;
}
.notes__page:hover { text-decoration: underline }

/* Conflict bar. Warning colour, not error colour: nothing has gone wrong and
   nothing has been lost - two versions exist and the reader picks. It stays
   until they do. */
.notes__conflict {
  margin-bottom: var(--s3); padding: var(--s2) var(--s3);
  border: 1px solid var(--bound-mix); border-radius: var(--r-sm);
  background: var(--bound-mix-bg);
}
.notes__conflictmsg {
  font-family: var(--font-ui); font-size: var(--t-micro);
  color: var(--ink-2); line-height: 1.45;
}
.notes__conflictacts {
  display: flex; flex-wrap: wrap; gap: var(--s1); margin-top: var(--s2);
}

/* Quiet footer: the fallback capture control and the shortcut hint. */
.notes__foot {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--s2);
  margin-top: var(--s4); padding-top: var(--s3); border-top: var(--hair);
}
.notes__hint {
  font-family: var(--font-mono); font-size: 10px; color: var(--ink-3);
  line-height: 1.5;
}
.notes__status {
  font-family: var(--font-ui); font-size: var(--t-micro);
  color: var(--ink-3); margin-top: var(--s3); min-height: 1.2em;
}

.notes__editor { font-family: var(--font-ui); font-size: 14px; color: var(--ink) }

/* Notion controls: destination picker, connect/disconnect. Deliberate
 * actions only: the everyday loop is the status line, so this is empty most
 * of the time. */
.notes__notion:not(:empty) { margin-bottom: var(--s3) }
.notes__notionmsg {
  font-family: var(--font-ui); font-size: var(--t-micro);
  color: var(--ink-3); line-height: 1.5; margin-top: var(--s2);
}
.notes__notionmsg a { color: var(--live) }
.notes__notionlabel {
  font-family: var(--font-ui); font-size: var(--t-micro);
  color: var(--ink-3); margin-top: var(--s2);
}
.notes__select {
  display: block; width: 100%; margin-top: var(--s1);
  font-family: var(--font-ui); font-size: var(--t-small);
  padding: 6px 8px; border-radius: var(--r-sm);
  border: 1px solid var(--rule); background: var(--paper);
  color: var(--ink);
}
.notes__notiongo { margin-top: var(--s2); }
/* Footer under a saved export: "Change destination" + the kit's unstyled
   connect button (<dobase-connect-button unstyled> renders a bare <button>
   we style to match our own .btn). */
.notes__notionrow {
  display: flex; gap: var(--s2); align-items: center; margin-top: var(--s2);
}
.notes__notionrow dobase-connect-button > button {
  font: inherit; font-size: 0.78rem; padding: 2px 8px;
  background: none; border: 1px solid var(--rule); border-radius: var(--r-sm);
  color: var(--ink-2); cursor: pointer;
}
.notes__notionrow dobase-connect-button[data-state="busy"] > button { opacity: 0.5 }

/* One row per block — the Notion shape.
 *
 * `align-items: flex-start` and an explicit line-height on BOTH the row and the
 * field matter more than they look: a contenteditable that inherits a different
 * line-height from its row is what makes glyphs appear to sit on top of one
 * another as you type. Keep them in step. */
.nb {
  display: flex; gap: var(--s2); align-items: flex-start;
  margin: 1px 0; line-height: 1.55; position: relative;
}
.nb__text {
  flex: 1; min-width: 0; outline: none;
  padding: 3px 4px; border-radius: var(--r-sm);
  line-height: 1.55;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal;
  caret-color: var(--live);
}
.nb__text:focus { background: var(--paper-sunk) }

/* Placeholder is an absolutely-positioned sibling toggled from JS, NOT a
 * `:empty::before`. Browsers drop a stray <br> into an empty contenteditable,
 * so `:empty` stops matching and the pseudo-element behaves unpredictably. */
.nb__ph {
  position: absolute; left: 4px; top: 3px; right: 4px;
  color: var(--ink-3); pointer-events: none; line-height: 1.55;
}
.nb__check { margin-top: 6px; flex: none; accent-color: var(--bound-cmp) }

/* Per-block delete — present but silent until the row is hovered or focused. */
.nb__del {
  flex: none; order: 3;
  width: 20px; height: 20px; margin-top: 3px; padding: 0;
  border: none; border-radius: var(--r-sm); background: transparent;
  color: var(--ink-3); font-size: 14px; line-height: 1; cursor: pointer;
  opacity: 0; transition: opacity var(--fast) var(--ease);
}
.nb:hover .nb__del, .nb:focus-within .nb__del { opacity: 1 }
.nb__del:hover { background: var(--bound-mem-bg); color: var(--bound-mem) }

/* The floating "add to notes" chip that follows a text selection. */
.capturechip {
  position: absolute; z-index: 70;
  font-family: var(--font-ui); font-size: var(--t-micro); font-weight: 500;
  padding: 6px 10px; border-radius: 999px;
  border: 1px solid var(--rule-strong);
  background: var(--ink); color: var(--paper);
  cursor: pointer; box-shadow: 0 4px 16px rgb(0 0 0 / .18);
}
.capturechip:hover { background: var(--live); border-color: var(--live) }
.nb__anchor {
  order: 2; flex-basis: 100%;
  font-family: var(--font-mono); font-size: var(--t-micro);
  color: var(--live); text-decoration: none; padding-left: 4px;
}
.nb__anchor:hover { text-decoration: underline }

.nb--heading_2 { margin-top: var(--s4) }
.nb--heading_2 .nb__text { font-size: 16px; font-weight: 600; line-height: 1.35 }
.nb--heading_2 .nb__ph { line-height: 1.35 }
.nb--heading_3 { margin-top: var(--s3) }
.nb--heading_3 .nb__text { font-size: 14.5px; font-weight: 600; line-height: 1.4 }
.nb--heading_3 .nb__ph { line-height: 1.4 }

.nb--bulleted_list_item::before,
.nb--numbered_list_item::before {
  color: var(--ink-3); flex: none; padding-top: 3px; line-height: 1.55;
}
.nb--bulleted_list_item::before { content: "•" }
.nb--numbered_list_item::before { content: "1."; font-size: 12px }

.nb--quote { border-left: 2px solid var(--rule-strong); padding-left: var(--s3) }
.nb--quote .nb__text { color: var(--ink-2); font-style: italic }
.nb--code .nb__text {
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5;
  background: var(--paper-sunk); border-radius: var(--r-sm); padding: var(--s2);
}
.nb--divider { display: block; margin: var(--s3) 0 }
.nb--divider hr { border: none; border-top: var(--hair); margin: 0 }

/* Slash menu. A child of <body>, not of the editor: it floats over the page
   so that opening, filtering and closing it can never touch the DOM of the
   contenteditable the reader is typing in. */
.slashmenu {
  position: absolute; z-index: 80;
  min-width: 200px; max-height: 258px; overflow-y: auto;
  padding: var(--s1); border-radius: var(--r-md);
  border: 1px solid var(--rule-strong); background: var(--paper-raise);
  box-shadow: 0 8px 24px rgb(0 0 0 / .14);
}
.slashmenu__item {
  display: flex; align-items: baseline; gap: var(--s2); width: 100%;
  padding: 5px var(--s2); border: none; border-radius: var(--r-sm);
  background: none; text-align: left; cursor: pointer;
  font-family: var(--font-ui); font-size: var(--t-small); color: var(--ink);
}
/* Hover and keyboard selection are the SAME state - the menu is keyboard
   first, and a mouse moving over it just moves the same highlight. */
.slashmenu__item.is-active { background: var(--live-bg); color: var(--live) }
.slashmenu__key {
  flex: none; min-width: 54px;
  font-family: var(--font-mono); font-size: var(--t-micro); color: var(--ink-3);
}
.slashmenu__item.is-active .slashmenu__key { color: var(--live) }
.slashmenu__label { flex: 1; min-width: 0 }
