/* ===========================================================================
   DESIGN SYSTEM
   Every value below comes from one of four fixed scales. Nothing in this
   sheet may invent a one-off number: if a value is needed, it is added to a
   scale first. That is what keeps spacing, alignment, and control heights
   consistent instead of drifting per component.

   SPACE     4px base, doubling and half-steps:  4 8 12 16 24 32 48
   TYPE      11 12 13 14 18 24 px, each with a fixed role (see --fs-*)
   CONTROL   fixed heights 22 / 28 / 34 / 40 shared by every button, input,
             select, chip and badge, so any row of controls aligns by default
   RADIUS    6 / 8 / 14 / pill

   COLOUR    a 4-step surface ladder (bg < surface < raised < sunken) plus
             semantic accents that each carry a -soft fill and a -line border,
             so a badge, a bar and a border always agree on tone.
   =========================================================================== */

:root {
  color-scheme: dark;

  /* Surface ladder, built from the specified --main-bg.
     Every step is the same neutral hue at a different lightness, so panels,
     rows and inputs read as one material instead of as separately tinted
     boxes. */
  --main-bg: #0d0e12;
  --bg: var(--main-bg);
  --surface: #14161c;
  --raised: #1a1d24;
  --sunken: #0a0b0f;
  --hover: #20232c;

  /* Text ramp */
  --text: #e9ecf2;
  --text-muted: #8b93a5;
  --text-faint: #626a7d;

  /* Lines */
  --line: #22252e;
  --line-strong: #30343f;

  /* Semantic accents: base / soft fill / line.
     Amber on near-black is bright enough to carry dark text, so filled buttons
     use a near-black label rather than white — white on amber falls below a
     readable contrast ratio. */
  --accent: #f59e0b;
  --accent-hover: #fbbf24;
  --accent-soft: #241a06;
  --accent-line: #4a3510;
  --accent-text: #1a1204;

  /* Category hues, used only for navigation and section icons so a dense
     panel stays scannable. They never become backgrounds or button fills. */
  --hue-amber: #f59e0b;
  --hue-emerald: #10b981;
  --hue-cyan: #06b6d4;
  --hue-rose: #f43f5e;
  --hue-slate: #94a3b8;

  --ok: #22c55e;
  --ok-soft: #0d2a1a;
  --ok-line: #17492c;

  --warn: #f59e0b;
  --warn-soft: #2b1f07;
  --warn-line: #4d3a10;

  --bad: #ef4444;
  --bad-soft: #2c1214;
  --bad-line: #5b2124;

  --info: #14b8a6;
  --info-soft: #08262a;
  --info-line: #124a4a;

  --neutral-soft: #1a2130;
  --neutral-line: #26304180;

  /* SPACE */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  /* TYPE */
  --fs-micro: 11px;   /* uppercase labels, chips, table headers */
  --fs-small: 12px;   /* secondary cell text, help text */
  --fs-body: 13px;    /* default UI text */
  --fs-base: 14px;    /* inputs, buttons, primary cell text */
  --fs-lg: 18px;      /* section titles */
  --fs-xl: 24px;      /* page title */

  /* CONTROL heights */
  --h-badge: 22px;
  --h-sm: 28px;
  --h-md: 34px;
  --h-lg: 40px;

  /* RADIUS */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 14px;
  --r-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.6);
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);

  --sidebar-w: 232px;
  --topbar-h: 56px;
  --drawer-w: 468px;
  --row-h: 56px;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #eef1f6;
    --surface: #ffffff;
    --raised: #f7f9fc;
    --sunken: #f2f5f9;
    --hover: #f0f4f9;
    --text: #111826;
    --text-muted: #55637a;
    --text-faint: #7d8ba1;
    --line: #e3e8f0;
    --line-strong: #cbd4e1;
    --accent: #b45309;
    --accent-hover: #92400e;
    --accent-soft: #fdf3e3;
    --accent-line: #f3d9ae;
    --ok: #15803d;
    --ok-soft: #e3f7e9;
    --ok-line: #b7e4c6;
    --warn: #b45309;
    --warn-soft: #fdf1dc;
    --warn-line: #f0d5a4;
    --bad: #dc2626;
    --bad-soft: #fdeaea;
    --bad-line: #f6c4c4;
    --info: #0f766e;
    --info-soft: #dff5f2;
    --info-line: #a9ded7;
    --neutral-soft: #eef1f6;
    --neutral-line: #dde3ec;
    --shadow-sm: 0 1px 2px rgba(17, 24, 38, 0.08);
    --shadow-lg: 0 20px 52px rgba(17, 24, 38, 0.16);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f6;
  --surface: #ffffff;
  --raised: #f7f9fc;
  --sunken: #f2f5f9;
  --hover: #f0f4f9;
  --text: #111826;
  --text-muted: #55637a;
  --text-faint: #7d8ba1;
  --line: #e3e8f0;
  --line-strong: #cbd4e1;
  --accent: #b45309;
  --accent-hover: #92400e;
  --accent-soft: #fdf3e3;
  --accent-line: #f3d9ae;
  --ok: #15803d;
  --ok-soft: #e3f7e9;
  --ok-line: #b7e4c6;
  --warn: #b45309;
  --warn-soft: #fdf1dc;
  --warn-line: #f0d5a4;
  --bad: #dc2626;
  --bad-soft: #fdeaea;
  --bad-line: #f6c4c4;
  --info: #0f766e;
  --info-soft: #dff5f2;
  --info-line: #a9ded7;
  --neutral-soft: #eef1f6;
  --neutral-line: #dde3ec;
  --shadow-sm: 0 1px 2px rgba(17, 24, 38, 0.08);
  --shadow-lg: 0 20px 52px rgba(17, 24, 38, 0.16);
}

