:root {
  --ink: #070b12;
  --ink-2: #0b1220;
  --panel: rgba(16, 24, 40, 0.78);
  --panel-solid: #101828;
  --line: rgba(212, 180, 131, 0.16);
  --line-strong: rgba(212, 180, 131, 0.32);
  --brass: #d4b483;
  --brass-dim: #a68554;
  --paper: #f4efe4;
  --muted: #8b9bb4;
  --text: #e8edf5;
  --danger: #f87171;
  --ok: #34d399;
  --sidebar: 248px;
  --top: 58px;
  --dock: 0px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --vvh: 100dvh;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 8% -12%, rgba(196, 165, 116, 0.09), transparent 52%),
    radial-gradient(900px 480px at 108% 0%, rgba(15, 118, 110, 0.11), transparent 46%),
    var(--ink);
  min-height: 100dvh;
}
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }

.lg-shell { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-rows: var(--top) 1fr; }
.lg-shell.fill-shell { height: 100vh; height: 100dvh; overflow: hidden; overscroll-behavior: none; }

.lg-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem;
  height: var(--top);
  border-bottom: 1px solid var(--line);
  background: rgba(7, 11, 18, 0.9);
  backdrop-filter: blur(18px);
  position: sticky; top: 0; z-index: 40;
}

.lg-mark {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 600;
  letter-spacing: 0.04em;
  font-size: 1.4rem;
  color: var(--brass);
  line-height: 1;
}

