/* Lighthouse — SAIL Training Fleet Transparency
   Palette: dataviz reference instance (validated). Light + dark. */

:root {
  --page: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #fbfbfa;
  --text-1: #16160f;
  --text-2: #54544e;
  --muted: #8e8e87;
  --grid: #ececea;
  --border: rgba(20,20,10,0.07);
  --good: #0ca30c;
  --good-bg: #e7f6e7;
  --warning: #b97e00;
  --warning-bg: #fdf3dd;
  --critical: #d03030;
  --critical-bg: #fbe9e9;
  --accent: #2a78d6;
  --accent-2: #1c5cab;
  --accent-bg: #eaf2fc;
  --seg-empty: #e4edf9;
  --shadow: 0 1px 2px rgba(20,20,10,0.05), 0 2px 8px rgba(20,20,10,0.04);
  --shadow-lg: 0 4px 16px rgba(20,20,10,0.08);
  --radius: 14px;
}
/* Dark tokens. Applied when the OS prefers dark AND no explicit choice is set,
   OR when the user has explicitly chosen dark via the toggle ([data-theme=dark]).
   The explicit [data-theme=light] block below wins over the media query so the
   toggle can force light even on a dark-mode OS. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0d0d0c;
    --surface: #1a1a18;
    --surface-2: #202020;
    --text-1: #f2f2ec;
    --text-2: #b9b9ad;
    --muted: #7c7c74;
    --grid: #2b2b28;
    --border: rgba(255,255,255,0.07);
    --good-bg: #12300f;
    --warning: #e5b453;
    --warning-bg: #33290f;
    --critical: #ef6b6b;
    --critical-bg: #3a1414;
    --accent: #4a9af5;
    --accent-2: #74b3f7;
    --accent-bg: #16283f;
    --seg-empty: #21303f;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.5);
  }
}
:root[data-theme="dark"] {
  --page: #0d0d0c;
  --surface: #1a1a18;
  --surface-2: #202020;
  --text-1: #f2f2ec;
  --text-2: #b9b9ad;
  --muted: #7c7c74;
  --grid: #2b2b28;
  --border: rgba(255,255,255,0.07);
  --good-bg: #12300f;
  --warning: #e5b453;
  --warning-bg: #33290f;
  --critical: #ef6b6b;
  --critical-bg: #3a1414;
  --accent: #4a9af5;
  --accent-2: #74b3f7;
  --accent-bg: #16283f;
  --seg-empty: #21303f;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.5);
}

/* Theme toggle button in the nav */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-2); font-size: 15px; line-height: 1; margin-left: 12px;
  transition: background 0.15s, color 0.15s;
}
.theme-toggle:hover { color: var(--text-1); background: var(--accent-bg); }

* { box-sizing: border-box; margin: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--page); color: var(--text-1);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.92em; }

/* ═══ Nav ═══ */
.nav {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 24px;
  padding: 0 28px; height: 56px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav-brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 750; font-size: 16px; letter-spacing: -0.02em;
  text-decoration: none; color: var(--text-1); white-space: nowrap;
}
.nav-brand::before {
  content: ""; width: 9px; height: 9px; border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.nav-links {
  display: flex; gap: 2px; flex: 1;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 3px; width: fit-content; flex: initial;
  margin: 0 auto;
}
.nav-link {
  padding: 6px 16px; border-radius: 8px; text-decoration: none;
  color: var(--text-2); font-weight: 500; font-size: 13px;
  transition: all 0.15s;
}
.nav-link:hover { color: var(--text-1); }
.nav-link.active { background: var(--surface); color: var(--text-1); font-weight: 650; box-shadow: var(--shadow); }
.nav-stamp {
  font-size: 11.5px; color: var(--muted); white-space: nowrap; margin-left: auto;
  font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 7px;
}
.nav-stamp .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); animation: pulse 2.4s ease-in-out infinite; }
.nav-stamp.stale .dot { background: var(--warning); animation: none; }
@keyframes pulse { 0%,100%{box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 45%, transparent)} 50%{box-shadow: 0 0 0 5px transparent} }

/* ═══ Layout ═══ */
.main { max-width: 1180px; margin: 0 auto; padding: 32px 28px 56px; }
.loading { color: var(--muted); padding: 80px 0; text-align: center; }

.page-head { margin-bottom: 26px; display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.page-head h1 { font-size: 24px; font-weight: 750; letter-spacing: -0.02em; }
.page-head .sub { color: var(--muted); font-size: 12.5px; }

/* ═══ Hero verdict (overview) ═══ */
.hero {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 22px; margin-bottom: 20px;
  border-left: 5px solid var(--good);
  font-size: 15px;
}
.hero.warn { border-left-color: var(--warning); }
.hero.crit { border-left-color: var(--critical); }
.hero .hico { font-size: 22px; }
.hero b { font-weight: 700; }
.hero .sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }

