:root {
  --navy: #1f2a44; --slate: #5b6778; --green: #2e9e6b; --amber: #d99a2b; --red: #c0392b;
  --bg: #f6f7f9; --card: #ffffff; --ink: #1f2a44; --muted: #5b6778; --line: #dfe3ea; --tint: #eaf6f0;
  --input-bg: #ffffff; --head: #eef1f5;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151c2c; --card: #1f2a44; --ink: #f6f7f9; --muted: #aebccc; --line: #30405d; --tint: #22394a;
          --input-bg: #16213a; --head: #27354f; }
}
* { box-sizing: border-box; }
html { font: 15px/1.5 Inter, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: var(--green); }
h1 { font-size: 1.8rem; margin: 0 0 .5rem; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; margin: 1.5rem 0 .5rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 .4rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.inline { display: inline; }
.hidden { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 1.25rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: .6rem; color: var(--ink); text-decoration: none; font-weight: 700; }
.brand img { border-radius: 8px; }
.top nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.top nav a { color: var(--ink); text-decoration: none; }
button.link { background: none; border: 0; color: var(--ink); cursor: pointer; font: inherit; padding: 0; }

main { max-width: 1180px; margin: 0 auto; padding: 1.25rem; }
.foot { max-width: 1180px; margin: 2rem auto; padding: 0 1.25rem; color: var(--muted); font-size: .85rem; }
.flashes { max-width: 1180px; margin: 1rem auto 0; padding: 0 1.25rem; }
.flash { padding: .6rem .9rem; border-radius: 8px; background: var(--tint); border: 1px solid var(--green); }
.flash.error { border-color: var(--red); background: rgba(192,57,43,.08); }

.btn { display: inline-block; background: var(--green); color: #fff; border: 0; border-radius: 8px; padding: .6rem 1.1rem; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn.danger { background: var(--red); }
.btn:disabled { opacity: .5; cursor: default; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1.4rem; }
.card.narrow { max-width: 480px; margin: 2rem auto; }
.card img, .explain img, picture img { max-width: 100%; height: auto; border-radius: 10px; }
label { display: block; margin: .8rem 0; font-weight: 600; }
label input, label select { display: block; width: 100%; margin-top: .25rem; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--input-bg); color: var(--ink); font: inherit; }
label.check { display: flex; gap: .5rem; align-items: center; font-weight: 500; }
label.check input { width: auto; margin: 0; }
textarea { width: 100%; min-height: 220px; padding: .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--input-bg); color: var(--ink); font: .85rem ui-monospace, Menlo, monospace; }
.code-box { background: var(--head); padding: 1rem; border-radius: 10px; text-align: center; font-size: 1.4rem; letter-spacing: .08em; }

.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 2rem; align-items: center; padding: 1.5rem 0 2rem; }
.hero h1 { font-size: 2.3rem; }
.lead { font-size: 1.1rem; color: var(--muted); }
.cta { display: flex; gap: .75rem; flex-wrap: wrap; }
.ticks { padding-left: 1.2rem; color: var(--muted); }
.explain { margin: 1.5rem 0; }
.two-up { display: grid; grid-template-columns: 1fr 1.4fr; gap: 1.5rem; align-items: center; }
@media (max-width: 820px) { .hero, .two-up { grid-template-columns: 1fr; } .hero h1 { font-size: 1.8rem; } }

/* app shell */
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: .6rem .9rem; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--green); }
.tabs button img { width: 18px; height: 18px; vertical-align: -3px; margin-right: .35rem; }
.panel { display: none; }
.panel.active { display: block; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: .5rem 0 1rem; }
.status { margin-left: auto; color: var(--muted); font-size: .85rem; }
.status.saving { color: var(--amber); }
.status.err { color: var(--red); }

