/* SMOAD Customer Portal — design tokens and components.
 *
 * Colour roles follow the validated reference palette. Dark values are declared
 * under BOTH the media query (OS setting) and the [data-theme] scope (explicit
 * toggle) so the toggle wins in either direction; the :not() guard lets an
 * explicit light choice beat OS dark.
 *
 * No colour is defined only inside a media block.
 */

:root {
  color-scheme: light;

  /* Surfaces */
  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --surface-sunk: #f2f2ef;

  /* Ink — text never wears a data colour, it wears these. */
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --ink-muted:    #898781;

  /* Chart chrome */
  --grid:         #e1e0d9;
  --axis:         #c3c2b7;
  --hairline:     rgba(11, 11, 11, .10);

  /* Data — categorical slot 1, the only series hue used here. */
  --series-1:     #2a78d6;
  /* Meter track. Neutral, not a step of the blue ramp: these meters are filled
     with status colours, and a blue track under a green fill reads as a second
     series rather than as the unfilled remainder. */
  --track:        #e6e6e2;

  /* Status — fixed, never themed. Always paired with an icon + label. */
  --ok:           #0ca30c;
  --warn:         #fab219;
  --bad:          #d03b3b;
  /* Maroon, for the offline arc of the customer donuts. Deliberately its own
     token rather than a redefinition of --bad: --bad is the status red used by
     tiles, chips and meters across the app, and darkening it there would cost
     contrast on small text. */
  --maroon:       #7d2028;
  --maroon-ink:   #8f2731;

  --focus:        #2a78d6;

  --radius:   10px;
  --radius-s: 6px;
  --shadow:      0 1px 2px rgba(11, 11, 11, .05), 0 6px 18px rgba(11, 11, 11, .04);
  --shadow-lift: 0 2px 4px rgba(11, 11, 11, .06), 0 12px 28px rgba(11, 11, 11, .10);

  /* Inline padding for the content column and the head's right edge. The
     content is fluid beside the sidebar rather than a centred fixed column. */
  --page-pad: 28px;

  --ease: cubic-bezier(.22, .61, .36, 1);

  /* Sidebar layout. --head-h is the sticky head's full height including its
     1px border; the sidebar sticks beneath it and fills the rest of the view. */
  --side-w: 232px;
  --head-h-inner: 60px;
  --head-h: 61px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane:        #0d0d0d;
    --surface:      #1a1a19;
    --surface-sunk: #232322;
    --ink:          #ffffff;
    --ink-2:        #c3c2b7;
    --ink-muted:    #898781;
    --grid:         #2c2c2a;
    --axis:         #383835;
    --hairline:     rgba(255, 255, 255, .10);
    --series-1:     #3987e5;
    --track:        #33332f;
    --maroon:       #8a252e;
    --maroon-ink:   #c9646c;
    --focus:        #3987e5;
    --shadow:       0 1px 2px rgba(0, 0, 0, .5), 0 6px 18px rgba(0, 0, 0, .35);
    --shadow-lift:  0 2px 4px rgba(0, 0, 0, .55), 0 14px 30px rgba(0, 0, 0, .45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:        #0d0d0d;
  --surface:      #1a1a19;
  --surface-sunk: #232322;
  --ink:          #ffffff;
  --ink-2:        #c3c2b7;
  --ink-muted:    #898781;
  --grid:         #2c2c2a;
  --axis:         #383835;
  --hairline:     rgba(255, 255, 255, .10);
  --series-1:     #3987e5;
  --track:        #33332f;
  --maroon:       #8a252e;
  --maroon-ink:   #c9646c;
  --focus:        #3987e5;
  --shadow:       0 1px 2px rgba(0, 0, 0, .5), 0 6px 18px rgba(0, 0, 0, .35);
  --shadow-lift:  0 2px 4px rgba(0, 0, 0, .55), 0 14px 30px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 14px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

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

/* ---------- Buttons & controls ---------- */

.btn {
  font: inherit;
  font-weight: 550;
  border-radius: var(--radius-s);
  padding: 7px 14px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  color: var(--ink);
  background: transparent;
}

.btn-primary { background: var(--series-1); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { border-color: var(--hairline); background: var(--surface); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-sunk); }
.btn:disabled { opacity: .45; cursor: default; }

input, select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-s);
  padding: 7px 10px;
  width: 100%;
}