/* ═══ Fleet segments ═══ */
.fleet { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; margin-bottom: 8px; }
.fleet-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
}
.fleet-card .fhead { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.fleet-card .fname { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.fleet-card .fmeta { color: var(--muted); font-size: 11.5px; }
.fleet-card .fcount { font-size: 26px; font-weight: 750; margin: 6px 0 10px; font-variant-numeric: tabular-nums; }
.fleet-card .fcount .of { font-size: 15px; color: var(--muted); font-weight: 500; }
.segs { display: flex; gap: 4px; flex-wrap: wrap; }
.seg {
  height: 22px; flex: 1 1 0; min-width: 12px; max-width: 34px;
  border-radius: 5px; background: var(--seg-empty);
  transition: background 0.3s;
}
.seg.used { background: var(--accent); box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--accent-2) 70%, transparent); }
.fleet-card .ffoot { margin-top: 10px; font-size: 12px; color: var(--text-2); display: flex; justify-content: space-between; align-items: center; }

/* ═══ KPI strip ═══ */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 22px 0; }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 18px; box-shadow: var(--shadow);
}
.tile .label { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650; }
.tile .val { font-size: 26px; font-weight: 750; line-height: 1.25; margin-top: 4px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.tile .val.sm { font-size: 21px; }
.tile .foot { color: var(--muted); font-size: 11px; margin-top: 3px; }
.tile .val.crit { color: var(--critical); }
.tile .val.warn { color: var(--warning); }
.tile .val.ok { color: var(--good); }

/* ═══ Pills ═══ */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 650; padding: 3px 9px; border-radius: 999px;
  white-space: nowrap; letter-spacing: 0.01em;
}
.pill.idle { color: var(--critical); background: var(--critical-bg); }
.pill.full { color: var(--good); background: var(--good-bg); }
.pill.warn { color: var(--warning); background: var(--warning-bg); }
.pill.running { color: var(--accent); background: var(--accent-bg); }
.pill.region { color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); font-weight: 550; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 10px; }

/* ═══ Tables ═══ */
/* Every table is wrapped in .card by the JS; bare tables also render cleanly. */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  color: var(--muted); font-weight: 650; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--surface-2); text-align: left;
  padding: 11px 16px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums; vertical-align: middle;
}
td.r, th.r { text-align: right; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: var(--surface-2); }
td .job-name { font-weight: 550; color: var(--text-1); }
.reason {
  color: var(--text-2); font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11.5px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Table caption row inside cards */
.card .thead-title {
  padding: 12px 16px; font-weight: 650; font-size: 13px;
  border-bottom: 1px solid var(--border);
}

/* ═══ Util bar ═══ */
.ubar { display: inline-block; width: 48px; height: 6px; border-radius: 3px; background: var(--seg-empty); vertical-align: middle; margin-right: 6px; overflow: hidden; }
.ubar > i { display: block; height: 100%; background: var(--good); border-radius: 3px; }
.ubar.low > i { background: var(--critical); }
.ubar.mid > i { background: var(--warning); }

/* ═══ Cluster cards ═══ */
.clusters { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin-bottom: 8px; }
.cluster {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
  border-top: 3px solid var(--muted);
}
.cluster.capacity { border-top-color: var(--warning); }
.cluster.vpc-config, .cluster.data-access, .cluster.oom, .cluster.user-code { border-top-color: var(--critical); }
.cluster.stopped { border-top-color: var(--grid); }
.cluster .ch { display: flex; justify-content: space-between; align-items: baseline; }
.cluster .cl { font-weight: 700; font-size: 14px; }
.cluster .cn { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; }
.cluster .cf { color: var(--text-2); font-size: 12.5px; margin-top: 8px; line-height: 1.45; }
.cluster .cm { color: var(--muted); font-size: 11px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--grid); }

/* ═══ Sections ═══ */
section { margin-top: 30px; }
section > h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 700; margin-bottom: 10px;
}
section > h2 .hint { text-transform: none; letter-spacing: 0; font-weight: 450; margin-left: 8px; }
.empty { color: var(--muted); padding: 28px 0; text-align: center; }
.more { color: var(--muted); font-size: 12px; margin-top: 10px; padding-left: 4px; }

/* ═══ Footers ═══ */
.global-foot {
  max-width: 1180px; margin: 0 auto; padding: 18px 28px 36px;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px;
  color: var(--muted); font-size: 11px; border-top: 1px solid var(--grid);
}
.foot { color: var(--muted); font-size: 11px; margin-top: 28px; line-height: 1.7; }

/* ═══ GPU calculator ═══ */
.calc-row { display: flex; gap: 20px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.calc-row label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; color: var(--text-2); }
.calc-row select, .calc-row input {
  font: inherit; padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-1);
}
.calc-out { font-size: 14px; }
.calc-badge { display: inline-block; padding: 8px 14px; border-radius: 10px; font-weight: 550; line-height: 1.4; }
.calc-badge.ok { background: var(--good-bg); color: var(--good); }
.calc-badge.warn { background: var(--warning-bg); color: var(--warning); }
.calc-badge.idle { background: var(--critical-bg); color: var(--critical); }

