:root {
  --bg: #f6f7f5; --surface: #ffffff; --surface-2: #f0f2ef; --text: #1d2420; --muted: #5d6862; --border: #dde2de;
  --accent: #2f6f5e; --accent-text: #ffffff; --accent-soft: #e2efe9;
  --critical: #b3261e; --critical-soft: #fbe9e7; --high: #c25e00; --high-soft: #fdf0e1;
  --medium: #8a6d00; --medium-soft: #fbf5dc; --low: #4a5a68; --low-soft: #eceff2;
  --ok: #2e7d32; --ok-soft: #e6f3e7;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; line-height: 1.5;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --surface: #1a1f1c; --surface-2: #222824; --text: #e6ebe7; --muted: #9aa59e; --border: #313833;
    --accent: #5fb39a; --accent-text: #0e1a15; --accent-soft: #1f3a31;
    --critical: #ff8a80; --critical-soft: #3a1f1d; --high: #ffb066; --high-soft: #3a2a17; --medium: #e8c95a; --medium-soft: #353015;
    --low: #a9b7c4; --low-soft: #262c32; --ok: #7bc47f; --ok-soft: #1d3320;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
p { margin: .25rem 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--critical); min-height: 1.2em; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: auto 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: .5rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; }
.spacer { flex: 1; }
.nav { display: flex; flex-direction: column; padding: 1rem .5rem; gap: 2px; border-right: 1px solid var(--border); background: var(--surface); }
.nav a { padding: .5rem .75rem; border-radius: 8px; text-decoration: none; color: var(--text); display: flex; justify-content: space-between; align-items: center; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.view { padding: 1.25rem; max-width: 1200px; width: 100%; outline: none; }
.btn.menu-toggle { display: none; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .btn.menu-toggle { display: inline-flex; }
  .nav { display: none; position: fixed; top: var(--topbar-h, 52px); left: 0; right: 0; z-index: 4; border-bottom: 1px solid var(--border); max-height: calc(100vh - 52px); overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
  .nav.open { display: flex; }
  .view { padding: 1rem; }
  #source-badge { display: none; }
}

/* components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; min-width: 0; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-bottom: 1rem; }
.grid > .card { margin-bottom: 0; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: .5rem; }
.btn { font: inherit; display: inline-flex; align-items: center; gap: .35rem; padding: .45rem .8rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--critical); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: .25rem .55rem; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: progress; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem; max-width: 100%; }
textarea { width: 100%; min-height: 5rem; resize: vertical; }
label { font-weight: 600; font-size: .9rem; display: block; margin: .5rem 0 .25rem; }
.badge { display: inline-block; font-size: .78rem; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.warn { background: var(--high-soft); color: var(--high); border-color: transparent; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.sev-critical { background: var(--critical-soft); color: var(--critical); border-color: transparent; }
.sev-high { background: var(--high-soft); color: var(--high); border-color: transparent; }
.sev-medium { background: var(--medium-soft); color: var(--medium); border-color: transparent; }
.sev-low { background: var(--low-soft); color: var(--low); border-color: transparent; }
.count { background: var(--accent); color: var(--accent-text); border-radius: 999px; font-size: .75rem; padding: 0 .45rem; min-width: 1.3rem; text-align: center; }
.notice { border-left: 4px solid var(--high); background: var(--high-soft); padding: .6rem .9rem; border-radius: 6px; margin-bottom: 1rem; }
.notice.info { border-color: var(--accent); background: var(--accent-soft); }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }

/* score */
.score { display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap; }
.score-num { font-size: 3rem; font-weight: 800; line-height: 1; }
.bars { flex: 1; min-width: 220px; }
.bar { display: grid; grid-template-columns: 90px 1fr 3rem; gap: .5rem; align-items: center; font-size: .88rem; margin: .2rem 0; }
.bar-track { display: block; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 99px; width: 0; }
.stat { font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .85rem; }
.measured { color: var(--ok); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.estimated { color: var(--high); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.url { word-break: break-all; }

/* issue / action items */
details.item { border: 1px solid var(--border); border-radius: 8px; margin: .5rem 0; background: var(--surface); }
details.item > summary { cursor: pointer; padding: .6rem .8rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; list-style: none; }
details.item > summary::-webkit-details-marker { display: none; }
details.item > summary::before { content: '▸'; color: var(--muted); }
details.item[open] > summary::before { content: '▾'; }
details.item .body { padding: 0 .9rem .8rem 1.6rem; }
dl.explain { display: grid; grid-template-columns: 9rem 1fr; gap: .3rem .8rem; margin: .25rem 0; }
dl.explain dt { color: var(--muted); font-weight: 600; font-size: .85rem; }
dl.explain dd { margin: 0; }
@media (max-width: 600px) { dl.explain { grid-template-columns: 1fr; } dl.explain dd { margin-bottom: .4rem; } }

/* proposals */
.proposal { border: 1px solid var(--border); border-radius: 8px; padding: .75rem; margin: .6rem 0; background: var(--surface); }
.diff { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: .5rem 0; }
.diff > div { background: var(--surface-2); border-radius: 6px; padding: .5rem .6rem; font-size: .88rem; overflow-wrap: anywhere; max-height: 16rem; overflow: auto; }
.diff .old { text-decoration: line-through; text-decoration-color: var(--muted); color: var(--muted); }
@media (max-width: 600px) { .diff { grid-template-columns: 1fr; } }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: .75rem; }
.tabs button { font: inherit; border: 1px solid var(--border); background: var(--surface); padding: .3rem .7rem; border-radius: 999px; cursor: pointer; color: var(--text); }
.tabs button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* charts */
svg.chart { width: 100%; height: 180px; display: block; }
svg.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
svg.chart .line2 { fill: none; stroke: var(--high); stroke-width: 2; }
svg.chart .axis { stroke: var(--border); }
svg.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 1rem; font-size: .85rem; color: var(--muted); }
.legend .sw { display: inline-block; width: .8rem; height: .2rem; vertical-align: middle; margin-right: .3rem; background: var(--accent); }
.legend .sw2 { background: var(--high); }

/* login & toast */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 360px; }
.login-card input { width: 100%; margin-bottom: .75rem; }
.login-card .btn { width: 100%; justify-content: center; }
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; z-index: 20; max-width: calc(100vw - 2rem); box-shadow: var(--shadow); }
.toast.bad { background: var(--critical); color: #fff; }

.card p { overflow-wrap: anywhere; }

/* plain-language layer */
.help { color: var(--muted); margin: -.25rem 0 1rem; max-width: 70ch; }
.nav details.more summary { padding: .5rem .75rem; cursor: pointer; color: var(--muted); list-style: none; }
.nav details.more summary::before { content: '▸ '; }
.nav details.more[open] summary::before { content: '▾ '; }
.nav details.more a { padding-left: 1.5rem; }
.job { border-left: 4px solid var(--accent); }
.job.kind-manual { border-left-color: var(--medium); }
.job h2 { margin: 0; }
.job .num-badge { display: inline-grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-weight: 700; margin-right: .5rem; flex: none; }
.job ol { margin: .25rem 0 .75rem 1.1rem; padding: 0; }
.job ol li { margin: .25rem 0; }
.preview-list { border: 1px solid var(--border); border-radius: 8px; margin: .5rem 0; max-height: 22rem; overflow: auto; }
.preview-row { padding: .5rem .7rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
.preview-row:last-child { border-bottom: 0; }
.preview-row .from { color: var(--muted); text-decoration: line-through; }
.stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 1rem; }
.stats .card { margin: 0; }
pre.summary { white-space: pre-wrap; background: var(--surface-2); padding: .75rem; border-radius: 8px; font-size: .88rem; font-family: inherit; }
.choice { display: flex; gap: .5rem; align-items: flex-start; margin: .35rem 0; font-weight: 400; }
.choice input { margin-top: .3rem; }
.job > .row:first-child { flex-wrap: nowrap; align-items: flex-start; }
.job > .row:first-child h2 { padding-top: .1rem; }
details.card > summary { cursor: pointer; }