/* Segmented control — the theme switch. */
.segmented {
  display: inline-flex;
  background: var(--surface-sunk);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-s);
  padding: 2px;
  gap: 2px;
}

.segmented button {
  font: inherit;
  font-size: 12px;
  font-weight: 550;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1.4;
}

.segmented button:hover { color: var(--ink); }

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
}

/* ---------- Login ---------- */

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

.login-card {
  width: 100%;
  max-width: 370px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px;
  display: flex;
  flex-direction: column;
}

.login-brand { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: .02em; }

.login-brand span {
  display: block;
  font-size: 11px;
  font-weight: 550;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-top: 3px;
}

.login-note { margin: 6px 0 18px; color: var(--ink-2); font-size: 13px; }
.login-card label { font-size: 12px; font-weight: 600; color: var(--ink-2); margin-top: 12px; }
.login-card input { margin-top: 5px; }
.login-card .btn { margin-top: 22px; }

/* ---------- Shell ---------- */

/* The head is sticky, and the sidebar sticks just beneath it, so neither the
   controls nor the menu ever need a scroll back to the top. Above the device
   table's own sticky header in the stacking order. */
.shell-head {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}

/* Fixed height on wide screens, so the sidebar can be sized against it. The
   brand's left inset matches the menu icons below it (12px rail + 12px link). */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: var(--head-h-inner);
  padding: 0 var(--page-pad) 0 24px;
}

/* ---------- Layout: sidebar + content ---------- */

.app-body {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  align-items: start;
}

.sidebar {
  position: sticky;
  top: var(--head-h);
  height: calc(100vh - var(--head-h));
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--hairline);
  padding: 18px 12px;
}

.mainnav { display: flex; flex-direction: column; gap: 2px; }

.nav-heading {
  margin: 0 12px 10px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.navlink {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-s);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-2);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color .15s var(--ease), color .15s var(--ease);
}

.navlink:hover { background: var(--surface-sunk); color: var(--ink); }

/* The current section is marked three ways — tinted row, full ink, and an
   accent bar on the rail edge — so the state never rests on colour alone. */
.navlink[aria-current="page"] { background: var(--surface-sunk); color: var(--ink); }

.navlink[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--series-1);
}

.navicon { width: 18px; height: 18px; flex: none; color: var(--ink-muted); transition: color .15s var(--ease); }
.navlink:hover .navicon,
.navlink[aria-current="page"] .navicon { color: var(--series-1); }

.navlabel { flex: 1; min-width: 0; }

.navcount {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--surface-sunk);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 1px 7px;
  font-variant-numeric: tabular-nums;
}

.navlink[aria-current="page"] .navcount { color: var(--ink); background: var(--surface); }

/* Toggling [hidden] restarts the animation, so each switch fades its section
   in rather than swapping instantly. */
.view { animation: rise .3s var(--ease) backwards; }

/* Narrow screens: a 232px rail would take most of a phone, so the menu folds
   back into a horizontal strip under the head, and the head is allowed to wrap. */
@media (max-width: 860px) {
  .topbar { height: auto; padding: 11px var(--page-pad); flex-wrap: wrap; }
  .app-body { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static;
    height: auto;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--hairline);
    padding: 6px var(--page-pad);
  }
  .mainnav { flex-direction: row; gap: 4px; }
  .nav-heading { display: none; }
  .navlink { padding: 8px 12px; }
  .navlink[aria-current="page"]::before {
    left: 10px; right: 10px; top: auto; bottom: -6px;
    width: auto; height: 2px; border-radius: 2px;
  }
}

