/* ws3watch dashboard -- one committed dark-navy look, no theme toggle.
 *
 * Every colour below is a token and every token has a job. The categorical
 * slots (--s1..--s8) are the dataviz dark categorical theme, re-validated
 * against THIS surface rather than the reference one:
 *
 *   validate_palette.js "#3987e5,#d95926,#199e70,#c98500,#d55181,#008300,\
 *                        #9085e9,#e66767" --mode dark --surface "#121829"
 *   lightness band PASS · chroma floor PASS · CVD adjacent dE 8.4 PASS
 *   normal-vision adjacent dE 19.3 PASS · contrast vs surface PASS (all >= 3:1)
 *
 * The status slots are the fixed status palette; on this surface they measure
 * good 5.71 : warning 10.44 : serious 7.26 : critical 3.99 -- all clear of 3:1
 * -- and they are NEVER used as a series colour, so a colour on this page
 * either means "this series" or "this state" and never both.
 *
 * There is no light mode on purpose: this is an internal tool on the house
 * navy, and a second selected palette is a second thing to keep validated.
 */
:root {
  color-scheme: dark;

  --plane: #0b0f19;          /* page */
  --surface: #121829;        /* card / chart surface */
  --surface-2: #161d31;      /* table header, hover wash */
  --line: #1f2740;           /* hairline ring */
  --grid: #1b2133;           /* gridline, one step off surface */
  --axis: #2b3346;           /* baseline / axis rule */

  --ink: #ffffff;            /* 17.7:1 on --surface */
  --ink-2: #c7cfe0;          /* 11.3:1 */
  --ink-3: #8f9ab3;          /* 6.3:1 -- axis ticks, captions */

  --good: #0ca30c;
  --warn: #fab219;
  --serious: #ec835a;
  --crit: #d03b3b;
  --stale: #8f9ab3;

  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s6: #008300;
  --s7: #9085e9;
  --s8: #e66767;

  --demph: #6b7ea8;          /* sparkline body, 4.4:1 -- recessive, not invisible */
  --track: #184f95;          /* meter track: darker step of the --s1 blue ramp */

  --r: 10px;
  --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0;
  background: var(--plane);
  color: var(--ink-2);
  font: 400 14px/1.5 var(--font);
  overflow-x: hidden;
}

h1, h2, h3, h4 { color: var(--ink); font-weight: 600; margin: 0; }
h1 { font-size: 18px; letter-spacing: -0.01em; }
h2 { font-size: 15px; letter-spacing: 0.02em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; }
h3 { font-size: 14px; }
p { margin: 0; }
a { color: var(--s1); }

:focus-visible {
  outline: 2px solid var(--s1);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 14px;
  z-index: 40;
}
.skip:focus { left: 8px; top: 8px; }

.sr {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --- shell ---------------------------------------------------------------- */
.wrap {
  width: 100%;
  max-width: 1720px;
  margin: 0 auto;
  padding-inline: 16px;      /* the >= 16px gutter, set once, never a shorthand */
}

main.wrap { padding-block: 0 8px; }

section { margin-block: 26px; }
section > header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
section > header .hint { color: var(--ink-3); font-size: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px;
}

.card.flush { padding: 0; }   /* tables bring their own padding */

/* --- 1. status bar -------------------------------------------------------- */
.statusbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--plane) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.statusbar .wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding-block: 12px;
}
.statusbar .who { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.statusbar .who .meta { color: var(--ink-3); font-size: 12px; }
.statusbar .spacer { flex: 1 1 auto; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.06em;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.pill .glyph { font-size: 12px; line-height: 1; }
.pill[data-verdict="OK"] { color: var(--good); }
.pill[data-verdict="WARN"] { color: var(--warn); }
.pill[data-verdict="CRIT"] { color: var(--crit); }
.pill[data-verdict="STALE"], .pill[data-verdict="…"] { color: var(--stale); }

.btn {
  font: inherit;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); color: var(--ink); }
.btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--s1) 22%, var(--surface));
  border-color: var(--s1);
  color: var(--ink);
  font-weight: 600;
}

/* --- banners -------------------------------------------------------------- */
.banner {
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  background: var(--surface);
  border-radius: var(--r);
  padding: 11px 14px;
  margin-block: 14px;
  color: var(--ink-2);
  font-size: 13px;
}
.banner[hidden] { display: none !important; }
.banner.is-error { border-left-color: var(--crit); }