* { box-sizing: border-box; }

/* Views toggle with the hidden attribute while their class sets display, so
   this must win or a "hidden" view stays on screen. */
[hidden] { display: none !important; }

html { min-width: 320px; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-size: var(--fs-body);
  line-height: 1.5;
}

button, input, textarea, select { font: inherit; }
button { color: inherit; }
button, a, input, textarea { -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin-top: 0; }

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: var(--r-sm);
}

.numeric, .tabular { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -60px; left: var(--s3);
  z-index: 100;
  padding: var(--s2) var(--s4);
  color: var(--accent-text);
  background: var(--accent);
  border-radius: var(--r-sm);
  text-decoration: none;
}
.skip-link:focus { top: var(--s3); }

.muted { color: var(--text-muted); margin-bottom: 0; }
.compact { font-size: var(--fs-small); }
.danger-text { color: var(--bad); }

/* Uppercase micro-label: the single treatment for every field label, table
   header, chip caption and definition term. */
.eyebrow,
.field label,
.field-label,
thead th,
.definition-grid dt,
.operations-context-details dt,
.summary-label,
.chip em {
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* ---------------------------------------------------------------- Buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: var(--h-md);
  padding: 0 var(--s3);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  font-size: var(--fs-body);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.button:disabled { opacity: 0.4; cursor: not-allowed; }

.button.primary { background: var(--accent); color: var(--accent-text); }
.button.primary:hover:not(:disabled) { background: var(--accent-hover); }

.button.secondary {
  background: var(--raised);
  border-color: var(--line-strong);
  color: var(--text);
}
.button.secondary:hover:not(:disabled) { background: var(--hover); }

.button.ghost { color: var(--text-muted); }
.button.ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); }

.button.quiet { color: var(--text-muted); }
.button.quiet:hover:not(:disabled) { background: var(--hover); color: var(--text); }

