:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c2330;
  --muted: #5d6676;
  --line: #e2e5ea;
  --accent: #0f6e6e;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1f0;
  --error: #b42318;
  --error-soft: #fdecea;
  --warning: #9a5b00;
  --warning-soft: #fff4e0;
  --assumption: #1d4f91;
  --assumption-soft: #e8f0fb;
  --ok: #1f7a3d;
  --bar: #9ccfcb;
  --moved: #c026d3;
  --c-exact: #008f84;
  --c-marked: #b06d00;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1318;
    --card: #171c23;
    --text: #e6e9ee;
    --muted: #98a1b0;
    --line: #2a313b;
    --accent: #3fb7ad;
    --accent-ink: #06201e;
    --accent-soft: #15302e;
    --error: #ff8a80;
    --error-soft: #3a1714;
    --warning: #ffc266;
    --warning-soft: #33260f;
    --assumption: #8ab4f8;
    --assumption-soft: #16243a;
    --ok: #6fd08c;
    --bar: #2f6f6a;
    --moved: #e879f9;
    --c-exact: #22a094;
    --c-marked: #bf7f12;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; max-width: 46em; }
.title-row { display: flex; align-items: center; gap: 8px; }
.about-btn {
  width: 20px; height: 20px; padding: 0; border-radius: 50%; border: 1.5px solid var(--accent);
  color: var(--accent); background: none; font: italic 700 12px/17px Georgia, serif;
}
.about-btn:hover { background: var(--accent); color: var(--accent-ink); }

.progress { height: 4px; margin-top: 8px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width 0.2s linear; }
.progress.done span { transition: width 0.25s ease-out; }
.panel-card.busy #panel { opacity: 0.5; pointer-events: none; transition: opacity 0.2s; }