/* Phone widths: with icons the three items need ~440px and the last one was
   clipped at the screen edge with no sign that the strip scrolls. The labels
   already say everything, so the icons go. */
@media (max-width: 520px) {
  .navicon { display: none; }
  .navlink { padding: 8px 10px; }
}

.brand { font-weight: 650; letter-spacing: .02em; }

.brand span {
  font-weight: 550;
  color: var(--ink-muted);
  margin-left: 9px;
  letter-spacing: .12em;
  font-size: 10px;
  text-transform: uppercase;
}

.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.who { color: var(--ink-2); font-size: 13px; }

.badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 3px 9px;
  border: 1px solid var(--hairline);
  color: var(--ink-muted);
}

.badge-readonly { border-color: var(--series-1); color: var(--series-1); }

/* Full-width block with a computed gutter rather than max-width + auto margin,
   so its content edge is identical to the topbar's by construction. */
.wrap { padding: 26px var(--page-pad) 72px; min-width: 0; }

/* Refetch holds the previous render at reduced opacity — no skeleton flash. */
.is-loading { opacity: .45; transition: opacity .15s ease; }

/* ---------- Stat tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

/* No hover lift on a tile: it is not clickable, and lifting it would promise an
   interaction that is not there. Only .gw-card, which does open something,
   responds to the pointer. */
.tile {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 17px 19px;
  box-shadow: var(--shadow);
}

.tile-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
}

/* Proportional figures: tabular-nums makes a big standalone number look loose. */
.tile-value {
  font-size: 30px;
  font-weight: 650;
  line-height: 1.15;
  margin-top: 8px;
  letter-spacing: -.01em;
}

.tile-sub { font-size: 12px; color: var(--ink-2); margin-top: 3px; }

/* Meter: fill over a lighter step of the same ramp. */
.meter {
  height: 4px;
  border-radius: 999px;
  background: var(--track);
  margin-top: 11px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--series-1);
  width: var(--pct, 0%);
}

.meter-fill.is-ok  { background: var(--ok); }
.meter-fill.is-bad { background: var(--bad); }

/* ---------- Status dot + label (never colour alone) ---------- */

.pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 550; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--ink-muted); }
.dot-up { background: var(--ok); }
.dot-down { background: var(--bad); }
.dot-disabled, .dot-unknown { background: var(--ink-muted); }
/* Waiting is a third state, not a shade of down: the peer is configured and
   handshaking but not yet carrying traffic. */
.dot-waiting { background: var(--warn); }

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

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

/* The three chart cards are static markup, so their stagger index is set here;
   the JS-built tiles and gateway cards set --i themselves. */
.charts .card:nth-child(1) { --i: 0; }
.charts .card:nth-child(2) { --i: 1; }
.charts .card:nth-child(3) { --i: 2; }

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px 18px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 3px;
}

.card-head h3 { margin: 0; font-size: 13px; font-weight: 650; }
.card-sub { color: var(--ink-muted); font-size: 12px; margin: 0 0 14px; }

.card-toggle {
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  background: none;
  border: 0;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 2px 4px;
}

.card-toggle:hover { color: var(--ink); }

/* Horizontal bars. One hue: these categories are nominal, so a value-ramp
   would double-encode length as colour. */
.bars { display: flex; flex-direction: column; gap: 2px; }

.bar-row {
  display: grid;
  grid-template-columns: minmax(72px, 26%) 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 3px 6px;
  border-radius: var(--radius-s);
  cursor: default;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  width: 100%;
}

.bar-row:hover, .bar-row:focus-visible { background: var(--surface-sunk); }

.bar-name {
  font-size: 12px;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 100%;
  min-height: 22px;
  display: flex;
  align-items: center;
  border-left: 1px solid var(--grid);
  padding-left: 1px;
}