.button.danger { background: var(--bad); color: #ffffff; }
.button.danger:hover:not(:disabled) { background: var(--bad); filter: brightness(1.1); }

.button.small-button { height: var(--h-sm); padding: 0 var(--s2); font-size: var(--fs-small); }
.button.icon-button { width: var(--h-md); padding: 0; }
.button.small-button.icon-button { width: var(--h-sm); }
.button.full-width { width: 100%; }

/* Tinted square icon actions, one per semantic tone. */
.icon-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--h-sm);
  height: var(--h-sm);
  padding: 0;
  border-radius: var(--r-sm);
  border: 1px solid var(--neutral-line);
  background: var(--neutral-soft);
  color: var(--text-muted);
  font-size: var(--fs-body);
  cursor: pointer;
  transition: filter 0.12s ease, opacity 0.12s ease;
}
.icon-action:hover:not(:disabled) { filter: brightness(1.35); }
.icon-action:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-action[data-tone="accent"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.icon-action[data-tone="ok"] { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.icon-action[data-tone="bad"] { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }
.icon-action[data-tone="info"] { background: var(--info-soft); border-color: var(--info-line); color: var(--info); }

/* ----------------------------------------------------------------- Badges */

/* One badge component. Tone is data-driven so a value's colour is decided by
   meaning, never by where it happens to be rendered. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  height: var(--h-badge);
  padding: 0 var(--s2);
  border: 1px solid var(--neutral-line);
  border-radius: var(--r-sm);
  background: var(--neutral-soft);
  color: var(--text-muted);
  font-size: var(--fs-micro);
  font-weight: 650;
  letter-spacing: 0.04em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.badge[data-tone="accent"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.badge[data-tone="ok"], .badge[data-tone="live"] { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.badge[data-tone="warn"], .badge[data-tone="pending"] { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.badge[data-tone="bad"], .badge[data-tone="error"] { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }
.badge[data-tone="info"] { background: var(--info-soft); border-color: var(--info-line); color: var(--info); }

/* Some badges are driven by runtime status rather than a chosen tone. They map
   onto exactly the same palette so a status and a tone never disagree. */
.badge[data-status="live"] { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.badge[data-status="pending"] { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.badge[data-status="error"] { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }

.badge.badge-dot::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.badge-pill { border-radius: var(--r-pill); }

/* Status pill: same construction as .badge, but tone comes from data-status
   so existing status rendering keeps working unchanged. */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  height: var(--h-badge);
  padding: 0 var(--s2);
  border: 1px solid var(--neutral-line);
  border-radius: var(--r-pill);
  background: var(--neutral-soft);
  color: var(--text-muted);
  font-size: var(--fs-micro);
  font-weight: 650;
  white-space: nowrap;
}
.status-badge::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.status-badge[data-status="live"] { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.status-badge[data-status="pending"] { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.status-badge[data-status="error"] { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }

/* ----------------------------------------------------------------- Fields */

.form-stack { display: flex; flex-direction: column; gap: var(--s3); }

.field { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; }

.field input,
.field select,
.field textarea {
  width: 100%;
  height: var(--h-md);
  padding: 0 var(--s3);
  color: var(--text);
  background: var(--sunken);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  font-size: var(--fs-body);
  transition: border-color 0.12s ease, background 0.12s ease;
}

.field textarea { height: auto; padding: var(--s2) var(--s3); resize: vertical; min-height: 60px; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--text-faint); }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus);
}
.field input:disabled, .field select:disabled { opacity: 0.45; cursor: not-allowed; }
.field input[type="number"] { font-variant-numeric: tabular-nums; }
.field input::placeholder, .field textarea::placeholder { color: var(--text-faint); }

.field small, .field-hint {
  font-size: var(--fs-small);
  color: var(--text-faint);
  line-height: 1.45;
}

/* Leading-icon input: the glyph sits inside the control, so the text baseline
   still aligns with plain inputs on the same row. */
.input-icon { position: relative; display: block; }
.input-icon .input-icon-glyph {
  position: absolute;
  left: var(--s3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  font-size: var(--fs-base);
  pointer-events: none;
}
.input-icon input { padding-left: calc(var(--s3) * 2 + 10px); }

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(176px, 1fr));
  gap: var(--s3);
  align-items: start;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: var(--h-md);
  font-size: var(--fs-body);
  cursor: pointer;
}
.checkbox-field input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

.derived-value, .latency-estimate {
  margin: 0;
  height: var(--h-md);
  display: flex;
  align-items: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}
.latency-estimate { color: var(--accent); }

.form-error {
  margin: 0;
  padding: var(--s2) var(--s3);
  font-size: var(--fs-small);
  color: var(--bad);
  background: var(--bad-soft);
  border: 1px solid var(--bad-line);
  border-radius: var(--r-sm);
}

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

.login-layout { display: grid; place-items: center; min-height: 100vh; padding: var(--s5); }

.login-card {
  width: 100%;
  max-width: 380px;
  padding: var(--s6);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}

.login-card h1 { font-size: var(--fs-xl); margin-bottom: var(--s1); letter-spacing: -0.02em; }
.login-card .form-stack { margin-top: var(--s5); }

.brand-mark {
  display: grid;
  place-items: center;
  width: var(--h-lg); height: var(--h-lg);
  margin-bottom: var(--s4);
  font-size: var(--fs-body);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--accent-text);
  background: linear-gradient(140deg, var(--accent), #7c3aed);
  border-radius: 10px;
}
.brand-mark.small { width: var(--h-md); height: var(--h-md); margin-bottom: 0; font-size: var(--fs-micro); border-radius: var(--r-md); }

/* -------------------------------------------------------------- App shell */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  padding: var(--s4) var(--s3);
  background: var(--surface);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand { display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s2); }
