:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #16232d;
  --muted: #5d6f7c;
  --line: #dde4e9;
  --accent: #0b6e99;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1f7;
  --pass: #1a7f4b;
  --pass-bg: #e2f4ea;
  --fail: #b42318;
  --fail-bg: #fde8e6;
  --warn: #a15c07;
  --warn-bg: #fdf1d9;
  --na: #6b7b87;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 35, 45, 0.06), 0 1px 3px rgba(16, 35, 45, 0.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f171d;
    --surface: #17222a;
    --surface-2: #1b2832;
    --text: #e5edf2;
    --muted: #91a4b1;
    --line: #2a3a46;
    --accent: #4db3dd;
    --accent-ink: #06222e;
    --accent-soft: #163344;
    --pass: #4ecb8b;
    --pass-bg: #123626;
    --fail: #ff8b80;
    --fail-bg: #3d1a17;
    --warn: #f0b95a;
    --warn-bg: #3a2b10;
    --na: #8a9ba7;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: 1.2; margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 34px; height: 34px; border-radius: 8px; flex: none;
  background: var(--accent)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M5 19c3-3 5 3 8 0s5 3 8 0 4 2 6 0' stroke='%23fff' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3Cpath d='M5 12c3-3 5 3 8 0s5 3 8 0 4 2 6 0' stroke='%23fff' stroke-width='2.4' fill='none' stroke-linecap='round' opacity='.6'/%3E%3C/svg%3E") center/100% no-repeat;
}
.app-name { font-weight: 650; letter-spacing: -0.01em; }
.proj { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 7px 12px; font-size: 14px; transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 5px 10px; font-size: 13px; margin-top: 8px; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ---------- layout ---------- */
.body { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 57px); }
.nav {
  padding: 14px 10px; border-right: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 57px; align-self: start; max-height: calc(100vh - 57px); overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; text-align: left; width: 100%;
  border: 0; background: transparent; padding: 9px 10px; border-radius: 8px;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--accent-soft); font-weight: 600; }
.nav-title { flex: 1; min-width: 0; }
.nav-sheet { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.d-pass { background: var(--pass); }
.d-fail { background: var(--fail); }
.d-warn { background: var(--warn); }
.d-none, .d-na { background: var(--line); }

.main { padding: 22px 26px 60px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.page-head h2 { font-size: 24px; letter-spacing: -0.02em; }
.sheet {
  font-size: 12px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); padding: 2px 9px; border-radius: 999px;
}
.intro { color: var(--muted); margin: 6px 0 18px; max-width: 78ch; }
.muted { color: var(--muted); }

.grid { display: grid; grid-template-columns: minmax(300px, 5fr) minmax(0, 7fr); gap: 18px; align-items: start; }
.grid.one { grid-template-columns: minmax(0, 640px); }
.grid.wide { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.grid .card { margin-bottom: 0; }
.card-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin-bottom: 12px; font-weight: 650; }

/* ---------- form ---------- */
.grp { font-size: 13px; font-weight: 650; margin: 18px 0 8px; padding-bottom: 5px; border-bottom: 1px solid var(--line); }
.card-title + .grp, .card-title + .linked + .grp, .field:first-child { margin-top: 0; }
.field { margin-bottom: 11px; }
.field label { display: block; font-size: 13px; margin-bottom: 3px; }
.ctl { display: flex; align-items: center; gap: 8px; }
.ctl .u { color: var(--muted); font-size: 13px; min-width: 2.5ch; white-space: nowrap; }
input[type='text'], input[type='number'], select, textarea {
  width: 100%; font: inherit; color: var(--text);
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2);
}
input[type='number'] { font-variant-numeric: tabular-nums; }
textarea { resize: vertical; }
.hint { color: var(--muted); font-size: 12px; margin-top: 3px; }
.linked {
  font-size: 12.5px; color: var(--muted); background: var(--surface-2); border: 1px dashed var(--line);
  border-radius: 8px; padding: 8px 10px; margin-bottom: 12px;
}
.linked b { color: var(--text); font-weight: 600; }
.link { border: 0; background: none; color: var(--accent); text-decoration: underline; padding: 0 0 0 4px; }

.tscroll { overflow-x: auto; }
table.edit { border-collapse: collapse; width: 100%; margin-bottom: 4px; }
table.edit th { font-size: 11.5px; color: var(--muted); font-weight: 600; text-align: left; padding: 0 4px 4px; white-space: nowrap; }
table.edit td { padding: 2px 3px; }
table.edit td.wide { min-width: 150px; }
table.edit td input, table.edit td select { padding: 6px 6px; }
table.edit td.wide input { min-width: 140px; }
.icon { border: 0; background: none; font-size: 18px; color: var(--muted); padding: 2px 8px; border-radius: 6px; }
.icon:hover { background: var(--fail-bg); color: var(--fail); }