/* 4px rounded data-end, square at the baseline; capped thickness. */
.bar-fill {
  height: 14px;
  max-height: 24px;
  /* The Guardian deck's bars sample ~#3f6388 — a muted steel blue, not the
     bright accent. A saturated blue beside the red and green status colours
     reads as a third status rather than as "a count of things". */
  background: linear-gradient(180deg, #4a7aa8 0%, #3a6288 100%);
  border-radius: 0 4px 4px 0;
  width: var(--pct, 0%);
  min-width: 2px;
  /* The animation grows the bar from the baseline on first paint; the
     transition carries it between values on a later refetch. */
  animation: grow-bar .6s var(--ease) backwards;
  transition: width .25s var(--ease);
}

.bar-fill.is-zero { background: var(--grid); }

/* Values align in a column, so tabular figures belong here. */
.bar-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bar-value small { color: var(--ink-muted); font-weight: 500; }

.card-empty { color: var(--ink-muted); font-size: 12px; padding: 14px 0; }

/* A gateway that is down is a real answer, not an empty state, so it reads as
   a statement rather than muted filler. The word carries it; the amber rule is
   only a secondary cue. */
.state-down {
  margin: 0;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--ink-2);
  background: var(--surface-sunk);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius-s);
}

/* Table-view twin — every chart's WCAG-clean equivalent. */
.card-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.card-table th, .card-table td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--grid); }
.card-table th { color: var(--ink-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.card-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Gateway connection cards ---------- */

.gw-panel { margin-bottom: 16px; }

.gw-note { color: var(--ink-muted); font-size: 12px; margin: 4px 20px 0; }

.gw-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
  gap: 14px;
  padding: 16px 20px 22px;
}

/* A button, so a card is reachable and operable by keyboard exactly as the
   chart rows are. The left edge is a plain accent: the card's meaning is
   carried by its status pill and its numbers, never by that stripe. */
.gw-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--series-1);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
  box-shadow: var(--shadow);
  transition:
    transform .18s var(--ease),
    box-shadow .18s var(--ease),
    background-color .18s var(--ease);
}

/* The card is clickable, so it lifts. Depth and background carry the hover —
   the accent stripe keeps its colour, because nothing on this card should
   change meaning just because a pointer is over it. */
.gw-card:hover,
.gw-card:focus-visible {
  background: var(--surface-sunk);
  transform: translateY(-3px);
  box-shadow: var(--shadow-lift);
}

/* Press returns it to the page — the click reads as a physical push. */
.gw-card:active { transform: translateY(0); box-shadow: var(--shadow); }

.gw-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

/* The status pill keeps its width; the name is what gives way. */
.gw-head .pill { flex: none; }

/* Two lines rather than one. At six columns a single ellipsised line cut
   "Collman Services-Chennai" down to "Collman Services-Che…", which is not a
   name anyone can act on. The title attribute still carries the full string,
   and the clamp keeps the card height bounded. */
.gw-name {
  font-weight: 650;
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.gw-meta, .gw-split { color: var(--ink-muted); font-size: 12px; }
.gw-ip { color: var(--ink-2); }

/* Pushed to the bottom of the card. Grid already makes every card in a row the
   same height, but hostnames wrap to different line counts, so without this the
   headline numbers sat at different heights across a row and read as ragged. */
.gw-count { margin-top: auto; padding-top: 10px; font-size: 12px; color: var(--ink-2); }

/* The count is the card's headline, so it wears ink, not a data colour. */
.gw-count strong {
  font-size: 22px;
  font-weight: 650;
  color: var(--ink);
  margin-right: 4px;
  font-variant-numeric: tabular-nums;
}

/* Customer widgets reuse the gateway card look and are clickable in the same
   way, so they keep the pointer affordance and the hover lift. */
.cust-card.is-unassigned { border-left-color: var(--ink-muted); }
.cust-panel { margin-bottom: 16px; }

/* Provenance badge. Live and Mirror differ in meaning, not just recency, so
   the word carries it — the tint is only a secondary cue. */
.src-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--surface-sunk);
  color: var(--ink-muted);
  white-space: nowrap;
}

.src-badge.is-live { border-color: var(--ok); color: var(--ok); }