.sidebar-brand-text { display: flex; flex-direction: column; min-width: 0; }
.sidebar-brand-text strong { font-size: var(--fs-base); letter-spacing: -0.01em; }

.connection-state { display: flex; align-items: center; gap: var(--s1); font-size: var(--fs-micro); color: var(--text-faint); }
.connection-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; }
.connection-dot[data-state="connected"] { background: var(--ok); }
.connection-dot[data-state="connecting"] { background: var(--warn); animation: pulse 1.6s ease-in-out infinite; }
.connection-dot[data-state="offline"] { background: var(--bad); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.view-navigation { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.view-navigation-button,
.nav-signout {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--s3);
  height: var(--h-lg);
  padding: 0 var(--s3);
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-base);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.view-navigation-button:hover, .nav-signout:hover { background: var(--hover); color: var(--text); }

/* The active item is marked with a soft tint and a left rail rather than a
   solid fill. A saturated block draws more attention than the content it is
   pointing at, and it forces the icon to lose its colour. */
.view-navigation-button[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--accent);
}

/* Each destination keeps a fixed hue so the sidebar is navigable by colour. */
.nav-icon {
  font-size: var(--fs-base);
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  background: color-mix(in srgb, currentColor 14%, transparent);
  flex-shrink: 0;
}
.view-navigation-button:nth-of-type(1) .nav-icon { color: var(--hue-amber); }
.view-navigation-button:nth-of-type(2) .nav-icon { color: var(--hue-emerald); }
.view-navigation-button:nth-of-type(3) .nav-icon { color: var(--hue-cyan); }
.nav-signout .nav-icon { color: var(--bad); }

.sidebar-footer { padding-top: var(--s3); border-top: 1px solid var(--line); }

/* ----------------------------------------------------------------- Topbar */

.workspace { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  height: var(--topbar-h);
  padding: 0 var(--s5);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.chip-row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; min-width: 0; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  height: var(--h-sm);
  padding: 0 var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--sunken);
  color: var(--text-muted);
  font-size: var(--fs-small);
  white-space: nowrap;
}

