:root {
  color-scheme: light;
  --navy: #40286B; --navy-2: #2f1d50; --red: #ED1C24; --magenta: #871C56;
  --bg: #f4f3f7; --surface: #ffffff; --surface-2: #f8f7fb; --line: #e4e1ec;
  --text: #17141f; --text-2: #4f4a5c; --muted: #7b7589;
  --accent: #40286B; --accent-soft: #ece7f5;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --crit: #d03b3b;
  --good-ink: #067a06; --warn-ink: #8a5d00; --crit-ink: #b42b2b;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --heat0: #f0eff4; --radius: 12px;
  --shadow: 0 1px 2px rgba(23,20,31,.06), 0 4px 16px rgba(23,20,31,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121016; --surface: #1c1a21; --surface-2: #232029; --line: #322e3a;
    --text: #f4f2f8; --text-2: #c6c1d1; --muted: #8f899c;
    --accent: #b9a3e6; --accent-soft: #2c2440;
    --good-ink: #4cc94c; --warn-ink: #fab219; --crit-ink: #ff7b7b;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --heat0: #26232c; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121016; --surface: #1c1a21; --surface-2: #232029; --line: #322e3a;
  --text: #f4f2f8; --text-2: #c6c1d1; --muted: #8f899c;
  --accent: #b9a3e6; --accent-soft: #2c2440;
  --good-ink: #4cc94c; --warn-ink: #fab219; --crit-ink: #ff7b7b;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --heat0: #26232c; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 14px; line-height: 1.5; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
h1 { font-size: 20px; margin: 0; font-weight: 700; }
h3 { font-size: 15px; margin: 0 0 4px; font-weight: 600; }
h4 { font-size: 14px; margin: 20px 0 8px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
.row { display: flex; align-items: center; } .gap { gap: 8px; } .wrap { flex-wrap: wrap; }
a.link { color: var(--accent); cursor: pointer; font-size: 13px; text-decoration: none; }
a.link:hover { text-decoration: underline; }

input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
textarea { resize: vertical; min-height: 64px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn { font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--crit-ink); border-color: color-mix(in srgb, var(--crit) 40%, transparent); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .5; cursor: progress; }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; color: #fff; }
.brand .star { width: 34px; height: 34px; border-radius: 9px; background: #fff; color: var(--red); display: grid; place-items: center; font-size: 20px; flex: none; }
.brand b { display: block; letter-spacing: .06em; font-size: 14px; }
.brand small { opacity: .75; font-size: 12px; }
.brand.big { color: var(--navy); margin-bottom: 18px; }
.brand.big .star { background: var(--navy); color: var(--red); }
:root[data-theme="dark"] .brand.big { color: var(--text); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--navy) 0%, #241640 60%, var(--magenta) 140%); }
.login-card { background: var(--surface); width: 100%; max-width: 380px; border-radius: 16px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card label { display: block; font-weight: 500; margin-bottom: 12px; font-size: 13px; }
.login-card input { width: 100%; margin-top: 4px; }
.err { color: var(--crit-ink); min-height: 20px; font-size: 13px; }

/* Layout */
.app { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #fff; padding: 18px 12px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: rgba(255,255,255,.82); font-weight: 500; }
.side nav a i { font-style: normal; width: 18px; text-align: center; opacity: .9; }
.side nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.side nav a.active { background: rgba(255,255,255,.14); color: #fff; box-shadow: inset 3px 0 0 var(--red); }
.side nav a em { margin-left: auto; font-style: normal; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.side-foot .btn { color: #fff; border-color: rgba(255,255,255,.25); }
.side-foot .muted { color: rgba(255,255,255,.6); }
.main { padding: 0 24px 40px; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 0 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.view { display: flex; flex-direction: column; gap: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.flush { padding: 0; }
.card-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.chart { position: relative; height: 280px; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 700px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kpi .val { font-size: 22px; } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); cursor: default; }
.kpi.click { cursor: pointer; } .kpi.click:hover { border-color: var(--accent); }
.kpi .lbl { color: var(--text-2); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.delta-up { color: var(--crit-ink); } .delta-down { color: var(--good-ink); }

/* Status chips */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.crit { background: var(--crit); } .dot.warn { background: var(--warn); } .dot.good { background: var(--good); } .dot.serious { background: var(--serious); }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); white-space: nowrap; }
.pill.crit { background: color-mix(in srgb, var(--crit) 14%, transparent); border-color: transparent; color: var(--crit-ink); }
.pill.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); border-color: transparent; color: var(--warn-ink); }
.pill.good { background: color-mix(in srgb, var(--good) 14%, transparent); border-color: transparent; color: var(--good-ink); }
.pill.info { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.side .pill.crit { background: var(--crit); color: #fff; }

/* Tables */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl.hover tbody tr { cursor: pointer; } .tbl.hover tbody tr:hover { background: var(--surface-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl .code { font-weight: 600; color: var(--accent); white-space: nowrap; }
.bar-cell { display: flex; align-items: center; gap: 8px; }
.bar-cell span { height: 6px; border-radius: 3px; background: var(--s1); }
.empty { padding: 24px; text-align: center; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.toolbar input[type=search] { flex: 1 1 280px; }
.pager { display: flex; gap: 6px; justify-content: center; }

/* Heatmap */
.heat { border-collapse: separate; border-spacing: 2px; font-size: 12px; }
.heat th { font-weight: 600; color: var(--text-2); padding: 4px 6px; text-align: left; }
.heat th.rot { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; height: 120px; vertical-align: bottom; text-align: left; }
.heat td { width: 44px; height: 34px; text-align: center; border-radius: 4px; font-variant-numeric: tabular-nums; }

/* Insights */
.insights { display: flex; flex-direction: column; gap: 10px; }
.ins { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.ins .ico { grid-row: span 3; font-size: 16px; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-weight: 700; }
.ins.crit .ico { background: color-mix(in srgb, var(--crit) 16%, transparent); color: var(--crit-ink); }
.ins.warn .ico { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn-ink); }
.ins.info .ico { background: var(--accent-soft); color: var(--accent); }
.ins.good .ico { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good-ink); }
.ins b { font-size: 14px; }
.ins ul { margin: 4px 0 0; padding-left: 18px; color: var(--text-2); }
.ins .tag { font-size: 11.5px; color: var(--muted); }

/* Form */
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.form .full { grid-column: 1 / -1; }
.form .sec { grid-column: 1 / -1; font-weight: 600; color: var(--accent); border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-top: 6px; font-size: 13px; }
.form .actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.req-star { color: var(--crit-ink); font-weight: 600; }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.dup-warn { grid-column: 1 / -1; }

/* Drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(10,8,16,.4); z-index: 20; }
.drawer { position: fixed; right: 0; top: 0; bottom: 0; width: min(760px, 100vw); background: var(--surface); z-index: 21; display: flex; flex-direction: column; box-shadow: -10px 0 40px rgba(0,0,0,.2); }
.drawer-h { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); gap: 8px; }
.drawer-h b { font-size: 16px; }
.drawer-b { padding: 16px 18px 40px; overflow-y: auto; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.timeline { list-style: none; padding: 0; margin: 12px 0 0; border-left: 2px solid var(--line); }
.timeline li { padding: 0 0 12px 14px; position: relative; font-size: 13px; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline .meta { color: var(--muted); font-size: 12px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 50; font-weight: 500; max-width: calc(100vw - 32px); }

.list-editor textarea { min-height: 150px; font-size: 13px; }

@media (max-width: 1100px) { .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; z-index: 15; padding: 4px 6px; flex-direction: row; }
  .side .brand, .side-foot { display: none; }
  .side nav { flex-direction: row; width: 100%; justify-content: space-between; overflow-x: auto; }
  .side nav a { flex-direction: column; gap: 0; padding: 6px 2px; font-size: 10px; flex: 1; min-width: 50px; text-align: center; position: relative; }
  .side nav a .dl { display: none; }
  .side nav a span { white-space: nowrap; }
  .side nav a.active { box-shadow: inset 0 -3px 0 var(--red); }
  .side nav a em { position: absolute; margin: 0; top: 0; right: 4px; font-size: 10px; padding: 0 5px; }
  .main { padding: 0 16px 90px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .chart { height: 240px; }
  .filters select, .filters input { flex: 1 1 140px; }
}
