/* Table of Contents / Bookmarks — tool styles. Tokens only (light + dark inherit
   from the theme). Motion is covered app-wide by the reduced-motion gate in main.css;
   keyframes (kpRise, rectPopIn, menuIn, editorOverlayIn/Out, editorBoxIn/Out) are
   reused from the global vocabulary, never invented.

   The review/edit surface is the full-screen editor shell (Editor v2, layout C) —
   it mirrors .redact-overlay / .redact-editor: a two-row toolbar, two equal panes
   (outline tree + page preview), and the output options in a toolbar popover. */

/* ── Scanned-PDF notice: offer one-click in-flow OCR (entrance rides .kp-enter). ── */
.outline-notice { text-align: center; padding: 28px 24px; }
.outline-notice h3 { margin: 0 0 8px; color: var(--text); }
.outline-notice p { margin: 0 auto 8px; max-width: 54ch; color: var(--text-soft); line-height: 1.5; }
.outline-notice p a { color: var(--primary); font-weight: 600; }
.outline-notice-hint { color: var(--text-mute); font-size: .82rem; font-variant-numeric: tabular-nums; }
.outline-notice-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }

/* ══ Full-screen editor shell (mirrors .redact-overlay / .redact-editor) ══ */
.outline-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(8, 10, 16, .88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  animation: editorOverlayIn .2s ease;
}
.outline-editor {
  /* Full-window edge-to-edge — no max-width cap, no card chrome. */
  background: var(--bg-elev);
  border: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  box-shadow: none;
  animation: editorBoxIn .32s cubic-bezier(.2, .7, .3, 1);
}
.outline-overlay.closing { animation: editorOverlayOut .2s ease forwards; pointer-events: none; }
.outline-overlay.closing .outline-editor { animation: editorBoxOut .2s ease forwards; }
@media (prefers-reduced-motion: reduce) {
  .outline-overlay, .outline-overlay.closing,
  .outline-editor, .outline-overlay.closing .outline-editor { animation: none; }
}

/* ── Two-row toolbar (mirrors .redact-toolbar*) ── */
.outline-tb {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.outline-tb-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px 14px; flex-wrap: wrap; }
.outline-tb-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.outline-tb-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.outline-tb-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.outline-tb-info strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 38vw; }
.outline-count { font-size: 12px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.outline-tb-main { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; }
.outline-tb-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.outline-tb-tools .btn { display: inline-flex; align-items: center; gap: 6px; }
/* Hairline divider (same 1px rule as the redact zoom-float sep) grouping the
   create/reset actions from the output-options popover. */
.outline-tb-sep { width: 1px; height: 20px; background: var(--border); flex: 0 0 auto; margin: 0 2px; }
.outline-reset:disabled { opacity: .45; cursor: default; }
.outline-tb-help { flex: 1; min-width: 200px; font-size: 12px; color: var(--text-soft); }
.outline-build { display: inline-flex; align-items: center; }

/* Mobile-only chrome — hidden on desktop, revealed in the ≤760 block at the foot
   of this file. (The primary keeps its full label; the options button reads
   "Output options"; the preview is a static pane.) */
.outline-build-m,
.outline-opts-m,
.outline-pv-toggle,
.outline-pop-actions { display: none; }

/* ── Body = two equal panes divided by a hairline (layout C) ── */
.outline-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 46%) minmax(0, 1fr);
  gap: 1px;
  background: var(--border);
}
.outline-pane { background: var(--bg-elev); min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.outline-pane-hd {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-mute);
}
.outline-hd-count { text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--text-soft); }

/* ── Outline tree (fills its pane; rounded rows, hover bg, no separators) ── */
.outline-tree {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 6px;
}
.outline-tree:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

.outline-row {
  display: flex;
  align-items: center;
  gap: 8px;
  /* Indent expresses nesting — no colored edge stripe (that "vibe-coded" look). */
  padding: 7px 10px 7px calc(10px + (var(--lvl, 1) - 1) * 18px);
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
  transition: background-color .15s, box-shadow .15s;
}
.outline-row + .outline-row { margin-top: 1px; }
.outline-row:hover { background: var(--bg-soft); }
.outline-row.is-focus {
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 2px var(--primary);
}
.outline-row:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.outline-row.is-new { animation: rectPopIn .36s cubic-bezier(.2, .7, .3, 1) both; }
.outline-row.is-leaving {
  opacity: 0;
  transform: translateX(-10px);
  pointer-events: none;
  transition: opacity .16s ease-in, transform .16s ease-in;
}

