:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #f0f3f7; --text: #18212b; --muted: #5d6b7a;
  --border: #d9e0e8; --accent: #1f4e79; --accent-2: #2e75b6; --accent-text: #ffffff;
  --red: #b42318; --red-bg: #fdecea; --amber: #a15c00; --amber-bg: #fff4e0;
  --green: #1d7a3e; --green-bg: #e7f6ec; --grey: #5d6b7a; --grey-bg: #eef1f4;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141a; --surface: #171e26; --surface-2: #1e2731; --text: #e6ebf0; --muted: #9aa7b4;
    --border: #2c3946; --accent: #5aa0e0; --accent-2: #7cb6ea; --accent-text: #0f141a;
    --red: #ff8a80; --red-bg: #3a1a18; --amber: #ffc266; --amber-bg: #3a2a10;
    --green: #7ed99b; --green-bg: #12301d; --grey: #9aa7b4; --grey-bg: #222b35;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141a; --surface: #171e26; --surface-2: #1e2731; --text: #e6ebf0; --muted: #9aa7b4;
  --border: #2c3946; --accent: #5aa0e0; --accent-2: #7cb6ea; --accent-text: #0f141a;
  --red: #ff8a80; --red-bg: #3a1a18; --amber: #ffc266; --amber-bg: #3a2a10;
  --green: #7ed99b; --green-bg: #12301d; --grey: #9aa7b4; --grey-bg: #222b35;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Arial, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

/* header */
.top { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 240px; }
.logo { width: 40px; height: 40px; border-radius: 8px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.title { font-weight: 700; font-size: 16px; }
.subtitle { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 4px; }
.tab { border: 1px solid transparent; background: none; padding: 7px 14px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--surface-2); color: var(--text); border-color: var(--border); font-weight: 600; }
.proto-banner.demo { background: var(--red-bg); color: var(--red); font-weight: 700; text-align: center; }
.proto-banner { background: var(--amber-bg); color: var(--text); border-bottom: 1px solid var(--border); padding: 7px 20px; font-size: 12.5px; }

/* layout */
.view { padding: 16px 20px 40px; max-width: 1400px; margin: 0 auto; }
.case-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 16px; align-items: start; }
.panel { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; }
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; order: -1; }
}

.btn { border: 1px solid var(--border); background: var(--surface); padding: 7px 14px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.ghost:hover, .tab:hover { background: var(--surface-2); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.danger { color: var(--red); }

/* form */
.section { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; box-shadow: var(--shadow); }
.section > summary { cursor: pointer; padding: 11px 14px; font-weight: 650; list-style: none; display: flex; align-items: center; gap: 8px; }
.section > summary::-webkit-details-marker { display: none; }
.section > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
.section[open] > summary::before { transform: rotate(90deg); }
.section .hint { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: auto; }
.section-body { padding: 4px 14px 14px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field > label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 6px 8px; width: 100%; min-width: 0; }
.field textarea { min-height: 56px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent-2); outline-offset: 0; border-color: transparent; }
.field .unit { font-size: 11px; color: var(--muted); }
.yn { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; width: fit-content; }
.yn button { border: 0; background: var(--surface); padding: 5px 12px; cursor: pointer; }
.yn button + button { border-left: 1px solid var(--border); }
.yn button.on[data-v="yes"] { background: var(--accent); color: var(--accent-text); }
.yn button.on[data-v="no"] { background: var(--surface-2); font-weight: 600; }
.group-title { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 6px; grid-column: 1 / -1; }
.assess { border: 1px dashed var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; background: var(--surface-2); }
.assess-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 600; }
.assess-head .sev { margin-left: auto; }

/* decision panel */
.mode-toggle { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 3px; margin-bottom: 10px; }
.mode { flex: 1; border: 0; background: none; padding: 7px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.mode.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.flag { border-radius: 10px; padding: 14px; margin-bottom: 10px; border: 1px solid; }
.flag .lvl { font-size: 12px; font-weight: 700; letter-spacing: .06em; }
.flag .dispo { font-size: 22px; font-weight: 750; margin: 4px 0; }
.flag .sev-line { font-size: 13px; }
.flag.RED { background: var(--red-bg); border-color: var(--red); color: var(--red); }
.flag.AMBER { background: var(--amber-bg); border-color: var(--amber); color: var(--amber); }
.flag.GREEN { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.flag.GREY { background: var(--grey-bg); border-color: var(--grey); color: var(--grey); }
.flag .dispo, .flag .sev-line { color: var(--text); }
ul.clean { margin: 0; padding-left: 18px; }
ul.clean li { margin: 3px 0; }
.alert { border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: 13px; border: 1px solid; }
.alert.hard { background: var(--red-bg); border-color: var(--red); font-weight: 600; }
.alert.warn { background: var(--amber-bg); border-color: var(--amber); }
.alert.info { background: var(--surface-2); border-color: var(--border); }
.rid { font-family: Consolas, monospace; font-size: 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; margin-right: 4px; color: var(--muted); white-space: nowrap; }
.src { display: block; font-size: 11px; color: var(--muted); }
.src.prop { color: var(--amber); }
.pill { display: inline-block; font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.pill.RED { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.pill.AMBER { background: var(--amber-bg); color: var(--amber); border-color: var(--amber); }
.pill.GREEN { background: var(--green-bg); color: var(--green); border-color: var(--green); }
.pill.GREY { color: var(--grey); }
.final { font-size: 12px; color: var(--muted); text-align: center; padding: 6px; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.grid th { background: var(--surface-2); font-weight: 650; font-size: 12px; color: var(--muted); }
table.grid tr.click { cursor: pointer; }
table.grid tr.click:hover td { background: var(--surface-2); }
.inline { display: inline-flex; align-items: center; gap: 6px; }
.inline select { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 6px 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.stat .v { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--muted); }
