/* ════════════════════════════════════════════════════════════════════════
   Lex Document Editor — Shell v2 (Phase 1)
   ────────────────────────────────────────────────────────────────────────
   Three primitives:
     1. .lex-doc-topbar    — one-row strip at top: breadcrumb / title /
                             saved-status / mode toggle / count / matter /
                             Ask Lex ⌘K / icon group / Sign / Save.
     2. .lex-doc-leftrail  — vertical icon column on the left holding the
                             workflow actions that used to live in Row 2.
     3. .lex-doc-bottom-bar — bottom strip with zoom / word count / find,
                              plus the existing Ask Lex pill.

   Mode toggle:
     body.lex-mode-workbench  (default) → left + right rails visible.
     body.lex-mode-focus                → both rails hidden; floating
                                          quick-action pill appears.

   Rulers:
     Default off. body.lex-rulers-on shows them. Toggle from the View
     popover anchored on the left rail.

   When the editor view is open, body.lex-editor-open hides the appnav
   and modulebar so the doc topbar IS the chrome.
   ──────────────────────────────────────────────────────────────────────── */


/* ── App chrome suppression when editor is open ────────────────────────── */
/* .appnav is a class with two instances (home + work contexts). Both hide
   when the editor view is up so the doc topbar IS the chrome.           */
body.lex-editor-open .appnav,
body.lex-editor-open #modulebar { display: none !important; }

/* Full-bleed canvas for the editor.
   ─────────────────────────────────
   .module ships with `max-width: 80rem; margin: 0 auto; padding: 1.5rem`
   (css/layout.css:46). That cap is correct for the documents LIST and
   every other module, but it squeezes the editor into a 1280px column
   with dead gutters on wide displays. Consultant call (2026-06-15):
   the cap + centering must live ONLY on the white page wrapper
   (#tiptap-editor: 210mm centered), not on any shared ancestor.

   So we lift the cap + padding + margin from #module-documents while
   the editor view is open. The cream canvas (.editor-shell background)
   then fills the 1fr grid cell viewport-edge to viewport-edge, the page
   stays centered inside it via its own `margin: 0 auto`, and the right
   rail sits at the actual right edge in Workbench mode. */
body.lex-editor-open #module-documents {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: none;
  margin: 0;
  padding: 0;
}
/* documents.css:10 adds `padding: 0.5rem 0.75rem` to #module-documents
   while the editor view is shown — neutralize that as well. */
body.lex-editor-open #module-documents:has(#document-editor-view:not(.hidden)) {
  padding: 0;
}
body.lex-editor-open #document-editor-view { flex: 1; min-height: 0; }


/* ── New top bar ───────────────────────────────────────────────────────── */
.lex-doc-topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.85rem;
  background: var(--white, #fff);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
  font-family: var(--font-sans, system-ui, sans-serif);
}
.lex-doc-topbar-left   { display: flex; align-items: center; gap: 0.45rem; min-width: 0; flex: 1; }
.lex-doc-topbar-center { display: flex; align-items: center; gap: 0.45rem; flex-shrink: 0; }
.lex-doc-topbar-right  { display: flex; align-items: center; gap: 0.25rem; flex: 1; justify-content: flex-end; }

.ldt-back {
  background: none; border: none; padding: 0.25rem; cursor: pointer;
  color: var(--mid); border-radius: var(--r-sm); display: inline-flex;
}
.ldt-back:hover { background: var(--border-2); color: var(--ink); }

.ldt-breadcrumb {
  background: none; border: none; padding: 0.15rem 0.25rem; cursor: pointer;
  color: var(--muted); font-size: 0.78rem; font-family: inherit;
  border-radius: var(--r-sm);
}
.ldt-breadcrumb:hover { color: var(--ink); background: var(--border-2); }

.ldt-sep-slash { color: var(--muted); font-size: 0.78rem; user-select: none; }