.outline-row-grip { display: inline-flex; gap: 3px; flex: 0 0 auto; }
.outline-mini {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-soft);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: border-color .15s, color .15s, background-color .15s;
}
.outline-mini:hover { border-color: var(--primary); color: var(--primary); }
.outline-mini:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

.outline-row-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .92rem;
  color: var(--text);
}
.outline-row[aria-level="1"] .outline-row-title { font-weight: 700; }
.outline-row[aria-level="3"] .outline-row-title,
.outline-row[aria-level="4"] .outline-row-title { color: var(--text-soft); }
.outline-row-page {
  flex: 0 0 auto;
  color: var(--text-mute);
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
}
.outline-row-del {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border: 0;
  background: transparent;
  color: var(--text-mute);
  cursor: pointer;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  transition: color .15s, background-color .15s;
}
.outline-row-del:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.outline-row-del:focus-visible { outline: 2px solid var(--danger); outline-offset: 1px; }

.outline-rename {
  flex: 1 1 auto;
  min-width: 0;
  font-size: .92rem;
  padding: 3px 6px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}
.outline-rename:focus { outline: none; box-shadow: 0 0 0 2px var(--primary-soft); }

/* Empty-detection state (inside the Outline pane). */
.outline-empty {
  margin: 6px;
  padding: 18px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--text-soft);
  font-size: .9rem;
}
.outline-empty p { margin: 0; line-height: 1.5; }

/* ── Preview header: section label (left) + page pager & "Heading here" (right).
   On mobile this whole bar doubles as the collapsible drawer's handle. ── */
.outline-pv-hd { justify-content: space-between; gap: 6px 10px; flex-wrap: wrap; padding-top: 6px; padding-bottom: 6px; }
.outline-pv-hd-main { display: inline-flex; align-items: center; gap: 4px; min-width: 0; }
.outline-pv-title { flex: 0 0 auto; }
.outline-pv-toggle {
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-mute);
  border-radius: 6px;
  cursor: pointer;
  transition: color .15s, background-color .15s;
}
.outline-pv-toggle:hover { color: var(--text); background: var(--bg-soft); }
.outline-pv-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
/* Chevron points up when collapsed ("pull up to reveal"); flips down when open. */
.outline-pv-toggle-chev { transition: transform .2s cubic-bezier(.2, .7, .3, 1); }
.outline-editor.is-pv-open .outline-pv-toggle-chev { transform: rotate(180deg); }
.outline-pv-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  /* The pager reads as data, not as the uppercase section label. */
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}
.outline-pv-btn {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 999px;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, transform .08s ease;
}
.outline-pv-btn:hover { background: var(--bg-soft); border-color: var(--border-strong); }
.outline-pv-btn:active { transform: scale(.92); }
.outline-pv-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.outline-pv-btn:disabled { opacity: .35; pointer-events: none; }
.outline-pv-page { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.outline-pv-jump {
  width: 3.4em;
  text-align: center;
  padding: 3px 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}
.outline-pv-jump::-webkit-outer-spin-button,
.outline-pv-jump::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.outline-pv-jump:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.outline-pv-total { color: var(--text-mute); }
.outline-pv-sep { width: 1px; height: 18px; background: var(--border); flex: 0 0 auto; margin: 0 3px; }
.outline-pv-add { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }

/* ── Page preview (fills its pane) ── */
.outline-preview {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background: var(--bg-soft);
  padding: 18px;
}
.outline-preview-stage { position: relative; box-shadow: var(--shadow-lg); border-radius: 2px; animation: kpRise .2s ease-out both; }
.outline-preview-stage canvas { display: block; max-width: 100%; height: auto; border-radius: 2px; }
.outline-preview-band {
  position: absolute;
  background: color-mix(in srgb, var(--primary) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--primary) 55%, transparent);
  border-radius: 2px;
  pointer-events: none;
  animation: kpRise .22s ease-out both;
}
/* The selected heading's band stands out from the others sharing the page. */
.outline-preview-band.is-focus {
  background: color-mix(in srgb, var(--primary) 26%, transparent);
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.outline-preview-empty { color: var(--text-mute); font-size: .85rem; text-align: center; padding: 22px 16px; }

/* ── Output-options popover (menuIn; toolbar-anchored) ── */
.outline-pop-wrap { position: relative; }
.outline-pop-chev { margin-left: 1px; }
.outline-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 300px;
  z-index: 5;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  animation: menuIn .16s cubic-bezier(.2, .7, .3, 1);
}
.outline-pop[hidden] { display: none; }
@media (prefers-reduced-motion: reduce) { .outline-pop { animation: none; } }

