:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e2e5ea;
  --text: #1c2230;
  --muted: #5d6576;
  --accent: #1d1d1b;
  --accent-soft: #efede8;
  --pass: #1a7f4b;
  --pass-soft: #e5f4ec;
  --warn: #a15c00;
  --warn-soft: #fdf1df;
  --fail: #b42318;
  --fail-soft: #fdeceb;
  --concrete: #d9dce1;
  --concrete-edge: #8a919d;
  --steel: #2b3340;
  --stirrup: #c2410c;
  --dim: #5d6576;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b;
    --surface: #1a1e26;
    --surface-2: #20252e;
    --border: #2d333e;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --accent: #c9a26b;
    --accent-soft: #2a2418;
    --pass: #4cc38a;
    --pass-soft: #16291f;
    --warn: #f0a849;
    --warn-soft: #2e2413;
    --fail: #f07167;
    --fail-soft: #331a18;
    --concrete: #3a404b;
    --concrete-edge: #7b8494;
    --steel: #e6e9ef;
    --stirrup: #f08a4b;
    --dim: #9aa3b2;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }

/* ---------- top bar & nav ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { display: grid; place-items: center; height: 42px; padding: 0 12px; border-radius: 9px; background: #000; }
.logo img { height: 20px; width: auto; display: block; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.brand h1 { font-size: 17px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.top-actions { display: flex; gap: 8px; }

.btn {
  font: inherit; font-weight: 600; font-size: 13px; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:hover { filter: brightness(0.96); }
.btn:focus-visible, .nav-btn:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.nav {
  display: flex; gap: 6px; padding: 10px 24px; overflow-x: auto;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.nav-btn {
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
  font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent; background: transparent; color: var(--muted);
}
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.nav-icon { font-size: 16px; }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(300px, 360px) 1fr; gap: 20px;
  padding: 20px 24px; max-width: 1400px; margin: 0 auto;
}
.panel { min-width: 0; }
.inputs {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; align-self: start; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto;
  box-shadow: var(--shadow);
}
.inputs h2 { font-size: 18px; }
.blurb { color: var(--muted); margin: 4px 0 14px; font-size: 13px; }

/* ---------- form ---------- */
.group { border-top: 1px solid var(--border); padding: 10px 0 4px; }
.group > summary {
  cursor: pointer; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); list-style: none; padding: 2px 0 8px;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: '▸ '; }
.group[open] > summary::before { content: '▾ '; }
.group-hint { margin: -2px 0 8px; font-size: 12px; color: var(--muted); }
.fields { display: grid; gap: 10px; padding-bottom: 8px; }
.field { display: grid; gap: 4px; }
.field-label { font-size: 13px; font-weight: 500; }
.field-hint { font-size: 11.5px; color: var(--muted); }
.field-control { display: flex; align-items: stretch; }
.field-control input, .field-control select {
  flex: 1; min-width: 0; font: inherit; padding: 7px 10px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px;
}
.field-control .unit {
  display: grid; place-items: center; padding: 0 10px; font-size: 12px; color: var(--muted);
  border: 1px solid var(--border); border-left: 0; border-radius: 0 7px 7px 0; background: var(--surface);
  min-width: 56px;
}
.field-control .unit ~ * { }
.field-control:has(.unit) input { border-radius: 7px 0 0 7px; }
.field-check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.field-check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- results ---------- */
.output { display: grid; gap: 16px; align-content: start; }
#results { display: grid; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.card h3 { font-size: 14px; margin-bottom: 12px; }

.banner {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid;
}
.banner p { margin: 2px 0 0; font-size: 13px; opacity: 0.85; }
.banner ul { margin: 4px 0 0; padding-left: 18px; }
.banner-icon { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: #fff; font-weight: 700; flex: none; }
.banner.pass { background: var(--pass-soft); border-color: color-mix(in srgb, var(--pass) 30%, transparent); color: var(--pass); }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--warn); }
.banner.fail { background: var(--fail-soft); border-color: color-mix(in srgb, var(--fail) 30%, transparent); color: var(--fail); }
.banner.pass .banner-icon { background: var(--pass); }
.banner.warn .banner-icon { background: var(--warn); }
.banner.fail .banner-icon { background: var(--fail); }
.banner strong { color: var(--text); }