.ldt-title {
  border: none; background: transparent; outline: none;
  font-family: var(--font-sans, system-ui, -apple-system, 'DM Sans', sans-serif);
  font-size: 0.95rem; font-weight: 500; color: var(--ink);
  padding: 0.15rem 0.35rem;
  min-width: 6rem; max-width: 26rem;
  flex-shrink: 1;
  border-radius: var(--r-sm);
}
.ldt-title:hover  { background: var(--border-2); }
.ldt-title:focus  { background: var(--gold-bg, #fdf6e3); box-shadow: 0 0 0 1px var(--gold, #c9a84c) inset; }
.ldt-title::placeholder { color: var(--muted); font-style: italic; }

.ldt-saved-dot {
  width: 5px; height: 5px; border-radius: 50%; background: var(--gold, #c9a84c);
  flex-shrink: 0;
}
.ldt-saved {
  font-size: 0.7rem; color: var(--muted); white-space: nowrap;
}
.ldt-offline {
  font-size: 0.65rem; color: var(--gold);
  background: var(--gold-bg); border: 1px solid var(--gold-dim);
  border-radius: var(--r-sm); padding: 0.1rem 0.35rem;
}


/* ── Focus / Workbench mode toggle ─────────────────────────────────────── */
.ldt-mode-toggle {
  display: inline-flex;
  background: var(--surface, #f1efe9);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.ldt-mode {
  background: transparent; border: none; cursor: pointer;
  padding: 0.25rem 0.65rem; border-radius: 999px;
  font-family: inherit; font-size: 0.72rem; color: var(--muted);
  display: inline-flex; align-items: center; gap: 0.35rem;
  transition: background var(--t), color var(--t);
}
.ldt-mode svg { opacity: 0.7; }
.ldt-mode:hover { color: var(--ink); }
.ldt-mode.is-active {
  background: var(--white, #fff);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.ldt-mode.is-active svg { opacity: 1; }


/* ── Topbar pills (word count, matter, ask lex) ────────────────────────── */
.ldt-pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.3rem 0.7rem;
  background: var(--white, #fff);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: inherit; font-size: 0.72rem; color: var(--mid);
  cursor: pointer;
  transition: border-color var(--t), color var(--t), background var(--t);
}
.ldt-pill:hover { border-color: var(--mid); color: var(--ink); }
.ldt-pill svg { flex-shrink: 0; opacity: 0.7; }
.ldt-pill:hover svg { opacity: 1; }

.ldt-count #tb-word-count { font-variant-numeric: tabular-nums; font-weight: 500; color: var(--ink); }

.ldt-matter-type {
  font-size: 0.6rem; font-weight: 600; letter-spacing: 0.04em;
  background: var(--gold-bg, #fdf6e3); color: var(--gold, #c9a84c);
  padding: 0.1rem 0.35rem; border-radius: var(--r-sm);
  text-transform: uppercase;
}
.ldt-matter-name { color: var(--ink); font-weight: 500; max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ldt-caret { opacity: 0.55; }

.ldt-ask-lex {
  background: var(--ink, #0f0f0d);
  color: var(--white, #fff);
  border-color: var(--ink, #0f0f0d);
  font-weight: 500;
}
.ldt-ask-lex:hover {
  background: var(--gold, #c9a84c);
  color: var(--ink, #0f0f0d);
  border-color: var(--gold, #c9a84c);
}
.ldt-ask-lex svg path { stroke: currentColor; }
.ldt-ask-lex kbd {
  font-family: inherit; font-size: 0.65rem; opacity: 0.7;
  border: 1px solid currentColor; padding: 0 0.25rem;
  border-radius: 3px; background: transparent;
}


/* ── Topbar right icon group ──────────────────────────────────────────── */
.ldt-icon-wrap { position: relative; display: inline-flex; }
.ldt-icon {
  background: none; border: none; cursor: pointer;
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  color: var(--mid);
  display: inline-flex; align-items: center; justify-content: center;
  position: relative;
}
.ldt-icon:hover { background: var(--border-2); color: var(--ink); }
.ldt-icon[disabled] { opacity: 0.4; cursor: not-allowed; }

.ldt-icon-badge {
  position: absolute; top: 2px; right: 2px;
  background: var(--gold, #c9a84c); color: var(--white);
  font-size: 0.55rem; font-weight: 600;
  min-width: 12px; height: 12px; padding: 0 3px;
  border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
}

.ldt-sign {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.3rem 0.7rem;
  background: var(--white, #fff);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--ink); font-family: inherit; font-size: 0.72rem; font-weight: 500;
  cursor: pointer;
}
.ldt-sign:hover { border-color: var(--ink); background: var(--surface); }

.ldt-save {
  background: var(--ink, #0f0f0d);
  color: var(--white, #fff);
  border: 1px solid var(--ink);
  border-radius: var(--r-md);
  padding: 0.3rem 0.85rem;
  font-family: inherit; font-size: 0.72rem; font-weight: 500;
  cursor: pointer;
}
.ldt-save:hover { background: var(--gold, #c9a84c); color: var(--ink); border-color: var(--gold); }


/* ── Body grid: leftrail + editor-layout ──────────────────────────────── */
.lex-doc-body {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}
.lex-doc-body > .editor-layout { flex: 1; min-width: 0; }


/* ── Left workflow rail (vertical) ────────────────────────────────────── */
.lex-doc-leftrail {
  display: flex; flex-direction: column;
  align-items: center; gap: 2px;
  padding: 0.5rem 0.25rem;
  width: 40px; flex-shrink: 0;
  background: var(--surface, #f7f5ef);
  /* No border — rail blends into the cream canvas. The icons themselves
     provide the visual separation. */
}
.ldr-btn {
  background: none; border: none; cursor: pointer;
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  color: var(--mid);
  display: inline-flex; align-items: center; justify-content: center;
  position: relative;
  transition: background var(--t), color var(--t);
}
.ldr-btn:hover { background: var(--border-2); color: var(--ink); }
.ldr-btn.is-active { background: var(--gold-bg); color: var(--gold); }
.ldr-btn svg { flex-shrink: 0; }

/* Tooltip on hover (CSS-only, right-anchored). */
.ldr-btn::after {
  content: attr(data-tooltip);
  position: absolute; left: calc(100% + 8px); top: 50%; transform: translateY(-50%);
  background: var(--ink, #0f0f0d); color: var(--white, #fff);
  font-family: var(--font-sans); font-size: 0.7rem; font-weight: 500;
  padding: 0.25rem 0.5rem; border-radius: var(--r-sm);
  white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s ease 0.4s;
  z-index: 100;
}
.ldr-btn:hover::after { opacity: 1; }
.ldr-spacer { flex: 1; }
.ldr-sep { height: 1px; width: 60%; background: var(--border); margin: 0.25rem 0; }


/* ── Bottom bar (zoom / count / find + center pill) ───────────────────── */
/* Transparent — the cream canvas behind it shows through. Only the small
   left pill and the center Ask-Lex pill should be visible, matching the
   redesign mockup. No border-top either: the canvas is continuous. */
.lex-doc-bottom-bar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.85rem;
  background: transparent;
  flex-shrink: 0;
  z-index: 18;
  pointer-events: none;
}
.lex-doc-bottom-bar > * { pointer-events: auto; }

.lex-doc-bottom-left {
  display: inline-flex; align-items: center; gap: 0.5rem;
  background: var(--surface);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.ldb-zoom-step {
  background: none; border: none; cursor: pointer;
  width: 18px; height: 18px;
  color: var(--mid); font-size: 0.85rem; line-height: 1;
  border-radius: var(--r-sm);
  display: inline-flex; align-items: center; justify-content: center;
}
.ldb-zoom-step:hover { background: var(--white); color: var(--ink); }
.ldb-zoom-label {
  font-size: 0.68rem; color: var(--ink); font-variant-numeric: tabular-nums;
  min-width: 2.5rem; text-align: center; cursor: pointer;
}
.ldb-zoom-label:hover { color: var(--gold, #c9a84c); }
.ldb-sep { width: 1px; height: 12px; background: var(--border); }
.ldb-wc { font-size: 0.68rem; color: var(--muted); white-space: nowrap; }
.ldb-find {
  background: none; border: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.25rem;
  color: var(--mid); font-family: inherit; font-size: 0.68rem;
  padding: 0.1rem 0.3rem; border-radius: var(--r-sm);
}
.ldb-find:hover { color: var(--ink); background: var(--white); }


/* ── Popovers (matter picker, view, properties, stats) ────────────────── */
.lex-doc-popover {
  position: absolute;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 80;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  min-width: 14rem;
  padding: 0.4rem;
}
.lex-doc-popover.hidden { display: none; }

/* Matter picker */
.ldm-search {
  width: 100%; border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 0.35rem 0.5rem; font-family: inherit; font-size: 0.72rem;
  margin-bottom: 0.35rem;
}
.ldm-list { max-height: 18rem; overflow-y: auto; }
.ldm-item {
  display: block; width: 100%;
  background: none; border: none; cursor: pointer;
  padding: 0.4rem 0.5rem; border-radius: var(--r-sm);
  text-align: left; font-family: inherit; font-size: 0.75rem;
  color: var(--ink);
}
.ldm-item:hover { background: var(--gold-bg); }
.ldm-item.is-active { background: var(--gold-bg); font-weight: 500; }
.ldm-item small { color: var(--muted); font-size: 0.66rem; display: block; margin-top: 1px; }
.ldm-divider { height: 1px; background: var(--border); margin: 0.35rem 0; }
.ldm-unlink {
  display: block; width: 100%;
  background: none; border: none; cursor: pointer;
  color: #b34141; padding: 0.4rem 0.5rem; border-radius: var(--r-sm);
  text-align: left; font-family: inherit; font-size: 0.72rem;
}
.ldm-unlink:hover { background: #fff0f0; }
.ldm-empty {
  padding: 0.6rem 0.5rem; color: var(--muted); font-size: 0.72rem; text-align: center;
}

/* View popover */
.ldv-row { padding: 0.35rem 0.4rem; }
.ldv-check {
  display: flex; align-items: center; gap: 0.4rem; cursor: pointer;
  color: var(--ink); font-size: 0.75rem;
}

/* Properties popover */
.ldp-row {
  display: grid; grid-template-columns: 5rem 1fr;
  align-items: center; gap: 0.5rem;
  padding: 0.3rem 0.4rem;
}
.ldp-row label { color: var(--muted); font-size: 0.7rem; }
.ldp-row select,
.ldp-row .ldp-toggle-wrap {
  font-size: 0.72rem; padding: 0.3rem 0.5rem;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--white);
}

/* Stats popover */
.lds-grid {
  display: grid; grid-template-columns: 1fr auto; gap: 0.35rem 0.85rem;
  padding: 0.25rem 0.4rem; font-size: 0.72rem;
}
.lds-grid dt { color: var(--muted); }
.lds-grid dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; }


/* ── Focus-mode floating quick-action pill ────────────────────────────── */
body:not(.lex-mode-focus) .lex-doc-focus-quick { display: none; }
.lex-doc-focus-quick {
  position: fixed;
  bottom: 4.5rem; right: 1.5rem;
  z-index: 60;
}
.ldfq-trigger {
  width: 40px; height: 40px;
  border-radius: 999px;
  background: var(--ink); color: var(--white);
  border: none; cursor: pointer;
  font-size: 1.1rem; font-weight: 600;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  display: inline-flex; align-items: center; justify-content: center;
}
.ldfq-trigger:hover { background: var(--gold, #c9a84c); color: var(--ink); }
.ldfq-menu {
  position: absolute; bottom: calc(100% + 0.5rem); right: 0;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.14);
  padding: 0.35rem;
  min-width: 13rem;
}
.ldfq-menu.hidden { display: none; }
.ldfq-item {
  display: flex; align-items: center; gap: 0.55rem;
  width: 100%;
  background: none; border: none; cursor: pointer;
  padding: 0.4rem 0.5rem;
  border-radius: var(--r-sm);
  font-family: inherit; font-size: 0.75rem;
  color: var(--ink); text-align: left;
}
.ldfq-item:hover { background: var(--gold-bg); }
.ldfq-item svg { color: var(--mid); flex-shrink: 0; }


/* ── Mode-driven visibility ───────────────────────────────────────────── */
/* Focus mode hides BOTH rails and the rail-toggle in the topbar.
   Workbench mode shows the left rail; the right rail is independent —
   controlled by body.lex-rail-open via the 📑 topbar button. */
body.lex-mode-focus .lex-doc-leftrail,
body.lex-mode-focus .editor-panel,
body.lex-mode-focus #ldt-rail-toggle {
  display: none;
}
/* When the right rail is closed (default), collapse the editor-layout
   grid to a single column so the page uses the full width. The grid
   only goes 2-column when body.lex-rail-open is set. */
.editor-layout { grid-template-columns: 1fr; }
body.lex-rail-open:not(.lex-mode-focus) .editor-layout {
  grid-template-columns: 1fr 20rem;
}
body:not(.lex-rail-open) .editor-panel,
body.lex-mode-focus    .editor-panel { display: none; }
/* Topbar toggle reflects open/closed state. */
body.lex-rail-open #ldt-rail-toggle {
  background: var(--gold-bg, #FDF6E3);
  color: var(--gold, #C9A84C);
}


/* ── Rulers: default OFF; body.lex-rulers-on shows them ──────────────── */
.editor-rulers-h-bar,
.ruler-v { display: none; }
body.lex-rulers-on .editor-rulers-h-bar { display: flex; }
body.lex-rulers-on .ruler-v { display: block; }
/* Also drop the left padding compensation that was added in documents.css
   when rulers are off — so the page sits flush against the leftrail edge. */
body:not(.lex-rulers-on) .editor-shell:has(.editor-rulers-h-bar) .editor-content {
  padding-left: 0.75rem;
}


/* ── Mobile: collapse rails, keep topbar simple ───────────────────────── */
@media (max-width: 700px) {
  .lex-doc-leftrail { width: 36px; }
  .ldr-btn { width: 28px; height: 28px; }
  .ldt-mode-toggle, .ldt-pill.ldt-count { display: none; }
  .lex-doc-topbar { gap: 0.3rem; padding: 0.35rem 0.5rem; }
  .ldt-title { max-width: 11rem; }
  .lex-doc-bottom-bar { padding: 0.25rem 0.4rem; }
}


/* ════════════════════════════════════════════════════════════════════════
   Phase 2: Ask Lex bottom pill + modal
   ──────────────────────────────────────────────────────────────────────── */

/* ── Bottom Ask Lex pill ──────────────────────────────────────────────── */
/* Restyled from doc-lex-pill — now wider, friendlier copy, ⌘K hint. */
#doc-lex-pill.doc-lex-pill {
  position: fixed;
  bottom: 3.2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 55;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 1.1rem;
  background: var(--white, #fff);
  border: 1px solid var(--border, #E8E2D0);
  border-radius: 999px;
  box-shadow: 0 8px 22px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.04);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
#doc-lex-pill.doc-lex-pill:hover {
  transform: translateX(-50%) translateY(-1px);
  box-shadow: 0 12px 28px rgba(0,0,0,0.14), 0 3px 8px rgba(0,0,0,0.06);
  border-color: var(--gold, #C9A84C);
}
.doc-lex-pill-icon {
  color: var(--gold, #C9A84C);
  display: inline-flex;
}
.doc-lex-pill-label {
  font-size: 0.78rem;
  color: var(--mid, #5A5648);
  font-style: italic;
}
.doc-lex-pill-kbd {
  font-family: inherit;
  font-size: 0.62rem;
  color: var(--muted, #8E8B7C);
  background: var(--surface, #F4F2EB);
  border: 1px solid var(--border, #E8E2D0);
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
  margin-left: 0.2rem;
}
/* Hide the pill while the modal is open so they don't stack. */
body.lex-ask-open #doc-lex-pill { display: none !important; }


/* ── Modal ────────────────────────────────────────────────────────────── */
.lex-ask-modal {
  position: fixed;
  bottom: 2.8rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  width: min(560px, calc(100vw - 2rem));
  font-family: var(--font-sans);
  animation: lex-ask-rise 0.22s cubic-bezier(.16,1,.3,1);
}
.lex-ask-modal.hidden { display: none; }
@keyframes lex-ask-rise {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.lex-ask-modal-card {
  background: var(--white, #fff);
  border: 1px solid var(--border, #E8E2D0);
  border-radius: var(--r-lg, 14px);
  box-shadow: 0 20px 50px rgba(0,0,0,0.18), 0 6px 14px rgba(0,0,0,0.06);
  padding: 1rem 1.1rem 0.9rem;
}

/* Header */
.lex-ask-modal-header {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}
.lex-ask-modal-icon {
  color: var(--gold, #C9A84C);
  display: inline-flex;
}
.lex-ask-modal-title {
  flex: 1;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink, #0F0F0D);
  font-family: var(--font-serif, Georgia, serif);
}
.lex-ask-modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted, #8E8B7C);
  width: 22px; height: 22px;
  border-radius: var(--r-sm, 4px);
  display: inline-flex; align-items: center; justify-content: center;
}
.lex-ask-modal-close:hover { background: var(--border-2, #ECE9DD); color: var(--ink); }

/* Chips */
.lex-ask-modal-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.85rem;
}
.lex-ask-chip {
  background: var(--surface, #F4F2EB);
  border: 1px solid var(--border, #E8E2D0);
  border-radius: 999px;
  padding: 0.35rem 0.7rem 0.35rem 0.6rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: inherit;
  font-size: 0.72rem;
  color: var(--ink, #0F0F0D);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.lex-ask-chip:hover {
  background: var(--white, #fff);
  border-color: var(--gold, #C9A84C);
}
.lex-ask-chip:disabled { opacity: 0.5; cursor: wait; }
.lex-ask-chip svg { color: var(--gold, #C9A84C); flex-shrink: 0; }
/* Stale-while-revalidating: dimmed but still clickable. */
.lex-ask-modal-chips.is-stale .lex-ask-chip { opacity: 0.75; }

/* Skeleton placeholder for chips while first generation runs. */
.lex-ask-chip-skeleton {
  background: var(--surface, #F4F2EB);
  border: 1px solid var(--border, #E8E2D0);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  height: 1.6rem;
  width: var(--w, 9rem);
  position: relative;
  overflow: hidden;
}
.lex-ask-chip-skeleton::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.45) 50%, transparent 100%);
  animation: lex-ask-shimmer 1.4s linear infinite;
}
@keyframes lex-ask-shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

/* Input + send */
.lex-ask-modal-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  background: var(--surface, #F4F2EB);
  border: 1px solid var(--border, #E8E2D0);
  border-radius: var(--r-md, 8px);
  padding: 0.5rem 0.55rem;
}
.lex-ask-modal-input-wrap:focus-within {
  border-color: var(--gold, #C9A84C);
  background: var(--white, #fff);
}
.lex-ask-modal-input-wrap .voice-mic-btn {
  background: none;
  border: none;
  color: var(--muted, #8E8B7C);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--r-sm);
  flex-shrink: 0;
  display: inline-flex;
  align-self: center;
}
.lex-ask-modal-input-wrap .voice-mic-btn:hover { color: var(--ink); }

.lex-ask-modal-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-serif, Georgia, serif);
  font-size: 0.82rem;
  font-style: italic;
  line-height: 1.45;
  color: var(--ink, #0F0F0D);
  padding: 0.25rem 0;
  max-height: 8rem;
  min-height: 1.4rem;
}
.lex-ask-modal-input::placeholder {
  color: var(--muted, #8E8B7C);
  font-style: italic;
}
.lex-ask-modal-input:not(:placeholder-shown) { font-style: normal; }

.lex-ask-modal-send {
  background: var(--gold, #C9A84C);
  color: var(--white, #fff);
  border: none;
  cursor: pointer;
  width: 34px; height: 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.15s ease;
}
.lex-ask-modal-send:hover { background: var(--ink, #0F0F0D); transform: scale(1.05); }
.lex-ask-modal-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* Footer */
.lex-ask-modal-footer {
  margin-top: 0.6rem;
  font-size: 0.65rem;
  color: var(--muted, #8E8B7C);
  text-align: center;
  letter-spacing: 0.01em;
}

/* Mobile shrink */
@media (max-width: 700px) {
  .lex-ask-modal { width: calc(100vw - 1rem); bottom: 1rem; }
  #doc-lex-pill.doc-lex-pill { bottom: 1rem; }
}


/* ════════════════════════════════════════════════════════════════════════
   Phase 3: Tabbed right rail (Sources / Research / History / Lex)
   ──────────────────────────────────────────────────────────────────────── */

/* Editor panel becomes a vertical flex when open: tabs on top, then the
   active pane fills remaining height with scroll.
   documents.css set overflow-y:auto + gap:1rem on the same selector — we
   override here so the OUTER container doesn't scroll (pane does) and the
   tab strip butts cleanly against the active pane. */
.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0.5rem 0.65rem;
  overflow: hidden;
  min-height: 0;
}
.lex-rail-tabs {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding-bottom: 0.4rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.lex-rail-tab {
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted, #8E8B7C);
  padding: 0.35rem 0.6rem;
  border-radius: 4px;
  transition: color var(--t), background var(--t);
}
.lex-rail-tab:hover { color: var(--ink); background: var(--border-2, #ECE9DD); }
.lex-rail-tab.is-active {
  color: var(--ink);
  background: var(--gold-bg, #FDF6E3);
}
.lex-rail-close {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted, #8E8B7C);
  width: 24px; height: 24px;
  border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
}
.lex-rail-close:hover { background: var(--border-2, #ECE9DD); color: var(--ink); }

/* Panes — only the active one is visible. */
.lex-rail-pane {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 0.85rem;
  overflow-y: auto;
}
.lex-rail-pane.is-active { display: flex; }

/* Empty-state hint for tabs without content yet. */
.lex-rail-empty {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--muted, #8E8B7C);
  font-size: 0.78rem;
}
.lex-rail-empty svg { margin: 0 auto 0.5rem; display: block; }

/* Lex tab — selection action buttons. */
.lex-rail-tab-status {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
  padding: 0.4rem 0.5rem;
  background: var(--surface, #F4F2EB);
  border: 1px solid var(--border);
  border-radius: 6px;
}
body.lex-has-selection .lex-rail-tab-status { display: none; }

.lex-rail-actions { display: flex; flex-direction: column; gap: 0.3rem; }
.lex-rail-action {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  background: var(--white, #fff);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  cursor: pointer;
  font-family: var(--font-sans);
  text-align: left;
}
.lex-rail-action:hover:not(:disabled) {
  background: var(--gold-bg, #FDF6E3);
  border-color: var(--gold, #C9A84C);
}
.lex-rail-action:disabled { opacity: 0.45; cursor: not-allowed; }
.lex-rail-action .lra-icon {
  width: 28px; height: 28px;
  background: var(--gold-bg, #FDF6E3);
  color: var(--gold-deep, #5A4A0E);
  border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.lex-rail-action span:not(.lra-icon) {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}
.lex-rail-action strong { font-size: 0.75rem; color: var(--ink); font-weight: 500; }
.lex-rail-action small  { font-size: 0.66rem; color: var(--muted); }

.lex-rail-prompt {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  resize: vertical;
  background: var(--white);
  color: var(--ink);
}
.lex-rail-prompt:focus {
  outline: none;
  border-color: var(--gold, #C9A84C);
}


/* ════════════════════════════════════════════════════════════════════════
   Grounded drafting Phase A — document type picker
   ──────────────────────────────────────────────────────────────────────── */

/* Properties popover Type-button — replaces the old <select>. */
.lex-type-button {
  display: inline-flex; align-items: center; gap: 0.3rem;
  flex: 1;
  background: var(--white, #fff);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0.3rem 0.5rem;
  font-family: inherit; font-size: 0.72rem; color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.lex-type-button:hover { border-color: var(--gold, #C9A84C); }
.lex-type-button .ldtb-label {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lex-type-button svg { opacity: 0.55; flex-shrink: 0; }

/* Modal overlay */
.lex-type-picker-overlay {
  position: fixed; inset: 0;
  background: rgba(15,15,13,0.36);
  z-index: 200;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 1rem 1rem;
  animation: lex-type-picker-fade 0.18s ease;
}
.lex-type-picker-overlay.hidden { display: none; }
@keyframes lex-type-picker-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.lex-type-picker {
  width: min(640px, 100%);
  max-height: 78vh;
  display: flex; flex-direction: column;
  background: var(--white, #fff);
  border: 1px solid var(--border);
  border-radius: var(--r-lg, 14px);
  box-shadow: 0 24px 60px rgba(0,0,0,0.22), 0 6px 14px rgba(0,0,0,0.08);
  font-family: var(--font-sans);
  overflow: hidden;
  animation: lex-type-picker-rise 0.22s cubic-bezier(.16,1,.3,1);
}
@keyframes lex-type-picker-rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.lex-type-picker-header {
  display: flex; align-items: flex-start; gap: 0.55rem;
  padding: 0.9rem 1rem 0.7rem;
  border-bottom: 1px solid var(--border);
}
.lex-type-picker-titlewrap { flex: 1; }
.lex-type-picker-title {
  font-family: var(--font-serif, Georgia, serif);
  font-size: 1rem; font-weight: 500; color: var(--ink);
  letter-spacing: 0.005em;
}
.lex-type-picker-sub {
  font-size: 0.72rem; color: var(--muted, #8E8B7C);
  margin-top: 0.15rem;
}
.lex-type-picker-close {
  background: none; border: none; cursor: pointer;
  color: var(--muted, #8E8B7C);
  width: 26px; height: 26px;
  border-radius: var(--r-sm);
  display: inline-flex; align-items: center; justify-content: center;
}
.lex-type-picker-close:hover { background: var(--border-2, #ECE9DD); color: var(--ink); }

/* Search row */
.lex-type-picker-search {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface, #F4F2EB);
}
.lex-type-picker-search svg { color: var(--muted, #8E8B7C); flex-shrink: 0; }
.lex-type-picker-search input {
  flex: 1;
  background: transparent; border: none; outline: none;
  font-family: inherit; font-size: 0.85rem; color: var(--ink);
  padding: 0.25rem 0;
}
.lex-type-picker-search input::placeholder { color: var(--muted); font-style: italic; }
.lex-type-picker-search kbd {
  font-family: inherit; font-size: 0.62rem; color: var(--muted);
  background: var(--white); border: 1px solid var(--border);
  border-radius: 3px; padding: 0.05rem 0.3rem;
}

/* Result list */
.lex-type-picker-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.35rem 0.5rem 0.6rem;
}
.lex-type-picker-loading,
.lex-type-picker-empty {
  text-align: center;
  color: var(--muted, #8E8B7C);
  font-size: 0.78rem;
  padding: 1.5rem 1rem;
}

.lex-type-group-header {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted, #8E8B7C);
  padding: 0.7rem 0.6rem 0.3rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.3rem;
}
.lex-type-group-header:first-child { padding-top: 0.35rem; }

.lex-type-row {
  display: flex; align-items: flex-start; gap: 0.55rem;
  background: none; border: none; cursor: pointer;
  width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  text-align: left;
  font-family: inherit;
}
.lex-type-row:hover,
.lex-type-row.is-focused { background: var(--gold-bg, #FDF6E3); }
.lex-type-row.is-active { background: var(--gold-bg, #FDF6E3); border: 1px solid var(--gold, #C9A84C); }

.lex-type-row-main { flex: 1; min-width: 0; }
.lex-type-row-label {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--ink, #0F0F0D);
  display: flex; align-items: center; gap: 0.45rem;
}
.lex-type-row-pill {
  display: inline-flex;
  font-size: 0.58rem; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--gold, #C9A84C);
  background: var(--gold-bg, #FDF6E3);
  border-radius: 3px;
  padding: 0.08rem 0.35rem;
}
.lex-type-row-desc {
  font-size: 0.7rem;
  color: var(--muted, #8E8B7C);
  margin-top: 0.15rem;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.lex-type-row-cat {
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 0.2rem;
}
.lex-type-row-mark {
  font-size: 0.62rem;
  background: var(--gold-bg);
  color: var(--gold-deep, #5A4A0E);
  border-radius: 2px;
  padding: 0 0.15rem;
}

/* "Other / not listed" footer row — always at the bottom of the list. */
.lex-type-other-wrap {
  border-top: 1px solid var(--border);
  margin-top: 0.4rem; padding-top: 0.35rem;
}
.lex-type-other-input {
  display: none;
  margin: 0.45rem 0.6rem 0.3rem;
}
.lex-type-other-input.is-visible { display: flex; gap: 0.35rem; }
.lex-type-other-input input {
  flex: 1;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-family: inherit; font-size: 0.78rem;
  background: var(--white);
}
.lex-type-other-input input:focus {
  outline: none;
  border-color: var(--gold, #C9A84C);
}
.lex-type-other-input button {
  background: var(--ink); color: var(--white);
  border: none; border-radius: 6px;
  padding: 0 0.85rem;
  font-family: inherit; font-size: 0.74rem; font-weight: 500;
  cursor: pointer;
}
.lex-type-other-input button:hover { background: var(--gold, #C9A84C); color: var(--ink); }

@media (max-width: 700px) {
  .lex-type-picker-overlay { padding: 1rem 0.5rem; align-items: flex-end; }
  .lex-type-picker { max-height: 92vh; }
}


/* ════════════════════════════════════════════════════════════════════════
   Grounded drafting Phase B — type confirmation strip inside Ask Lex modal
   ──────────────────────────────────────────────────────────────────────── */

.lex-ground-strip {
  margin: 0 0 0.85rem;
  padding: 0.7rem 0.85rem;
  background: var(--gold-bg, #FDF6E3);
  border: 1px solid var(--gold, #C9A84C);
  border-radius: 10px;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.lex-ground-strip.hidden { display: none; }

.lex-ground-strip.is-thinking {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  color: var(--gold-deep, #5A4A0E);
}
.lex-ground-strip .lgs-icon {
  display: inline-flex;
  color: var(--gold-deep, #5A4A0E);
}
.lex-ground-strip.is-thinking .lgs-icon svg {
  animation: lgs-spin 1.1s linear infinite;
}
@keyframes lgs-spin {
  from { transform: rotate(0); }
  to   { transform: rotate(360deg); }
}

.lex-ground-strip .lgs-row { display: flex; align-items: center; gap: 0.4rem; }
.lex-ground-strip .lgs-msg {
  flex: 1;
  font-size: 0.82rem;
  line-height: 1.4;
}
.lex-ground-strip .lgs-msg strong {
  font-weight: 600;
}

.lex-ground-strip .lgs-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.lex-ground-strip .lgs-btn {
  cursor: pointer;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
}
.lex-ground-strip .lgs-btn-primary {
  background: var(--ink, #0F0F0D);
  color: var(--white, #fff);
  border: 1px solid var(--ink);
}
.lex-ground-strip .lgs-btn-primary:hover {
  background: var(--gold, #C9A84C);
  color: var(--ink);
  border-color: var(--gold);
}
.lex-ground-strip .lgs-btn-secondary {
  background: var(--white, #fff);
  color: var(--ink);
  border: 1px solid var(--border);
}
.lex-ground-strip .lgs-btn-secondary:hover {
  border-color: var(--ink);
}
.lex-ground-strip .lgs-btn-ghost {
  background: transparent;
  color: var(--muted, #8E8B7C);
  border: 1px solid transparent;
}
.lex-ground-strip .lgs-btn-ghost:hover {
  color: var(--ink);
  background: var(--white);
}


/* ════════════════════════════════════════════════════════════════════════
   Grounded drafting Phase C — Brief tab pane (right rail interview)
   ──────────────────────────────────────────────────────────────────────── */

.lex-brief-pane {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--ink);
}

/* Header card — type + brief details + progress */
.lex-brief-header {
  background: var(--white, #fff);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0.7rem 0.8rem;
}
.lex-brief-type-row {
  display: flex; align-items: center; gap: 0.4rem;
  margin-bottom: 0.5rem;
}
.lex-brief-type-pill {
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--gold-bg, #FDF6E3);
  color: var(--gold-deep, #5A4A0E);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
}
.lex-brief-type-label {
  font-family: var(--font-serif, Georgia, serif);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink);
}

.lex-brief-brief {
  margin-bottom: 0.45rem;
}
.lex-brief-brief > summary {
  cursor: pointer;
  font-size: 0.7rem;
  color: var(--muted);
  list-style: none;
  display: flex; align-items: center; gap: 0.3rem;
}
.lex-brief-brief > summary::before {
  content: '▸';
  display: inline-block;
  transition: transform 0.15s ease;
  font-size: 0.6rem;
}
.lex-brief-brief[open] > summary::before {
  transform: rotate(90deg);
}
.lex-brief-brief-text {
  margin-top: 0.4rem;
  padding: 0.5rem 0.6rem;
  background: var(--surface, #F4F2EB);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-serif, Georgia, serif);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.lex-brief-progress {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  font-size: 0.65rem;
  color: var(--muted);
}
.lex-brief-progress strong { color: var(--ink); font-weight: 600; }

/* Section headers within the pane */
.lex-brief-section {
  background: var(--white, #fff);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0.7rem 0.8rem;
}
.lex-brief-section-title {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

/* Turn log — answered Q&As stack vertically */
.lex-brief-turns {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.lex-brief-turn {
  border-left: 2px solid var(--gold-bg, #FDF6E3);
  padding: 0.15rem 0 0.15rem 0.65rem;
}
.lex-brief-turn-q {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.lex-brief-turn-a {
  font-family: var(--font-serif, Georgia, serif);
  font-size: 0.82rem;
  color: var(--ink);
  line-height: 1.4;
}

/* Current question form */
.lex-brief-current {
  border-color: var(--gold, #C9A84C);
  background: var(--gold-bg, #FDF6E3);
}
.lex-brief-question-meta {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold-deep, #5A4A0E);
  margin-bottom: 0.35rem;
}
.lex-brief-question-text {
  font-family: var(--font-serif, Georgia, serif);
  font-size: 0.95rem;
  line-height: 1.45;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 0.45rem;
}
.lex-brief-why {
  font-size: 0.7rem;
  color: var(--gold-deep, #5A4A0E);
  background: var(--white);
  border: 1px solid var(--gold, #C9A84C);
  border-radius: 5px;
  padding: 0.35rem 0.5rem;
  margin-bottom: 0.55rem;
  line-height: 1.4;
}

.lex-brief-answer-wrap {
  margin-bottom: 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.lex-brief-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-family: var(--font-serif, Georgia, serif);
  font-size: 0.85rem;
  background: var(--white);
  color: var(--ink);
}
.lex-brief-input:focus {
  outline: none;
  border-color: var(--gold-deep, #5A4A0E);
}
.lex-brief-textarea {
  resize: vertical;
  min-height: 4rem;
}
.lex-brief-helper {
  font-size: 0.65rem;
  color: var(--muted);
  font-style: italic;
}

.lex-brief-choice {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.45rem 0.55rem;
  cursor: pointer;
  font-size: 0.8rem;
}
.lex-brief-choice:hover { border-color: var(--gold, #C9A84C); }
.lex-brief-choice input { margin: 0; }

.lex-brief-choice-other { font-style: italic; }
.lex-brief-other-input { margin-top: 0.4rem; }

.lex-brief-submit-row {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
  align-items: center;
}

/* Buttons */
.lex-brief-cta {
  background: var(--white, #fff);
  border: 1px solid var(--gold, #C9A84C);
  border-radius: var(--r-md);
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.lex-brief-cta-msg {
  font-family: var(--font-serif, Georgia, serif);
  font-size: 0.85rem;
  color: var(--ink);
}
.lex-brief-cta-btn {
  background: var(--ink, #0F0F0D);
  color: var(--white, #fff);
  border: none;
  border-radius: 6px;
  padding: 0.55rem 0.95rem;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
}
.lex-brief-cta-btn:hover {
  background: var(--gold, #C9A84C);
  color: var(--ink);
}
.lex-brief-cta-btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}
.lex-brief-cta-btn-secondary:hover {
  background: var(--surface);
  border-color: var(--gold, #C9A84C);
}
.lex-brief-skip {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0.4rem 0.6rem;
  font-family: inherit;
  font-size: 0.72rem;
  cursor: pointer;
  border-radius: 5px;
}
.lex-brief-skip:hover { color: var(--ink); background: var(--surface); }

.lex-brief-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
}

/* Loading state — three pulsing dots */
.lex-brief-loading {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 1rem 0.8rem;
  font-size: 0.76rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.lex-brief-dot {
  width: 5px; height: 5px;
  background: var(--gold, #C9A84C);
  border-radius: 50%;
  animation: lex-brief-dot 1.1s infinite ease-in-out;
}
.lex-brief-dot:nth-child(2) { animation-delay: 0.15s; }
.lex-brief-dot:nth-child(3) { animation-delay: 0.30s; }
@keyframes lex-brief-dot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40%           { transform: scale(1);   opacity: 1; }
}


/* ════════════════════════════════════════════════════════════════════════
   Grounded drafting Phase D — Suggestion cards in the Brief tab
   ──────────────────────────────────────────────────────────────────────── */

.lex-sug-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.65rem;
}
.lex-sug-group-title {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted, #8E8B7C);
  padding: 0.25rem 0;
}

.lex-sug-card {
  background: var(--white, #fff);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.lex-sug-card.is-confirmed {
  background: linear-gradient(180deg, #F5FAEF 0%, var(--white) 100%);
  border-color: #6DAA52;
}
.lex-sug-card-advisory {
  background: var(--surface, #F4F2EB);
  border-style: dashed;
}

.lex-sug-card-head {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.lex-sug-kind {
  font-size: 0.55rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: var(--gold-bg, #FDF6E3);
  color: var(--gold-deep, #5A4A0E);
  padding: 0.08rem 0.4rem;
  border-radius: 3px;
}
.lex-sug-conf {
  font-size: 0.55rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.08rem 0.4rem;
  border-radius: 3px;
}
.lex-sug-conf-high   { background: #E6F3DD; color: #3D6B2A; }
.lex-sug-conf-medium { background: #FFF4D6; color: #8C6A05; }
.lex-sug-conf-low    { background: #FFE6E6; color: #B23B3B; }
.lex-sug-confirmed-pill {
  margin-left: auto;
  font-size: 0.6rem;
  font-weight: 600;
  color: #3D6B2A;
  background: #E6F3DD;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
}

.lex-sug-card-title {
  font-family: var(--font-serif, Georgia, serif);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ink, #0F0F0D);
  line-height: 1.35;
}
.lex-sug-card-sub {
  font-size: 0.72rem;
  color: var(--muted, #8E8B7C);
}
.lex-sug-card-why {
  font-size: 0.74rem;
  color: var(--ink);
  line-height: 1.45;
  padding: 0.4rem 0.5rem;
  background: var(--surface, #F4F2EB);
  border-left: 2px solid var(--gold, #C9A84C);
  border-radius: 0 4px 4px 0;
}

.lex-sug-source {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.66rem;
  color: var(--muted);
  cursor: help;
}
.lex-sug-source svg { color: var(--gold, #C9A84C); flex-shrink: 0; }
.lex-sug-source strong { color: var(--ink); font-weight: 500; }

.lex-sug-card-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
  align-items: center;
}
.lex-sug-card-actions .lex-brief-cta-btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.7rem;
}

.lex-sug-alt {
  font-size: 0.72rem;
}
.lex-sug-alt > summary {
  cursor: pointer;
  color: var(--muted);
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.lex-sug-alt > summary::before {
  content: '▸';
  display: inline-block;
  font-size: 0.6rem;
  transition: transform 0.15s;
}
.lex-sug-alt[open] > summary::before { transform: rotate(90deg); }
.lex-sug-alt-row {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}
.lex-sug-alt-row:last-child { border-bottom: none; }
.lex-sug-alt-why {
  margin-top: 0.15rem;
  font-size: 0.7rem;
  color: var(--muted);
}

.lex-sug-empty {
  background: var(--surface, #F4F2EB);
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.45;
  margin-top: 0.5rem;
}
.lex-sug-empty strong { color: var(--ink); font-weight: 500; }

/* Web-search authority pill (Phase D extension). */
.lex-sug-web-pill {
  font-size: 0.55rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: #FFEFD6;
  color: #8A4A05;
  padding: 0.08rem 0.4rem;
  border-radius: 3px;
}
.lex-sug-card.is-web {
  border-left: 3px solid #E89A2F;
}
/* Pending state shown while web fallback runs. */
.lex-sug-web-pending {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.7rem;
  background: var(--surface, #F4F2EB);
  border: 1px dashed var(--border);
  border-radius: 6px;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.6rem;
}


/* ════════════════════════════════════════════════════════════════════════
   Grounded drafting Phase E — Reasoning breakdown in Sources tab
   ──────────────────────────────────────────────────────────────────────── */

.lex-reasoning {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.lex-reasoning-block {
  background: var(--white, #fff);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
}
.lex-reasoning-block-title {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold-deep, #5A4A0E);
  margin-bottom: 0.4rem;
}
.lex-reasoning-block-value {
  font-family: var(--font-serif, Georgia, serif);
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 0.3rem;
}
.lex-reasoning-block-why {
  font-size: 0.72rem;
  color: var(--ink);
  line-height: 1.45;
  padding: 0.35rem 0.5rem;
  background: var(--surface, #F4F2EB);
  border-left: 2px solid var(--gold, #C9A84C);
  border-radius: 0 4px 4px 0;
}

.lex-reasoning-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.lex-reasoning-item:last-child { border-bottom: none; }
.lex-reasoning-item-head {
  font-family: var(--font-serif, Georgia, serif);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.35;
}
.lex-reasoning-item-where {
  font-size: 0.62rem;
  color: var(--gold-deep, #5A4A0E);
  background: var(--gold-bg, #FDF6E3);
  display: inline-block;
  padding: 0.08rem 0.4rem;
  border-radius: 3px;
  margin: 0.25rem 0;
  letter-spacing: 0.03em;
}
.lex-reasoning-item-why {
  font-size: 0.72rem;
  color: var(--mid, #5A5648);
  line-height: 1.45;
  margin-top: 0.2rem;
}
.lex-reasoning-item-src {
  font-size: 0.66rem;
  margin-top: 0.25rem;
}
.lex-reasoning-item-src a {
  color: var(--gold-deep, #5A4A0E);
  text-decoration: underline;
}

.lex-reasoning-decisions {
  margin: 0; padding-left: 1rem;
  font-size: 0.74rem;
  line-height: 1.55;
  color: var(--ink);
}
.lex-reasoning-decisions li { margin-bottom: 0.2rem; }