.lg-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.lg-chip {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brass);
  border: 1px solid var(--line);
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  line-height: 1.2;
}
.lg-chip-muted { color: var(--muted); border-color: rgba(148,163,184,0.18); }
.lg-chip-ok { color: var(--ok); border-color: rgba(52,211,153,0.28); }
.lg-chip-warn { color: #fbbf24; border-color: rgba(251,191,36,0.28); }
/* The document date. Its own class, not .lg-chip-ok: green reads as "status
   good", and a date is not a status. Neutral-bright so the chronology is the
   first thing the eye finds on a document card. */
.lg-chip-date { color: var(--paper); border-color: rgba(226,232,240,0.24); font-variant-numeric: tabular-nums; }
/* Tabular figures so the date column forms a readable vertical block instead of
   ragged digits -- the whole point of the column is scanning it top to bottom. */
.docs-docdate { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* The graph-excerpt chip needs its OWN class: .lg-chip-warn is already worn by
 * the OCR / weak-text / heuristic chips, so styling that class would have given
 * every one of them `cursor: help` and, below 720px, a full-width row. Amber,
 * not red -- the graph is incomplete, but nothing is broken or lost. */
.lg-chip-trunc {
  color: #fbbf24;
  border-color: rgba(251,191,36,0.38);
  background: rgba(251,191,36,0.08);
  cursor: help;
}
@media (max-width: 720px) {
  .lg-chip-trunc { flex: 1 1 100%; justify-content: center; text-align: center; }
}

.lg-btn {
  background: linear-gradient(180deg, #dcc49a, #b08950);
  color: #1a140c;
  font-weight: 600;
  border: 0;
  border-radius: 11px;
  padding: 0.55rem 1rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
}
.lg-btn:hover { filter: brightness(1.06); }
.lg-btn:disabled { opacity: 0.55; cursor: wait; }
.lg-btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: #e2e8f0;
  border-radius: 11px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
}
.lg-btn-ghost:hover { border-color: var(--brass); color: var(--brass); }
.lg-btn-ghost.active {
  background: rgba(212, 180, 131, 0.12);
  border-color: var(--brass);
  color: var(--brass);
}

.lg-input, .lg-textarea, select.lg-input {
  background: #0b1220;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: #e2e8f0;
  padding: 0.6rem 0.8rem;
  width: 100%;
  font-family: inherit;
  font-size: 0.92rem;
}
.lg-input:focus, .lg-textarea:focus {
  outline: none;
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(212, 180, 131, 0.12);
}
.lg-textarea { resize: vertical; min-height: 5.5rem; }

/* —— Case layout —— */
.lg-case {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: calc(100vh - var(--top));
}
.lg-case.fill { height: calc(100vh - var(--top)); min-height: 0; }
.lg-sidebar {
  border-right: 1px solid var(--line);
  padding: 1rem 0.85rem;
  background: rgba(8, 12, 20, 0.55);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.lg-sidebar-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.15rem;
  color: var(--brass);
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0.65rem 0 1rem;
}
.lg-nav a, .lg-nav button {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  color: #94a3b8;
  width: 100%;
  text-align: left;
  text-decoration: none;
  font-size: 0.9rem;
}
.lg-nav a.active, .lg-nav a:hover {
  background: rgba(212, 180, 131, 0.1);
  color: var(--brass);
}
.lg-side-stats {
  margin-top: auto;
  padding-top: 1rem;
  font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
  color: #64748b;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.5rem;
}
.lg-side-stats b { color: #cbd5e1; font-weight: 500; display: block; }
.lg-main {
  padding: 1.25rem 1.5rem 2rem;
  overflow: auto;
  min-width: 0;
}
.lg-case.fill .lg-main {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0;
}

/* —— Home case cards —— */
.case-card {
  cursor: pointer;
  padding: 1.15rem 1.2rem 1rem;
  transition: border-color 0.15s, transform 0.15s;
  min-width: 0;
}
.case-card:hover { border-color: rgba(212, 180, 131, 0.42); transform: translateY(-1px); }
.case-card-head {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}
.case-card-head h2 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.45rem;
  line-height: 1.2;
  color: var(--brass);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.case-card-head .lg-chip { flex-shrink: 0; margin-top: 0.28rem; }
.case-card p.lede {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.case-meta {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem 0.9rem;
}
.case-meta div { min-width: 0; }
.case-meta dt {
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #64748b;
  margin: 0 0 0.12rem;
}
.case-meta dd {
  margin: 0;
  color: #e2e8f0;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.case-foot {
  margin-top: 0.9rem;
  display: flex;
  gap: 0.9rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  color: #64748b;
  flex-wrap: wrap;
}
.case-foot b { color: #94a3b8; font-weight: 500; }

/* —— Overview stats —— */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}
.stat-card {
  padding: 0.95rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.stat-ico {
  width: 2.4rem; height: 2.4rem;
  border-radius: 10px;
  display: grid; place-items: center;
  background: rgba(212, 180, 131, 0.1);
  color: var(--brass);
  flex-shrink: 0;
}
.stat-card .k { font-size: 0.7rem; color: #64748b; text-transform: uppercase; letter-spacing: 0.08em; }
.stat-card .v {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.85rem;
  color: var(--paper);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.statcard {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.85rem;
  padding: 0.9rem 1rem;
  min-height: 4.4rem;
  min-width: 0;
}
.statcard .stat-ico {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(212, 180, 131, 0.1);
  color: var(--brass);
  flex-shrink: 0;
  font-size: 0.95rem;
}
.statcard > div {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}
.statcard .k {
  font-size: 0.68rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.statcard .v {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.75rem;
  color: var(--paper);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* —— Dropzone / file input —— */
.sr-file {
  position: absolute !important;
  width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important;
  overflow: hidden !important; clip: rect(0,0,0,0) !important;
  white-space: nowrap !important; border: 0 !important;
}
.dropzone {
  position: relative;
  border: 1.5px dashed rgba(212, 180, 131, 0.32);
  border-radius: 16px;
  padding: 1.6rem 1.2rem;
  text-align: center;
  color: var(--muted);
  background: rgba(12, 18, 32, 0.4);
  cursor: pointer;
}
.dropzone:hover, .dropzone.drag {
  border-color: var(--brass);
  background: rgba(212, 180, 131, 0.06);
}
.dropzone .fa-cloud-arrow-up { font-size: 1.35rem; color: var(--brass); display: block; margin-bottom: 0.45rem; }
.docs-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.docs-table th {
  text-align: left; font-size: 0.68rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: #64748b; font-weight: 500;
  padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--line);
}
.docs-table td { padding: 0.7rem 0.9rem; border-bottom: 1px solid rgba(212,180,131,0.08); vertical-align: middle; }
.docs-table tr:last-child td { border-bottom: 0; }
.type-pill {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  padding: 0.12rem 0.45rem;
  border-radius: 6px;
  background: rgba(148,163,184,0.12);
  color: #cbd5e1;
  /* A type label is a label, never a line break: it keeps its own width and
     never steals the space the filename needs. */
  white-space: nowrap;
  flex: 0 0 auto;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* —— Graph (vis-network) —— */
.graph-page {
  flex: 1;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: 1fr minmax(260px, 300px);
  background: #070b12;
}
.graph-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
}
#graph-host {
  width: 100%;
  height: 100%;
  background:
    radial-gradient(800px 400px at 50% 40%, rgba(212,180,131,0.04), transparent 60%),
    #080e18;
}
.graph-toolbar {
  position: absolute;
  z-index: 5;
  top: 0.85rem; left: 0.85rem; right: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  pointer-events: none;
}
.graph-toolbar > * { pointer-events: auto; }
.graph-toolbar .lg-input { width: 220px; padding: 0.4rem 0.65rem; font-size: 0.82rem; background: rgba(11,18,32,0.92); }
.graph-legend {
  position: absolute;
  z-index: 5;
  left: 0.85rem; right: 0.85rem; bottom: 0.75rem;
  display: flex; flex-wrap: wrap; gap: 0.35rem;
  pointer-events: none;
}
.graph-legend > * { pointer-events: auto; }
.node-pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(8, 14, 24, 0.88);
  color: #cbd5e1;
  cursor: pointer;
  user-select: none;
}
.node-pill.off { opacity: 0.35; }
.node-pill .dot { width: 8px; height: 8px; border-radius: 99px; display: inline-block; }
.graph-inspector {
  padding: 1.1rem 1.15rem;
  overflow: auto;
  background: rgba(10, 15, 26, 0.92);
}
.graph-inspector h2 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.35rem;
  color: var(--brass);
  margin: 0 0 0.35rem;
  line-height: 1.25;
}
.insp-kv { display: grid; gap: 0.55rem; margin-top: 1rem; }
.insp-kv div {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.65rem;
}
.insp-kv dt { font-size: 0.62rem; letter-spacing: 0.1em; text-transform: uppercase; color: #64748b; }
.insp-kv dd { margin: 0.15rem 0 0; font-size: 0.86rem; word-break: break-word; }
.insp-empty { color: var(--muted); font-size: 0.88rem; line-height: 1.5; }
.neigh { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.35rem; }
.neigh button {
  text-align: left;
  background: transparent;
  border: 1px solid var(--line);
  color: #e2e8f0;
  border-radius: 9px;
  padding: 0.4rem 0.55rem;
  cursor: pointer;
  font-size: 0.78rem;
}
.neigh button:hover { border-color: var(--brass); color: var(--brass); }

/* vis-network tooltip */
div.vis-tooltip {
  background: #101828 !important;
  color: #e2e8f0 !important;
  border: 1px solid var(--line) !important;
  border-radius: 8px !important;
  padding: 0.4rem 0.55rem !important;
  font-family: 'IBM Plex Sans', sans-serif !important;
  font-size: 12px !important;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4) !important;
}

/* —— Timeline —— */
.tl { list-style: none; margin: 0; padding: 0.2rem 0 1rem; }
.timeline-item { position: relative; padding: 0 0 1.15rem 1.4rem; }
.timeline-item::before {
  content: '';
  position: absolute; left: 0.15rem; top: 0.35rem;
  width: 0.55rem; height: 0.55rem; border-radius: 999px;
  background: var(--brass);
  box-shadow: 0 0 0 3px rgba(212,180,131,0.15);
}
.timeline-item::after {
  content: '';
  position: absolute; left: 0.38rem; top: 1.05rem; bottom: 0;
  width: 1px; background: var(--line);
}
.timeline-item:last-child::after { display: none; }
.tl-date { font-family: 'IBM Plex Mono', monospace; font-size: 0.72rem; color: var(--brass); }
.tl-title { color: var(--paper); margin-top: 0.15rem; }
.tl-meta { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }
/* Clickable entries: only rows that actually carry a document link get affordance. */
.timeline-item.tl-clickable { cursor: pointer; border-radius: 0.4rem; transition: background 0.12s ease; }
.timeline-item.tl-clickable:hover { background: rgba(212,180,131,0.07); }
.timeline-item.tl-clickable:hover .tl-doc { color: var(--brass); border-color: rgba(212,180,131,0.45); }
.tl-foot { margin-top: 0.35rem; }
.tl-doc {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.7rem; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 0.1rem 0.5rem;
}
.tl-doc-none { opacity: 0.55; font-style: italic; }
.tl-prov {
  margin-left: 0.45rem; font-size: 0.62rem; letter-spacing: 0.02em;
  border-radius: 999px; padding: 0.05rem 0.4rem; cursor: help;
  background: rgba(129,140,248,0.14); color: #a5b4fc; border: 1px solid rgba(129,140,248,0.3);
}
/* Where proven chronology ends and undated events begin. */
.tl-divider {
  list-style: none; margin: 0.4rem 0 0.9rem; padding: 0 0 0 1.4rem;
  font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); cursor: help;
  border-top: 1px dashed var(--line); padding-top: 0.5rem;
}

/* —— Chat —— */
.chat-page {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
}
.chat-head {
  padding: 1rem 1.5rem 0.75rem;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--line);
}
.chat-log {
  flex: 1; overflow: auto;
  min-width: 0;
  padding: 1.25rem 1.5rem;
  display: flex; flex-direction: column; gap: 0.75rem;
}
.chat-row { display: flex; width: 100%; min-width: 0; }
.chat-row.is-user { justify-content: flex-end; }
.chat-row.is-agent { justify-content: flex-start; }
.chat-bubble {
  max-width: min(78%, 720px);
  min-width: 0;
  padding: 0.8rem 1rem;
  border-radius: 16px;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.chat-bubble.md, .chat-bubble.md p, .chat-bubble.md li, .chat-bubble.md code {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.chat-bubble .lg-chip {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
  letter-spacing: 0.04em;
}
.chat-user { margin-left: auto; background: #1c2740; color: #e2e8f0; }
.chat-agent { background: rgba(212, 180, 131, 0.07); border: 1px solid var(--line); }

/* Copy button: discreet by request. Nearly invisible until the answer is
   hovered, and it must never cover the last line of text -- hence the bubble
   gets bottom padding to reserve the corner rather than the button floating
   over the prose. */
.chat-agent { position: relative; padding-bottom: 1.6rem; }
.chat-copy {
  position: absolute;
  right: 0.4rem;
  bottom: 0.3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted, #7c8798);
  opacity: 0.35;
  cursor: pointer;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  font-size: 0.78rem;
  line-height: 1;
}
.chat-row.is-agent:hover .chat-copy,
.chat-copy:focus-visible { opacity: 1; }
.chat-copy:hover { color: var(--paper, #e9e2d3); border-color: var(--line); }
.chat-copy.is-copied { opacity: 1; color: #6fcf97; border-color: rgba(111, 207, 151, 0.4); }
.chat-copy.is-failed { opacity: 1; color: #eb5757; border-color: rgba(235, 87, 87, 0.4); }
/* Touch devices have no hover, so the button stays faintly visible there. */
@media (hover: none) {
  .chat-copy { opacity: 0.55; }
}
.agent-back { display: none; }
.chat-composer {
  padding: 0.85rem 1.25rem 1.1rem;
  border-top: 1px solid var(--line);
  background: rgba(7, 11, 18, 0.92);
  backdrop-filter: blur(12px);
}
.suggest {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  margin-bottom: 1.25rem;
}
.suggest button {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
  color: #cbd5e1;
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.8rem;
}
.suggest button:hover { border-color: var(--brass); color: var(--brass); }
.lg-empty {
  margin: auto;
  max-width: 28rem;
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}
.lg-empty h3 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.6rem;
  color: var(--paper);
  margin: 0.4rem 0 0.35rem;
}

/* —— Toast —— */
.lg-toast {
  position: fixed; right: 1rem; top: calc(var(--top) + 0.75rem); z-index: 80;
  background: #121a2c;
  border: 1px solid var(--line-strong);
  color: var(--paper);
  padding: 0.65rem 0.9rem;
  border-radius: 12px;
  font-size: 0.86rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  max-width: 22rem;
}

/*
 * Progress for the batched AI rebuild. Pinned to the bottom rather than the top
 * so it never collides with the toast, and it stays for the whole run: an AI
 * rebuild of a large matter takes minutes, and the run only survives while the
 * page stays open, so the user has to be able to see that it is still working.
 */
.lg-rebuild-progress {
  position: fixed; left: 1rem; right: 1rem; bottom: 1rem; z-index: 90;
  margin: 0 auto; max-width: 26rem;
  background: #121a2c;
  border: 1px solid var(--line-strong);
  color: var(--paper);
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
}
.lg-rebuild-progress-label {
  font-size: 0.86rem; font-variant-numeric: tabular-nums; margin-bottom: 0.45rem;
}
.lg-rebuild-bar {
  height: 6px; border-radius: 999px; background: #1f2a44; overflow: hidden;
}
.lg-rebuild-bar > span {
  display: block; height: 100%; background: var(--brass);
  transition: width 0.35s ease;
}
.lg-rebuild-hint {
  margin-top: 0.45rem; font-size: 0.72rem; color: #94a3b8; line-height: 1.35;
}
.lg-rebuild-cancel {
  margin-top: 0.55rem; width: 100%;
  background: transparent; border: 1px solid var(--line-strong); color: #cbd5e1;
  padding: 0.35rem 0.6rem; border-radius: 8px; font-size: 0.78rem; cursor: pointer;
}
.lg-rebuild-cancel:hover { border-color: var(--brass); color: var(--brass); }
.lg-rebuild-cancel:disabled { opacity: 0.5; cursor: default; }
@media (max-width: 720px) {
  /* Clear of the bottom dock on phones, which is where this bug appeared. */
  .lg-rebuild-progress { bottom: 4.6rem; }
}

.md h1, .md h2, .md h3 { font-family: 'Cormorant Garamond', serif; color: var(--brass); margin: 0.8rem 0 0.4rem; overflow-wrap: anywhere; }
.md p, .md li { line-height: 1.65; color: #cbd5e1; overflow-wrap: anywhere; word-break: break-word; }
.md code { font-family: 'IBM Plex Mono', monospace; font-size: 0.82em; color: #fde68a; overflow-wrap: anywhere; word-break: break-word; }
.md pre { background: #0b1220; padding: 0.8rem; border-radius: 10px; overflow: auto; }
.md ul { margin: 0.4rem 0; padding-left: 1.1rem; }

.stat { font-variant-numeric: tabular-nums; }


/* —— Header chips: never overlap the mark —— */
.lg-top {
  gap: 0.75rem;
  overflow: hidden;
}
.lg-top > a {
  flex: 0 0 auto;
  min-width: 0;
  z-index: 2;
  background: rgba(7, 11, 18, 0.96);
  position: relative;
}
.lg-top-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}
.lg-top-meta .lg-chip,
.lg-top-meta .lg-btn-ghost {
  flex-shrink: 0;
}

/* —— Danger / delete —— */
.lg-btn-danger {
  background: transparent;
  border: 1px solid rgba(248, 113, 113, 0.38);
  color: #fca5a5;
  border-radius: 11px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
}
.lg-btn-danger:hover {
  background: rgba(248, 113, 113, 0.12);
  border-color: var(--danger);
  color: #fecaca;
}
.lg-btn-tiny {
  padding: 0.28rem 0.5rem;
  font-size: 0.74rem;
  border-radius: 8px;
}
.case-del {
  flex-shrink: 0;
  padding: 0.28rem 0.5rem;
  margin-top: 0.15rem;
}

/* —— Overview restructure —— */
.ov-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.25rem;
  margin-bottom: 1.15rem;
  flex-wrap: wrap;
}
.ov-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  flex-shrink: 0;
}
.stat-grid.ov-stats {
  grid-template-columns: repeat(6, 1fr);
}
.ov-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
}
.ov-block {
  padding: 0.95rem 1.05rem 1.05rem;
  min-width: 0;
}
.ov-block h3 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.15rem;
  color: var(--brass);
  margin: 0 0 0.7rem;
  font-weight: 600;
}
.ov-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.ov-list li {
  font-size: 0.84rem;
  color: #e2e8f0;
  line-height: 1.4;
  padding: 0.28rem 0;
  border-bottom: 1px solid rgba(212,180,131,0.08);
}
.ov-list li:last-child { border-bottom: 0; }
.ov-party {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
}
.ov-role {
  flex-shrink: 0;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brass);
}
/* Provenance marker on an AI-proposed party (hover shows the verbatim quote). */
.ov-prov {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  font-size: 0.6rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  border: 1px solid rgba(139,92,246,0.4);
  background: rgba(139,92,246,0.12);
  color: #c4b5fd;
  cursor: help;
}
.ov-empty { margin: 0; color: var(--muted); font-size: 0.84rem; }

/* --- graph inspector: provenance + evidence ---------------------------- */
.insp-prov-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0 0.2rem;
}
.insp-prov {
  display: inline-flex;
  align-items: center;
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.14rem 0.48rem;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.35);
  background: rgba(148,163,184,0.1);
  color: #cbd5e1;
}
.insp-prov.llm {
  border-color: rgba(139,92,246,0.45);
  background: rgba(139,92,246,0.14);
  color: #c4b5fd;
}
.insp-prov.rule {
  border-color: rgba(22,163,74,0.4);
  background: rgba(22,163,74,0.12);
  color: #86efac;
}
.insp-prov.warn {
  border-color: rgba(234,88,12,0.45);
  background: rgba(234,88,12,0.12);
  color: #fdba74;
}
.insp-evidence {
  margin: 0;
  padding: 0.55rem 0.7rem;
  border-left: 2px solid var(--brass);
  background: rgba(212,180,131,0.06);
  border-radius: 0 6px 6px 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  line-height: 1.55;
  color: #d6dee9;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 11rem;
  overflow-y: auto;
}

/* Rebuild pair: plain rule rebuild + opt-in AI rebuild. */
.rebuild-group { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }
.ov-sub {
  margin: 0.7rem 0 0.3rem;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #64748b;
}
.ov-date {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  color: var(--brass);
  display: inline-block;
  min-width: 5.2rem;
}
/* A deadline whose day/month order the document never proved. Amber, not brass:
   it must not read as a date the system stands behind. */
.ov-date-warn {
  color: #fbbf24;
  cursor: help;
  min-width: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-right: 0.4rem;
}
.ov-deadline { display: flex; align-items: baseline; gap: 0.4rem; flex-wrap: wrap; }
.ov-cx li span { color: var(--muted); font-size: 0.78rem; }
.ov-span { grid-column: 1 / -1; }
.memory-form { display: grid; gap: 0.55rem; }
.memory-form .lg-textarea {
  min-height: 8.5rem;
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 0.8rem;
  line-height: 1.45;
}
.memory-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.skill-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.32rem;
  margin-top: 0.45rem;
}
.skill-chip {
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  background: rgba(212, 180, 131, 0.12);
}
/* Each card carries three things that cannot share one line: a filename of
   unknown length, a type label and a timestamp. The filename gets the whole
   first line, the two fixed-width items the second. A one-line layout made the
   filename (the only shrinkable child) collapse to zero width. */
.ov-docs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.5rem;
}
.ov-docs li {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.3rem;
  font-size: 0.84rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 0;
  overflow: hidden;
}
.ov-doc-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}
.ov-doc-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--paper);
}
.ov-doc-ocr { flex: 0 0 auto; }
.ov-doc-foot {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}
.ov-doc-when {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 0.68rem;
  color: #7b8aa3;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ov-doc-when i { opacity: 0.7; font-size: 0.62rem; }
.docs-when {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 0.72rem;
  color: #7b8aa3;
  white-space: nowrap;
}


@media (max-width: 1100px) {
  .stat-grid.ov-stats { grid-template-columns: repeat(3, 1fr); }
  .ov-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .stat-grid.ov-stats { grid-template-columns: 1fr 1fr; }
  .ov-grid { grid-template-columns: 1fr; }
}

/* Desktop: dock / cards / sheet chrome hidden */
.lg-dock, .docs-cards, .sheet-handle, .graph-sheet-backdrop, .lg-mobile-nav, .case-mobile-bar, .case-mobile-del, .agent-back { display: none; }
.composer-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.composer-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  resize: none;
  min-height: 44px;
  max-height: 132px;
  line-height: 1.45;
  overflow-y: auto;
  field-sizing: content;
}
.composer-send {
  flex-shrink: 0;
  min-width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 1rem;
}