.chip b { color: var(--text); font-weight: 650; }
.chip em { font-style: normal; }
.chip-icon { color: var(--accent); font-size: var(--fs-small); }
.chip-mono b { font-family: var(--mono); font-size: var(--fs-base); color: var(--accent); letter-spacing: 0.02em; }
.chip-accent { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); font-weight: 700; }

.chip-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex-shrink: 0; }
.chip[data-env="production"] .chip-dot { background: var(--ok); }

.topbar-actions { display: flex; align-items: center; gap: var(--s2); }
.topbar-divider { width: 1px; height: 22px; background: var(--line-strong); margin: 0 var(--s1); }

.account { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.account-name { font-size: var(--fs-body); font-weight: 650; color: var(--text); }
.account-role { font-size: var(--fs-micro); color: var(--text-faint); }

.avatar {
  width: var(--h-md); height: var(--h-md);
  border-radius: 50%;
  background: linear-gradient(140deg, var(--accent), #7c3aed);
  flex-shrink: 0;
}

.content { padding: var(--s5); min-width: 0; }
.content:focus { outline: none; }

.panel-view { display: flex; flex-direction: column; gap: var(--s4); max-width: 1480px; }

/* -------------------------------------------------------------- Page head */

.page-head { padding-bottom: var(--s4); border-bottom: 2px solid var(--accent); }
.page-head h1 { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.02em; margin-bottom: var(--s1); }
.page-subtitle { margin: 0; font-size: var(--fs-base); color: var(--text-muted); }

.toolbar-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }

.stat-strip { display: flex; align-items: center; gap: var(--s4); font-size: var(--fs-body); color: var(--text-muted); }
.stat { display: inline-flex; align-items: baseline; gap: var(--s1); }
.stat strong { font-size: var(--fs-lg); font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-live strong { color: var(--ok); }
.stat-error strong { color: var(--bad); }

.table-caption { margin: 0; font-size: var(--fs-small); color: var(--text-faint); font-variant-numeric: tabular-nums; }

.search-field { width: 220px; }
.search-field input { background: var(--sunken); }
.search-field input,
.input-icon input[type="search"] {
  height: var(--h-sm);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  width: 100%;
  padding-left: calc(var(--s3) * 2 + 6px);
  font-size: var(--fs-body);
}
.search-field input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }

.count-label {
  font-size: var(--fs-small);
  color: var(--text-muted);
  padding: 2px var(--s2);
  background: var(--neutral-soft);
  border-radius: var(--r-pill);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------- Panels and tables */

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

.panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
}

.panel-title { display: flex; align-items: center; gap: var(--s2); margin: 0; font-size: var(--fs-base); font-weight: 700; }
.panel-title-icon { color: var(--ok); }
.toolbar-actions { display: flex; align-items: center; gap: var(--s3); }

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

table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.stream-table { min-width: 1020px; }

.col-name { width: auto; }
.col-sources { width: 150px; }
.col-output { width: 190px; }
.col-latency { width: 150px; }
.col-uptime { width: 104px; }
.col-actions { width: 168px; }

thead th {
  height: var(--h-md);
  padding: 0 var(--s4);
  text-align: left;
  background: var(--sunken);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
thead th.numeric { text-align: right; }

tbody td {
  height: var(--row-h);
  padding: 0 var(--s4);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  overflow: hidden;
}
tbody tr:last-child td { border-bottom: none; }

.stream-table tbody tr { cursor: pointer; transition: background 0.1s ease; }
.stream-table tbody tr:hover { background: var(--hover); }
.stream-table tbody tr[data-selected="true"] { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }

/* Row internals */

.stream-identity { display: flex; align-items: center; gap: var(--s3); min-width: 0; }

.state-dot { width: 8px; height: 8px; flex-shrink: 0; border-radius: 50%; background: var(--text-faint); }
.state-dot[data-status="live"] { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.state-dot[data-status="pending"] { background: var(--warn); animation: pulse 1.6s ease-in-out infinite; }
.state-dot[data-status="error"] { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

.stream-logo {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--h-md); height: var(--h-md);
  flex-shrink: 0;
  font-size: var(--fs-micro);
  font-weight: 700;
  color: var(--text-muted);
  background: var(--neutral-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.stream-logo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.stream-primary { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.stream-name { font-weight: 650; font-size: var(--fs-base); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stream-description { font-size: var(--fs-small); color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cell-stack { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; line-height: 1.3; }
.cell-primary { font-size: var(--fs-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cell-secondary { font-size: var(--fs-small); color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cell-secondary[data-tone="warning"] { color: var(--warn); }
.cell-secondary[data-tone="danger"] { color: var(--bad); }

.source-badge { display: inline-flex; align-items: center; gap: var(--s1); }
.source-host { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.source-pips { display: inline-flex; gap: 2px; flex-shrink: 0; }
.source-pip { width: 4px; height: 4px; border-radius: 50%; background: var(--line-strong); }
.source-pip[data-state="active"] { background: var(--ok); }
.source-pip[data-state="failed"] { background: var(--bad); }

.uptime-cell { text-align: right; font-variant-numeric: tabular-nums; font-size: var(--fs-body); color: var(--text-muted); font-family: var(--mono); }

.row-actions { display: flex; align-items: center; gap: var(--s1); justify-content: flex-end; }

/* ----------------------------------------------------------------- States */

.loading-state { display: flex; align-items: center; justify-content: center; gap: var(--s3); padding: var(--s7) var(--s4); color: var(--text-muted); }
.spinner { width: 15px; height: 15px; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: var(--s7) var(--s5); text-align: center; }
.empty-state h2, .empty-state h3 { margin: 0; font-size: var(--fs-lg); }
.empty-icon {
  display: grid; place-items: center;
  width: var(--h-lg); height: var(--h-lg);
  margin-bottom: var(--s1);
  color: var(--text-faint);
  background: var(--neutral-soft);
  border-radius: 50%;
}
.empty-state .button { margin-top: var(--s2); }
.compact-empty-state { padding: var(--s6) var(--s4); }

/* ----------------------------------------------------------------- Drawer */

.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(4, 6, 11, 0.55); }

.drawer {
  position: fixed;
  top: 0; right: 0;
  z-index: 41;
  display: flex;
  flex-direction: column;
  width: min(var(--drawer-w), 100vw);
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  animation: drawer-in 0.16s ease-out;
}
@keyframes drawer-in { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }

.drawer-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); }
.drawer-identity { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }
.drawer-identity h2 { margin: 0; font-size: var(--fs-lg); overflow: hidden; text-overflow: ellipsis; }
.drawer-identity .status-badge { align-self: flex-start; }

.drawer-tabs { display: flex; gap: var(--s1); padding: 0 var(--s5); border-bottom: 1px solid var(--line); }
.drawer-tab {
  height: var(--h-lg);
  padding: 0 var(--s3);
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-body);
  font-weight: 600;
  cursor: pointer;
}
.drawer-tab:hover { color: var(--text); }
.drawer-tab[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }

.drawer-body { flex: 1; overflow-y: auto; padding: var(--s5); }
.drawer-footer { display: flex; gap: var(--s2); padding: var(--s3) var(--s5); background: var(--sunken); border-top: 1px solid var(--line); }
.drawer-footer .button:last-child { margin-left: auto; }

.preview-frame { position: relative; aspect-ratio: 16 / 9; background: #000; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.preview-frame video { width: 100%; height: 100%; object-fit: contain; display: block; }
.preview-overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: var(--s4); text-align: center; font-size: var(--fs-small); color: var(--text-muted); background: var(--neutral-soft); }
.preview-actions { display: flex; align-items: center; gap: var(--s3); margin-top: var(--s3); flex-wrap: wrap; }

.drawer-definitions { margin-top: var(--s5); }
.definition-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(136px, 1fr)); gap: var(--s4); margin: 0; }
.definition-grid dd { margin: var(--s1) 0 0; font-size: var(--fs-base); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.definition-help { display: block; font-size: var(--fs-small); color: var(--text-faint); }

.drawer-source-list { display: flex; flex-direction: column; gap: var(--s2); }
.drawer-source { display: flex; align-items: center; gap: var(--s3); padding: var(--s3); background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r-sm); }
.drawer-source[data-active="true"] { border-color: var(--ok-line); background: var(--ok-soft); }
.drawer-source-body { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.35; }

.drawer-log { display: flex; flex-direction: column; font-size: var(--fs-body); }
.log-entry { display: flex; gap: var(--s3); padding: var(--s2) 0; border-bottom: 1px solid var(--line); }
.log-time { color: var(--text-faint); font-family: var(--mono); font-size: var(--fs-small); white-space: nowrap; }
.log-action { color: var(--text); }

/* ---------------------------------------------------------------- Dialogs */

.dialog {
  width: min(600px, calc(100vw - var(--s6)));
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}
.dialog.wide-dialog { width: min(760px, calc(100vw - var(--s6))); }
.dialog::backdrop { background: rgba(4, 6, 11, 0.7); }

.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5) var(--s3); border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: var(--fs-lg); }
.dialog-body { padding: var(--s5); max-height: min(72vh, 660px); overflow-y: auto; }
.dialog-footer { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s3) var(--s5); background: var(--sunken); border-top: 1px solid var(--line); }

.form-section { padding: var(--s4); background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r-md); }
.form-section-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.form-section-header h3 { margin: 0; font-size: var(--fs-base); font-weight: 700; }
.form-section .field-row { margin-top: var(--s3); }

/* -------------------------------------------------------- Source repeater */

.source-list { display: flex; flex-direction: column; gap: var(--s2); }

.source-row { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); }
.source-row[data-primary="true"] { border-color: var(--accent-line); box-shadow: inset 2px 0 0 var(--accent); }

.source-rank {
  display: grid; place-items: center;
  width: var(--h-sm); height: var(--h-sm);
  flex-shrink: 0;
  margin-top: 22px;
  font-size: var(--fs-micro);
  font-weight: 700;
  color: var(--text-muted);
  background: var(--neutral-soft);
  border-radius: var(--r-sm);
  font-variant-numeric: tabular-nums;
}
.source-row[data-primary="true"] .source-rank { background: var(--accent-soft); color: var(--accent); }

.source-fields { display: grid; grid-template-columns: minmax(96px, 0.36fr) minmax(0, 1fr); gap: var(--s3); flex: 1; min-width: 0; }
.source-url-field { min-width: 0; }
.source-controls { display: flex; gap: var(--s1); margin-top: 22px; flex-shrink: 0; }
.source-note-error { color: var(--bad); }

#encoding-fields { margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--line); }
.custom-encoding { margin-top: var(--s3); padding-top: var(--s3); border-top: 1px dashed var(--line-strong); display: flex; flex-direction: column; gap: var(--s3); }
.encoding-summary { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- Toasts */

.toast-region { position: fixed; right: var(--s5); bottom: var(--s5); z-index: 60; display: flex; flex-direction: column; gap: var(--s2); pointer-events: none; }
.toast {
  padding: var(--s3) var(--s4);
  font-size: var(--fs-body);
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.16s ease-out;
}
.toast[data-type="error"] { border-left-color: var(--bad); }
.toast[data-type="success"] { border-left-color: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --------------------------------------------------------- Infrastructure */

.operations-context { padding: var(--s3) var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.operations-context-details { display: flex; gap: var(--s6); margin: 0; }
.operations-context-details dd { margin: var(--s1) 0 0; font-size: var(--fs-body); font-variant-numeric: tabular-nums; }

.operations-warning { padding: var(--s3) var(--s4); font-size: var(--fs-body); color: var(--warn); background: var(--warn-soft); border: 1px solid var(--warn-line); border-radius: var(--r-sm); }
.operations-content { display: flex; flex-direction: column; gap: var(--s5); }
.section-heading { margin-bottom: var(--s3); }
.section-heading h2 { font-size: var(--fs-lg); font-weight: 700; }

.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--s3); }
.summary-card { display: flex; flex-direction: column; gap: var(--s1); padding: var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.summary-card strong { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.summary-detail { font-size: var(--fs-small); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.summary-card.live-card strong { color: var(--ok); }
.summary-card.error-card strong { color: var(--bad); }

.metrics-disclaimer { margin-top: var(--s3); font-size: var(--fs-small); color: var(--text-faint); line-height: 1.5; }
.metrics-disclaimer p { margin: 0 0 var(--s1); }

.infrastructure-table-wrap { font-size: var(--fs-body); }
.server-table { min-width: 1140px; table-layout: auto; }

.node-identity { display: flex; flex-direction: column; min-width: 150px; }
.node-name { font-weight: 650; }
.node-role { font-size: var(--fs-small); color: var(--text-faint); }

.metric-stack { display: flex; flex-direction: column; gap: var(--s1); min-width: 112px; }
.metric-value { font-variant-numeric: tabular-nums; font-size: var(--fs-body); }
.metric-detail { font-size: var(--fs-small); color: var(--text-faint); font-variant-numeric: tabular-nums; }
.metric-bar { height: 4px; background: var(--neutral-soft); border-radius: var(--r-pill); overflow: hidden; }
.metric-bar span { display: block; height: 100%; background: var(--accent); border-radius: var(--r-pill); }
.metric-bar[data-level="warning"] span { background: var(--warn); }
.metric-bar[data-level="critical"] span { background: var(--bad); }

.load-balancer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--s3); }
.load-balancer-card { padding: var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.load-balancer-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s3); }

.backend-details { margin-top: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--line); }
.backend-details summary { font-size: var(--fs-body); color: var(--text-muted); cursor: pointer; }
.backend-details summary:hover { color: var(--text); }
.backend-table { margin-top: var(--s2); font-size: var(--fs-small); table-layout: auto; }
.backend-table th, .backend-table td { height: var(--h-sm); padding: 0 var(--s2); }

/* ------------------------------------------------------------- Responsive */

@media (max-width: 1000px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto;
    flex-direction: row; align-items: center; flex-wrap: wrap;
    gap: var(--s3);
    border-right: none; border-bottom: 1px solid var(--line);
  }
  .view-navigation { flex-direction: row; flex: 1 1 100%; order: 3; }
  .sidebar-footer { padding-top: 0; border-top: none; margin-left: auto; }
  .topbar { height: auto; padding: var(--s3) var(--s4); flex-wrap: wrap; gap: var(--s3); }
  .content { padding: var(--s4); }
  .source-fields { grid-template-columns: 1fr; }
  .drawer { width: 100vw; }
}

@media (max-width: 640px) {
  .search-field { width: 148px; }
  .toolbar-row { align-items: stretch; }
  .chip-mono em, .chip em { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ------------------------------------------------------------ League tabs */

/* A row of filters, not navigation between pages: the active one is marked
   with the accent underline rather than a filled pill, so it reads as a
   refinement of the list below rather than a separate destination. */
.league-tabs {
  display: flex;
  align-items: center;
  gap: var(--s1);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.league-tab {
  flex-shrink: 0;
  height: var(--h-md);
  padding: 0 var(--s3);
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-muted);
  font-size: var(--fs-body);
  font-weight: 600;
  cursor: pointer;
  transition: color 0.1s ease, border-color 0.1s ease;
}
.league-tab:hover { color: var(--text); }
.league-tab[aria-current="page"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.league-tab .count {
  margin-left: var(--s1);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