.outline-check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: .88rem;
  color: var(--text-soft);
  cursor: pointer;
  line-height: 1.4;
}
.outline-check input { flex: 0 0 auto; margin-top: 2px; accent-color: var(--primary); }
.outline-title-field { margin: 0; }
.outline-pop-note { font-size: .78rem; color: var(--text-mute); line-height: 1.45; border-top: 1px solid var(--border); padding-top: 11px; }

/* ══ Mobile: hand the vertical space to the outline list ══
   The list is what you came to read on a phone, so: drop the keyboard-only help,
   fold the secondary actions into the "More" popover, shrink Cancel to an ✕, and
   turn the page preview into a collapsible bottom drawer (collapsed by default). */
@media (max-width: 760px) {
  .outline-overlay { padding: 0; }
  .outline-editor { border-radius: 0; height: 100vh; height: 100dvh; }

  /* — Toolbar: swap long labels for short ones, hide the desktop-only controls — */
  .outline-tb { gap: 6px; padding: 9px 12px; }
  .outline-tb-help { display: none; }                 /* Tab/Up-Down hints — no keyboard here */
  .outline-build-d, .outline-opts-d { display: none; }
  .outline-build-m, .outline-opts-m { display: inline; }
  .outline-tb-tools .outline-tb-sep,
  .outline-tb-tools [data-act="add"],
  .outline-tb-tools .outline-reset { display: none; }  /* these now live in "More" */
  .outline-tb-info strong { max-width: 52vw; }
  .outline-pop { width: min(320px, calc(100vw - 24px)); }

  /* "More" popover leads with the two actions it absorbed, ruled off from the options. */
  .outline-pop-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
  }
  .outline-pop-actions .btn { justify-content: flex-start; width: 100%; }

  /* — Preview = a bottom drawer. Collapsed: only its header (the handle) shows; the
       list takes the rest. Open: it rises to ~48dvh. The track animates on the house
       curve (gated below for reduced motion). — */
  .outline-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) 3rem;
    transition: grid-template-rows .28s cubic-bezier(.2, .7, .3, 1);
  }
  .outline-editor.is-pv-open .outline-body { grid-template-rows: minmax(0, 1fr) 48dvh; }

  .outline-pv-toggle { display: inline-flex; }
  .outline-pv-hd { cursor: pointer; flex-wrap: nowrap; }
  /* Collapsed: hide the pager (it would wrap the handle) and the canvas. */
  .outline-pv-nav { transition: opacity .15s ease; }
  .outline-editor:not(.is-pv-open) .outline-pv-nav { display: none; }
  .outline-preview { max-height: none; opacity: 1; transition: opacity .2s ease; }
  .outline-editor:not(.is-pv-open) .outline-preview { opacity: 0; }
}

/* On a phone the pager keeps its arrows + jump; the add button collapses to its icon. */
@media (max-width: 460px) {
  .outline-pv-add-lbl { display: none; }
  .outline-pv-add { padding-left: 8px; padding-right: 8px; }
}

/* Reduced motion: the drawer + chevron snap rather than glide (durations are also
   pinned by the global gate in main.css; this kills the transform/track end-states). */
@media (max-width: 760px) and (prefers-reduced-motion: reduce) {
  .outline-body, .outline-pv-nav, .outline-preview, .outline-pv-toggle-chev { transition: none; }
}