.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.kvs { display: grid; gap: 2px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.kv strong { text-align: right; font-variant-numeric: tabular-nums; }

.drawing-card { display: flex; flex-direction: column; }
#drawing { flex: 1; display: grid; place-items: center; min-height: 220px; }
.section-svg { width: 100%; max-height: 320px; }
.section-svg .concrete { fill: var(--concrete); stroke: var(--concrete-edge); stroke-width: 2; vector-effect: non-scaling-stroke; }
.section-svg .stirrup { fill: none; stroke: var(--stirrup); }
.section-svg .bar { fill: var(--steel); }
.section-svg .dist { stroke: var(--stirrup); stroke-linecap: round; }
.section-svg .mesh { stroke: var(--steel); opacity: 0.55; }
.section-svg .column-fill { fill: var(--accent); opacity: 0.85; }
.section-svg .dim { stroke: var(--dim); stroke-width: 1; vector-effect: non-scaling-stroke; }
.section-svg .dim-text, .section-svg .label { fill: var(--dim); font-family: system-ui, sans-serif; }
.section-svg .label { fill: var(--text); font-weight: 600; }
.caption { margin: 8px 0 0; text-align: center; color: var(--muted); font-size: 12.5px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.checks th {
  text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
  padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.checks td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.checks tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.unit-cell { color: var(--muted); font-size: 12px; white-space: nowrap; }
.note { font-size: 12px; color: var(--muted); margin-top: 3px; }
.st-fail .note { color: var(--fail); }
.st-warn .note { color: var(--warn); }
.pill { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 999px; letter-spacing: 0.04em; }
.pill.pass { background: var(--pass-soft); color: var(--pass); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.fail { background: var(--fail-soft); color: var(--fail); }
.ratio { display: flex; align-items: center; gap: 8px; justify-content: flex-end; min-width: 120px; }
.meter { position: relative; width: 70px; height: 6px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.meter span { position: absolute; inset: 0 auto 0 0; background: var(--pass); }
.st-warn .meter span { background: var(--warn); }
.st-fail .meter span { background: var(--fail); }
.meter i { position: absolute; top: -1px; bottom: -1px; left: 66.7%; width: 1px; background: var(--text); opacity: 0.5; }

.calc { border-top: 1px solid var(--border); }
.calc:first-of-type { border-top: 0; }
.calc > summary { cursor: pointer; font-weight: 600; padding: 10px 0; }
.calc-table td { padding: 6px 8px; border-top: 1px solid var(--border); vertical-align: top; }
.calc-table td:first-child { width: 30%; }
.calc-table .expr { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.calc-actions { display: flex; gap: 12px; margin: -6px 0 6px; }
.link-btn { font: inherit; font-size: 12.5px; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; }
.notes ul { margin: 0; padding-left: 18px; color: var(--muted); }
.notes li + li { margin-top: 4px; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 24px 28px; }
.print-only { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .inputs { position: static; max-height: none; }
  .result-grid { grid-template-columns: 1fr; }
  .topbar, .nav { padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 560px) {
  .calc-table td:first-child { width: auto; }
  .calc-table .expr { display: none; }
  .checks .unit-cell { display: none; }
}

/* ---------- print ---------- */
@media print {
  :root { --bg: #fff; --surface: #fff; --shadow: none; }
  body { background: #fff; font-size: 11pt; }
  .no-print { display: none !important; }
  .print-only { display: block; }
  .layout { display: block; padding: 0; }
  .topbar { border: 0; padding: 0 0 8px; }
  .card { break-inside: avoid; border-color: #ccc; }
  .calc-table .expr { display: table-cell; }
  .report-head h2 { font-size: 16pt; }
  .report-head p { color: #555; margin: 2px 0 12px; }
}