/* --- 2. findings ---------------------------------------------------------- */
.findings { display: grid; gap: 8px; }
.finding {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  align-items: start;
}
.finding .title { color: var(--ink); font-weight: 600; }
.finding .detail { color: var(--ink-3); font-size: 12.5px; grid-column: 2; }
.finding .since { color: var(--ink-3); font-size: 12.5px; grid-column: 2; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.chip[data-sev="CRIT"] { color: var(--crit); }
.chip[data-sev="WARN"] { color: var(--warn); }
.chip[data-sev="INFO"] { color: var(--s1); }
.chip[data-sev="OK"] { color: var(--good); }

/* --- 3. host tiles -------------------------------------------------------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
  gap: var(--gap);
}
.tile { display: flex; flex-direction: column; gap: 6px; }
.tile .label { color: var(--ink-3); font-size: 12px; }
.tile .value {
  color: var(--ink);
  font-size: 27px;
  font-weight: 600;
  line-height: 1.1;
  /* proportional figures on purpose: tabular-nums makes a big number loose */
}
.tile .value .unit { font-size: 15px; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.tile .sub { color: var(--ink-3); font-size: 12px; min-height: 18px; }
.tile .spark { margin-top: 2px; }
.tile .spark svg { display: block; width: 100%; height: 34px; }
.tile .sparkcap { color: var(--ink-3); font-size: 11px; letter-spacing: 0.04em; }
.tile[data-sev="WARN"] { border-color: color-mix(in srgb, var(--warn) 55%, var(--line)); }
.tile[data-sev="CRIT"] { border-color: color-mix(in srgb, var(--crit) 65%, var(--line)); }
.tile .state { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; }
.tile[data-sev="WARN"] .state { color: var(--warn); }
.tile[data-sev="CRIT"] .state { color: var(--crit); }

.meter {
  height: 6px;
  border-radius: 3px;
  background: var(--track);
  overflow: hidden;
}
.meter > span {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--s1);
}
.meter[data-sev="WARN"] > span { background: var(--warn); }
.meter[data-sev="CRIT"] > span { background: var(--crit); }

/* --- 4. charts ------------------------------------------------------------ */
.filterrow {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.filterrow .lab { color: var(--ink-3); font-size: 12px; margin-right: 2px; }

.chartgrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: var(--gap);
}
.chartgrid.is-loading { opacity: 0.55; }   /* hold the frame, never a skeleton */

.chart { position: relative; }
.chart > .head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.chart > .head .sub { color: var(--ink-3); font-size: 12px; }
.chart .plot { position: relative; margin-top: 8px; }
.chart .plot svg { display: block; width: 100%; }
.chart .plot .empty {
  color: var(--ink-3);
  font-size: 13px;
  text-align: center;
  padding: 46px 0;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 10px;
}
.legend button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 12px;
  color: var(--ink-2);
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 3px 4px;
  cursor: pointer;
}
.legend button:hover { color: var(--ink); background: var(--surface-2); }
.legend button[aria-pressed="false"] { color: var(--ink-3); text-decoration: line-through; }
.legend button[aria-pressed="false"] .key { opacity: 0.3; }
.legend .key { width: 14px; height: 3px; border-radius: 2px; background: currentColor; flex: 0 0 auto; }
.legend.static { gap: 6px 14px; }
.legend.static span { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; }

.tip {
  position: absolute;
  z-index: 15;
  min-width: 132px;
  max-width: 260px;
  background: var(--plane);
  border: 1px solid var(--axis);
  border-radius: 8px;
  padding: 8px 10px;
  pointer-events: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}
