:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #dcd8d0;
  --accent: #8a3b12;
  --accent-soft: #f6e7dd;
  --link: #1d4f91;
  --quote-bg: #fff4c2;
  --hl: rgba(255, 196, 0, 0.45);
  --find: rgba(42, 120, 214, 0.25);
  --find-current: rgba(235, 104, 52, 0.6);
  --note-red: #c62828;
  --ok: #2e7d32;
  --bad: #b3261e;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body, #root { height: 100%; margin: 0; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 0.5rem 0; }

.login { display: grid; place-items: center; height: 100%; }
.login form { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 2rem; width: min(360px, 92vw); display: grid; gap: 0.9rem; }
.login h1 { margin: 0; font-size: 1.3rem; }
.login-sub { margin: -0.6rem 0 0.4rem; color: var(--muted); }
.login label { display: grid; gap: 0.3rem; font-size: 0.9rem; }
.login input { font: inherit; padding: 0.5rem 0.6rem; border: 1px solid var(--line); border-radius: 5px; }
.login button { padding: 0.55rem; border: none; border-radius: 5px; background: var(--accent); color: #fff; }
.login button:disabled { opacity: 0.55; cursor: default; }
.password-field { position: relative; display: block; }
.password-field input { width: 100%; padding-right: 2.6rem; }
.login .reveal { position: absolute; right: 0.3rem; top: 50%; transform: translateY(-50%); display: grid; place-items: center;
  padding: 0.25rem; background: none; color: var(--muted); border-radius: 4px; }
.login .reveal:hover, .login .reveal:focus-visible { color: var(--ink); background: var(--bg); }

.shell { display: flex; flex-direction: column; height: 100%; }
.top { display: flex; align-items: center; gap: 1.5rem; padding: 0.55rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; }
.tabs { display: flex; gap: 0.25rem; }
.switch { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; cursor: pointer; user-select: none; }
.switch input { accent-color: var(--accent); width: 1rem; height: 1rem; margin: 0; cursor: pointer; }
.tabs button { border: 1px solid transparent; background: none; padding: 0.3rem 0.8rem; border-radius: 5px; }
.tabs button.active { border-color: var(--line); background: var(--accent-soft); }
.who { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; font-size: 0.9rem; }
.who button { border: 1px solid var(--line); background: none; border-radius: 5px; padding: 0.2rem 0.6rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }

.docs { flex: 1; display: flex; min-height: 0; }

.toc { width: clamp(280px, 28vw, 450px); flex: none; overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); padding: 0.5rem 0 2rem; }
.toc-group { border-left: 3px solid var(--line); margin: 0 0.6rem 0.6rem 1rem; padding-left: 0.6rem; position: relative; }
.toc-group::before { content: ''; position: absolute; left: -8px; top: 0.75rem; width: 11px; height: 11px; border-radius: 50%; background: var(--accent); }
.toc-group.future { border-left-style: dashed; }
.toc-group.future::before { background: var(--panel); border: 2px solid var(--accent); box-sizing: border-box; }
.toc-group.future .toc-date { font-style: italic; }
.toc-head { display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 0.5rem; width: 100%; text-align: left; border: none; background: none; padding: 0.4rem 0.2rem; }
.toc-date { grid-column: 1; font-size: 0.78rem; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.toc-title { grid-column: 1; font-weight: 600; font-size: 0.92rem; }
.toc-count { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: var(--muted); font-size: 0.8rem; }
.toc-desc { margin: 0 0.2rem 0.4rem; font-size: 0.82rem; color: var(--muted); }
.toc ul { list-style: none; margin: 0 0 0.3rem; padding: 0; }
.toc-doc { display: flex; gap: 0.4rem; width: 100%; text-align: left; border: none; background: none; padding: 0.25rem 0.4rem; border-radius: 4px; font-size: 0.86rem; color: var(--link); }
.toc-doc:hover { background: var(--bg); }
.toc-doc.base { background: var(--bg); }
.toc-doc.top { background: var(--accent-soft); color: var(--ink); }
.toc-label { flex: none; min-width: 2.4rem; font-weight: 600; color: var(--muted); }

.stack { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0.6rem 0.8rem; }
.stack.empty { display: grid; place-items: center; color: var(--muted); }
.strips { display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; }
.strip { display: flex; align-items: center; border: 1px solid var(--line); border-bottom: none; border-radius: 6px 6px 0 0; background: #ebe7e0; min-width: 0; }
.strip-title { flex: 1; min-width: 0; text-align: left; border: none; background: none; padding: 0.3rem 0.7rem; font-size: 0.82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strip-title:hover { color: var(--ink); }
.strip-close { flex: none; border: none; background: none; color: var(--muted); font-size: 1rem; line-height: 1; padding: 0.15rem 0.6rem; }
.strip-close:hover { color: var(--bad); }
.card { flex: 1; min-height: 0; display: flex; }

.doc { flex: 1; min-width: 0; container-type: inline-size; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06); }
.doc-head { display: flex; align-items: flex-start; gap: 1rem; padding: 0.7rem 1rem; border-bottom: 1px solid var(--line); }
.doc-head > div { flex: 1; }
.doc-title { font-weight: 600; }
.doc-label { display: inline-block; margin-right: 0.5rem; padding: 0 0.4rem; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-size: 0.85rem; }
.doc-source { font-size: 0.82rem; color: var(--muted); margin-top: 0.2rem; }
.close { border: none; background: none; font-size: 1.5rem; line-height: 1; color: var(--muted); }
.close:hover { color: var(--ink); }
.doc-body { flex: 1; overflow: auto; padding: 1rem 1.2rem 3rem; }

.part + .part { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px dashed var(--line); }
.part-head { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.5rem; }
button.link { border: none; background: none; color: var(--link); padding: 0; font-size: 0.85rem; }
.caption { font-size: 0.85rem; color: var(--muted); }

.progress { position: relative; height: 1.6rem; background: var(--bg); border-radius: 4px; overflow: hidden; max-width: 420px; }
.progress .bar { position: absolute; inset: 0 auto 0 0; background: var(--accent-soft); }
.progress span { position: relative; padding-left: 0.6rem; font-size: 0.82rem; line-height: 1.6rem; color: var(--muted); }

.html-doc { max-width: 52rem; line-height: 1.55; }
.html-doc table { border-collapse: collapse; margin: 0.8rem 0; font-size: 0.88rem; }
.html-doc th, .html-doc td { border: 1px solid var(--line); padding: 0.3rem 0.5rem; vertical-align: top; text-align: left; }
.html-doc blockquote { margin: 0.8rem 0; padding: 0.3rem 0.9rem; border-left: 3px solid var(--line); background: #faf8f4; }
.html-doc pre.plain { white-space: pre-wrap; font: 0.92rem/1.5 ui-monospace, 'SFMono-Regular', Menlo, monospace; }
.html-doc .cover { border-bottom: 1px solid var(--line); margin-bottom: 1rem; padding-bottom: 1rem; }
.html-doc .cover .title { font-size: 1.3rem; font-weight: 700; }
.html-doc .cover .subtitle { font-size: 1.05rem; margin: 0.3rem 0 0.6rem; }
.html-doc .cover .notice { margin-top: 0.6rem; font-style: italic; color: var(--muted); }
.html-doc .email-head th { width: 6rem; background: #faf8f4; }
.html-doc:has(.sheet) { max-width: none; }
.html-doc .sheet { overflow-x: auto; }
.html-doc .sheet th { background: #faf8f4; }
.html-doc .sheet td { white-space: nowrap; }
.html-doc .sheet td.long { white-space: normal; min-width: 22rem; max-width: 40rem; }
.html-doc .sheet-title { font-weight: 600; margin: 0.3rem 0; }
a.ctx { color: var(--link); background: var(--quote-bg); text-decoration: none; border-radius: 3px; cursor: pointer; }
a.ctx:hover { text-decoration: underline; }
a.ctx.cite { background: none; font-weight: 600; }

.image.fit { max-width: 100%; max-height: 80vh; cursor: zoom-in; display: block; }
.image.full { cursor: zoom-out; display: block; }
.video { max-width: 100%; max-height: 75vh; display: block; background: #000; }

.pdf-tools { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; font-size: 0.85rem; position: sticky; top: -1rem; background: var(--panel); padding: 0.3rem 0; z-index: 2; }
.pdf-tools button { border: 1px solid var(--line); background: none; border-radius: 4px; width: 1.8rem; }
.pdf-page { position: relative; margin: 0 auto 0.8rem; box-shadow: 0 0 0 1px var(--line); background: #fff; }
.pdf-page canvas { display: block; }
.pdf-page .textLayer { opacity: 1; }
.pdf-page .textLayer span.hl { background: var(--hl); border-radius: 2px; }
.pdf-links { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.pdf-links a { position: absolute; pointer-events: auto; border-radius: 2px; }
.pdf-links a:hover { background: rgba(29, 79, 145, 0.15); }

.sysop { flex: 1; overflow: auto; padding: 1rem; display: grid; gap: 1rem; align-content: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 0.8rem 1rem; }
.panel td.actions { white-space: nowrap; }
.panel td.actions button { margin-right: 0.35rem; }
.notes { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(16rem, 22rem) minmax(0, 1fr); gap: 1rem; padding: 1rem; }
.notes-list { overflow: auto; display: flex; flex-direction: column; gap: 0.5rem; }
.notes-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.notes-head h2 { margin: 0; font-size: 1.1rem; }
.notes .small { margin: 0; font-size: 0.8rem; }
.notes-list ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.2rem; }
.notes-list li button { width: 100%; display: grid; gap: 0.1rem; text-align: left; border: none; background: none; padding: 0.45rem 0.6rem; border-radius: 6px; color: var(--ink); }
.notes-list li button:hover { background: var(--bg); }
.notes-list li button.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.notes-title { font-weight: 600; overflow-wrap: anywhere; }
.notes-meta { color: var(--muted); font-size: 0.78rem; }
.note { overflow: auto; }
.note-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.note-head h3 { margin: 0; font-size: 1.15rem; overflow-wrap: anywhere; }
.note-dates { color: var(--muted); font-size: 0.82rem; margin: 0.3rem 0 0.9rem; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; font-size: 0.95rem; max-width: 46rem; }
.note-form { display: grid; gap: 0.8rem; max-width: 46rem; }
.note-form label { display: grid; gap: 0.3rem; font-size: 0.85rem; font-weight: 600; }
.note-form input, .note-form textarea { font: inherit; font-weight: 400; font-size: 0.95rem; padding: 0.5rem 0.6rem; border: 1px solid var(--line); border-radius: 5px; background: var(--panel); color: var(--ink); }
.note-form textarea { resize: vertical; min-height: 16rem; line-height: 1.5; }
.note-form-actions { display: flex; align-items: center; gap: 0.6rem; }
.note-form-actions .muted { margin-right: auto; }
.notes button.primary { background: var(--accent); color: #fff; border: none; border-radius: 5px; padding: 0.35rem 0.8rem; }
.notes button.primary:disabled { opacity: 0.5; cursor: default; }
.note-head button, .note-form-actions button:not(.primary) { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 5px; padding: 0.3rem 0.8rem; }
.notes-section { margin: 0.6rem 0 0; font-size: 0.74rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.notes-excerpt { min-width: 0; color: var(--note-red); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-after { font-size: 0.78rem; color: var(--muted); }
.note-test { display: inline-block; margin-bottom: 0.4rem; padding: 0.1rem 0.5rem; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-size: 0.78rem; font-weight: 600; }
.note-quote { margin: 0.2rem 0 0.9rem; padding: 0.4rem 0.8rem; border-left: 3px solid var(--line); background: var(--bg); font-size: 0.9rem; max-width: 46rem; }
@media (max-width: 800px) { .notes { grid-template-columns: 1fr; } }
.panel h2 { margin: 0 0 0.6rem; font-size: 1.05rem; }
.filters { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; }
.filters input, .filters select { font: inherit; padding: 0.25rem 0.4rem; border: 1px solid var(--line); border-radius: 4px; }
.filters button, .more { border: 1px solid var(--line); background: none; border-radius: 4px; padding: 0.25rem 0.7rem; }
.more { margin-top: 0.6rem; }
.grid { border-collapse: collapse; width: 100%; font-size: 0.84rem; }
.grid th, .grid td { border-bottom: 1px solid var(--line); padding: 0.3rem 0.45rem; text-align: left; vertical-align: top; }
.grid th { background: #faf8f4; position: sticky; top: 0; }
.grid tr.own td { background: var(--accent-soft); }
.grid tr.warn td { color: var(--bad); }
.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
  .top { flex-wrap: wrap; row-gap: 0.4rem; }
  .top .brand { flex-basis: 100%; }
  .patterns-main.with-detail { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 40%); }
  .docs { flex-direction: column; }
  .toc { width: auto; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--line); }
}

.patterns { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 0.8rem; padding: 1rem;
  --viz-decision: #2a78d6; --viz-service: #eb6834; --viz-role: #1baf7a; --viz-violation: #eda100; --viz-correspondence: #4a3aa7; --viz-unlogged: #e34948; --viz-grid: #e1e0d9; --viz-axis: #898781; }
.patterns-head { flex: none; }
.patterns-head > p { margin: 0 0 0.6rem; }
.subtabs { flex: none; display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); }
.subtabs button { border: none; background: none; font: inherit; padding: 0.35rem 0.9rem; border-bottom: 2px solid transparent; color: var(--muted); }
.subtabs button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.patterns-main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 1rem; }
.patterns-main.with-detail { grid-template-columns: minmax(0, 1fr) minmax(20rem, 28rem); }
.patterns-main > .panel { min-height: 0; }
.patterns-main .detail { overflow-y: auto; }
.flag-chip { font-size: 0.95rem; font-weight: 600; }
.patterns .small { font-size: 0.8rem; }
.pattern-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
.pattern-filters select, .pattern-filters input[type='search'] { font: inherit; font-size: 0.85rem; padding: 0.25rem 0.4rem; border: 1px solid var(--line); border-radius: 4px; }
.pattern-filters input[type='search'] { min-width: 16rem; }
.legend { display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; }
.chip { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; cursor: pointer; }
.people-filter { margin-top: 0.6rem; font-size: 0.85rem; }
.people-filter summary { cursor: pointer; color: var(--link); }
.people-groups { display: inline-flex; flex-wrap: wrap; gap: 0.3rem 0.5rem; margin-left: 1rem; vertical-align: middle; }
.people-groups .chip { font: inherit; font-size: 0.82rem; padding: 0.1rem 0.7rem; cursor: pointer; }
.people-groups .chip.on { font-weight: 600; }
.people-list { display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; margin-top: 0.4rem; }
.timeline-panel { padding: 0.4rem 0.4rem 0.6rem; display: flex; }
.timeline { position: relative; overflow: auto; flex: 1; min-height: 0; }
.timeline-axis { position: sticky; top: 0; z-index: 2; background: var(--panel); }
.owners-band { fill: var(--accent-soft); }
.lane.owners .lane-name { font-size: 13px; }
.timeline svg { display: block; font-family: inherit; }
.grid-line { stroke: var(--viz-grid); stroke-width: 1; }
.lane-line { stroke: var(--line); stroke-width: 1; }
.axis-label { fill: var(--viz-axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.lane-name { fill: var(--ink); font-size: 12px; font-weight: 600; }
.lane-name.link { fill: var(--link); cursor: pointer; }
.lane-name.link:hover, .lane-name.link:focus { text-decoration: underline; outline: none; }
.lane-sub { fill: var(--muted); font-size: 11px; }
.lane-position { fill: var(--muted); font-size: 10px; }
.lane-email { fill: var(--link); font-size: 10px; }
a:hover .lane-email { text-decoration: underline; }
.lane-spend { fill: var(--ink); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; cursor: help; }
.spend-head { fill: var(--viz-axis); font-size: 11px; font-weight: 600; }
.row-label { fill: var(--viz-axis); font-size: 9px; }
.dot.decision { fill: var(--viz-decision); }
.dot.service { fill: var(--viz-service); }
.dot.role { fill: var(--viz-role); }
.dot.violation { fill: var(--viz-violation); }
.dot.correspondence { fill: var(--viz-correspondence); }
.dot.unlogged { fill: var(--viz-unlogged); }
.row-label.unlogged { fill: var(--viz-unlogged); font-weight: 600; }
.surface-ring { fill: var(--panel); }
.flag-ring { fill: none; stroke: var(--ink); stroke-width: 2; }
.mark .hit { fill: transparent; }
.mark { cursor: pointer; outline: none; }
.mark:hover .dot, .mark:focus .dot { filter: brightness(1.15); }
.mark:focus .surface-ring, .mark.selected .surface-ring { stroke: var(--ink); stroke-width: 1; }
.viz-tip { position: absolute; z-index: 5; width: 290px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); padding: 0.45rem 0.6rem; font-size: 0.8rem; pointer-events: none; }
.viz-tip .tip-value { font-weight: 600; color: var(--ink); }
.viz-tip .tip-who { color: var(--muted); margin-bottom: 0.25rem; }
.viz-tip ul { margin: 0; padding-left: 1rem; }
.detail-head { display: flex; justify-content: space-between; align-items: start; }
.detail h3 { margin: 0 0 0.3rem; font-size: 1rem; }
.event-card { border-top: 1px solid var(--line); padding: 0.6rem 0 0.4rem; }
.event-card.flagged { border-left: 3px solid var(--ink); padding-left: 0.6rem; }
.event-summary { margin: 0 0 0.4rem; }
.event-card dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 0.2rem 1rem; margin: 0 0 0.4rem; font-size: 0.82rem; }
.event-card dt { color: var(--muted); }
.event-card dd { margin: 0; }
.event-card blockquote { margin: 0.3rem 0; padding: 0.4rem 0.6rem; background: var(--quote-bg); border-radius: 4px; font-size: 0.85rem; white-space: pre-wrap; }
.badge { display: inline-block; font-size: 0.75rem; padding: 0 0.35rem; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); }
.badge.flag { color: var(--ink); border-color: var(--ink); }
.table-wrap { overflow-x: auto; }
.patterns-table td { font-size: 0.8rem; }
.table-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.table-panel > h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.table-scroll { flex: 1; min-height: 0; overflow: auto; }
.table-scroll .grid th { z-index: 1; box-shadow: inset 0 -1px 0 var(--line); }
.table-scroll .more { margin: 0.6rem 0.45rem; }
.source-link { font-size: inherit; text-align: left; }
.research-strip, .others { margin: 0.4rem 0 0.2rem; line-height: 1.6; }
.research-strip button.link, .others button.link { font-size: inherit; text-align: left; }
.chat-hint .recap-link.current { font-weight: 600; }
.chat-hint .small { margin: 0; font-size: 0.8rem; }
.chat-hint .chat-fixed { font-weight: 600; }
.chat-history { display: grid; gap: 0.4rem; font-size: 0.86rem; }
.chat-history-head { display: flex; align-items: baseline; justify-content: space-between; }
.chat-history-head button.link { font-size: 0.8rem; }
.chat-history ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.15rem; }
.chat-history li { display: flex; align-items: flex-start; border-radius: 6px; }
.chat-history li:hover, .chat-history li.current { background: var(--bg); }
.chat-history li.current { box-shadow: inset 3px 0 0 var(--accent); }
.chat-history-open { flex: 1; min-width: 0; display: grid; gap: 0.1rem; text-align: left; border: none; background: none; padding: 0.35rem 0.5rem; color: var(--ink); }
.chat-history-open:disabled { cursor: default; opacity: 0.6; }
.chat-history-title { color: var(--link); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chat-history-meta { color: var(--muted); font-size: 0.76rem; }
.chat-history-remove { border: none; background: none; color: var(--muted); font-size: 1.05rem; line-height: 1; padding: 0.45rem 0.5rem; border-radius: 4px; }
.chat-history-remove:hover:not(:disabled) { color: var(--bad); background: var(--panel); }
.chat-history-remove:disabled { opacity: 0.4; cursor: default; }
.drag-scroll { cursor: grab; }
.drag-scroll.dragging, .drag-scroll.dragging * { cursor: grabbing; user-select: none; }
.precedents h3 { margin: 0 0 0.3rem; font-size: 1rem; }
.precedents .pattern-filters { margin: 0.5rem 0; }
.patterns-table tr.clickable { cursor: pointer; }
.patterns-table tr.clickable:hover td { background: var(--bg); }
.patterns-table tr.refused td { color: var(--bad); }
.patterns-table tr.detail-row td { background: var(--bg); }

.left-tabs { display: flex; gap: 0.25rem; margin: 0.2rem 0.8rem 0.6rem; border-bottom: 1px solid var(--line); }
.left-tabs button { border: none; background: none; padding: 0.35rem 0.7rem; border-bottom: 2px solid transparent; color: var(--muted); font-size: 0.95rem; }
.left-tabs button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.star { border: none; background: none; padding: 0 0.2rem; font-size: 1.15rem; line-height: 1; color: var(--muted); cursor: pointer; }
.star:hover, .star.on { color: #c98500; }
.doc-head-actions { display: flex; align-items: center; gap: 0.4rem; flex: none !important; }
.reading-tally { font-weight: 400; color: var(--muted); font-size: 0.78rem; }
.reading-read .reading-state { color: var(--ok); font-weight: 600; }
.reading-opened .reading-state { color: var(--ink); }
.reading-read > button.link { color: var(--muted); }
.favorites { padding: 0 0.8rem 1rem 1rem; }
.favorites h3 { margin: 0.6rem 0 0.3rem; font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.favorites ul { list-style: none; margin: 0; padding: 0; }
.favorites li { display: flex; align-items: flex-start; gap: 0.3rem; margin-bottom: 0.45rem; font-size: 0.86rem; }
.favorites li button.link { text-align: left; font-size: 0.86rem; }
.toc-empty { margin: 0.5rem 1rem; font-size: 0.86rem; }
.toc-tools { display: flex; gap: 1rem; margin: 0 0.6rem 0.4rem 1rem; }
.toc-pinned { margin: 0 0.6rem 0.6rem 1rem; }
.toc-pinned .toc-doc { font-size: 1rem; font-weight: 600; padding: 0.55rem 0.8rem; border: 1px solid var(--accent); border-radius: 6px; background: var(--panel); color: var(--accent); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.toc-pinned .toc-doc:hover { background: var(--accent-soft); }
.toc-pinned .toc-doc.top, .toc-pinned .toc-doc.base { background: var(--accent-soft); color: var(--accent); }
.toc-section { margin: 0.5rem 0.4rem 0.1rem; font-size: 0.74rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

.tag-filter { margin: 0 0.8rem 0.4rem; border: 1px solid var(--line); border-radius: 6px; }
.tag-filter-head { display: flex; justify-content: space-between; align-items: baseline; width: 100%; border: none; background: none; padding: 0.4rem 0.6rem; font-weight: 600; font-size: 0.86rem; cursor: default; }
.tag-cloud { padding: 0 0.3rem; }
.tag-cloud-fold { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 280ms ease; }
.tag-cloud-fold > .tag-cloud { overflow: hidden; min-height: 0; }
.tag-filter:hover .tag-cloud-fold, .tag-filter:focus-within .tag-cloud-fold { grid-template-rows: 1fr; }
.tag-filter:hover .tag-filter-hint, .tag-filter:focus-within .tag-filter-hint { visibility: hidden; }
.tag-filter-hint { font-weight: 400; font-size: 0.76rem; }
@media (prefers-reduced-motion: reduce) { .tag-cloud-fold { transition: none; } }
.tag-cloud svg { width: 100%; height: auto; display: block; margin-bottom: 0.3rem; }
.tag-word { fill: var(--ink); cursor: pointer; outline: none; }
.tag-word:hover, .tag-word:focus { fill: var(--link); }
.tag-word.on { fill: var(--accent); }
.tag-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; padding: 0 0.6rem 0.5rem; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 0.05rem 0.55rem; font-size: 0.78rem; color: var(--ink); }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip.label, .chip.label:hover { cursor: default; border-color: var(--line); }

.doc-summary { font-size: 0.86rem; margin-top: 0.3rem; }
.doc-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.4rem; }
.doc-bar { position: relative; min-height: 2.5rem; border-bottom: 1px solid var(--line); }
.see-also { padding: 0.4rem 1rem; font-size: 0.86rem; }
.see-also summary { cursor: pointer; font-weight: 600; color: var(--accent); line-height: 1.7rem; }
.see-also ul { list-style: none; margin: 0.4rem 0 0.2rem; padding: 0; display: grid; gap: 0.45rem; }
.see-also button.link { font-size: 0.86rem; text-align: left; }
.see-also-why { color: var(--ink); font-size: 0.82rem; }
.passage-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.3rem 1rem; background: var(--quote-bg); border-bottom: 1px solid var(--line); font-size: 0.84rem; }
.passage-nav { display: flex; gap: 0.25rem; }
.passage-nav button, .tour-nav { border: 1px solid var(--line); background: var(--panel); border-radius: 4px; width: 1.8rem; line-height: 1.4; }
.passage-nav button:disabled, .tour-nav:disabled { opacity: 0.4; cursor: default; }
.html-doc mark.hl { background: var(--hl); color: inherit; }
mark.find { background: var(--find); color: inherit; border-radius: 2px; }
mark.find.current { background: var(--find-current); }
.impersonating { background: var(--note-red); color: #fff; border-radius: 4px; padding: 0.15rem 0.5rem; font-size: 0.8rem; font-weight: 600; }
.annotated.editable { position: relative; padding-left: 2.2rem; }
.annot-gutter { position: absolute; left: 0; top: 0; bottom: 0; width: 1.6rem; cursor: pointer; border-right: 1px dashed var(--line); }
.annot-gutter:hover { background: rgba(198, 40, 40, 0.05); }
.annot-gutter.busy { cursor: default; }
.annot-gutter.busy:hover { background: none; }
.annot-span { position: absolute; right: -1px; width: 3px; background: rgba(198, 40, 40, 0.35); border-radius: 2px; pointer-events: none; }
.annot-plus { position: absolute; left: 0.1rem; width: 1.3rem; height: 1.3rem; border-radius: 50%; background: var(--note-red); color: #fff; display: grid; place-items: center; font-weight: 700; line-height: 1; pointer-events: none; }
.annot { margin: 0.35rem 0 0.8rem; padding: 0.1rem 0 0.1rem 0.7rem; border-left: 3px solid var(--note-red); }
.annot-text { color: var(--note-red); font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.annotated.editable .annot-text { cursor: text; }
.annot-meta { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: baseline; font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }
.annot-meta button.link { font-size: 0.75rem; }
.annot-editor textarea { display: block; width: 100%; box-sizing: border-box; color: var(--note-red); font: inherit; font-weight: 600; line-height: inherit; border: 1px solid var(--note-red); border-radius: 4px; padding: 0.3rem 0.45rem; resize: none; overflow: hidden; background: var(--panel); }
.annot-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.3rem; font-size: 0.8rem; }
.annot-actions button { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 4px; padding: 0.15rem 0.6rem; font-size: 0.8rem; }
.annot-actions .annot-save { background: var(--note-red); border-color: var(--note-red); color: #fff; }
.annot-actions button:disabled { opacity: 0.5; cursor: default; }
.annot-hint { color: var(--muted); }
.annot-actions .annot-delete { margin-left: auto; color: var(--note-red); border-color: var(--note-red); }
.annot-orphans-head { font-size: 0.8rem; color: var(--muted); margin-top: 1rem; }
@container (max-width: 560px) { .doc-find { position: static !important; margin: 0 1rem 0.45rem; } .doc-find input { flex: 1; width: auto; min-width: 0; } }
.doc-find { position: absolute; top: 0.3rem; right: 1rem; display: flex; align-items: center; gap: 0.1rem; border: 1px solid var(--line); border-radius: 6px; padding: 0 0.15rem 0 0.5rem; background: var(--panel); }
.doc-find:focus-within { border-color: var(--accent); }
.doc-find input { border: none; outline: none; background: none; font: inherit; font-size: 0.85rem; width: 11rem; padding: 0.3rem 0; color: var(--ink); }
.doc-find-count { font-size: 0.76rem; color: var(--muted); min-width: 4.8rem; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.doc-find button { border: none; background: none; width: 1.5rem; font-size: 1.05rem; line-height: 1.3; border-radius: 4px; color: var(--ink); }
.doc-find button:hover:not(:disabled) { background: var(--bg); }
.doc-find button:disabled { opacity: 0.35; cursor: default; }
.find-note { padding: 0.3rem 1rem; background: var(--accent-soft); border-bottom: 1px solid var(--line); font-size: 0.84rem; }

.tour-bar { background: var(--panel); border: 1px solid var(--accent); border-radius: 6px; padding: 0.45rem 0.8rem; margin-bottom: 0.5rem; font-size: 0.86rem; }
.tour-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.tour-name { font-weight: 600; color: var(--accent); margin-right: auto; }
.tour-row select { max-width: 22rem; font: inherit; }
.tour-note summary, .tour-related summary { cursor: pointer; font-weight: 600; margin-top: 0.3rem; }
.tour-note p { margin: 0.25rem 0 0.1rem; }
.tour-related ul { list-style: none; margin: 0.3rem 0 0; padding: 0; display: grid; gap: 0.3rem; }

.chat { position: relative; width: min(var(--chat-width, 400px), max(300px, 30vw)); flex: none; display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--line); }
.chat-resize { position: absolute; top: 0; bottom: 0; left: -4px; width: 8px; cursor: col-resize; z-index: 3; touch-action: none; }
.chat-resize:hover, .chat-resize:active { background: var(--accent-soft); box-shadow: inset 4px 0 0 -3px var(--accent); }
.chat-head { display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.chat-head strong { margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.chat-log { flex: 1; overflow-y: auto; padding: 0.6rem 0.8rem; display: grid; align-content: start; gap: 0.7rem; }
.chat-hint { display: grid; gap: 0.4rem; justify-items: start; font-size: 0.86rem; }
.chat-hint button.link { text-align: left; font-size: 0.86rem; }
.chat-hint h4, .chat-history h4 { margin: 0.5rem 0 0; font-size: 0.74rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.chat-msg { font-size: 0.88rem; line-height: 1.5; }
.chat-msg.user { justify-self: end; max-width: 85%; background: var(--accent-soft); border-radius: 8px; padding: 0.35rem 0.7rem; }
.chat-msg.user p { margin: 0; white-space: pre-wrap; }
.chat-text p { margin: 0 0 0.5rem; }
.chat-text ul, .chat-text ol { margin: 0 0 0.5rem; padding-left: 1.2rem; }
.chat-table-wrap { overflow-x: auto; margin: 0 0 0.5rem; }
.chat-table { border-collapse: collapse; font-size: 0.84rem; }
.chat-table th, .chat-table td { border-bottom: 1px solid var(--line); padding: 0.2rem 0.6rem 0.2rem 0; text-align: left; vertical-align: top; }
.chat-table th { font-weight: 600; }
.chat-status { color: var(--muted); font-style: italic; margin: 0.2rem 0; }
.chat-prepared { color: var(--muted); font-size: 0.76rem; margin: 0.2rem 0 0; }
.cite { border: 1px solid var(--line); background: var(--quote-bg); border-radius: 4px; padding: 0 0.35rem; margin: 0 0.15rem; font-size: 0.76rem; color: var(--link); vertical-align: baseline; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }
.cite:hover { border-color: var(--accent); }
.chat-input { display: flex; gap: 0.5rem; padding: 0.6rem 0.8rem; border-top: 1px solid var(--line); }
.chat-input textarea { flex: 1; resize: vertical; font: inherit; font-size: 0.88rem; padding: 0.4rem; border: 1px solid var(--line); border-radius: 5px; }
.chat-input button { align-self: flex-end; border: 1px solid var(--accent); background: var(--accent); color: var(--panel); border-radius: 5px; padding: 0.35rem 0.9rem; }
.chat-input button:disabled { opacity: 0.5; cursor: default; }
.chat-answer { white-space: pre-wrap; font: inherit; margin: 0.3rem 0; }
@media (max-width: 900px) {
  .chat { width: auto; height: 55vh; border-left: none; border-top: 1px solid var(--line); }
  .chat-resize { display: none; }
}
.crashed { display: grid; place-items: center; align-content: center; gap: 0.8rem; height: 100%; color: var(--muted); }
.crashed button { border: 1px solid var(--line); background: var(--panel); border-radius: 5px; padding: 0.3rem 0.9rem; }
.icon-button { display: inline-flex; align-items: center; gap: 0.3rem; border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 4px; padding: 0.15rem 0.35rem; font-size: 0.78rem; }
.icon-button:hover:not(:disabled) { color: var(--ink); border-color: var(--accent); }
.icon-button:disabled { opacity: 0.4; cursor: default; }

/* Coverage map */
.coverage-glyph { display: inline-flex; align-items: center; gap: 0.35rem; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 0.15rem 0.6rem 0.15rem 0.35rem; font-size: 0.82rem; color: var(--ink); }
.coverage-glyph:hover, .coverage-glyph.on { border-color: var(--accent); background: var(--accent-soft); }
.glyph-ring { fill: #f0efec; stroke: #8f8d86; stroke-width: 1; }
.glyph-fill { fill: #2a78d6; }
.coverage-panel { position: fixed; top: 52px; right: 12px; z-index: 50; width: min(820px, calc(100vw - 24px)); height: min(600px, calc(100vh - 70px)); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18); transform-origin: top right; animation: coverage-open 200ms ease-out; }
@keyframes coverage-open { from { opacity: 0; transform: scale(0.15); } to { opacity: 1; transform: scale(1); } }
.coverage-panel-head { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0.8rem; border-bottom: 1px solid var(--line); }
.coverage-panel .topic-map { flex: 1; min-height: 0; }
.topic-map { display: grid; grid-template-columns: minmax(0, 1fr) 250px; }
.topic-map-plot { display: flex; flex-direction: column; min-height: 0; padding: 0.4rem 0.6rem; }
.topic-map-plot svg { flex: 1; min-height: 0; width: 100%; height: 100%; }
.topic-crumb { font-size: 0.85rem; color: var(--muted); }
.topic-crumb button.link { font-size: inherit; }
.map-enter { transform-origin: 260px 230px; animation: map-zoom 220ms ease-out; }
@keyframes map-zoom { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: scale(1); } }
.map-node { cursor: pointer; outline: none; }
.node-ring { fill: none; stroke: transparent; stroke-width: 2; }
.node-base { fill: var(--panel); }
.map-node.on .node-ring, .map-node:focus .node-ring { stroke: var(--ink); }
.slice-art { pointer-events: none; transition: transform 140ms ease-out; }
.slice-empty { fill: #f0efec; stroke: #a8a59d; stroke-width: 1; stroke-opacity: 0.55; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.slice-art.on .slice-empty { stroke-opacity: 1; }
.slice-fill { fill: #2a78d6; }
.slice-hit { fill: transparent; pointer-events: all; }
.node-label { fill: var(--ink); font-size: 12px; font-weight: 600; pointer-events: none; paint-order: stroke; stroke: var(--panel); stroke-width: 3px; stroke-linejoin: round; }
.node-share { fill: var(--muted); font-size: 11px; pointer-events: none; paint-order: stroke; stroke: var(--panel); stroke-width: 3px; stroke-linejoin: round; }
.map-edge line { stroke: #cfccc4; stroke-linecap: round; }
.map-edge.crossed line { stroke: #52514e; }
.map-edge.on line:not(.hit) { stroke: var(--accent); }
.map-edge line.hit, .map-stub line.hit { stroke: transparent; stroke-width: 14; cursor: pointer; }
.map-stub line { stroke: #bdbab2; stroke-width: 1.5; stroke-dasharray: 3 3; }
.map-legend { display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; font-size: 0.78rem; color: var(--muted); }
.map-legend > span { display: inline-flex; align-items: center; gap: 0.3rem; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }
.legend-line { display: inline-block; width: 18px; height: 3px; border-radius: 2px; background: #cfccc4; }
.legend-line.crossed { background: #52514e; }
.topic-pane { border-left: 1px solid var(--line); padding: 0.6rem 0.8rem; overflow-y: auto; font-size: 0.84rem; }
.topic-pane h3 { margin: 0 0 0.4rem; font-size: 0.95rem; }
.topic-pane p { margin: 0 0 0.5rem; }
.topic-pane button.link { font-size: 0.84rem; font-weight: 600; }
.pane-slices, .pane-docs { margin: 0 0 0.5rem; padding-left: 1rem; }
.pane-slices { list-style: none; padding-left: 0; }
.pane-slices li { display: flex; align-items: center; gap: 0.35rem; }
.pane-slices li.on { font-weight: 600; }
.topic-pane button.link { display: block; text-align: left; margin-top: 0.2rem; }
.reading-list { margin: 0 0.8rem 0.6rem; border: 1px solid var(--accent); border-radius: 6px; background: var(--panel); max-height: 45vh; display: flex; flex-direction: column; }
.reading-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line); font-size: 0.86rem; }
.reading-list ol { margin: 0; padding: 0.3rem 0.6rem 0.4rem 1.8rem; overflow-y: auto; font-size: 0.84rem; }
.reading-list li { margin-bottom: 0.35rem; }
.reading-list button.link { text-align: left; font-size: 0.84rem; }
.reading-meta { color: var(--muted); font-size: 0.76rem; }
.reading-summary { font-size: 0.78rem; }
.admin-map { height: 560px; border: 1px solid var(--line); border-radius: 6px; margin: 0.6rem 0; display: flex; }
.admin-map .topic-map { flex: 1; }
.engagement-tables { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 1rem; }
.engagement-tables h3 { font-size: 0.95rem; margin: 0.8rem 0 0.3rem; }
.engagement-questions { margin: 0; padding-left: 1rem; font-size: 0.84rem; }
.mode-pills { display: inline-flex; gap: 0.4rem; }
.mode-pills .chip { font: inherit; font-size: 0.82rem; padding: 0.1rem 0.7rem; cursor: pointer; }
.mode-pills .chip.on { font-weight: 600; }
@media (prefers-reduced-motion: reduce) { .coverage-panel, .map-enter { animation: none; } .slice-art { transition: none; } }
@media (max-width: 700px) {
  .coverage-panel { inset: 0; width: auto; height: auto; border-radius: 0; }
  .topic-map { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .topic-pane { border-left: none; border-top: 1px solid var(--line); max-height: 35vh; }
  .engagement-tables { grid-template-columns: 1fr; }
}
