:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #151a23;
  --muted: #667085;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --good: #15803d;
  --good-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --mono: ui-monospace, 'Cascadia Code', 'SFMono-Regular', Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #151b23;
    --surface-2: #1c232d;
    --border: #2a323d;
    --text: #e6edf3;
    --muted: #8b95a3;
    --accent: #2dd4bf;
    --accent-soft: #134e4a;
    --good: #4ade80;
    --good-soft: #14532d;
    --warn: #fbbf24;
    --warn-soft: #452c06;
    --bad: #f87171;
    --bad-soft: #4c1616;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
code, .mono { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
h2, h3 { margin: 0 0 8px; font-weight: 600; }
h2 { font-size: 16px; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { color: var(--muted); margin: 0 0 12px; font-size: 13px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.logo {
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;
  background: var(--text); color: var(--bg); font-weight: 700;
}
.topbar-right { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
label.inline { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; margin: 0; }

.pill { padding: 3px 10px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

.tabs { display: flex; gap: 4px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  padding: 10px 12px; color: var(--muted); font-weight: 500;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 20px 24px 60px; max-width: 1500px; margin: 0 auto; }
.tabpanel { display: flex; flex-direction: column; gap: 16px; }
.tabpanel[hidden] { display: none; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 960px) { .grid2, .grid3 { grid-template-columns: 1fr; } main { padding: 16px; } .topbar, .tabs { padding-left: 16px; padding-right: 16px; } }

.step { width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 700; }

label { display: block; margin: 10px 0; font-size: 13px; font-weight: 500; }
.label { margin: 12px 0 6px; font-size: 13px; font-weight: 500; }
input[type='text'], input[type='number'], input[type='search'], input[type='password'], select, textarea {
  width: 100%; margin-top: 4px; padding: 7px 9px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px;
}
label.inline select { width: auto; margin: 0; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row input[type='search'], .row select { width: auto; margin: 0; }

button {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: 7px; padding: 7px 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { button.primary { color: #042f2e; } }
button.ghost:hover:not(:disabled) { background: var(--surface-2); }
button.small { padding: 3px 10px; font-size: 12px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.file input { display: none; }
.file span { display: inline-block; padding: 7px 14px; border-radius: 7px; background: var(--text); color: var(--bg); cursor: pointer; font-weight: 500; }
.file { margin: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; margin: 0; font-weight: 400; cursor: pointer; background: var(--surface-2); }
.chip input { margin: 0; }
.checks label { display: flex; gap: 8px; align-items: center; margin: 4px 0; font-weight: 400; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--muted); font-size: 13px; }

.runbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.runbar > div:first-child { flex: 1; min-width: 240px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--muted); }
#results { display: flex; flex-direction: column; gap: 16px; }
#results[hidden] { display: none; }

.tablewrap { overflow: auto; max-height: 360px; border: 1px solid var(--border); border-radius: 8px; }
.tablewrap.tall { max-height: 640px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; font-size: 12px; white-space: nowrap; cursor: pointer; user-select: none; z-index: 1; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.clickable tbody tr { cursor: pointer; }
table.clickable tbody tr:hover { background: var(--surface-2); }
td .sub { color: var(--muted); font-size: 12px; }
.clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tag { display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.tag.good { background: var(--good-soft); color: var(--good); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.neutral { background: var(--surface-2); color: var(--muted); }
.sig { display: inline-block; margin: 1px 3px 1px 0; padding: 0 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-size: 11px; }
.bar { display: inline-block; width: 48px; height: 6px; background: var(--surface-2); border-radius: 999px; margin-right: 6px; vertical-align: middle; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface);
  border-left: 1px solid var(--border); box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12); overflow: auto; padding: 16px 20px; z-index: 10;
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.drawer h4 { margin: 16px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; font-size: 13px; }
.kv div:nth-child(odd) { color: var(--muted); }
pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow: auto; max-height: 420px; white-space: pre-wrap; word-break: break-word; }
.msgbox { background: var(--surface-2); padding: 10px; border-radius: 8px; white-space: pre-wrap; font-size: 13px; }

.answer { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.answer .head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.dist { display: grid; grid-template-columns: minmax(0, 1fr) 140px 48px; gap: 3px 8px; font-size: 12px; align-items: center; }
.dist .track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.dist .track i { display: block; height: 100%; background: var(--accent); }
.dist .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: 460px; width: calc(100vw - 32px); }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.prose { max-width: 860px; }
.prose li { margin: 4px 0; }
.error-text { color: var(--bad); }