.grid-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
table.grid { border-collapse: collapse; width: 100%; font-size: .85rem; min-width: 1080px; }
table.grid th, table.grid td { padding: .3rem .35rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.grid th { background: var(--head); position: sticky; top: 0; font-weight: 600; }
table.grid th:first-child, table.grid td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); }
table.grid th:first-child { background: var(--head); }
table.grid tr.regimeB td:first-child { border-left: 3px solid var(--green); }
table.grid input { width: 4.6rem; padding: .25rem .3rem; border: 1px solid var(--line); border-radius: 6px; background: var(--input-bg); color: var(--ink); font: inherit; text-align: right; }
table.grid input.rate { width: 5.2rem; }
table.grid input.wide { width: 6rem; }
table.grid input.touched { border-color: var(--green); }
table.grid tr.detail td { background: var(--head); white-space: normal; text-align: left; }
table.grid .pp { font-weight: 700; }
.badge { display: inline-block; padding: .05rem .4rem; border-radius: 999px; font-size: .72rem; background: var(--head); color: var(--muted); }
.badge.stub { background: var(--tint); color: var(--green); }
.badge.warn { background: rgba(217,154,43,.15); color: var(--amber); }
.badge.err { background: rgba(192,57,43,.12); color: var(--red); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .8rem; margin: 1rem 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem; }
.stat .k { color: var(--muted); font-size: .8rem; }
.stat .v { font-size: 1.5rem; font-weight: 700; margin-top: .2rem; }
.stat.good .v { color: var(--green); }
.stat.warn .v { color: var(--amber); }
table.plain { border-collapse: collapse; width: 100%; font-size: .9rem; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
table.plain th, table.plain td { padding: .45rem .6rem; border-bottom: 1px solid var(--line); text-align: right; }
table.plain th:first-child, table.plain td:first-child { text-align: left; }
table.plain th { background: var(--head); font-weight: 600; }
table.plain tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
.note { border-left: 4px solid var(--amber); background: rgba(217,154,43,.08); padding: .6rem .9rem; border-radius: 8px; margin: .8rem 0; }
.note.ok { border-color: var(--green); background: var(--tint); }
.note.bad { border-color: var(--red); background: rgba(192,57,43,.08); }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1.2rem; }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 1rem; text-align: center; color: var(--muted); margin: .5rem 0; }
.drop.over { border-color: var(--green); background: var(--tint); }
.empty { text-align: center; padding: 2rem; color: var(--muted); }
.empty img { width: 64px; height: 64px; opacity: .8; }
.bars { display: grid; gap: .3rem; margin: 1rem 0; }
.bar { display: grid; grid-template-columns: 70px 1fr 90px; align-items: center; gap: .6rem; font-size: .85rem; }
.bar i { display: block; height: 14px; background: var(--green); border-radius: 4px; }
.bar.b i { background: var(--navy); } @media (prefers-color-scheme: dark) { .bar.b i { background: #7fb2ff; } }
.theme-dark { display: none; } @media (prefers-color-scheme: dark) { .theme-dark { display: inline; } .theme-light { display: none; } }
@media print {
  .top, .tabs, .toolbar, .foot, .no-print { display: none !important; }
  main { max-width: none; padding: 0; }
  .panel { display: block !important; page-break-inside: avoid; }
  body { background: #fff; color: #000; }
}

/* wizard */
fieldset { border: 0; padding: 0; margin: 0 0 1.2rem; }
legend { font-weight: 700; font-size: 1.1rem; padding: 0; margin-bottom: .2rem; }
.wizard { max-width: 760px; margin: 1rem auto; }
.wiz-progress { display: flex; gap: .4rem; margin-bottom: 1rem; }
.wiz-progress i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.wiz-progress i.done { background: var(--green); }
.wiz-nav { margin-top: 1.2rem; justify-content: space-between; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.choice { text-align: left; background: var(--bg); border: 2px solid var(--line); border-radius: 12px; padding: 1rem; font: inherit; color: var(--ink); cursor: pointer; }
.choice:hover { border-color: var(--green); }
.choice strong { display: block; margin-bottom: .3rem; }
.choice span { color: var(--muted); font-size: .9rem; }
@media (max-width: 640px) { .choices { grid-template-columns: 1fr; } }
body.wizard .tabs { display: none; }
#wiz-host fieldset { display: none; }
#wiz-host fieldset.active { display: block; }
#wiz-host .settings-only { display: none; }

/* editor modal */
.modal { position: fixed; inset: 0; background: rgba(15,20,35,.55); display: flex; align-items: flex-start; justify-content: center; padding: 3vh 1rem; z-index: 20; overflow: auto; }
.modal-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; width: min(980px, 100%); padding: 1.2rem 1.4rem; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; }
.modal-foot { justify-content: flex-end; margin-top: 1rem; }
table.lines { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.lines th, table.lines td { padding: .35rem .45rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.lines th:first-child, table.lines td:first-child { text-align: left; }
table.lines th { background: var(--head); font-weight: 600; }
table.lines input { width: 6.5rem; padding: .3rem .4rem; border: 1px solid var(--line); border-radius: 6px; background: var(--input-bg); color: var(--ink); font: inherit; text-align: right; }
table.lines tr.off td { color: var(--muted); }
table.lines td.diff { color: var(--amber); font-weight: 600; }
.recon { margin-top: .8rem; }
table.grid td.num { font-variant-numeric: tabular-nums; }
table.grid tr[data-pp] { cursor: pointer; }
table.grid tr[data-pp]:hover td { background: var(--head); }
table.grid tr.flag td.pp-cell { border-left: 3px solid var(--amber); }
.pp-link { font-weight: 700; color: var(--green); }

details { margin: .6rem 0 1.2rem; }
details summary { cursor: pointer; }