/* —— Login —— */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(900px 420px at 12% -10%, rgba(196, 165, 116, 0.12), transparent 55%),
    radial-gradient(700px 380px at 100% 8%, rgba(15, 118, 110, 0.12), transparent 50%),
    var(--ink);
}
.login-card {
  width: min(26rem, 100%);
  padding: 1.75rem 1.6rem 1.85rem;
  box-shadow: 0 24px 80px rgba(0,0,0,0.35);
}
.login-err {
  color: #fca5a5;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.28);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font-size: 0.82rem;
  margin: 0;
}


.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(7, 11, 18, 0.55);
}
.lang-switch button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.28rem 0.55rem;
  cursor: pointer;
  line-height: 1.2;
}
.lang-switch button + button { border-left: 1px solid var(--line); }
.lang-switch button.active {
  color: #1a140c;
  background: linear-gradient(180deg, #dcc49a, #b08950);
}
.lang-switch button:hover:not(.active) { color: var(--brass); }
@media (max-width: 720px) {
  .lang-switch button { padding: 0.26rem 0.42rem; }
}

/* —— Mobile Case OS —— */
@media (max-width: 900px) {
  :root {
    --top: calc(52px + env(safe-area-inset-top, 0px));
    --dock: calc(58px + env(safe-area-inset-bottom, 0px));
  }

  html, body {
    min-height: 100dvh;
    height: auto;
    overflow: auto;
    overscroll-behavior: none;
  }
  #app { min-height: 100dvh; }
  body:has(.fill-shell),
  #app:has(.fill-shell) {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }
  body.agent-open {
    overflow: hidden;
    overscroll-behavior: none;
  }
  body.agent-open .lg-top,
  body.agent-open .lg-dock,
  body.agent-open .case-mobile-bar {
    display: none !important;
  }
  .lg-shell {
    min-height: 100dvh;
    grid-template-rows: var(--top) 1fr;
  }
  .lg-shell.fill-shell {
    height: 100dvh;
    height: var(--vvh, 100dvh);
    overflow: hidden;
  }

  html, body, #app { overflow-x: hidden; }
  .lg-top {
    height: var(--top);
    padding: env(safe-area-inset-top, 0px) 0.7rem 0;
    gap: 0.4rem;
    overflow: hidden;
  }
  .lg-top > a { gap: 0.55rem !important; }
  .lg-top .w-9 { width: 1.85rem; height: 1.85rem; }
  .lg-top .lg-mark { font-size: 1.18rem; }
  .lg-top .lg-mark + div { display: none; }
  .lg-top-meta { gap: 0.3rem; }
  .lg-top-meta .lg-chip { display: none !important; }
  .lg-top-meta #logout-btn,
  .lg-top-meta .lg-btn-ghost {
    min-height: 36px;
    padding: 0.35rem 0.6rem !important;
    font-size: 0.72rem !important;
  }

  .lg-input, .lg-textarea, select.lg-input {
    font-size: 16px !important;
    min-height: 44px;
    padding: 0.7rem 0.85rem;
  }

  .lg-btn, .lg-btn-ghost, .lg-btn-danger {
    min-height: 44px;
    padding: 0.6rem 0.95rem;
  }
  .lg-btn-tiny { min-height: 40px; min-width: 40px; padding: 0.4rem 0.55rem; }

  .lg-case {
    grid-template-columns: 1fr;
    min-height: calc(100dvh - var(--top));
    padding-bottom: var(--dock);
  }
  .lg-case.fill {
    height: calc(100dvh - var(--top));
    height: calc(var(--vvh, 100dvh) - var(--top));
  }
  body.agent-open .lg-case,
  body.agent-open .lg-case.fill {
    height: 100%;
    min-height: 0;
    padding-bottom: 0;
  }
  body.agent-open .lg-main,
  body.agent-open .lg-case.fill .lg-main {
    padding: 0;
    overflow: hidden;
    min-height: 0;
  }
  .lg-sidebar { display: none !important; }
  .lg-mobile-nav { display: none !important; }

  .lg-main {
    padding: 0.5rem 0.7rem 0.7rem;
    -webkit-overflow-scrolling: touch;
  }
  .lg-case.fill .lg-main { padding: 0; }

  .lg-dock {
    display: flex !important;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    height: var(--dock);
    padding: 0.2rem 0.2rem env(safe-area-inset-bottom, 0px);
    background: rgba(7, 11, 18, 0.94);
    backdrop-filter: blur(22px) saturate(1.35);
    -webkit-backdrop-filter: blur(22px) saturate(1.35);
    border-top: 1px solid var(--line);
    justify-content: space-around;
    align-items: stretch;
    gap: 0;
  }
  body.kb-open .lg-dock,
  body.agent-open .lg-dock { display: none !important; }
  body.kb-open .lg-toast,
  body.agent-open .lg-toast { bottom: 0.75rem; }
  .lg-dock a {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.18rem;
    min-width: 0;
    min-height: 44px;
    padding: 0.28rem 0.08rem 0.2rem;
    border-radius: 12px;
    color: #7b8aa3;
    text-decoration: none;
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    line-height: 1;
    width: auto;
    white-space: nowrap;
  }
  .lg-dock a i {
    font-size: 1.08rem;
    width: auto;
    line-height: 1;
  }
  .lg-dock a.active,
  .lg-dock a[aria-current="page"] {
    color: var(--brass);
    background: rgba(212, 180, 131, 0.1);
  }

  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-grid.ov-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.38rem;
    margin-bottom: 0.55rem !important;
  }
  .stat-card { padding: 0.75rem 0.8rem; gap: 0.6rem; }
  .stat-card .v { font-size: 1.45rem; }
  .statcard {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.16rem;
    padding: 0.48rem 0.52rem 0.5rem;
    min-width: 0;
  }
  .statcard .stat-ico {
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 7px;
    font-size: 0.62rem;
  }
  .statcard .k {
    font-size: 0.52rem;
    letter-spacing: 0.05em;
    color: #7b8aa3;
    text-transform: uppercase;
  }
  .statcard .v {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 1.18rem;
    color: var(--paper);
    line-height: 1;
  }
  .overview-page { padding-bottom: 0.1rem; }
  .ov-head { gap: 0.28rem; margin-bottom: 0.45rem; flex-direction: column; }
  .ov-head .lg-chip { font-size: 0.62rem; padding: 0.1rem 0.42rem; }
  .ov-title { display: none !important; }
  .ov-summary { font-size: 0.84rem; margin: 0; line-height: 1.35; }
  .ov-summary:empty { display: none; }
  .ov-actions { display: none !important; }
  .ov-docs { grid-template-columns: 1fr; }
  .ov-grid { gap: 0.5rem; }
  .case-meta { grid-template-columns: 1fr 1fr; gap: 0.35rem 0.65rem; }
  .ov-block { padding: 0.58rem 0.68rem; }
  .ov-block h3 { font-size: 0.95rem; margin-bottom: 0.35rem; }

  .case-mobile-bar {
    display: flex !important;
    align-items: center;
    gap: 0.45rem;
    margin: -0.5rem -0.7rem 0.45rem;
    padding: 0.38rem 0.7rem 0.35rem;
    border-bottom: 1px solid var(--line);
    background: rgba(7, 11, 18, 0.92);
    position: sticky;
    top: 0;
    z-index: 8;
  }
  .lg-case.fill .case-mobile-bar { display: none !important; }
  .case-mobile-back {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    color: var(--brass);
    text-decoration: none;
    border: 1px solid var(--line);
  }
  .case-mobile-title {
    margin: 0;
    min-width: 0;
    flex: 1;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 1.05rem;
    color: var(--paper);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
  }
  .case-mobile-del {
    display: none;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 10px;
    color: #94a3b8;
    background: transparent;
    border: 1px solid var(--line);
    cursor: pointer;
  }
  .lg-case.is-overview .case-mobile-del { display: grid; }
  .case-mobile-del:hover,
  .case-mobile-del:active { color: var(--danger); border-color: rgba(248,113,113,0.4); }

  .home-page {
    padding: 1rem 0.9rem 1.4rem !important;
    gap: 1.15rem !important;
  }
  .home-page h1 { font-size: 1.7rem !important; }
  .home-page > section > p.text-slate-400 { font-size: 0.92rem; }
  .lg-main h1.font-serif { font-size: 1.55rem !important; overflow-wrap: anywhere; }
  .tl-title { overflow-wrap: anywhere; }
  .tl-meta { overflow-wrap: anywhere; }

  .dropzone { padding: 1.15rem 0.9rem; }
  .docs-table-wrap { display: none; }
  .docs-cards {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
  }
  .doc-card {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.45rem 0.7rem;
    padding: 0.85rem 0.9rem;
    align-items: start;
  }
  .doc-card-name {
    font-weight: 500;
    color: #e2e8f0;
    word-break: break-word;
    line-height: 1.35;
  }
  .doc-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    margin-top: 0.35rem;
  }
  .doc-card-actions {
    display: flex;
    gap: 0.35rem;
    grid-row: 1 / span 2;
    grid-column: 2;
  }

  .graph-page {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    position: relative;
    height: 100%;
    min-height: 0;
  }
  .graph-stage,
  .graph-sheet-backdrop,
  .graph-inspector {
    grid-area: 1 / 1;
  }
  .graph-inspector h2, .graph-inspector .insp-kv dd {
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .graph-stage { border-right: 0; min-height: 0; height: 100%; }
  .graph-toolbar {
    top: 0.5rem;
    left: 0.5rem;
    right: 0.5rem;
    gap: 0.3rem;
  }
  .graph-toolbar .lg-input {
    width: auto;
    flex: 1 1 100%;
    min-height: 44px;
    font-size: 16px !important;
    background: rgba(11, 18, 32, 0.94);
  }
  .graph-toolbar .lg-btn-ghost {
    min-height: 40px;
    min-width: 40px;
    padding: 0.4rem 0.55rem;
    font-size: 0;
    background: rgba(11, 18, 32, 0.94);
  }
  .graph-toolbar .lg-btn-ghost i {
    font-size: 0.92rem;
    margin: 0 !important;
  }
  /* Chips are hidden on a phone to keep the toolbar to one row -- but a
   * truncation warning is not decoration. Hiding it would leave the small
   * screen, where the excerpt is hardest to notice, as the one place that
   * never says the graph is incomplete. It stays, on its own row. */
  .graph-toolbar .lg-chip { display: none; }
  .graph-toolbar .lg-chip-trunc { display: inline-flex; }
  .graph-legend {
    left: 0.5rem;
    right: 0.5rem;
    bottom: 2.6rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.15rem;
    mask-image: linear-gradient(90deg, #000 88%, transparent);
  }
  .graph-page.sheet-open .graph-legend { opacity: 0; pointer-events: none; }
  .graph-legend .node-pill {
    flex-shrink: 0;
    min-height: 32px;
    font-size: 0.7rem;
  }

  .graph-sheet-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 8;
    background: rgba(4, 8, 14, 0.35);
    border: 0;
    padding: 0;
    cursor: pointer;
  }
  .graph-page.sheet-open .graph-sheet-backdrop {
    display: block;
  }

  .graph-inspector {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 12;
    max-height: none;
    height: auto;
    padding: 0 1rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    background: rgba(10, 15, 26, 0.97);
    backdrop-filter: blur(18px);
    transform: translateY(calc(100% - 36px));
    transition: transform 0.34s cubic-bezier(0.32, 0.72, 0.25, 1);
    box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.38);
    overflow: hidden;
  }
  .graph-page.sheet-open .graph-inspector,
  .graph-inspector.open {
    transform: translateY(0);
    max-height: min(52vh, 460px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sheet-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 28px;
    padding: 0.45rem 0 0.2rem;
    background: transparent;
    border: 0;
    cursor: pointer;
  }
  .sheet-handle::before {
    content: '';
    width: 2.4rem;
    height: 4px;
    border-radius: 99px;
    background: rgba(212, 180, 131, 0.38);
  }
  .graph-inspector h2 { font-size: 1.2rem; }

  /* Agent = dedicated visualViewport overlay (iMessage pattern) */
  .agent-stage {
    position: fixed;
    top: var(--vv-top, 0px);
    left: var(--vv-left, 0px);
    width: 100%;
    height: var(--vvh, 100dvh);
    max-height: var(--vvh, 100dvh);
    z-index: 80;
    display: flex;
    flex-direction: column;
    background: var(--ink);
    overflow: hidden;
  }
  .agent-stage .chat-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.7rem;
    min-height: 48px;
    border-bottom: 1px solid var(--line);
    background: rgba(7, 11, 18, 0.96);
  }
  .agent-stage .chat-head .skill-chips { margin-top: 0.3rem; }
  .agent-stage .chat-head h1 {
    font-size: 1.15rem !important;
    margin: 0;
    line-height: 1.15;
  }
  .agent-stage .chat-head p { display: none; }
  .agent-back {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: grid !important;
    place-items: center;
    border-radius: 10px;
    color: var(--brass);
    text-decoration: none;
    border: 1px solid var(--line);
  }
  .agent-head-copy { flex: 1; min-width: 0; }
  .agent-model { flex-shrink: 0; }
  .agent-stage .chat-log {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0.7rem 0.8rem 0.5rem;
    gap: 0.55rem;
  }
  .chat-row { display: flex; width: 100%; min-width: 0; }
  .chat-row.is-user { justify-content: flex-end; }
  .chat-row.is-agent { justify-content: flex-start; }
  .agent-stage .chat-bubble {
    max-width: 92%;
    min-width: 0;
    padding: 0.65rem 0.8rem;
    font-size: 0.95rem;
  }
  .agent-stage .chat-bubble.md { width: min(92%, 100%); }
  .agent-empty {
    margin: 0;
    padding: 0.4rem 0.1rem 0.2rem;
    max-width: none;
    text-align: left;
  }
  .agent-empty i { font-size: 1.05rem; display: block; margin-bottom: 0.35rem; }
  .agent-empty h3 { font-size: 1.15rem; margin: 0 0 0.25rem; }
  .agent-empty p {
    font-size: 0.82rem;
    line-height: 1.35;
    margin: 0 0 0.7rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  body.kb-open .agent-empty p { display: none; }
  .agent-stage .suggest {
    margin: 0;
    gap: 0.4rem;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
  }
  .agent-stage .suggest button {
    font-size: 0.78rem;
    line-height: 1.3;
    white-space: normal;
    text-align: left;
    border-radius: 12px;
    padding: 0.55rem 0.7rem;
    min-height: 40px;
    width: auto;
    max-width: 100%;
    flex: 1 1 100%;
  }
  .agent-stage .chat-composer {
    flex: 0 0 auto;
    padding: 0.45rem 0.65rem calc(0.45rem + env(safe-area-inset-bottom, 0px));
    background: rgba(7, 11, 18, 0.98);
    border-top: 1px solid var(--line);
  }
  body.kb-open .agent-stage .chat-composer {
    padding: 0.4rem 0.65rem 0.4rem;
  }
  .composer-input {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
  }
  .composer-send .send-label { display: none; }
  .composer-send {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
  }

  .tl { padding-left: 0.1rem; }
  .login-page {
    min-height: 100dvh;
    padding: calc(1.25rem + env(safe-area-inset-top, 0px)) 0.9rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
    place-items: stretch;
    align-content: center;
  }
  .login-card { padding: 1.35rem 1.1rem 1.45rem; width: 100%; }

  .lg-toast {
    left: 0.75rem;
    right: 0.75rem;
    top: auto;
    bottom: calc(var(--dock) + 0.65rem);
    max-width: none;
  }

  .case-card-head h2 { font-size: 1.25rem; }
  .home-lead-br { display: none; }
}