.about {
  width: min(760px, calc(100% - 32px)); max-height: 86vh; padding: 0 28px 24px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text);
  font-size: 14.5px; line-height: 1.55;
}
.about::backdrop { background: rgba(10, 14, 20, 0.5); }
.about-head {
  position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center;
  background: var(--card); padding: 20px 0 8px; border-bottom: 1px solid var(--line);
}
.about-head h2 { margin: 0; font-size: 19px; }
.about .lead { font-size: 15.5px; margin: 14px 0 4px; }
.about h3 { margin-top: 20px; }
.about p, .about li { margin: 6px 0; }
.about ol, .about ul { padding-left: 20px; margin: 6px 0; }
.about .legend { list-style: none; padding: 0; }
.about .legend .fstate { margin-right: 6px; }
.swatch { display: inline-block; width: 26px; height: 14px; margin-right: 8px; vertical-align: -2px; border-radius: 4px; }
.swatch.moved { outline: 2px solid var(--moved); outline-offset: -2px; }
.about .two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.about .brief li { margin-bottom: 6px; }
.rchart { margin: 10px 0; font-size: 12.5px; }
.rlegend { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); margin-bottom: 8px; }
.rlegend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.rlegend i.exact, .rbar .exact { background: var(--c-exact); }
.rlegend i.marked, .rbar .marked { background: var(--c-marked); }
.rlegend i.unmarked { background: var(--error); }
.rrow { display: grid; grid-template-columns: 11.5em 1fr 6.5em; gap: 10px; align-items: center; padding: 3px 0; }
.rname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rbar { display: flex; gap: 2px; height: 12px; }
.rbar span:first-child { border-radius: 4px 0 0 4px; }
.rbar span:last-child { border-radius: 0 4px 4px 0; }
.rnum { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.rnum b { color: var(--text); }
@media (max-width: 560px) {
  .about { padding: 0 16px 18px; }
  .about .two { grid-template-columns: 1fr; }
  .rrow { grid-template-columns: 1fr 5.5em; }
  .rbar { grid-column: 1 / -1; grid-row: 2; }
}

.logo {
  width: 34px; height: 34px; border-radius: 9px;
  background:
    radial-gradient(circle at 38% 38%, transparent 8px, var(--accent-ink) 8.5px, var(--accent-ink) 10.5px, transparent 11px),
    var(--accent);
  position: relative;
}
.logo::after {
  content: ""; position: absolute; width: 9px; height: 3px; background: var(--accent-ink);
  right: 6px; bottom: 9px; transform: rotate(45deg); border-radius: 2px;
}

.status {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px;
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.ok .dot { background: var(--ok); }
.status.down .dot { background: var(--error); }

main {
  display: grid;
  grid-template-columns: minmax(380px, 460px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  padding: 20px 24px 40px;
  max-width: 1500px;
  margin: 0 auto;
}

.panel-card {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding-bottom: 8px;
}
.panel-card > .hint { margin: -4px 0 4px; }

@media (max-width: 1000px) {
  main { grid-template-columns: 1fr; }
  .panel-card { position: static; max-height: none; order: 1; }
}

@media (max-width: 700px) {
  main { padding: 16px; }
  .top { padding: 14px 16px; }
}

.col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
}

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 16px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

.label { display: block; font-weight: 600; margin-bottom: 8px; }

textarea, input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
textarea { resize: vertical; min-height: 72px; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.big { padding: 10px 20px; }
button.ghost { border-style: dashed; color: var(--muted); margin-top: 8px; }
button.icon { padding: 6px 10px; color: var(--muted); }
button.small { padding: 4px 10px; font-size: 13px; }
button.link { border: 0; background: none; padding: 0 2px; font-size: 12px; color: var(--accent); }
button.link:hover { text-decoration: underline; }
.group summary .link { opacity: 0; }
.group summary:hover .link, .group summary .link:focus-visible { opacity: 1; }

.actions, .run-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.run-row { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.hint { color: var(--muted); font-size: 13px; }

.examples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.request-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.request-head .label { flex: 1; margin: 0; }
.langs { display: inline-flex; gap: 6px; align-self: center; }
.flag { padding: 2px; line-height: 0; border-radius: 4px; border: 2px solid transparent; background: none; opacity: 0.55; }
.flag svg { width: 24px; height: 16px; border-radius: 2px; box-shadow: 0 0 0 1px var(--line); }
.flag[aria-pressed="true"] { opacity: 1; border-color: var(--accent); }
.flag:hover:not(:disabled) { opacity: 1; }
.chip {
  font-size: 12.5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid transparent;
  color: var(--text);
}

.note { background: var(--bg); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; font-size: 13.5px; }

.psec h3 { margin: 18px 0 2px; }
.facet { border-top: 1px solid var(--line); padding: 8px 6px; margin: 0 -6px; border-radius: 8px; transition: background 0.15s; }
.psec h3 + .facet { border-top: 0; }
.facet.hot { background: var(--bg); }
.facet.moved { outline: 2px solid var(--moved); outline-offset: -2px; animation: moved 1.2s ease-out 1; }
@keyframes moved { 0% { background: color-mix(in srgb, var(--moved) 22%, transparent); } 100% { background: transparent; } }
.facet-head { display: flex; align-items: center; gap: 8px; min-height: 28px; }
.facet-name { flex: 1; font-weight: 600; font-size: 14px; }
.facet-name::first-letter { text-transform: uppercase; }
.facet:not(.set) .facet-name { font-weight: 500; }
.facet .clear { padding: 0 7px; font-size: 12px; line-height: 20px; visibility: hidden; }
.facet.set .clear { visibility: visible; }
.fstate { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.fstate.any { color: var(--muted); font-weight: 500; }
.fstate.ok { background: var(--accent-soft); color: var(--accent); }
.fstate.hand { background: var(--bg); color: var(--text); }
.fstate.assumed { background: var(--assumption-soft); color: var(--assumption); }
.fstate.check, .fstate.missing { background: var(--warning-soft); color: var(--warning); }
.fstate.fix { background: var(--error-soft); color: var(--error); }
.facet-body { margin-top: 4px; }
.facet .from:empty { display: none; }
.facet.has-error { background: var(--error-soft); }

select.mini { width: auto; padding: 3px 6px; font-size: 12.5px; border-radius: 6px; }
.range-w { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.range-w input { width: 7.2em; padding: 5px 8px; font-size: 13.5px; }
.range-w input[type="date"] { width: 10.5em; }
.range-w .to, .range-w .unit { color: var(--muted); font-size: 12.5px; }

.picks { display: flex; flex-wrap: wrap; gap: 5px; }
.pick {
  font-size: 12.5px; padding: 3px 9px; border-radius: 999px;
  background: var(--card); color: var(--text); border: 1px solid var(--line);
}
.pick[aria-pressed="true"], .pick[data-s="has"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pick[data-s="has"]::before { content: "\2713\00a0"; }
.pick[data-s="not"], .facet.neg .pick[aria-pressed="true"] {
  background: var(--error-soft); color: var(--error); border-color: var(--error); text-decoration: line-through;
}
.pick.tri::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; border: 1px solid rgba(0, 0, 0, 0.25); }
.tri-1::before { background: #d92d20; }
.tri-2::before { background: #f79009; }
.tri-3::before { background: #53b1fd; }
.tri-4::before { background: #12b76a; }
.tri-5::before { background: #ffffff; }

.group { margin-top: 2px; }
.group summary { display: flex; align-items: baseline; gap: 8px; cursor: pointer; padding: 3px 0; font-size: 13px; list-style: none; }
.group summary::-webkit-details-marker { display: none; }
.group summary::before {
  content: ""; width: 5px; height: 5px; flex: none; align-self: center; margin: 0 3px 0 2px;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg);
}
.group[open] summary::before { transform: rotate(45deg); margin-top: -3px; }
.group-name { flex: 1; }
.group .icd { color: var(--muted); font-size: 11.5px; margin-left: 4px; }
.group .count { color: var(--accent); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.group .picks { padding: 2px 0 6px 16px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 2px 8px; font-size: 12px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.clause { border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin-top: 6px; background: var(--card); }
.clause-fields { display: grid; grid-template-columns: minmax(8em, 0.8fr) 2fr auto; gap: 8px; align-items: center; }
.clause-fields.wide { grid-template-columns: 1fr 0.8fr 1.6fr auto; }
.clause-fields code { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; grid-column: 1 / -2; }
.range { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
.facet.rows .hint { margin: 2px 0 0; }
@media (max-width: 560px) {
  .clause-fields, .clause-fields.wide { grid-template-columns: 1fr auto; grid-auto-flow: dense; }
  .clause-fields > input, .clause-fields > .range, .clause-fields > select[data-f="value"] { grid-column: 1 / -1; }
}
.from { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.from.none { color: var(--assumption); font-style: italic; }

.issue {
  display: flex; gap: 8px; align-items: flex-start;
  font-size: 13.5px;
  border-radius: 8px;
  padding: 7px 10px;
  margin-top: 6px;
}
.issue { position: relative; }
.issue .tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; padding-top: 1px; cursor: help; }
.issue .tag::after {
  content: "i"; display: inline-block; width: 13px; height: 13px; margin-left: 4px; border-radius: 50%;
  border: 1px solid currentColor; font: italic 700 9px/12px Georgia, serif; text-align: center; text-transform: none; vertical-align: 1px;
}
.issue .tag:hover::before, .issue .tag:focus::before {
  content: attr(data-help); position: absolute; left: 8px; right: 8px; top: calc(100% + 4px); z-index: 5;
  background: var(--text); color: var(--card); padding: 7px 10px; border-radius: 8px;
  font-size: 12.5px; font-weight: 500; letter-spacing: 0; text-transform: none; white-space: normal; line-height: 1.4;
}
.issue .tag:focus { outline: none; }
.issue.error { background: var(--error-soft); color: var(--error); }
.issue.warning { background: var(--warning-soft); color: var(--warning); }
.issue.assumption { background: var(--assumption-soft); color: var(--assumption); }
.issue .msg { color: var(--text); }

#read-card > h3:first-child { margin-top: 0; }
h3 .aside { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 6px; }
.echo { font-size: 14.5px; background: var(--bg); border-radius: 8px; padding: 8px 12px; margin: 0 0 8px; }
.echo mark { background: var(--accent-soft); color: inherit; border-radius: 3px; box-shadow: inset 0 -2px 0 var(--bar); }
.echo mark.hot { background: var(--bar); }
.reading { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.reading li { display: grid; grid-template-columns: minmax(7em, 1fr) 2fr; gap: 10px; padding: 3px 6px; border-radius: 6px; }
.reading li.hot { background: var(--bg); }
.reading .from { overflow-wrap: anywhere; }
.li-issues { grid-column: 1 / -1; margin-bottom: 4px; }
.reading .to::before { content: "\2192\00a0"; color: var(--muted); }
.reading .unsourced .from { color: var(--assumption); font-style: italic; }
.reading .byhand .from { font-style: italic; }
.expansions { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.expansions:empty { display: none; }
.expansions li { margin-bottom: 4px; }

#sql.blocked { color: var(--muted); font-family: inherit; font-style: italic; }
.help { margin-top: 14px; font-size: 13px; }
.help summary { cursor: pointer; color: var(--muted); }
.checks { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 5px; }
.checks li { display: grid; grid-template-columns: 7.5em 1fr; gap: 10px; align-items: baseline; }
.pill { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 8px; border-radius: 999px; text-align: center; }
.pill.error { background: var(--error-soft); color: var(--error); }
.pill.warning { background: var(--warning-soft); color: var(--warning); }
.pill.assumption { background: var(--assumption-soft); color: var(--assumption); }
pre { font-family: var(--mono); font-size: 12.5px; background: var(--bg); border-radius: 8px; padding: 10px; overflow-x: auto; margin: 8px 0 0; white-space: pre-wrap; }

.count-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.count { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.badge { font-size: 12px; background: var(--assumption-soft); color: var(--assumption); padding: 4px 10px; border-radius: 999px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

.bars { display: flex; flex-direction: column; gap: 4px; }
.bar { display: grid; grid-template-columns: minmax(6em, 11em) 1fr 3.8em; gap: 8px; align-items: center; font-size: 12.5px; }
.bar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .track { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; }
.bar .fill { display: block; height: 100%; background: var(--bar); border-radius: 5px; }
.bar .n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.funnel { display: flex; flex-direction: column; gap: 5px; }
.step { display: grid; grid-template-columns: minmax(8em, 16em) 1fr 5.5em 7.5em; gap: 8px; align-items: center; font-size: 12.5px; }
.step .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step .track { height: 12px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.step .fill { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.step .n { text-align: right; font-variant-numeric: tabular-nums; }
.step .cut { color: var(--muted); font-variant-numeric: tabular-nums; }
.step .flag { color: var(--warning); font-weight: 600; }
.step .flag.empty { color: var(--error); }
@media (max-width: 560px) { .step { grid-template-columns: 1fr 4.5em 6.5em; } .step .track { display: none; } }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.conds { white-space: normal; color: var(--muted); }
td.conds div { min-width: 16em; max-width: 30em; }
th { color: var(--muted); font-weight: 600; }

.empty-state ol { padding-left: 20px; margin: 0 0 10px; }
.empty-state li { margin-bottom: 6px; }
.foot { text-align: right; }
td.conds .more { color: var(--accent); font-weight: 600; }