.tip[hidden] { display: none !important; }
.tip .when { color: var(--ink-3); font-size: 11px; margin-bottom: 5px; }
.tip table { width: 100%; border-collapse: collapse; }
.tip td { padding: 1px 0; font-size: 12px; vertical-align: middle; }
.tip td.k { width: 16px; }
.tip td.k i { display: block; width: 12px; height: 3px; border-radius: 2px; }
.tip td.n { color: var(--ink-3); padding-right: 10px; }
.tip td.v {
  color: var(--ink);
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

details.tableview { margin-top: 10px; }
details.tableview summary {
  color: var(--ink-3);
  font-size: 12px;
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
details.tableview summary::-webkit-details-marker { display: none; }
details.tableview summary::before { content: "▸"; font-size: 10px; }
details.tableview[open] summary::before { content: "▾"; }
details.tableview summary:hover { color: var(--ink); }
details.tableview .scroll { max-height: 260px; overflow: auto; margin-top: 8px; }

/* --- tables --------------------------------------------------------------- */
.tablewrap { overflow-x: auto; }
table.data {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th, table.data td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  z-index: 1;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.name { color: var(--ink); font-weight: 600; }
table.data td.wrapok { white-space: normal; min-width: 160px; }
/* Containers: every column fits the desktop viewport without a horizontal
   scroll. The image tag is one truncated line (the full tag is in title=),
   the memory bar drops under its number, and rx/tx and r/w stack as two
   short lines instead of one wide one. */
#containers th, #containers td { padding: 7px 9px; font-size: 12.5px; }
#containers td.name .img {
  display: block; max-width: 230px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; font-weight: 400;
}
#containers td.io span { display: block; line-height: 1.35; }
#containers td.io span b { font-weight: 400; color: var(--ink-3); margin-right: 4px; }
#containers td.mem .membar { display: block; margin: 0; width: 100%; max-width: 116px; }
#containers td.mem .pct { color: var(--ink-3); }
/* The memory cell is now three short lines instead of one: the numbers, then
   the bar next to the `Limit...` button, then the page-cache note. The button
   sits INSIDE the cell rather than in a column of its own so the table still
   fits 1366 px without a horizontal scroll. */
#containers td.mem .membarrow {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
}
#containers td.mem .cache { display: block; margin-top: 3px; font-size: 11.5px; }
table.data .muted { color: var(--ink-3); }

/* --- 5b. the memory-limit panel (SDD §10.6) ------------------------------- */
/* One row's worth of form, opened under the container it is about. A modal
   would hide the very number the operator is deciding from. */
.btn.tiny {
  padding: 2px 7px;
  font-size: 11px;
  border-radius: 6px;
  line-height: 1.5;
  flex: 0 0 auto;
}

table.data tbody tr.limitrow:hover { background: transparent; }
table.data tbody tr.limitrow > td { white-space: normal; padding: 0; }

.limitpanel {
  display: grid;
  gap: 10px;
  padding: 14px 10px 16px;
  background: var(--surface-2);
  box-shadow: inset 3px 0 0 var(--s1);
}
.limitpanel .head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.limitpanel .head strong { color: var(--ink); font-size: 13px; }
.limitpanel .facts { color: var(--ink-3); font-size: 12px; }
.limitpanel .controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.limitpanel label { color: var(--ink-3); font-size: 12px; }
.limitpanel input[type="number"] {
  width: 96px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--plane);
  border: 1px solid var(--axis);
  border-radius: 8px;
  padding: 6px 8px;
}
.limitpanel input[type="number"]:focus-visible { border-color: var(--s1); }
.limitpanel select {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--plane);
  border: 1px solid var(--axis);
  border-radius: 8px;
  padding: 6px 6px;
}
.limitpanel .bounds { color: var(--ink-3); font-size: 11.5px; }
.limitpanel .confirm {
  color: var(--ink-2);
  font-size: 13px;
  max-width: 88ch;
}
.limitpanel .confirm.is-bad { color: var(--crit); font-weight: 600; }
.limitpanel .compose { color: var(--ink-3); font-size: 12px; max-width: 88ch; }
.limitpanel .act { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.limitpanel .btn.primary {
  color: #ffffff;
  background: #256abf;
  border-color: var(--s1);
  font-weight: 600;
}
.limitpanel .btn.primary:hover { background: var(--s1); color: #ffffff; }
.limitpanel .btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.limitpanel .btn.primary[disabled]:hover { background: #256abf; }
.limitpanel .actstatus { font-size: 12.5px; color: var(--ink-2); }
.limitpanel .actstatus[data-sev="OK"] { color: var(--good); font-weight: 600; }
.limitpanel .actstatus[data-sev="WARN"] { color: var(--warn); font-weight: 600; }
.limitpanel .actstatus[data-sev="CRIT"] { color: var(--crit); font-weight: 600; }

/* --- 7.5 actions ---------------------------------------------------------- */
#actions td.when { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
#actions td.limits { font-variant-numeric: tabular-nums; }
#actions td.why { white-space: normal; min-width: 220px; max-width: 520px; color: var(--ink-3); font-size: 12px; }
#actions td .who { display: block; color: var(--ink-3); font-size: 11.5px; }

table.data tbody tr.problem { box-shadow: inset 3px 0 0 var(--crit); }
table.data tbody tr.restarted { box-shadow: inset 3px 0 0 var(--warn); }

.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: 0;
  background: var(--ink-3);
}
.dot[data-sev="OK"] { background: var(--good); }
.dot[data-sev="WARN"] { background: var(--warn); }
.dot[data-sev="CRIT"] { background: var(--crit); }

.badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 6px;
}
.badge[data-role="test"] { color: var(--s7); border-color: color-mix(in srgb, var(--s7) 45%, var(--line)); }
.badge[data-role="infra"] { color: var(--s3); border-color: color-mix(in srgb, var(--s3) 45%, var(--line)); }

.membar {
  display: inline-block;
  width: 74px;
  height: 5px;
  border-radius: 3px;
  background: var(--track);
  overflow: hidden;
  margin-left: 9px;
  vertical-align: 2px;
}
.membar > i { display: block; height: 100%; background: var(--s1); border-radius: 3px; }
.membar[data-sev="WARN"] > i { background: var(--warn); }
.membar[data-sev="CRIT"] > i { background: var(--crit); }

.certwarn { color: var(--warn); font-weight: 600; }
.certcrit { color: var(--crit); font-weight: 600; }

/* --- 7. livekit ----------------------------------------------------------- */
.lk { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: var(--gap); }
.lk .rooms { grid-column: 1 / -1; }

/* --- 8. events ------------------------------------------------------------ */
.timeline { display: grid; gap: 0; }
.timeline .ev {
  display: grid;
  grid-template-columns: 124px auto 1fr;
  gap: 4px 12px;
  align-items: start;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.timeline .ev:last-child { border-bottom: 0; }
.timeline .ev .when { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.timeline .ev .title { color: var(--ink); }
.timeline .ev .detail { grid-column: 3; color: var(--ink-3); font-size: 12.5px; }

/* --- footer --------------------------------------------------------------- */
footer.wrap {
  color: var(--ink-3);
  font-size: 12px;
  padding-block: 22px 30px;
  border-top: 1px solid var(--line);
  margin-top: 28px;
}

/* --- login ---------------------------------------------------------------- */
body[data-page="login"] {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100svh;
  padding: 24px 16px;
}
.loginbox { width: 100%; max-width: 360px; }
.loginbox h1 { font-size: 20px; margin-bottom: 4px; }
.loginbox .lede { color: var(--ink-3); font-size: 12.5px; margin-bottom: 18px; }
.loginbox label { display: block; color: var(--ink-3); font-size: 12px; margin-bottom: 6px; }
.loginbox input[type="password"] {
  width: 100%;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--plane);
  border: 1px solid var(--axis);
  border-radius: 8px;
  padding: 11px 12px;
}
.loginbox input[type="password"]:focus-visible { border-color: var(--s1); }
.loginbox button {
  width: 100%;
  margin-top: 12px;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  color: #ffffff;
  background: #256abf;
  border: 1px solid var(--s1);
  border-radius: 8px;
  padding: 11px 12px;
  cursor: pointer;
}
.loginbox button:hover { background: var(--s1); }
.loginbox .err {
  color: var(--crit);
  font-size: 13px;
  font-weight: 600;
  margin-top: 12px;
}
.loginbox .err[hidden] { display: none !important; }
.loginbox .foot { color: var(--ink-3); font-size: 11.5px; margin-top: 18px; }

/* --- narrow --------------------------------------------------------------- */
@media (max-width: 980px) {
  .chartgrid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .tiles, .lk { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  /* The bar wraps to two rows on a phone; ~90px of permanently-occupied
     viewport is too high a price for keeping the pill in sight, and the pill
     is the first thing on the page anyway. */
  .statusbar { position: static; }
  .statusbar .wrap { gap: 10px; }
  .statusbar .spacer { flex-basis: 100%; height: 0; }
  .timeline .ev { grid-template-columns: 1fr; }
  .timeline .ev .detail { grid-column: 1; }
  .finding { grid-template-columns: 1fr; }
  .finding .detail, .finding .since { grid-column: 1; }
  h1 { font-size: 16px; }
  .tile .value { font-size: 24px; }
}
@media (max-width: 420px) {
  .tiles, .lk { grid-template-columns: 1fr 1fr; }
  .tile .value { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media (forced-colors: active) {
  .card, .banner, .tip { border: 1px solid CanvasText; }
  .pill, .chip, .badge { border: 1px solid CanvasText; }
}