.src-note { color: var(--ink-muted); font-size: 12px; margin-right: 10px; }

/* ---------- Panel & device table ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px 0;
}

.panel-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.panel-meta { color: var(--ink-muted); font-size: 13px; }

/* One filter row, above everything it scopes. */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--hairline);
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 132px; }
.field-grow { flex: 1 1 240px; }
.field-actions { flex-direction: row; align-items: flex-end; gap: 8px; }

.field label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.table-scroll { overflow-x: auto; }

table.devices { width: 100%; border-collapse: collapse; font-size: 13px; }

.devices th, .devices td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

.devices th {
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  background: var(--surface-sunk);
  position: sticky;
  top: 0;
  /* Below the topbar's 50 so the two sticky layers never fight. */
  z-index: 1;
  font-weight: 600;
}

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th.sortable[aria-sort="ascending"]::after { content: " \2191"; }
th.sortable[aria-sort="descending"]::after { content: " \2193"; }

.devices tbody tr { cursor: pointer; }
.devices tbody tr:hover, .devices tbody tr:focus-visible { background: var(--surface-sunk); }

.devices td.details { white-space: normal; max-width: 250px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-muted); }

/* Inline link chips in the device row. */
.chips { display: inline-flex; gap: 3px; }

.chip {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 2px 5px;
  border-radius: 3px;
  background: var(--surface-sunk);
  color: var(--ink-muted);
  border: 1px solid var(--grid);
}

.chip-up { color: var(--ok); border-color: var(--ok); }
.chip-down { color: var(--bad); border-color: var(--bad); }

.state { padding: 30px 20px; text-align: center; color: var(--ink-muted); }

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 14px;
  color: var(--ink-2);
  font-size: 13px;
}

/* ---------- Tooltip ---------- */

.tooltip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-s);
  box-shadow: var(--shadow);
  padding: 8px 10px;
  font-size: 12px;
  max-width: 260px;
}

/* Value leads, label follows. */
.tooltip-value { font-weight: 650; font-size: 14px; }
.tooltip-label { color: var(--ink-2); margin-top: 2px; }

.tooltip-key {
  display: inline-block;
  width: 12px;
  height: 2px;
  border-radius: 1px;
  background: var(--series-1);
  vertical-align: middle;
  margin-right: 6px;
}

/* ---------- Detail dialogs ---------- */

/*
 * The overlay is a plain fixed div, not a <dialog>.
 *
 * <dialog>.showModal() puts the element in the browser's top layer and gives
 * Escape-to-close for free, but that behaviour turned out not to be reliable
 * across the browsers this portal is actually opened in — the popup rendered
 * without being modal, so Escape did nothing and the close control could not
 * be reached. A positioned div behaves the same everywhere; Escape and
 * backdrop dismissal are handled explicitly in app.js instead.
 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(11, 11, 11, .6);
  backdrop-filter: blur(2px);
}

/*
 * A column: a fixed head, then a body that scrolls. overflow:hidden lets the
 * rounded corners clip that scrolling body, which otherwise squares off the
 * bottom two.
 */
.detail {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lift);
  padding: 0;
  width: min(760px, 94vw);
  max-height: 88vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* The gateway and customer drill-downs carry seven-column tables, which wrap
   badly at the default width. */
.detail-wide { width: min(1180px, 95vw); }

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--hairline);
  flex: none;
}

.detail-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Styled by class, not by id. This was `#detail-body`, so only the device
   dialog was padded and the gateway and customer popups rendered flush against
   their own edges. */
.detail-body {
  padding: 20px 22px 24px;
  overflow: auto;
  flex: 1 1 auto;
}

/* Stat blocks. Each dt/dd pair is wrapped in .kv-item, so a label always stays
   with its own value however the grid wraps — previously the pairs were direct
   grid children and could be split across a row boundary. */
.kv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 10px;
  margin: 0 0 22px;
}

.kv-item {
  background: var(--surface-sunk);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-s);
  padding: 10px 12px;
  min-width: 0;
}

