:root {
  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface-alt: #eef1f6;
  --text: #17233a;
  --muted: #5d6b82;
  --line: #d9dfe9;
  --brand: #243f6b;
  --brand-strong: #172c4d;
  --accent: #e5a33d;
  --pass: #17794a;
  --pass-bg: #e2f4ea;
  --problem: #b3261e;
  --problem-bg: #fbe5e3;
  --skip: #5b6475;
  --skip-bg: #e9ebf0;
  --warn: #85560a;
  --warn-bg: #fff2d4;
  --info: #1d4f91;
  --info-bg: #e5eefb;
  --focus: #2c6bd6;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1624;
    --surface: #172136;
    --surface-alt: #1f2b44;
    --text: #e8edf6;
    --muted: #a3b0c6;
    --line: #2d3b58;
    --brand: #8fb0e8;
    --brand-strong: #bcd0f2;
    --accent: #f0b955;
    --pass: #7fd6a2;
    --pass-bg: #163326;
    --problem: #ff9f97;
    --problem-bg: #3b1d1f;
    --skip: #b7c0d1;
    --skip-bg: #263149;
    --warn: #f2cd80;
    --warn-bg: #3a2e14;
    --info: #9cc2f7;
    --info-bg: #182c4b;
    --focus: #8fb4ff;
  }
}

