:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.04);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --neg: #e34948;
  --mid: #f0efec;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --up-good: #006300;
  /* sequential blue: low recedes towards the surface */
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5;
  --seq-5: #256abf; --seq-6: #184f95; --seq-7: #0d366b;
  --seq-ink-flip: 4; /* from this step on, cell text is white */
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.05);
    --accent: #3987e5;
    --neg: #e66767;
    --mid: #383835;
    --up-good: #0ca30c;
    --seq-1: #0d366b; --seq-2: #184f95; --seq-3: #256abf; --seq-4: #3987e5;
    --seq-5: #6da7ec; --seq-6: #9ec5f4; --seq-7: #cde2fb;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
[hidden] { display: none !important; }
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 4px; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 4px; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 650; }
p { margin: 0 0 12px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.error { color: var(--critical); min-height: 1.5em; margin: 0; }
a { color: inherit; }

.btn {
  font: inherit; font-weight: 550; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
}
.btn:hover { background: var(--wash); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--critical); }
.btn:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--axis);
  border-radius: 8px; padding: 8px 10px; max-width: 100%;
}

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; display: grid; gap: 14px;
}
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--ink-2); }

/* shell */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100%; }
.shell.with-chat { grid-template-columns: 220px minmax(0, 1fr) 380px; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 20px 14px; display: flex; flex-direction: column;
  gap: 18px; border-right: 1px solid var(--border); background: var(--surface);
}
.brand { font-weight: 700; font-size: 16px; padding: 0 8px; }
#nav { display: grid; gap: 2px; }
#nav a { text-decoration: none; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); }
#nav a:hover { background: var(--wash); }
#nav a[aria-current="page"] { background: var(--wash); color: var(--ink); font-weight: 600; }
.side-foot { margin-top: auto; display: grid; gap: 8px; }
.view { padding: 28px 32px 64px; min-width: 0; outline: none; max-width: 1280px; }
.view.loading { opacity: 0.55; transition: opacity 0.15s; }
.lede { color: var(--ink-2); max-width: 70ch; margin-bottom: 20px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 0 0 18px; }
.filters label { display: grid; gap: 4px; font-size: 12px; color: var(--ink-2); }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px;
  min-width: 0;
}
.card > .sub { color: var(--ink-2); font-size: 13px; margin: 0 0 12px; }
.section { margin-top: 20px; }

/* figures */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 16px; }
.tile .label { font-size: 13px; color: var(--ink-2); }
.tile .value { font-size: 26px; font-weight: 650; line-height: 1.2; margin-top: 2px; }
.tile .note { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.hero .value { font-size: 52px; line-height: 1.05; }
.delta { font-weight: 600; }
.delta.good { color: var(--up-good); }
.delta.bad { color: var(--critical); }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
th button { all: unset; cursor: pointer; }
th button:hover { color: var(--ink); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--wash); }
td .sub { display: block; font-size: 12px; color: var(--ink-2); }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.badge .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.badge .ico { font-size: 12px; width: 12px; text-align: center; font-weight: 700; }
.s-good .ico { color: var(--good); } .s-warning .ico { color: var(--warning); }
.s-serious .ico { color: var(--serious); } .s-critical .ico { color: var(--critical); }
.s-neutral .ico { color: var(--muted); }

/* heat grid */
.heat { border-collapse: separate; border-spacing: 2px; }
.heat th, .heat td { border: 0; padding: 0; }
.heat th { padding: 4px 8px; }
.heat td.cell {
  text-align: center; font-size: 12px; font-variant-numeric: tabular-nums; height: 28px; min-width: 62px;
  border-radius: 4px; cursor: default;
}
.heat td.cell:hover, .heat td.cell:focus { outline: 2px solid var(--ink); outline-offset: -2px; }
.heat td.name { padding-right: 12px; white-space: nowrap; font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--ink-2); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 10px; border-radius: 2px; display: inline-block; }
.legend i.line { height: 2px; width: 16px; border-radius: 0; }

/* charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-size: 12px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart text.val { fill: var(--ink); font-weight: 600; }
.chart text.lab { fill: var(--ink-2); }
details.tbl { margin-top: 8px; font-size: 13px; }
details.tbl summary { cursor: pointer; color: var(--ink-2); }
.tip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: var(--page);
  padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.45; max-width: 280px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}
.tip strong { font-size: 13px; display: block; }
.tip .k { opacity: 0.75; }

.notice { border-left: 3px solid var(--axis); padding: 8px 12px; background: var(--wash); border-radius: 0 8px 8px 0;
  font-size: 14px; margin: 0 0 12px; }
.notice.warn { border-left-color: var(--warning); }
ul.plain { margin: 0; padding-left: 18px; }
ul.plain li { margin-bottom: 4px; }

.slider { display: flex; align-items: center; gap: 12px; }
.slider input[type=range] { padding: 0; width: 220px; accent-color: var(--accent); }
.slider output { font-weight: 650; font-size: 18px; min-width: 3ch; }

.map-grid { display: grid; grid-template-columns: minmax(160px, 240px) minmax(0, 1fr); gap: 8px 12px; align-items: center; margin: 12px 0; }
.drop { border: 1px dashed var(--axis); border-radius: 10px; padding: 16px; display: grid; gap: 10px; }

/* drawer + chat */
.drawer-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--surface);
  z-index: 31; padding: 24px; overflow-y: auto; border-left: 1px solid var(--border);
}
.chat {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  border-left: 1px solid var(--border); background: var(--surface);
}
.chat header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: grid; gap: 12px; align-content: start; }
.msg { padding: 10px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.msg.user { background: var(--accent); color: var(--accent-ink); justify-self: end; max-width: 88%; }
.msg.bot { background: var(--wash); justify-self: start; max-width: 96%; }
.msg.err { background: transparent; border: 1px solid var(--critical); }
.msg .tools { display: block; margin-top: 6px; font-size: 11px; color: var(--ink-2); }
.chat-suggest { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.chat-suggest button { font: inherit; font-size: 12px; padding: 5px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: transparent; color: var(--ink-2); text-align: left; }
.chat-suggest button:hover { background: var(--wash); color: var(--ink); }
.chat-form { display: flex; gap: 8px; padding: 12px 16px 16px; border-top: 1px solid var(--border); }
.chat-form textarea { flex: 1; resize: none; }

@media (max-width: 1100px) {
  .shell.with-chat { grid-template-columns: 220px minmax(0, 1fr); }
  .chat { position: fixed; right: 0; top: 0; width: min(400px, 100%); z-index: 20; box-shadow: -8px 0 24px rgba(0, 0, 0, 0.15); }
}
@media (max-width: 760px) {
  .shell, .shell.with-chat { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: column; border-right: 0; border-bottom: 1px solid var(--border); padding: 12px 16px; gap: 10px; }
  #nav { display: flex; overflow-x: auto; gap: 4px; }
  #nav a { white-space: nowrap; }
  .side-foot { margin-top: 0; display: flex; }
  .view { padding: 20px 16px 48px; }
  .hero .value { font-size: 44px; }
  .map-grid { grid-template-columns: 1fr; }
}

/* sequential steps for the heat grid and its legend; ink flips where the fill gets dark */
.q1 { background: var(--seq-1); } .q2 { background: var(--seq-2); } .q3 { background: var(--seq-3); }
.q4 { background: var(--seq-4); } .q5 { background: var(--seq-5); } .q6 { background: var(--seq-6); }
.q7 { background: var(--seq-7); }
.q1, .q2, .q3, .q4 { color: #0b0b0b; } .q5, .q6, .q7 { color: #ffffff; }
@media (prefers-color-scheme: dark) {
  .q1, .q2, .q3 { color: #ffffff; } .q4, .q5, .q6, .q7 { color: #0b0b0b; }
}

/* keep the name column readable when a wide table scrolls sideways on a phone */
.table-wrap td:first-child, .table-wrap th:first-child { min-width: 190px; }
.heat td:first-child, .heat th:first-child { min-width: 0; }

/* first sign-in authenticator wizard */
.wizard { width: min(480px, 100%); }
.wizard-head { display: flex; justify-content: space-between; }
.wizard-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.wizard-bar i { height: 4px; border-radius: 2px; background: var(--grid); }
.wizard-bar i.on { background: var(--accent); }
.wizard p { margin: 0; }
.wizard-stores { display: flex; flex-wrap: wrap; gap: 8px; }
.wizard-stores a { text-decoration: none; }
.wizard-choice { display: grid; gap: 6px; margin: 10px 0; }
.wizard-choice label { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 14px; }
.wizard-list { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.wizard-qr { justify-self: center; border-radius: 8px; background: #fff; }
.wizard-key { user-select: all; overflow-wrap: anywhere; font-size: 14px; }
.wizard-code { font-size: 22px; letter-spacing: 0.12em; text-align: center; }
.wizard-nav { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 4px; }