/* ═══ News — tiny single-line strip ═══ */
#news-ticker { max-width: 1180px; margin: 0 auto; padding: 0 28px 28px; }
.news-mini {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 12px; box-shadow: var(--shadow);
}
.news-cap {
  flex-shrink: 0; font-size: 9.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--accent);
}
.news-list { display: flex; gap: 16px; align-items: center; overflow-x: auto; scrollbar-width: none; }
.news-list::-webkit-scrollbar { display: none; }
.news-li {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  text-decoration: none; color: var(--text-2); font-size: 12px; max-width: 300px;
}
.news-li:hover { color: var(--accent); }
.news-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.news-tx { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.news-pt { font-size: 10px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* ODCR source tag on fleet cards */
.fsrc { margin-top: 8px; font-size: 10.5px; color: var(--muted); font-family: ui-monospace, "SF Mono", Menlo, monospace; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.src-tag { font-family: system-ui, sans-serif; font-size: 10px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.src-tag.ok { color: var(--good); background: var(--good-bg); border-color: transparent; }
.src-tag.warn { color: var(--warning); background: var(--warning-bg); border-color: transparent; }

/* ═══ Waitlist strip (Overview) ═══ */
.wl-card { padding: 14px 18px; }
.wl-line { display: flex; align-items: center; gap: 12px; padding: 7px 0; }
.wl-line + .wl-line { border-top: 1px solid var(--grid); }
.wl-label {
  flex-shrink: 0; width: 38px; font-weight: 700; font-size: 12px;
  color: var(--text-2); font-variant-numeric: tabular-nums;
}
.wl-chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.wl-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 10px 3px 3px; font-size: 12.5px; font-weight: 550;
}
.wl-chip:first-child { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.wl-pos {
  display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 10.5px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.wl-n { color: var(--accent); font-weight: 700; font-size: 11.5px; }
.wl-x { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 10px; padding: 0 0 0 2px; }
.wl-x:hover { color: var(--critical); }
.wl-none { color: var(--muted); font-size: 12.5px; }
.wl-actions { margin-top: 10px; }
.wl-add {
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  background: transparent; color: var(--accent); border: 1px dashed color-mix(in srgb, var(--accent) 45%, var(--border));
  border-radius: 8px; padding: 5px 12px; transition: background 0.15s;
}
.wl-add:hover { background: var(--accent-bg); }
.wl-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.wl-in { font: inherit; font-size: 12.5px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-1); }
.wl-submit { font: inherit; font-weight: 650; font-size: 12.5px; cursor: pointer; border: none; background: var(--accent); color: #fff; border-radius: 8px; padding: 6px 14px; }
.wl-submit:hover { filter: brightness(1.08); }
.wl-msg { font-size: 12px; color: var(--muted); }
.wl-msg.ok { color: var(--good); }
.wl-msg.err { color: var(--critical); }

/* Waitlist overflow → Greenland */
.wl-chip.ovf { border-color: color-mix(in srgb, var(--warning) 45%, var(--border)); background: var(--warning-bg); }
.wl-gl { font-size: 10px; font-weight: 700; color: var(--warning); margin-left: 2px; white-space: nowrap; }
.wl-cap { flex-shrink: 0; font-size: 10px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; padding-left: 6px; }

/* ODCR-vs-pool note on fleet cards */
.fpool { margin-top: 8px; font-size: 11.5px; color: var(--warning); }
.fpool b { font-weight: 700; }
.fpool-hint { color: var(--muted); font-weight: 400; }

/* Under-utilization alarm banner */
.alarm-banner {
  background: var(--warning-bg); border: 1px solid color-mix(in srgb, var(--warning) 40%, var(--border));
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 20px;
}
.alarm-head { font-weight: 700; color: var(--warning); font-size: 14px; margin-bottom: 8px; }
.alarm-row { display: flex; align-items: baseline; gap: 12px; font-size: 12.5px; padding: 4px 0; border-top: 1px solid color-mix(in srgb, var(--warning) 18%, transparent); }
.alarm-job { font-weight: 600; font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; }
.alarm-detail { color: var(--text-2); flex: 1; }
.alarm-waste { font-weight: 700; color: var(--warning); font-variant-numeric: tabular-nums; }

/* ETA source tags */
.eta-tag { font-size: 9px; font-weight: 700; padding: 1px 5px; border-radius: 4px; margin-left: 3px; vertical-align: middle; }
.eta-tag.eta-live { color: var(--good); background: var(--good-bg); }
.eta-tag.eta-hist { color: var(--accent); background: var(--accent-bg); }
.eta-tag.eta-ceil { color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); }

/* Pending (provisioning) note on fleet cards */
.fpend { margin-top: 6px; font-size: 12px; color: var(--text-2); }
