/* Hermes Cost Console — design system.
 *
 * Dark-only by choice: this is an ops console that lives on a second monitor,
 * and a single committed theme is sharper than two mediocre ones.
 *
 * The series palette is NOT hand-picked. It is the validated categorical set
 * from the dataviz skill, in its documented order, re-run against this page's
 * own chart surface (#0e1223): lightness band, chroma floor, adjacent-pair CVD
 * separation, normal-vision floor and 3:1 contrast all pass. The order is the
 * colorblind-safety mechanism, so do not reorder these to taste.
 *
 * No CSS framework: a browser-compiled Tailwind build was vendored first and
 * then dropped. It cost 259 KB of JS plus a compile on every page load, and it
 * fought the strict CSP, to supply utilities this file already expresses as
 * tokens. Everything here is modern plain CSS — custom properties, grid,
 * color-mix — so there is no build step and no flash of unstyled dashboard.
 */

:root {
  color-scheme: dark;

  /* surfaces */
  --plane:        #020617;   /* page */
  --surface:      #0e1223;   /* cards, chart surface (validator target) */
  --surface-2:    #141a2e;   /* nested rows, table headers */
  --surface-3:    #1b2238;   /* hover */

  /* ink */
  --ink:          #f8fafc;
  --ink-2:        #c3c8d4;
  --muted:        #8b93a7;
  --faint:        #5c6479;

  /* lines */
  --grid:         #1e2439;
  --border:       rgba(255, 255, 255, 0.09);
  --border-2:     rgba(255, 255, 255, 0.16);
  --baseline:     #334155;

  /* brand accent — used for focus + active nav, never as a series color */
  --accent:       #38bdf8;
  --accent-ink:   #04121c;

  /* status — reserved. Never reused as a series color. Always with a label. */
  --good:         #0ca30c;
  --warning:      #fab219;
  --serious:      #ec835a;
  --critical:     #d03b3b;
  --dead:         #6b7280;

  /* categorical series, fixed order */
  --s1: #3987e5;  --s2: #d95926;  --s3: #199e70;  --s4: #c98500;
  --s5: #d55181;  --s6: #008300;  --s7: #9085e9;  --s8: #e66767;
  --s-other: #8b93a7;

  /* spacing — density 9/10 */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px;

  --radius: 10px;
  --radius-sm: 6px;

  --font-sans: "Fira Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Fira Code", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --sidebar-w: 216px;
  --topbar-h: 52px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------- layout */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 26px; height: 26px; flex: 0 0 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--s7));
  display: grid; place-items: center;
  color: var(--accent-ink); font-weight: 700; font-size: 13px;
}
.brand-name { font-weight: 600; font-size: 14px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--faint); }

.nav { padding: var(--sp-2); display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 7px var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-size: 13px;
  transition: background 160ms ease, color 160ms ease;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a.active {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--ink);
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav svg { width: 15px; height: 15px; flex: 0 0 15px; stroke-width: 1.8; }

.sidebar-foot {
  padding: var(--sp-3);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--faint);
  display: flex; flex-direction: column; gap: var(--sp-1);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-4);
}
.topbar h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.topbar .spacer { flex: 1; }

.content { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }

/* ----------------------------------------------------------- components */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 13px; font-weight: 600; margin: 0; letter-spacing: 0.01em; }
.card-head .hint { font-size: 11px; color: var(--faint); font-weight: 400; }
.card-head .spacer { flex: 1; }
.card-body { padding: var(--sp-4); }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: var(--sp-3); }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* KPI tile — hero number in proportional figures, per the mark spec */
.kpi { position: relative; padding: var(--sp-3) var(--sp-4); }
.kpi-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 500;
}
.kpi-value {
  font-size: 26px; font-weight: 600; letter-spacing: -0.02em;
  margin-top: 2px; line-height: 1.15;
}
.kpi-sub { font-size: 11px; color: var(--faint); margin-top: 2px; }
.kpi-spark { height: 34px; margin-top: var(--sp-2); }

/* status pills — always icon/label, never colour alone */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 500; white-space: nowrap;
  border: 1px solid var(--border-2);
  background: var(--surface-2); color: var(--ink-2);
}
.pill::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex: 0 0 6px;
}
.pill.good     { color: #4ade80; border-color: color-mix(in srgb, var(--good) 45%, transparent); }
.pill.notice   { color: #a5b4fc; border-color: color-mix(in srgb, #a5b4fc 40%, transparent); }
.pill.warning  { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 45%, transparent); }
.pill.serious  { color: var(--serious); border-color: color-mix(in srgb, var(--serious) 45%, transparent); }
.pill.critical,
.pill.exhausted{ color: #f87171; border-color: color-mix(in srgb, var(--critical) 55%, transparent); }
.pill.dead     { color: var(--dead); border-color: var(--border); }
.pill.no-api,
.pill.unknown  { color: var(--muted); border-color: var(--border); }
.pill.low      { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 45%, transparent); }
.pill.ok       { color: #4ade80; border-color: color-mix(in srgb, var(--good) 45%, transparent); }

.tag {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  font-family: var(--font-mono); font-size: 11px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--ink-2);
}

/* ------------------------------------------------------------- controls */
.seg {
  display: inline-flex; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px;
}
.seg button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  color: var(--muted); font: inherit; font-size: 12px;
  padding: 4px 10px; border-radius: 4px;
  transition: background 160ms ease, color 160ms ease;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.btn {
  appearance: none; cursor: pointer; font: inherit; font-size: 12px;
  padding: 5px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border-2); color: var(--ink-2);
  transition: background 160ms ease, color 160ms ease;
}
.btn:hover { background: var(--surface-3); color: var(--ink); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn-primary:hover { background: #7dd3fc; color: var(--accent-ink); }

select.input, input.input {
  appearance: none; font: inherit; font-size: 12px;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  padding: 5px 10px; min-width: 0;
}
select.input { padding-right: 26px; background-image:
  linear-gradient(45deg, transparent 50%, var(--muted) 50%),
  linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 12px, calc(100% - 9px) 12px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--accent); width: 14px; height: 14px; }

/* --------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }        /* wide tables scroll, the page never does */
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--muted);
  font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  text-align: left; padding: 7px var(--sp-3); white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