@media (max-width: 420px) {
  .lg-dock a { font-size: 0.55rem; }
  .stat-grid, .stat-grid.ov-stats { gap: 0.32rem; }
  .lg-main { padding: 0.42rem 0.55rem 0.6rem; }
  .case-mobile-bar { margin: -0.42rem -0.55rem 0.4rem; padding: 0.32rem 0.55rem 0.3rem; }
}

/* —— Live exhibit (agent cites + Akten) —— */
.cite-doc {
  display: inline-flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.32rem;
  margin: 0.15rem 0.12rem 0.15rem 0;
  padding: 0.18rem 0.5rem;
  border-radius: 10px;
  border: 1px solid rgba(212, 180, 131, 0.42);
  background: rgba(212, 180, 131, 0.12);
  color: var(--brass);
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 0.72rem;
  line-height: 1.35;
  cursor: pointer;
  vertical-align: baseline;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  text-align: left;
}
.cite-doc:hover, .cite-doc:focus-visible {
  background: rgba(212, 180, 131, 0.22);
  outline: none;
}
.cite-doc i { font-size: 0.68rem; }
.lg-chip-al {
  color: var(--paper);
  border-color: rgba(212, 180, 131, 0.55);
  background: rgba(212, 180, 131, 0.14);
}
.ov-docs li[data-open-doc], .doc-open-hit {
  cursor: pointer;
}
.ov-docs li[data-open-doc]:hover,
.doc-card[data-open-doc]:hover {
  border-color: rgba(212, 180, 131, 0.5);
}
.doc-card-name[data-open-doc],
.docs-table td[data-open-doc] {
  cursor: pointer;
  color: var(--brass);
}
.doc-viewer {
  position: fixed;
  inset: 0;
  z-index: 140;
  background: rgba(4, 7, 12, 0.78);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: env(safe-area-inset-top, 0px) 0.6rem calc(0.6rem + env(safe-area-inset-bottom, 0px));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.doc-viewer-panel {
  width: min(1100px, 100%);
  background: #0c1220;
  border: 1px solid var(--line);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.doc-viewer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.doc-viewer-kicker {
  margin: 0;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #7b8aa3;
}
.doc-viewer-head h2 {
  margin: 0.12rem 0 0;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.15rem;
  color: var(--paper);
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.doc-viewer-page { margin: 0.15rem 0 0; font-size: 0.75rem; color: var(--brass); }
.doc-viewer-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.doc-viewer-frame, .doc-viewer-embed {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  border: 0;
  background: #111827;
}
body.doc-open { overflow: hidden; }

@media (max-width: 900px) {
  .doc-viewer {
    padding: env(safe-area-inset-top, 0px) 0 0;
  }
  .doc-viewer-panel {
    width: 100%;
    border-radius: 0;
    height: 100%;
  }
  .doc-viewer-head { padding: 0.55rem 0.7rem; }
  .doc-viewer-actions .lg-btn, .doc-viewer-actions .lg-btn-ghost {
    min-height: 40px;
    padding: 0.4rem 0.7rem;
  }
}

/* —— Counsel thinking (live NDJSON) —— */
.think-card {
  width: min(92%, 420px);
  align-self: flex-start;
  background: rgba(12, 18, 32, 0.92);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.7rem 0.8rem 0.65rem;
}
.think-kicker {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
  margin: 0 0 0.45rem;
}
.think-kicker i { font-size: 0.72rem; }
.think-pulse {
  width: 7px; height: 7px; border-radius: 99px;
  background: var(--brass);
  box-shadow: 0 0 0 0 rgba(212, 180, 131, 0.7);
  animation: think-pulse 1.4s ease-out infinite;
}
@keyframes think-pulse {
  0% { box-shadow: 0 0 0 0 rgba(212, 180, 131, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(212, 180, 131, 0); }
  100% { box-shadow: 0 0 0 0 rgba(212, 180, 131, 0); }
}
.think-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.28rem; }
.think-steps li {
  display: grid;
  grid-template-columns: 1.1rem 1fr;
  gap: 0.4rem;
  align-items: start;
  font-size: 0.8rem;
  color: #94a3b8;
  line-height: 1.35;
}
.think-steps li.is-run { color: var(--paper); }
.think-steps li.is-done { color: #86efac; }
.think-steps .dot {
  width: 8px; height: 8px; border-radius: 99px;
  margin-top: 0.35rem;
  background: #334155;
}
.think-steps li.is-run .dot {
  background: var(--brass);
  animation: think-pulse 1.4s ease-out infinite;
}
.think-steps li.is-done .dot { background: #34d399; }
.think-plan {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: #cbd5e1;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.think-tools {
  margin: 0.4rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
}
/* Live tail of the answer while it is being written. Fixed height so the card
   does not jump as tokens arrive; the full text lands in the chat bubble. */
.think-draft {
  margin: 0.5rem 0 0;
  padding: 0.45rem 0.55rem;
  border-left: 2px solid rgba(212, 175, 55, 0.55);
  background: rgba(148, 163, 184, 0.08);
  border-radius: 0 6px 6px 0;
  font-size: 0.76rem;
  line-height: 1.45;
  color: #e2e8f0;
  overflow-wrap: anywhere;
  max-height: 4.6rem;
  overflow: hidden;
}
.think-caret {
  display: inline-block;
  width: 0.42rem;
  height: 0.85rem;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: #d4af37;
  animation: think-blink 1s step-end infinite;
}
@keyframes think-blink {
  50% { opacity: 0; }
}
.think-tools span {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  color: var(--brass);
  border: 1px solid rgba(212, 180, 131, 0.28);
  border-radius: 8px;
  padding: 0.12rem 0.38rem;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.think-elapsed { margin: 0.45rem 0 0; font-size: 0.68rem; color: #64748b; }
.composer-send.is-busy i, .composer-send.is-busy .send-label { display: none; }
.composer-send.is-busy::after {
  content: '';
  width: 14px; height: 14px;
  border: 2px solid rgba(26, 20, 12, 0.25);
  border-top-color: #1a140c;
  border-radius: 99px;
  animation: think-spin 0.7s linear infinite;
}
@keyframes think-spin { to { transform: rotate(360deg); } }

/* Upload recovery banner: documents whose OCR was interrupted. Amber, not red
   -- nothing is lost, the original PDF is already in R2 and only the text
   recognition needs to be re-run. Red would overstate the problem. */
.lg-recovery {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(217, 160, 60, 0.45);
  border-left: 3px solid rgba(217, 160, 60, 0.9);
  border-radius: 0.55rem;
  background: rgba(217, 160, 60, 0.09);
}
.lg-recovery-text { min-width: 0; }
.lg-recovery-title {
  font-weight: 600;
  color: #f0d9a8;
  font-size: 0.95rem;
}
.lg-recovery-sub {
  color: #cbd5e1;
  font-size: 0.8rem;
  margin-top: 0.2rem;
  max-width: 60ch;
  line-height: 1.45;
}
.lg-recovery-files {
  color: #94a3b8;
  font-size: 0.72rem;
  margin-top: 0.35rem;
  overflow-wrap: anywhere;
}
.lg-recovery button { flex: 0 0 auto; }
@media (max-width: 720px) {
  .lg-recovery { align-items: stretch; }
  .lg-recovery button { width: 100%; }
  .memory-actions { flex-direction: column; align-items: stretch; }
  .memory-actions .lg-btn { width: 100%; }
  .skill-chips { gap: 0.28rem; }
}
 color: #f0d9a8;
  font-size: 0.95rem;
}
.lg-recovery-sub {
  color: #cbd5e1;
  font-size: 0.8rem;
  margin-top: 0.2rem;
  max-width: 60ch;
  line-height: 1.45;
}
.lg-recovery-files {
  color: #94a3b8;
  font-size: 0.72rem;
  margin-top: 0.35rem;
  overflow-wrap: anywhere;
}
.lg-recovery button { flex: 0 0 auto; }
@media (max-width: 720px) {
  .lg-recovery { align-items: stretch; }
  .lg-recovery button { width: 100%; }
}

/* Missing original: the analysis is intact, only the stored file is gone. */
.doc-nofile { margin-left: 0.5rem; vertical-align: middle; }
.doc-viewer-notice {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  height: 100%;
  min-height: 16rem;
  padding: 2.2rem 1.6rem;
  text-align: center;
  color: var(--paper, #e9e2d3);
}
.doc-viewer-notice-icon { font-size: 2.4rem; opacity: 0.55; }
.doc-viewer-notice h3 { font-size: 1.05rem; font-weight: 600; }
.doc-viewer-notice p { max-width: 34rem; font-size: 0.9rem; line-height: 1.55; opacity: 0.75; }
