/* ==========================================================================
   MVC Inference Portal
   ==========================================================================

   Two token groups, deliberately separate:

   --brand-*    chrome: sidebar, accent, buttons. Swap these for your own
                brand and nothing else changes.
   --series-* / --ink-* / --grid-*
                chart tokens from the validated data-viz palette. These are
                NOT brand colours: they are chosen for contrast and CVD
                separation against the chart surface, and re-tinting them to
                match a brand breaks that. Leave them alone.

   Dark mode is declared twice on purpose: the media query follows the OS, the
   [data-theme] scope follows the in-page toggle, and the toggle must win in
   both directions.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Brand chrome */
  --brand-accent:      #f5c518;
  --brand-accent-ink:  #1a1a19;
  --brand-accent-dim:  rgba(245, 197, 24, 0.16);
  --brand-shell:       #16181c;
  --brand-shell-2:     #1e2126;
  --brand-shell-ink:   #e8e8e4;
  --brand-shell-muted: #9a9c9f;

  /* Planes */
  --page:       #f9f9f7;
  --surface:    #fcfcfb;
  --surface-2:  #f3f3f0;

  /* Ink */
  --ink:        #0b0b0b;
  --ink-2:      #52514e;
  --ink-muted:  #898781;

  /* Lines */
  --grid:       #e1e0d9;
  --axis:       #c3c2b7;
  --border:     rgba(11, 11, 11, 0.10);

  /* Chart series (validated: blue / orange / aqua) */
  --series-1:   #2a78d6;
  --series-2:   #eb6834;
  --series-3:   #1baf7a;
  --series-1-fill: rgba(42, 120, 214, 0.14);
  --series-2-fill: rgba(235, 104, 52, 0.14);

  /* Status (fixed, never themed — always paired with an icon + label) */
  --good:       #0ca30c;
  --warning:    #fab219;
  --serious:    #ec835a;
  --critical:   #d03b3b;

  --radius:     10px;
  --radius-sm:  6px;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:      #0d0d0d;
    --surface:   #1a1a19;
    --surface-2: #222220;
    --ink:       #ffffff;
    --ink-2:     #c3c2b7;
    --ink-muted: #898781;
    --grid:      #2c2c2a;
    --axis:      #383835;
    --border:    rgba(255, 255, 255, 0.10);
    --series-1:  #3987e5;
    --series-2:  #d95926;
    --series-3:  #199e70;
    --series-1-fill: rgba(57, 135, 229, 0.18);
    --series-2-fill: rgba(217, 89, 38, 0.18);
    --brand-shell:   #111316;
    --brand-shell-2: #191c20;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:      #0d0d0d;
  --surface:   #1a1a19;
  --surface-2: #222220;
  --ink:       #ffffff;
  --ink-2:     #c3c2b7;
  --ink-muted: #898781;
  --grid:      #2c2c2a;
  --axis:      #383835;
  --border:    rgba(255, 255, 255, 0.10);
  --series-1:  #3987e5;
  --series-2:  #d95926;
  --series-3:  #199e70;
  --series-1-fill: rgba(57, 135, 229, 0.18);
  --series-2-fill: rgba(217, 89, 38, 0.18);
  --brand-shell:   #111316;
  --brand-shell-2: #191c20;
}

/* ------------------------------------------------------------------ reset */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 400 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }

code, .mono { font-family: var(--mono); font-size: 0.92em; }

/* ----------------------------------------------------------------- layout */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  flex: 0 0 232px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--brand-shell);
  color: var(--brand-shell-ink);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.brand-mark {
  width: 28px; height: 28px;
  flex: 0 0 28px;
  border-radius: 7px;
  background: var(--brand-accent);
  color: var(--brand-accent-ink);
  display: grid; place-items: center;
  font-weight: 700; font-size: 15px;
}
.brand-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.brand-sub {
  font-size: 11px;
  color: var(--brand-shell-muted);
  letter-spacing: 0.02em;
}

.nav { padding: 10px 8px; flex: 1; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--brand-shell-muted);
  font-size: 13px;
  font-weight: 500;
}
.nav a:hover { background: var(--brand-shell-2); color: var(--brand-shell-ink); }
.nav a.on {
  background: var(--brand-accent-dim);
  color: #fff;
  box-shadow: inset 2px 0 0 var(--brand-accent);
}
.nav svg { width: 16px; height: 16px; flex: 0 0 16px; opacity: 0.9; }

.sidebar-foot {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 11px;
  color: var(--brand-shell-muted);
}

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar .grow { flex: 1; }
.crumb { font-size: 12px; color: var(--ink-muted); margin-bottom: 2px; }

.content { padding: 22px 24px 60px; }
.stack > * + * { margin-top: 18px; }

/* ------------------------------------------------------------------ user */

.who { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--brand-shell); color: #fff;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
}
.who-name { font-size: 12px; font-weight: 600; line-height: 1.3; }
.who-role { font-size: 11px; color: var(--ink-muted); }

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.card-head .grow { flex: 1; }
.card-head p { margin: 2px 0 0; font-size: 12px; color: var(--ink-muted); }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.c3, .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) { .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; } }

