:root {
  --bg: #f6f7f9; --card: #ffffff; --text: #1b1f24; --muted: #5d6673; --line: #e2e5ea;
  --accent: #1f6feb; --ok: #1a7f37; --warn: #9a6700; --bad: #cf222e;
  --ok-bg: #dafbe1; --warn-bg: #fff8c5; --bad-bg: #ffebe9;
  --radius: 10px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117; --card: #161b22; --text: #e6edf3; --muted: #9198a1; --line: #30363d;
    --accent: #4493f8; --ok: #3fb950; --warn: #d29922; --bad: #f85149;
    --ok-bg: #12261e; --warn-bg: #272115; --bad-bg: #2d1414;
  }
}
* { box-sizing: border-box; }
html, body { overflow-x: hidden; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.25; }
h2 { font-size: 1.05rem; } h3 { font-size: .95rem; margin-top: 1.4rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.error { color: var(--bad); min-height: 1.2em; }
.pre { white-space: pre-line; }
[hidden] { display: none !important; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; min-width: 0; }
.btn { font: inherit; min-height: 44px; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.warn { color: var(--warn); border-color: var(--warn); }
.btn.danger { color: var(--bad); border-color: var(--bad); font-weight: 600; }
.btn.danger.on { background: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 32px; padding: .25rem .6rem; font-size: .85rem; }
.btn.wide { width: 100%; }
input, select { font: inherit; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); min-width: 0; }
input:focus-visible, select:focus-visible, .btn:focus-visible, [role=tab]:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label.inline { display: flex; gap: .4rem; align-items: center; color: var(--muted); font-size: .9rem; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: .6rem; }

/* top bar + verdict */
.topbar { display: flex; align-items: center; gap: .4rem 1rem; padding: .6rem 16px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 650; }
.topbar-right { margin-left: auto; display: flex; gap: .7rem; align-items: center; }
.tag { font-size: .7rem; font-weight: 700; letter-spacing: .05em; padding: .1rem .4rem; border-radius: 4px; background: var(--warn-bg); color: var(--warn); }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; width: 100%; }
.chip { font-size: .85rem; font-weight: 500; padding: .15rem .6rem; border-radius: 999px; border: 1px solid var(--line); }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }

.verdict { position: sticky; top: 0; z-index: 10; padding: .75rem 16px; font-size: 1.05rem; font-weight: 600; border-bottom: 1px solid var(--line); }
.verdict.ok { background: var(--ok-bg); color: var(--ok); }
.verdict.warn { background: var(--warn-bg); color: var(--warn); }
.verdict.bad { background: var(--bad-bg); color: var(--bad); }
.verdict .sub { display: block; font-weight: 400; font-size: .9rem; color: var(--text); margin-top: .15rem; }
.verdict form { display: flex; gap: .5rem; margin-top: .5rem; flex-wrap: wrap; }
.verdict form input { flex: 1; min-width: 0; }
.btn.resume { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.btn.resume:disabled { opacity: 1; background: transparent; color: var(--bad); border-style: dashed; }

.layout { max-width: 1200px; margin: 0 auto; padding: 1rem 16px 3rem; display: grid; gap: 1rem; min-width: 0; }
.layout > * { min-width: 0; }
.grid-top { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; min-width: 0; }
@media (max-width: 820px) { .grid-top { grid-template-columns: 1fr; } }

.state { font-size: 1.35rem; font-weight: 650; margin-bottom: .2rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: .7rem 0 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }
.next { font-weight: 600; }
@media (max-width: 480px) { .kv { grid-template-columns: 1fr; gap: 0; } .kv dd { margin-bottom: .45rem; } }

.control-group { margin-bottom: .9rem; }
.group-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .35rem; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.report { margin-top: .4rem; font-family: var(--mono); font-size: .8rem; white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .6rem; max-height: 300px; overflow: auto; }
.report-head { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; color: var(--muted); }

.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs [role=tab] { font: inherit; background: none; border: 0; border-bottom: 2px solid transparent; padding: .55rem .9rem; min-height: 44px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs [role=tab][aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .8rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; }
.tile { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; min-width: 0; }
.tile .v { font-size: 1.25rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: .8rem; }
.tile .s { font-size: .8rem; font-variant-numeric: tabular-nums; }
.tile.key { border-width: 2px; }
.pos { color: var(--ok); } .neg { color: var(--bad); }
.note { color: var(--muted); font-size: .82rem; margin: .4rem 0 0; }

.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); } .chart .zero { stroke: var(--muted); stroke-dasharray: 4 3; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart circle { fill: var(--accent); }

.table-wrap { overflow-x: auto; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: .4rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; white-space: normal; vertical-align: bottom; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: .8rem 0; }
details summary { cursor: pointer; color: var(--accent); }
details pre { font-family: var(--mono); font-size: .78rem; white-space: pre-wrap; margin: .3rem 0; }
.section-details { margin-top: 1.4rem; }
.section-details > summary { font-weight: 600; color: var(--text); }
td details summary { color: var(--text); white-space: normal; }
td.wrap { white-space: normal; min-width: 260px; }

.params { display: grid; gap: 1.2rem; }
.params fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; display: grid; gap: .9rem; min-width: 0; }
.params legend { font-weight: 600; padding: 0 .3rem; }
.param { display: grid; grid-template-columns: minmax(200px, 1fr) minmax(160px, 260px); gap: .2rem 1rem; align-items: start; }
.param .help { grid-column: 1; color: var(--muted); font-size: .82rem; }
.param .inputs { display: flex; gap: .4rem; grid-row: 1 / span 2; grid-column: 2; }
.param .inputs > * { flex: 1; width: 100%; }
.param.changed { background: color-mix(in srgb, var(--accent) 9%, transparent); border-radius: 6px; padding: .3rem .4rem; margin: -.3rem -.4rem; }
.param.changed label { font-weight: 650; }
.param .was { color: var(--accent); font-weight: 600; }
.param.changed input, .param.changed select { border-color: var(--accent); }
@media (max-width: 600px) { .param { grid-template-columns: 1fr; } .param .inputs { grid-row: auto; grid-column: 1; } }

.log { font-family: var(--mono); font-size: .78rem; white-space: pre-wrap; max-height: 560px; overflow: auto; margin: 0; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); width: min(460px, calc(100vw - 32px)); max-width: calc(100vw - 32px); padding: 0; }
dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog { padding: 1.1rem; display: grid; gap: .6rem; }
.dialog input { width: 100%; }

.toast { position: fixed; bottom: 16px; left: 16px; right: 16px; margin: 0 auto; width: fit-content; max-width: calc(100vw - 32px); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20; }
.toast.show { opacity: 1; pointer-events: auto; }
.toast.bad { background: var(--bad); color: #fff; }

/* Phone: tables become label/value cards so no column is hidden off-screen. */
@media (max-width: 600px) {
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; margin-bottom: .5rem; }
  .table-wrap td { border: 0; padding: .15rem 0; white-space: normal; text-align: left !important; display: grid; grid-template-columns: 9.5rem 1fr; gap: .5rem; overflow-wrap: anywhere; }
  .table-wrap td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; }
  td.wrap { min-width: 0; }
  .topbar-right { margin-left: 0; width: 100%; justify-content: space-between; }
}