* { box-sizing: border-box; }
html { scroll-padding-top: 76px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 26px; letter-spacing: -0.02em; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 22px 0 8px; }
h3 { font-size: 14px; margin: 16px 0 6px; }
p { margin: 0 0 10px; }
a { color: var(--brand); }
code, .mono { font: 12px/1.45 ui-monospace, Consolas, monospace; }
code { background: var(--surface-alt); padding: 1px 5px; border-radius: 4px; word-break: break-word; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.visually-hidden, .offscreen { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.narrow { max-width: 420px; }
.grow { flex: 1; min-width: 200px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 22px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; text-decoration: none; color: var(--text); }
.brand-mark { height: 30px; width: auto; }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav-item { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 550; }
.topnav-item:hover { background: var(--surface-alt); }
.topnav-item.active { color: var(--brand-strong); background: var(--surface-alt); }
.user-menu { display: flex; align-items: center; gap: 10px; }
.user-link { text-decoration: none; color: var(--text); display: inline-flex; align-items: center; gap: 8px; }

/* layout */
.page { max-width: 760px; margin: 0 auto; padding: 28px 20px 60px; }
.page.wide { max-width: 1320px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; flex-wrap: wrap; margin-bottom: 14px; }
.subnav { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin: 8px 0 12px; }
.subnav-item { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 550; }
.subnav-item.active { color: var(--brand-strong); border-bottom-color: var(--accent); }

/* buttons and fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 6px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); text-decoration: none; cursor: pointer; color: var(--text); }
.btn:hover:not(:disabled) { background: var(--surface-alt); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0f1624; } }
.btn.primary:hover:not(:disabled) { background: var(--brand-strong); }
.btn.danger { color: var(--problem); border-color: color-mix(in srgb, var(--problem) 45%, var(--line)); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 28px; padding: 2px 10px; font-size: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.field > span { font-weight: 600; }
.field.inline { min-width: 160px; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
input[readonly] { background: var(--surface-alt); }
textarea { resize: vertical; min-height: 60px; }
input[type="checkbox"] { width: auto; }
.check-inline { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; }
.form-error { color: var(--problem); background: var(--problem-bg); padding: 8px 12px; border-radius: 8px; margin: 0; }
.form-error[hidden] { display: none; }

/* auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.auth-logo { height: 54px; width: auto; align-self: flex-start; }

/* chips, banners */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 0; }
.chip { display: inline-flex; align-items: center; padding: 1px 9px; border-radius: 999px; background: var(--surface-alt); color: var(--muted); font-size: 12px; line-height: 20px; white-space: nowrap; }
.chip.small { font-size: 11px; line-height: 18px; }
.chip.ok, .chip.s-complete, .chip.s-pass { background: var(--pass-bg); color: var(--pass); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.alert, .chip.s-complete_problems, .chip.s-problem, .chip.sev-blocker, .chip.sev-major { background: var(--problem-bg); color: var(--problem); }
.chip.s-in_progress { background: var(--info-bg); color: var(--info); }
.chip.s-skip, .chip.sev-minor, .chip.sev-cosmetic { background: var(--skip-bg); color: var(--skip); }
.banner { padding: 10px 14px; border-radius: 10px; margin-bottom: 10px; border: 1px solid transparent; }
.banner.info { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.banner.warn { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
ul.plain { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }

/* summary table */
.toolbar { display: grid; grid-template-columns: minmax(240px, 1fr) auto; gap: 12px; margin-bottom: 8px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filter select { min-width: 170px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); margin: 8px 0 14px; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
table.grid.compact th, table.grid.compact td { padding: 6px 10px; font-size: 13px; }
table.grid thead th { position: sticky; top: 0; background: var(--surface-alt); font-size: 12px; white-space: nowrap; z-index: 1; padding: 0; }
table.grid thead th:has(.th-btn) { padding: 0; }
table.grid.compact thead th { padding: 6px 10px; }
.th-btn { width: 100%; text-align: left; padding: 9px 12px; background: none; border: 0; font-weight: 650; cursor: pointer; color: var(--text); }
.th-btn:hover { background: var(--line); }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.bad { color: var(--problem); font-weight: 650; }
tr.tool-row { cursor: pointer; }
tr.tool-row:hover { background: var(--surface-alt); }
.tool-cell { display: flex; align-items: flex-start; gap: 10px; min-width: 280px; }
.tool-text { display: flex; flex-direction: column; gap: 2px; }
.tool-link { font-weight: 600; text-decoration: none; color: var(--text); }
.tool-link:hover { text-decoration: underline; }
.tool-icon { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; flex-shrink: 0; border-radius: 9px; background: var(--surface-alt); color: var(--brand); }
.tool-icon.big { width: 48px; height: 48px; border-radius: 12px; }
.progress-cell { min-width: 150px; }
.pbar { display: flex; height: 8px; width: 120px; border-radius: 999px; overflow: hidden; background: var(--surface-alt); margin-bottom: 2px; }
.pbar.big { width: 100%; height: 12px; }
.seg.pass { background: var(--pass); }
.seg.problem { background: var(--problem); }
.seg.skip { background: var(--skip); }
.empty { text-align: center; padding: 30px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); }
.empty[hidden] { display: none; }

/* tool workbench */
.tool-top { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.tool-progress { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.tool-progress p { margin: 0; }
details.about, details.team, details.history { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; margin-bottom: 10px; }
details > summary { cursor: pointer; font-weight: 600; }
.notes { white-space: pre-wrap; }
.workbench { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 18px; margin-top: 14px; align-items: start; }
.rail { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; max-height: calc(100vh - 90px); overflow-y: auto; }
.rail-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 4px 6px 6px; }
.rail-item { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; text-align: left; padding: 8px 10px; border: 1px solid transparent; border-radius: 8px; background: none; cursor: pointer; }
.rail-item:hover { background: var(--surface-alt); }
.rail-item.active { background: var(--surface-alt); border-color: var(--line); font-weight: 600; }
.rail-count { grid-column: 2; display: flex; gap: 6px; align-items: center; }
.fn-head { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; margin-bottom: 12px; }
.fn-head h2 { margin: 0; }
details.options { margin-top: 8px; }
.steps { display: flex; flex-direction: column; gap: 10px; }
.step { background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.step.status-pass { border-left-color: var(--pass); }
.step.status-problem { border-left-color: var(--problem); }
.step.status-skip { border-left-color: var(--skip); }
.step.focused { outline: 2px solid var(--focus); outline-offset: 1px; }
.step-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.step-id { font-weight: 700; }
.step-action, .step-expected { display: grid; grid-template-columns: 52px 1fr; gap: 8px; margin: 4px 0; }
.step-action { font-weight: 550; }
.label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding-top: 2px; }
.preview { display: flex; align-items: center; gap: 10px; margin: 6px 0 6px 60px; }
.coderef { margin: 4px 0 8px 60px; }
.step-actions { display: flex; gap: 8px; margin-left: 60px; flex-wrap: wrap; }
.btn.status.pass.active { background: var(--pass-bg); color: var(--pass); border-color: var(--pass); font-weight: 650; }
.btn.status.problem.active { background: var(--problem-bg); color: var(--problem); border-color: var(--problem); font-weight: 650; }
.btn.status.skip.active { background: var(--skip-bg); color: var(--skip); border-color: var(--skip); font-weight: 650; }
.problem-form, .problem-summary { margin: 12px 0 2px 60px; padding: 12px 14px; background: var(--surface-alt); border-radius: 10px; display: flex; flex-direction: column; gap: 10px; }
.problem-form .row { align-items: flex-end; }
.problem-summary p { margin: 0; white-space: pre-wrap; }
.thumbs { display: flex; gap: 10px; flex-wrap: wrap; }
.thumb { margin: 0; width: 160px; display: flex; flex-direction: column; gap: 4px; }
.thumb img { width: 100%; max-height: 110px; object-fit: cover; object-position: top left; border: 1px solid var(--line); border-radius: 8px; display: block; }
.fn-nav { margin-top: 10px; }
.keys { margin-top: 14px; }
pre.code { background: var(--surface-alt); border: 1px solid var(--line); border-radius: 8px; padding: 12px; max-height: 52vh; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 12px/1.5 ui-monospace, Consolas, monospace; }

/* dialogs and toast */
dialog.modal { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog.modal.wide { width: min(860px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(8, 13, 24, 0.55); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 10px; }
.toast { position: fixed; right: 18px; bottom: 18px; max-width: 380px; padding: 10px 14px; border-radius: 10px; font-size: 13px; display: none; z-index: 60; border: 1px solid; }
.toast.show { display: block; }
.toast.error { background: var(--problem-bg); color: var(--problem); border-color: var(--problem); }
.toast.ok { background: var(--pass-bg); color: var(--pass); border-color: var(--pass); }

.add-user { align-items: flex-end; }

@media (max-width: 900px) {
  .workbench { grid-template-columns: 1fr; }
  .rail { position: static; max-height: none; flex-direction: row; flex-wrap: wrap; }
  .rail-title { width: 100%; }
  .toolbar { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 8px 14px; }
  .step-action, .step-expected { grid-template-columns: 1fr; gap: 0; }
  .preview, .coderef, .step-actions, .problem-form, .problem-summary { margin-left: 0; }
}