.kv dt {
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
}

.kv dd {
  margin: 5px 0 0;
  font-weight: 600;
  font-size: 14px;
  overflow-wrap: anywhere;
}

h4.section {
  margin: 0 0 11px;
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
}

/* Tables inside a dialog. The header sticks to the top of the scrolling body so
   the columns stay identifiable in a long list. */
.links { width: 100%; border-collapse: collapse; font-size: 13px; }

.links th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-sunk);
  padding: 9px 12px;
  text-align: left;
  font-size: 10.5px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 1px solid var(--grid);
}

.links td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--grid);
  vertical-align: middle;
}

.links tbody tr:last-child td { border-bottom: 0; }
.links tbody tr:hover { background: var(--surface-sunk); }
.links td.num { text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .modal { padding: 12px; }
  .detail, .detail-wide { width: 100%; max-height: 92vh; }
  .detail-head { padding: 13px 16px; }
  .detail-body { padding: 16px 16px 20px; }
}

.form-error { margin: 14px 0 0; color: var(--bad); font-size: 13px; }

/* ---------- Motion ----------
 *
 * Entrance only, and once. Nothing here loops, and nothing moves in response to
 * data changing — a dashboard that keeps moving is harder to read, not nicer.
 */

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes grow-bar {
  from { width: 0; }
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(12px) scale(.985); }
}

/* `backwards` holds the from-state through the stagger delay, so a late card
   does not flash at full opacity before its turn comes. --i is set per element
   in app.js via CSSOM, which this page's CSP allows — a style attribute would
   be blocked. */
.tile,
.charts .card,
.gw-card {
  animation: rise .45s var(--ease) backwards;
  animation-delay: calc(var(--i, 0) * 45ms);
}

.modal { animation: fade-in .18s linear; }
.modal .detail { animation: dialog-in .2s var(--ease); }

@media (prefers-reduced-motion: reduce) {
  /* Covers animation as well as transition now, and ::before/::after with it —
     an entrance animation is exactly what this preference is asking us to drop. */
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

@media (max-width: 640px) {
  /* Shrinking the shared pad keeps the topbar and the content column aligned
     at every width, instead of overriding each of them separately. */
  :root { --page-pad: 14px; }

  .wrap { padding-top: 18px; padding-bottom: 44px; }
  .topbar { padding-top: 11px; padding-bottom: 11px; }
  .who { display: none; }
  .tile-value { font-size: 26px; }
  .gw-note { margin-left: 14px; margin-right: 14px; }
  .gw-grid { padding-left: 14px; padding-right: 14px; }
  .panel-head, .filters { padding-left: 14px; padding-right: 14px; }
}

/* ---------------------------------------------------------------------------
   Customer group donuts.

   These lead the dashboard: the per-customer split is the question an operator
   opens this page to answer, so it sits above the fleet-wide totals.

   Each widget is a button. The ring is decorative (aria-hidden) and every
   figure on it is repeated in the button's accessible name, so nothing is
   conveyed by colour alone.
   --------------------------------------------------------------------------- */
/* align-items: stretch is the default and is what equalises the row. */
.cust-donuts {
  display: grid;
  /* auto-fit rather than a fixed count: one customer fills the row, twelve wrap
     into a tidy grid, with no breakpoint arithmetic. */
  grid-template-columns: repeat(auto-fit, minmax(268px, 1fr));
  gap: 18px;
}

.cust-donut {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  /* stretch + the auto margin below keep every card the same height and the
     rings on a common baseline, whatever each group's callouts do. */
  height: 100%;
  padding: 18px 12px 14px;
  border: 1px solid var(--hairline);
  border-radius: 16px;
  background: var(--surface);
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: center;
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
  animation: rise .34s var(--ease) backwards;
  animation-delay: calc(var(--i, 0) * 40ms);
}

.cust-donut:hover,
.cust-donut:focus-visible {
  transform: translateY(-2px);
  border-color: var(--series-1);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .22);
}