/* ---------- results ---------- */
.res-sec + .res-sec { margin-top: 20px; }
.res-sec h3 { font-size: 14px; margin-bottom: 6px; }
table.res { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.res th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; padding: 3px 8px; text-align: left; }
table.res th.val, td.val { text-align: right; }
table.res td { padding: 6px 8px; border-top: 1px solid var(--line); vertical-align: top; }
td.lbl { min-width: 170px; }
td.val { white-space: nowrap; font-weight: 600; }
td.val.txt { white-space: normal; max-width: 260px; }
.unit { color: var(--muted); font-weight: 400; font-size: 12.5px; }
.note { color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 2px; line-height: 1.4; }
table.res tr.has-note td { padding-bottom: 2px; }
table.res tr.note-row td { border-top: 0; padding: 0 8px 7px; }
table.res tr.note-row .note { margin: 0; max-width: 70ch; }
.formula { color: var(--muted); font-size: 11.5px; font-weight: 400; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; margin: 0 0 2px; line-height: 1.4; }
table.res tr.formula-row td { border-top: 0; padding: 0 8px 0; }
.f-tag { display: inline-block; font-family: inherit; font-size: 10px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); border-radius: 3px; padding: 1px 4px; margin-right: 5px; }
td.bd { width: 34px; text-align: center; }
.badge {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  font-size: 12px; font-weight: 800; line-height: 1;
}
.b-pass { background: var(--pass-bg); color: var(--pass); }
.b-fail { background: var(--fail-bg); color: var(--fail); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-na { background: var(--surface-2); color: var(--na); border: 1px solid var(--line); }
tr.st-fail td.val { color: var(--fail); }
tr.st-warn td.val { color: var(--warn); }
tr.st-na td.val { color: var(--na); font-weight: 500; }

/* ---------- summary ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 14px 0 16px; }
.stat { border-radius: var(--radius); padding: 12px 14px; border: 1px solid var(--line); background: var(--surface); }
.stat .n { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat.s-pass .n { color: var(--pass); }
.stat.s-fail .n { color: var(--fail); }
.stat.s-warn .n { color: var(--warn); }
.stat.s-na .n { color: var(--na); }
.mod-row {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 0; border-top: 1px solid var(--line); background: none; padding: 10px 4px;
}
.mod-row:first-of-type { border-top: 0; }
.mod-row:hover { background: var(--surface-2); }
.mod-name { flex: 1; font-weight: 550; }
.mod-st { font-size: 13px; }
.s-pass { color: var(--pass); } .s-fail { color: var(--fail); } .s-warn { color: var(--warn); } .s-none { color: var(--muted); }
.findings { list-style: none; margin: 0; padding: 0; }
.findings li { padding: 9px 0 9px 12px; border-left: 3px solid var(--line); margin-bottom: 8px; }
.findings li.f-warn { border-left-color: var(--warn); }
.findings li.f-fail { border-left-color: var(--fail); }

/* ---------- report ---------- */
.report h1 { font-size: 22px; margin-bottom: 10px; }
.report h2, .rep-mod h2 { font-size: 17px; margin: 26px 0 8px; display: flex; align-items: center; gap: 10px; }
.report h4, .rep-mod h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 0 4px; }
table.meta td:first-child { width: 150px; color: var(--muted); }
.rep-sum { margin: 12px 0 0; }
.disclaimer { color: var(--muted); font-size: 12px; margin-top: 28px; }
.badge:empty { display: none; }

.print-root { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .grid, .grid.wide { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .body { grid-template-columns: minmax(0, 1fr); }
  .nav {
    position: static; max-height: none; flex-direction: row; overflow-x: auto; gap: 4px;
    border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px;
  }
  .nav-item { width: auto; white-space: nowrap; }
  .nav-sheet { display: none; }
  .main { padding: 16px 16px 48px; }
  .topbar { padding: 10px 16px; }
  .proj { max-width: 70vw; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  td.lbl { min-width: 0; }
  td.val.txt { max-width: 170px; }
}

/* ---------- print ---------- */
@media print {
  :root { color-scheme: light; --bg: #fff; --surface: #fff; --surface-2: #fff; --text: #000; --muted: #444; --line: #bbb; --pass: #146c3f; --fail: #a01d12; --warn: #8a4f05; }
  body { background: #fff; font-size: 11px; }
  .app { display: none !important; }
  .print-root { display: block; padding: 0; }
  .rep-mod { break-inside: avoid-page; }
  .res-sec { break-inside: avoid; }
  .badge { border: 1px solid #999; background: #fff !important; }
  td { padding: 3px 6px !important; }
}