/* -------------------------------------------------------------- stat tiles */

.stat { padding: 14px 16px; }
.stat-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-muted);
}
.stat-value {
  margin-top: 6px;
  font-size: 26px; font-weight: 600; line-height: 1.1;
  letter-spacing: -0.02em;
}
.stat-value small { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.stat-note { margin-top: 4px; font-size: 12px; color: var(--ink-muted); }

/* ------------------------------------------------------------------ pills */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px 2px 7px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-2);
  white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ready    { color: var(--good);     border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.pill.scaling  { color: var(--warning);  border-color: color-mix(in srgb, var(--warning) 45%, transparent); }
.pill.starting { color: var(--serious);  border-color: color-mix(in srgb, var(--serious) 45%, transparent); }
.pill.failed   { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 45%, transparent); }
.pill.idle     { color: var(--ink-muted); }
.pill.on  { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.pill.off { color: var(--ink-muted); }

.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--mono); font-size: 11px;
  color: var(--ink-2);
}

/* ----------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th {
  text-align: left;
  padding: 9px 14px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--ink-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.t td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover { background: var(--surface-2); }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t a.link { font-weight: 600; }
table.t a.link:hover { color: var(--series-1); }

/* ---------------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font: 600 13px var(--sans);
  cursor: pointer;
}
.btn:hover { background: var(--surface); border-color: var(--axis); }
.btn.primary {
  background: var(--brand-accent);
  border-color: transparent;
  color: var(--brand-accent-ink);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, transparent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.sm { padding: 4px 9px; font-size: 12px; }

.field { display: block; margin-bottom: 12px; }
.field > span {
  display: block; margin-bottom: 5px;
  font-size: 12px; font-weight: 600; color: var(--ink-2);
}
.field > em {
  display: block; margin-top: 4px;
  font-size: 11px; font-style: normal; color: var(--ink-muted);
}
input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--axis);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: 400 13px var(--sans);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--series-1);
  outline-offset: -1px;
  border-color: var(--series-1);
}
.switch { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 600; }
.switch input { width: 16px; height: 16px; accent-color: var(--series-1); }

.inline-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; }
.inline-form input[type="number"] { width: 90px; }

/* ---------------------------------------------------------------- messages */

.note {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px; color: var(--ink-2);
}
.note.warn   { border-color: color-mix(in srgb, var(--warning) 45%, transparent);
               background: color-mix(in srgb, var(--warning) 8%, var(--surface)); }
.note.bad    { border-color: color-mix(in srgb, var(--critical) 45%, transparent);
               background: color-mix(in srgb, var(--critical) 8%, var(--surface)); }
.note strong { color: var(--ink); }
.note-row { display: flex; gap: 9px; align-items: flex-start; }
.note-row svg { flex: 0 0 16px; width: 16px; height: 16px; margin-top: 1px; }

.empty { padding: 40px 20px; text-align: center; color: var(--ink-muted); }
.empty h2 { color: var(--ink); margin-bottom: 6px; }
.empty p { margin: 0 auto; max-width: 460px; font-size: 13px; }

/* ------------------------------------------------------------------ charts */

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-title {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 2px;
}
.chart-title h3 { font-size: 12px; color: var(--ink-2); }
.chart-title .now {
  font-size: 18px; font-weight: 600; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.chart-sub { font-size: 11px; color: var(--ink-muted); margin-bottom: 8px; }

.tip {
  position: absolute;
  pointer-events: none;
  z-index: 10;
  min-width: 132px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--axis);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.08s;
}
.tip.on { opacity: 1; }
.tip .tip-t { color: var(--ink-muted); font-size: 11px; margin-bottom: 4px; }
.tip .tip-r { display: flex; justify-content: space-between; gap: 12px; }
.tip .tip-r b { font-variant-numeric: tabular-nums; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px;
               font-size: 11px; color: var(--ink-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: block; }
.legend i.dash {
  width: 14px; height: 0; border-radius: 0;
  border-top: 2px dashed var(--ink-muted);
}

/* ------------------------------------------------------------------- login */

.login-page {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(1000px 500px at 50% -10%, var(--brand-accent-dim), transparent),
    var(--page);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 30px 28px;
  text-align: center;
}
.login-card .brand-mark { width: 40px; height: 40px; font-size: 20px; margin: 0 auto 16px; }
.login-card h1 { font-size: 19px; }
.login-card p { color: var(--ink-2); font-size: 13px; margin: 8px 0 22px; }
.btn-ms {
  width: 100%;
  justify-content: center;
  padding: 11px;
  font-size: 14px;
}
.login-foot {
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 11px; color: var(--ink-muted);
}

.ms-logo { width: 17px; height: 17px; flex: 0 0 17px; }

/* -------------------------------------------------------------- utilities */

.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--ink-muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hide { display: none !important; }
.sr {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.bar {
  height: 6px; border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
  border: 1px solid var(--border);
}
.bar > i { display: block; height: 100%; background: var(--series-1); }
.bar > i.hot { background: var(--critical); }
.bar > i.warm { background: var(--warning); }

@media print {
  .sidebar, .topbar, .btn { display: none !important; }
  .card { break-inside: avoid; }
}
