:root {
	--bg: #fafaf9;
	--panel: #ffffff;
	--fg: #1c1917;
	--muted: #78716c;
	--border: #e7e5e4;
	--hover: #f5f5f4;
	--grid: #eeeceb;
	--fix: #2563eb;
	--rich: #d97706;
	--context: #a8a29e;
	--mark: rgba(37, 99, 235, 0.14);
	--term: #dc2626;
	--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font: 14px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
	color: var(--fg);
	background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }
h2, h3, p { margin: 0; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
a { color: var(--fix); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12px; }

.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.brand { display: flex; align-items: baseline; gap: 10px; flex: 1; min-width: 0; flex-wrap: wrap; }
.brand strong { font-size: 15px; }

.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.badge.warn { background: #fef3c7; border-color: #fcd34d; color: #92400e; }
.btn { border: 1px solid var(--fg); background: var(--fg); color: #fff; border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 13px; }
.btn.outline { background: var(--panel); color: var(--fg); border-color: var(--border); }
.btn.outline:hover, .btn.outline[aria-expanded='true'] { background: var(--hover); }
.btn.sm { padding: 2px 8px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.layout { flex: 1; display: grid; grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); min-height: 0; }
.layout.with-sql { grid-template-columns: minmax(300px, 360px) minmax(0, 1fr) minmax(300px, 420px); }
/* Below 1440 px the SQL panel is a drawer over the topic, so the topic keeps its width. */
@media (max-width: 1439px) {
	.layout.with-sql { grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); }
	.sql { position: fixed; top: 49px; right: 0; bottom: 0; width: min(460px, 100vw); max-height: none; box-shadow: -6px 0 24px rgba(0, 0, 0, 0.15); z-index: 5; }
}
.narrow-only { display: none; }
.pane { min-width: 0; overflow: auto; max-height: calc(100vh - 49px); }
.queue { border-right: 1px solid var(--border); background: var(--panel); }
.topic { padding: 16px 20px 32px; }
.sql { border-left: 1px solid var(--border); background: var(--panel); padding: 12px 14px; }
@media (max-width: 900px) {
	.layout, .layout.with-sql { grid-template-columns: minmax(0, 1fr); }
	.pane { max-height: none; }
	/* One pane at a time: the topic, or the queue after "All topics"; the page scrolls, not an inner box. */
	.queue { border-right: 0; border-bottom: 1px solid var(--border); }
	.layout:not(.queue-open) .queue, .layout.queue-open .topic { display: none; }
	.narrow-only { display: inline-block; margin-bottom: 8px; }
	.sql { top: 0; }
}

.pane-head { padding: 12px 14px 10px; border-bottom: 1px solid var(--border); display: grid; gap: 8px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed='true'] { background: var(--fg); color: #fff; }
input[type='search'] { font: inherit; font-size: 13px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; width: 100%; }

.rows { list-style: none; margin: 0; padding: 0; }
.rows a { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 9px 14px; color: inherit; border-bottom: 1px solid var(--border); text-decoration: none; }
.rows a:hover { background: var(--hover); }
.rows a[aria-current='true'] { background: #eff6ff; box-shadow: inset 3px 0 0 var(--fix); }
.rows .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .score { font-weight: 600; }
.rows .meta { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.bar { position: relative; width: 70px; height: 6px; background: var(--grid); border-radius: 2px; overflow: hidden; flex: none; }
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--fix); }
.lang { font-size: 11px; font-weight: 600; letter-spacing: 0.02em; color: var(--muted); }

.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 1px 7px; border-radius: 4px; background: var(--hover); white-space: nowrap; }
.chip::before { content: ''; width: 7px; height: 7px; border-radius: 2px; background: var(--c, var(--context)); }
.t-coverage { --c: #64748b; }
.t-missing_fact { --c: #0891b2; }
.t-contradiction { --c: #dc2626; }
.t-framing { --c: #9333ea; }
.t-numbers { --c: #d97706; }
.s-covered { --c: var(--context); }
.s-partly { --c: var(--rich); }
.s-missing { --c: var(--fix); }

.topic-head { display: grid; gap: 4px; margin-bottom: 12px; }
.topic-head h2 { font-size: 20px; }
.facts { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs a { padding: 6px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--fg); text-decoration: none; }
.tabs a[aria-current='true'] { color: var(--fg); border-color: var(--fg); font-weight: 500; }

.leads { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
@media (max-width: 1100px) { .leads { grid-template-columns: minmax(0, 1fr); } }
.lead { display: grid; gap: 4px; align-content: start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.lead.fix { border-color: var(--fix); }
.lead p { text-wrap: pretty; }
.label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
mark.term { background: none; color: var(--term); font-weight: 600; box-shadow: inset 0 -2px 0 var(--term); }

.findings { display: grid; gap: 10px; }
.finding { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--panel); display: grid; gap: 8px; }
.finding.reviewed, .finding.closed { opacity: 0.6; }
.finding .row { display: flex; row-gap: 6px; align-items: center; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; }
.finding .actions { padding-top: 8px; border-top: 1px solid var(--border); }
.suggestion { font-size: 13px; color: var(--muted); text-wrap: pretty; }
.suggestion .label { margin-right: 4px; font-size: 10px; border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; }
.cite { font-size: 12px; color: var(--muted); margin-top: 2px; }
.cite.none { color: var(--term); }
input.rev { font: inherit; font-size: 13px; padding: 2px 8px; border: 1px solid var(--border); border-radius: 6px; min-width: 260px; flex: 1; }
.quotes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 700px) { .quotes { grid-template-columns: minmax(0, 1fr); } }
.quote { border-left: 3px solid var(--border); padding: 2px 0 2px 8px; font-size: 13px; text-wrap: pretty; }
.quote.fix { border-color: var(--fix); }
.quote.rich { border-color: var(--rich); }
details.more > summary { cursor: pointer; color: var(--muted); font-size: 13px; margin: 14px 0 8px; }

.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.controls select { font: inherit; font-size: 13px; padding: 2px 6px; border: 1px solid var(--border); border-radius: 6px; }
.note { font-size: 12px; color: #92400e; background: #fffbeb; border: 1px solid #fde68a; border-radius: 6px; padding: 6px 10px; margin-bottom: 12px; }
.align { width: 100%; border-collapse: collapse; table-layout: fixed; }
.align th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); }
.align td { vertical-align: top; padding: 8px; border-bottom: 1px solid var(--border); font-size: 13px; }
.align tr.sec td { background: var(--hover); font-size: 12px; font-weight: 600; padding: 5px 8px; }
.align td.st { width: 120px; }
.align .none { color: var(--muted); font-style: italic; }
.clip { white-space: pre-line; cursor: pointer; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; text-wrap: pretty; }
.clip.open { display: block; }
.lead .lead-text { -webkit-line-clamp: 8; }
.dist { font-family: var(--mono); font-size: 11px; color: var(--muted); }

.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .yr { cursor: pointer; fill: transparent; }
.chart .yr:hover { fill: rgba(0, 0, 0, 0.04); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); flex-wrap: wrap; margin: 2px 0 10px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.events { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 0; }
.events li { display: grid; grid-template-columns: 150px 64px minmax(0, 1fr); gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); font-size: 13px; }
.events .kind-closed { color: #15803d; }
.events .kind-opened { color: var(--term); }
.events .kind-reviewed { color: var(--fix); }
.section-title { margin: 18px 0 6px; }

.sqlhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.q { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; overflow: hidden; }
.q header { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; background: var(--hover); font-size: 12px; }
.q pre { margin: 0; padding: 8px 10px; font-family: var(--mono); font-size: 11.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.q .kw { color: #7c3aed; font-weight: 600; }
.q .cm { color: var(--muted); font-style: italic; }
.q .st { color: #b45309; }
.empty { padding: 24px; color: var(--muted); }
.error { color: var(--term); }

.rows .meta.why { color: var(--fg); opacity: 0.75; }
.more-rows { padding: 10px 14px; }
.s-pending { --c: var(--grid); }
.legend-line { margin-bottom: 10px; }

/* Phones: more queue rows, readable chart labels, passages stacked instead of three narrow columns */
@media (max-width: 600px) {
	.chart text { font-size: 20px; }
	.align thead { display: none; }
	.align, .align tbody, .align tr, .align td { display: block; width: auto; }
	.align tr:not(.sec) { padding: 6px 0; border-bottom: 1px solid var(--border); }
	.align td { border: 0; padding: 4px 8px; }
	.align td.st { width: auto; display: flex; gap: 8px; align-items: center; }
	.events li { grid-template-columns: 1fr; gap: 2px; }
}
.more-type { justify-self: start; margin: -2px 0 6px; }
.features { color: var(--muted); margin: 4px 0 10px; }
.sql .features { margin: 0 0 4px; color: var(--term); }
.linkbtn { border: 0; background: none; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; }
.saved { color: #15803d; font-weight: 600; }
.events a, .quote a.small { white-space: nowrap; }
