:root {
  color-scheme: light;
  --bg: #f6f7f5; --surface: #ffffff; --surface-2: #f9f9f7; --surface-3: #f0efec;
  --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781;
  --line: #e1e0d9; --line-strong: #c3c2b7;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #e3f3f1;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --good: #0ca30c; --good-ink: #006300; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --cold: #2a78d6; --warm: #c98500; --hot: #d03b3b; --won: #0ca30c; --dead: #898781;
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95; --seq-7: #0d366b;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 10px rgba(0,0,0,.04);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #202020; --surface-3: #2a2a28;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
    --line: #2c2c2a; --line-strong: #383835;
    --brand: #2bb3a6; --brand-ink: #041b19; --brand-soft: #12302d;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --good-ink: #0ca30c; --cold: #3987e5; --warm: #eda100; --hot: #e66767;
    --shadow: none;
    --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #256abf; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #86b6ef; --seq-7: #cde2fb;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #202020; --surface-3: #2a2a28;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --line: #2c2c2a; --line-strong: #383835;
  --brand: #2bb3a6; --brand-ink: #041b19; --brand-soft: #12302d;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --good-ink: #0ca30c; --cold: #3987e5; --warm: #eda100; --hot: #e66767;
  --shadow: none;
    --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #256abf; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #86b6ef; --seq-7: #cde2fb;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--ink-2); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 9px; padding: 4px 10px 18px; font-weight: 700; font-size: 15px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 16px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--surface-3); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 16px 10px 6px; }
.nav svg { width: 17px; height: 17px; flex: none; }
.sidebar-foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.main { min-width: 0; padding: 22px 28px 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn.mobile-nav { display: none; }

/* cards & grids */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 1fr) 360px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 12px; color: var(--ink-2); display: flex; justify-content: space-between; gap: 6px; }
.tile .value { font-size: 26px; font-weight: 650; margin: 4px 0 2px; letter-spacing: -.02em; }
.tile .sub { font-size: 12px; color: var(--muted); }
.delta-up { color: var(--good-ink); } .delta-down { color: var(--critical); }

/* status pill (icon + label, never color alone) */
.status { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status.good::before { background: var(--good); } .status.warning::before { background: var(--warning); }
.status.critical::before { background: var(--critical); } .status.serious::before { background: var(--serious); }
.status.info::before { background: var(--s1); }

/* temperature badges */
.temp { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.temp.cold { background: color-mix(in srgb, var(--cold) 14%, transparent); color: var(--cold); }
.temp.warm { background: color-mix(in srgb, var(--warm) 18%, transparent); color: var(--warm); }
.temp.hot  { background: color-mix(in srgb, var(--hot) 15%, transparent); color: var(--hot); }
.temp.won  { background: color-mix(in srgb, var(--won) 15%, transparent); color: var(--good-ink); }
.temp.dead { background: var(--surface-3); color: var(--muted); }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--surface-3); color: var(--ink-2); margin: 1px 2px 1px 0; white-space: nowrap; }
.score { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.score .bar { width: 42px; height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.score .bar i { display: block; height: 100%; background: var(--brand); border-radius: 3px; }

/* forms */
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
textarea { width: 100%; resize: vertical; }
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.field { margin-bottom: 12px; min-width: 0; }
.field input, .field select, .field textarea { width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.checks label { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 4px 9px; border: 1px solid var(--line-strong); border-radius: 99px; cursor: pointer; user-select: none; }
.checks input { margin: 0; accent-color: var(--brand); }
.checks label:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
select[multiple] { min-height: 90px; }

.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; padding: 7px 13px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--critical); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
th.sortable { cursor: pointer; } th.sortable:hover { color: var(--ink); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }

/* filter bar */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { width: 240px; }
.bulkbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 12px; background: var(--brand-soft); border-radius: 8px; margin-bottom: 10px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--ink-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--brand); border-color: var(--brand); text-decoration: none; }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* kanban */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { flex: 0 0 250px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 170px); }
.col-head { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.col-head .t { font-weight: 700; display: flex; justify-content: space-between; }
.col-body { padding: 8px; overflow-y: auto; flex: 1; min-height: 80px; }
.col.drag-over { outline: 2px dashed var(--brand); }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); }
.kcard:active { cursor: grabbing; }
.kcard .n { font-weight: 600; }
.kcard .a { font-size: 12px; color: var(--ink-2); margin: 2px 0 6px; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 26px 1fr; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.ti { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); font-size: 13px; }
.timeline .meta { font-size: 11px; color: var(--muted); }

/* modal, toast */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 980px; }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-b { padding: 18px 20px; }
.modal-f { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 18px; border-radius: 10px; z-index: 99; font-weight: 600; box-shadow: 0 6px 30px rgba(0,0,0,.25); max-width: calc(100vw - 32px); }
.toast.err { background: var(--critical); color: #fff; }

/* insights */
.insight { display: grid; grid-template-columns: 22px 1fr; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.insight:last-child { border-bottom: 0; }
.insight .ic { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; color: #fff; }
.insight .ic.critical { background: var(--critical); } .insight .ic.warning { background: var(--warning); color: #3a2a00; }
.insight .ic.good { background: var(--good); } .insight .ic.info { background: var(--s1); }
.insight .t { font-weight: 650; }
.insight .d { color: var(--ink-2); font-size: 13px; margin-top: 2px; }

/* funnel */
.funnel .step { display: grid; grid-template-columns: 110px 1fr 110px; gap: 10px; align-items: center; margin: 6px 0; }
.funnel .track { height: 22px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.funnel .fill { height: 100%; background: var(--seq-4); border-radius: 0 4px 4px 0; }

/* heatmap */
.heat { display: grid; grid-template-columns: 38px repeat(24, minmax(12px, 1fr)); gap: 2px; font-size: 10px; color: var(--muted); }
.heat .c { aspect-ratio: 1.3; border-radius: 3px; background: var(--surface-3); position: relative; }
.heat .c:hover { outline: 2px solid var(--ink); }
.heat .hl { display: flex; align-items: center; }
.legend-ramp { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 8px; }
.legend-ramp span.sw { width: 18px; height: 10px; border-radius: 2px; display: inline-block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.chart-box { position: relative; height: 240px; }
.tip { position: fixed; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: 0 4px 18px rgba(0,0,0,.15); z-index: 60; }

.hbar { display: grid; grid-template-columns: 1fr; gap: 8px; }
.hbar .r { display: grid; grid-template-columns: 130px 1fr 60px; gap: 8px; align-items: center; font-size: 13px; }
.hbar .track { height: 12px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 0 4px 4px 0; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }
.preview-frame { width: 100%; height: 460px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.copy { display: flex; gap: 6px; } .copy input { flex: 1; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.warnlist { margin: 6px 0 0; padding-left: 18px; color: var(--ink-2); font-size: 12px; }

/* auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth { width: 100%; max-width: 420px; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-side { grid-template-columns: 1fr; } }
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.open { display: flex; position: fixed; inset: 0 30% 0 0; z-index: 40; min-width: 240px; }
  .btn.mobile-nav { display: inline-flex; }
  .main { padding: 14px 16px 60px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .filters input[type=search] { width: 100%; }
  .funnel .step { grid-template-columns: 80px 1fr 80px; }
  .hbar .r { grid-template-columns: 90px 1fr 50px; }
}
.tiles.k8 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .tiles.k8 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