table.data th.num, table.data td.num { text-align: right; }
table.data td {
  padding: 6px var(--sp-3);
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}
table.data tbody tr { transition: background 120ms ease; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data .mono {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
}
table.data td.wrap { white-space: normal; min-width: 220px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* share bar behind a percentage — magnitude without a whole extra chart */
.bar {
  position: relative; display: block; height: 4px; border-radius: 2px;
  background: var(--grid); overflow: hidden; min-width: 46px;
}
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

/* ---------------------------------------------------------------- charts */
.chart { width: 100%; height: 300px; }
.chart.tall { height: 380px; }
.chart.short { height: 200px; }

.legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4) 0; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-2); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 10px; }

/* --------------------------------------------------------------- notices */
.note {
  display: flex; gap: var(--sp-2); align-items: flex-start;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius); font-size: 12.5px; line-height: 1.5;
  border: 1px solid var(--border-2); background: var(--surface-2); color: var(--ink-2);
}
.note strong { color: var(--ink); }
.note.warn     { border-color: color-mix(in srgb, var(--warning) 45%, transparent);
                 background: color-mix(in srgb, var(--warning) 9%, var(--surface)); }
.note.critical { border-color: color-mix(in srgb, var(--critical) 55%, transparent);
                 background: color-mix(in srgb, var(--critical) 11%, var(--surface)); }
.note.info     { border-color: color-mix(in srgb, var(--accent) 35%, transparent);
                 background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }

.empty { padding: var(--sp-6); text-align: center; color: var(--faint); font-size: 13px; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* -------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-4); }
.login-card { width: 100%; max-width: 360px; }
.login-card .card-body { display: flex; flex-direction: column; gap: var(--sp-3); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); }
.field input {
  font: inherit; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border-2); color: var(--ink);
}

/* -------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; z-index: 40; transform: translateX(-100%);
    transition: transform 200ms ease;
  }
  .sidebar.open { transform: translateX(0); }
  .nav-toggle { display: inline-flex !important; }
  .content { padding: var(--sp-3); }
  .kpi-value { font-size: 22px; }
}
.nav-toggle { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================== mobile
 * The dashboard is dense by design, which is right on a desktop and wrong on a
 * phone. Below 900px the multi-column grids collapse, the card headers stack
 * instead of squeezing their controls, and every control grows to a 44px touch
 * target. Wide tables keep scrolling inside their own container so the page
 * itself never scrolls sideways.
 */
@media (max-width: 900px) {
  :root { --sp-4: 12px; --topbar-h: auto; }

  /* Off-canvas sidebar with a dimming overlay. */
  .sidebar { width: 260px; flex-basis: 260px; box-shadow: 0 0 40px rgba(0,0,0,.6); }
  .scrim {
    position: fixed; inset: 0; z-index: 35;
    background: rgba(2, 6, 23, 0.6); backdrop-filter: blur(2px);
    opacity: 0; pointer-events: none; transition: opacity 200ms ease;
  }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .nav a { padding: 11px var(--sp-3); font-size: 14px; }

  .topbar {
    flex-wrap: wrap;
    padding: 8px var(--sp-3);
    row-gap: 8px;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  .topbar h1 { font-size: 16px; }
  .topbar .spacer { display: none; }
  /* The range picker gets its own full-width row and scrolls if it must. */
  .topbar .seg {
    order: 10; flex: 1 1 100%;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .topbar .seg::-webkit-scrollbar { display: none; }
  .topbar .seg button { flex: 1 0 auto; padding: 9px 12px; font-size: 13px; }
  .nav-toggle { min-width: 44px; min-height: 38px; }

  /* Every multi-column grid becomes one column — including the inline
     grid-template-columns set on a few sections. */
  .grid, .grid-2, .grid-3, .grid-kpi { grid-template-columns: 1fr !important; }
  .grid-kpi { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)) !important; }

  /* Card headers stack so a title never fights a control for width. */
  .card-head { flex-wrap: wrap; row-gap: 8px; padding: var(--sp-3); }
  .card-head .spacer { flex-basis: 100%; height: 0; }
  .card-head .seg { flex: 1 1 100%; }
  .card-head .seg button { flex: 1; padding: 9px 8px; }

  .card-body { padding: var(--sp-3); }
  .chart { height: 240px; }
  .chart.tall { height: 280px; }

  .kpi-value { font-size: 21px; }
  .kpi { padding: var(--sp-3); }

  /* Keep the identifying column visible while the rest of a wide row scrolls. */
  table.data th:first-child,
  table.data td:first-child {
    position: sticky; left: 0; z-index: 2;
    background: var(--surface);
    box-shadow: 1px 0 0 var(--grid);
  }
  table.data th:first-child { background: var(--surface-2); z-index: 3; }
  table.data tbody tr:hover td:first-child { background: var(--surface-2); }
  table.data td, table.data th { padding: 9px var(--sp-2); }

  .btn, select.input, input.input { min-height: 40px; }
  .field input { min-height: 44px; font-size: 16px; }  /* 16px stops iOS zoom-on-focus */

  .content { padding: var(--sp-3); padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  .note { padding: var(--sp-3); font-size: 13px; }
}

@media (max-width: 460px) {
  .grid-kpi { grid-template-columns: 1fr !important; }
  .brand-sub { display: none; }
}