.cust-donut.is-unassigned { border-style: dashed; }

.donut-title {
  font-weight: 650;
  font-size: 14px;
  letter-spacing: .01em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.donut-sub { font-size: 11px; color: var(--ink-muted); }

.donut-svg {
  width: 100%;
  max-width: 300px;
  height: auto;
  display: block;
  overflow: visible;
  margin-top: auto;
}

/* The unfilled remainder of the ring. Very low contrast on purpose: it is the
   backdrop the coloured arcs sit on, not a category of its own. */
/* The unfilled ring beneath the wedges. Now a filled path rather than a
   stroke, since the wedges are paths too. */
.donut-track { fill: var(--grid); opacity: .5; }

/* The glow is what gives the arcs their depth in the reference design. It is a
   drop-shadow in the arc's own colour rather than a blur filter, so it stays
   crisp at any size and costs nothing to composite. */
/* The lit face of each wedge. The gradient is set per element (ids must be
   unique per card), so only the shared treatment lives here. */
/* The rim highlight is what gives the Guardian ring its depth: its outer edge
   samples ~#c96c63 against a #a63b33 body, i.e. a bright lip rather than a
   gradient. Reproduced as a light stroke on the lit face. */
.donut-seg { stroke: rgba(255, 255, 255, .22); stroke-width: 1; }

/* The shaded side face, drawn offset beneath the lit one. This is what reads
   as thickness — a darker tone rather than a blur, so it stays crisp and costs
   nothing to composite. */
.donut-face.is-up      { fill: #146b32; }
.donut-face.is-waiting { fill: #8a6410; }
.donut-face.is-down    { fill: #4d1119; }

/* A soft halo on the whole wedge, including its side face. Kept small: a wide
   glow bleeds inward across the hole and the ring stops reading as a ring. */
/* A coloured halo outside the rim, as in the reference, plus a little depth. */
.donut-wedge { filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .5)); }
.donut-wedge.is-lifted { filter: drop-shadow(0 5px 8px rgba(0, 0, 0, .6)); }

/* The hub carries the total. Its ring is the accent colour so the figure reads
   as a separate number rather than part of the chart. */
/* The hub paints over the ring's inner edge, so the ring reads as a ring
   rather than a pie. It uses the sunk surface rather than the card colour so it
   reads as a well, which is what gives the reference its depth. */
.donut-hub {
  /* The deck's hub is the card colour, not a lighter well, with a muted indigo
     rule (#494e77) rather than the bright accent blue. */
  fill: var(--surface);
  stroke: #5b6499;
  stroke-width: 2;
}

.donut-total-label {
  font-size: 10px;
  letter-spacing: .16em;
  fill: #7e8fc4;
  font-weight: 600;
}

.donut-total-num {
  font-size: 22px;
  font-weight: 700;
  fill: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* Leader lines out to the figures. */
.donut-lead { stroke-width: 1.2; opacity: .8; }
.donut-lead.is-up      { stroke: var(--ok); }
.donut-lead.is-waiting { stroke: var(--warn); }
.donut-lead.is-down    { stroke: var(--maroon); }

.donut-pin { r: 3; }
.donut-pin.is-up      { fill: var(--ok); }
.donut-pin.is-waiting { fill: var(--warn); }
.donut-pin.is-down    { fill: var(--maroon); }

.donut-callout-num {
  font-size: 17px;
  font-weight: 700;
  fill: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* Underlined, as in the reference. text-decoration on an SVG tspan is honoured
   by every current browser; where it is not, the colour still distinguishes it. */
.donut-callout-label {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .09em;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.donut-callout.is-up .donut-callout-label      { fill: var(--ok); }
.donut-callout.is-waiting .donut-callout-label { fill: var(--warn); }
.donut-callout.is-down .donut-callout-label    { fill: var(--maroon-ink); }

@media (prefers-reduced-motion: reduce) {
  .cust-donut { animation: none; transition: none; }
  .cust-donut:hover, .cust-donut:focus-visible { transform: none; }
}
