/*
 * app.css — the CCML Engine dashboard design system.
 * Spec: docs/Dashboard-Web-GUI.md §3 (layout, responsive), §6 (accessibility,
 *       WCAG AA both themes), §7 (error presentation) · docs/Security.md §7.
 *
 * One hand-written file, no framework (ADR-0004). Everything is token-based so
 * the light and dark themes differ only in the token block. Dark is the default
 * (§2.6); `prefers-color-scheme` and an explicit [data-theme] both switch it.
 * Contrast pairs are chosen for WCAG AA (>=4.5:1 text, >=3:1 large/UI) in both
 * themes. All state colour is paired with a glyph + label in the markup, so the
 * palette never carries meaning alone (§6).
 */

/* ---------------------------------------------------------------- design tokens */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --radius: 8px;
  --radius-sm: 5px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --topbar-h: 56px;
  --sidebar-w: 220px;
  --sidebar-w-icons: 64px;

  --z-toast: 1000;
  --z-modal: 1100;

  --dur: 160ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

/* Dark theme — the default look existing operators expect (§2.6). */
:root,
:root[data-theme="dark"] {
  --bg: #0e1116;
  --bg-elevated: #161b22;
  --bg-inset: #0a0d12;
  --surface: #1b222c;
  --surface-2: #232b37;
  --border: #2b3340;
  --border-strong: #3a4453;
  --text: #e6edf3;
  --text-muted: #9aa7b4;
  --text-faint: #6b7684;

  --accent: #4c9be8;
  --accent-contrast: #06121f;
  --focus: #7cc0ff;

  --ok: #3fb950; /* green — RUNNING / connected */
  --warn: var(--warn); /* amber — FALLBACK / reconnecting */
  --danger: #f85149; /* red — FAILED / disconnected */
  --info: #58a6ff; /* blue — PREPARING / STARTING */
  --neutral: #7d8590; /* grey — STOPPED */

  --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}

/* Light theme — offered, prefers-color-scheme respected (§2.6). */
:root[data-theme="light"] {
  --bg: #f4f6f9;
  --bg-elevated: #ffffff;
  --bg-inset: #eaeef3;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --border: #d6dde5;
  --border-strong: #b9c3ce;
  --text: #10151b;
  --text-muted: #4a5560;
  --text-faint: #6b7684;

  --accent: #1660c4;
  --accent-contrast: #ffffff;
  --focus: #0a4da3;

  --ok: #1a7f37;
  --warn: #8a6100;
  --danger: #cf222e;
  --info: #0a58ca;
  --neutral: #57606a;

  --shadow: 0 8px 24px rgba(16, 21, 27, 0.12);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f6f9;
    --bg-elevated: #ffffff;
    --bg-inset: #eaeef3;
    --surface: #ffffff;
    --surface-2: #f0f3f7;
    --border: #d6dde5;
    --border-strong: #b9c3ce;
    --text: #10151b;
    --text-muted: #4a5560;
    --text-faint: #6b7684;
    --accent: #1660c4;
    --accent-contrast: #ffffff;
    --focus: #0a4da3;
    --ok: #1a7f37;
    --warn: #8a6100;
    --danger: #cf222e;
    --info: #0a58ca;
    --neutral: #57606a;
    --shadow: 0 8px 24px rgba(16, 21, 27, 0.12);
  }
}

/* ---------------------------------------------------------------- base */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* Alpine: hide declaratively-toggled elements until Alpine initializes. */
[x-cloak] {
  display: none !important;
}

/* ---------------------------------------------------------------- a11y helpers */
.visually-hidden {
  position: absolute !important;
  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;
  left: var(--space-2);
  top: -48px;
  z-index: var(--z-modal);
  padding: var(--space-2) var(--space-3);
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: var(--radius-sm);
  transition: top var(--dur) var(--ease);
}
.skip-link:focus {
  top: var(--space-2);
}

/* Visible focus rings everywhere (§6). */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------- app frame */
.app-frame {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar content";
  min-height: 100vh;
}

/* ---------------------------------------------------------------- top bar */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-4);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
}
.brand-mark {
  color: var(--ok);
}
.brand-name {
  letter-spacing: 0.04em;
}

.topbar__search {
  flex: 0 1 320px;
}
.search-input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
}
.search-input::placeholder {
  color: var(--text-faint);
}

.topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  position: relative;
}

.live-count {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-radius: 999px;
  background: var(--bg-inset);
  color: var(--text-muted);
  font-size: 12px;
}
.live-count__dot {
  color: var(--ok);
}
.live-count__label {
  color: var(--text-faint);
}

.iconbtn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.iconbtn:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.usermenu__name {
  font-size: 13px;
}

.badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}

/* ---------------------------------------------------------------- menus */
.menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  min-width: 180px;
  padding: var(--space-1);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 30;
}
.menu__item {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.menu__item:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.menu__item--danger {
  color: var(--danger);
}
.menu form {
  margin: 0;
}

/* ---------------------------------------------------------------- telemetry */
.telemetry {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  font-variant-numeric: tabular-nums;
}
.telemetry__item {
  display: inline-flex;
  gap: var(--space-1);
  align-items: baseline;
}
.telemetry__k {
  color: var(--text-faint);
  font-size: 11px;
  letter-spacing: 0.04em;
}
.telemetry__v {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
}
.telemetry__stale {
  color: var(--warn);
  font-size: 11px;
}

/* When the socket is down, dim live values and stop trusting them (§5). */
.is-stale {
  opacity: 0.55;
  filter: saturate(0.6);
}

/* ---------------------------------------------------------------- sidebar */
.sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-2);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}
.nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
}
.nav__item:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.nav__item.is-active {
  background: var(--surface-2);
  color: var(--text);
}
.nav__item.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}
.nav__glyph {
  width: 20px;
  text-align: center;
  flex: 0 0 auto;
}
.nav__badge {
  margin-left: auto;
  min-width: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--info);
  color: #fff;
  font-size: 11px;
  text-align: center;
}

/* connection indicator (§5): the class carries colour, the label carries text. */
.connstate {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  margin-top: auto;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.connstate__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--neutral);
  flex: 0 0 auto;
}
.connstate__dot.is-connected {
  background: var(--ok);
}
.connstate__dot.is-reconnecting {
  background: var(--warn);
  animation: pulse 1.4s var(--ease) infinite;
}
.connstate__dot.is-disconnected {
  background: var(--danger);
}

/* ---------------------------------------------------------------- content */
.content {
  grid-area: content;
  padding: var(--space-5);
  overflow-x: hidden;
}
.page__title {
  margin: 0 0 var(--space-4);
  font-size: 20px;
}
.page__placeholder {
  padding: var(--space-6);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-faint);
  text-align: center;
}

/* ---------------------------------------------------------------- state pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px var(--space-2);
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill__glyph {
  font-size: 11px;
}
.pill__meta {
  color: var(--text-muted);
  font-weight: 500;
}
.pill.is-stopped {
  color: var(--neutral);
}
.pill.is-stopped .pill__glyph {
  color: var(--neutral);
}
.pill.is-running {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 40%, transparent);
}
.pill.is-running .pill__glyph {
  color: var(--ok);
}
.pill.is-preparing,
.pill.is-starting {
  color: var(--info);
  border-color: color-mix(in srgb, var(--info) 40%, transparent);
}
.pill.is-preparing .pill__glyph,
.pill.is-starting .pill__glyph {
  color: var(--info);
  animation: pulse 1.4s var(--ease) infinite;
}
.pill.is-fallback,
.pill.is-restarting,
.pill.is-stopping {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
}
.pill.is-fallback .pill__glyph,
.pill.is-restarting .pill__glyph {
  color: var(--warn);
  animation: pulse 1.4s var(--ease) infinite;
}
.pill.is-failed {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}
.pill.is-failed .pill__glyph {
  color: var(--danger);
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover {
  background: var(--surface-2);
}
.btn--ghost {
  background: transparent;
  border-color: var(--border);
}
.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* ---------------------------------------------------------------- toasts */
.toasts {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: min(420px, calc(100vw - 2 * var(--space-4)));
}
.toast {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left-width: 4px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
}
.toast--info {
  border-left-color: var(--info);
}
.toast--success {
  border-left-color: var(--ok);
}
.toast--warning {
  border-left-color: var(--warn);
}
.toast--critical,
.toast--error {
  border-left-color: var(--danger);
}
.toast__body {
  flex: 1;
}
.toast__title {
  margin: 0;
  font-weight: 700;
}
.toast__message {
  margin: var(--space-1) 0 0;
  color: var(--text-muted);
}
.toast__action {
  display: inline-block;
  margin-top: var(--space-2);
  font-weight: 600;
}
.toast__close {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

/* ---------------------------------------------------------------- modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: rgba(0, 0, 0, 0.55);
}
.modal {
  width: min(440px, 100%);
  padding: var(--space-5);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.modal__title {
  margin: 0 0 var(--space-2);
  font-size: 17px;
}
.modal__message {
  margin: 0 0 var(--space-5);
  color: var(--text-muted);
}
.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* ---------------------------------------------------------------- login */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: var(--bg);
}
.login__card {
  width: min(380px, 100%);
  padding: var(--space-6);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.login__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  margin-bottom: var(--space-4);
}
.login__title {
  margin: 0 0 var(--space-4);
  font-size: 20px;
}

/* ---------------------------------------------------------------- animation */
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* Respect reduced-motion: pulses become static, transitions removed (§6). */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------------------------------------------------------------- responsive */
/* Sidebar collapses to icons below 1100px (§3). */
@media (max-width: 1100px) {
  .app-frame {
    grid-template-columns: var(--sidebar-w-icons) 1fr;
  }
  .nav__label,
  .connstate__label,
  .nav__badge {
    display: none;
  }
  .nav__item {
    justify-content: center;
    padding: var(--space-2);
  }
  .topbar__search {
    flex-basis: 200px;
  }
  .telemetry {
    gap: var(--space-2);
  }
}

/* Below 700px the sidebar becomes a bottom tab bar; content reflows (§3). */
@media (max-width: 700px) {
  .app-frame {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) 1fr auto;
    grid-template-areas:
      "topbar"
      "content"
      "sidebar";
  }
  .sidebar {
    position: sticky;
    bottom: 0;
    top: auto;
    height: auto;
    flex-direction: row;
    border-right: 0;
    border-top: 1px solid var(--border);
    padding: var(--space-1);
    overflow-x: auto;
  }
  .nav {
    flex-direction: row;
    justify-content: space-around;
    width: 100%;
  }
  .nav__item.is-active::before {
    left: 6px;
    right: 6px;
    top: 0;
    bottom: auto;
    width: auto;
    height: 3px;
  }
  .connstate {
    display: none;
  }
  .usermenu__name,
  .live-count__label {
    display: none;
  }
  .topbar__search {
    flex-basis: 120px;
  }
  .telemetry__k {
    display: none;
  }
  .content {
    padding: var(--space-4);
  }
}

/* ============================================================================
 * Dashboard core pages — grouped stream rows, stream detail tabs, config
 * editor, media manager and log view (docs/Dashboard-Web-GUI.md §4.1–§4.4).
 * Appended to the single design-system file (§1: "Hand-written, one file");
 * token-based so both themes come along for free.
 * ========================================================================== */

/* --- page header bar + buttons ------------------------------------------- */
.page__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.page__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.btn--sm {
  padding: var(--space-1) var(--space-3);
  font-size: 12px;
}
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.btn--primary:hover {
  filter: brightness(1.08);
  background: var(--accent);
}
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn__badge {
  min-width: 16px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--info);
  color: #fff;
  font-size: 10px;
}
.dash-search {
  flex: 0 1 260px;
}

/* --- channel groups (collapse/expand — M-01) ----------------------------- */
.stream-groups {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.chan-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  overflow: hidden;
}
.chan-group__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.chan-group__toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.chan-group__caret {
  width: 1em;
  color: var(--text-muted);
}
.chan-group__aside {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-muted);
  font-size: 12px;
}
.chan-group__count {
  color: var(--text-faint);
}
.chan-group__body {
  display: flex;
  flex-direction: column;
}

/* --- stream row ---------------------------------------------------------- */
.stream-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
}
.stream-row:last-child {
  border-bottom: 0;
}
.stream-row__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.stream-row__ident {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.stream-row__name {
  font-weight: 600;
  color: var(--text);
}
.stream-row__anchor {
  color: var(--ok);
}
.stream-row__meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.stream-row__stats {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.stat {
  white-space: nowrap;
}
.stream-row__reason {
  margin: 0;
  font-size: 12px;
  color: var(--warn);
}
.stream-row__reason.state-failed,
.stream-row__reason.state-invalid_config {
  color: var(--danger);
}
.stream-row__warn {
  margin: 0;
  font-size: 12px;
  color: var(--warn);
}
.yt-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 1px var(--space-2);
  border-radius: 999px;
  border: 1px solid var(--border);
}
.stream-row__watch {
  display: inline-flex;
  align-items: center;
  padding: 1px var(--space-2);
  border-radius: 999px;
  border: 1px solid var(--border);
  text-decoration: none;
  white-space: nowrap;
}
.stream-row__watch:hover {
  border-color: var(--accent);
}
.yt-chip--good {
  color: var(--ok);
}
.yt-chip--ok {
  color: var(--info);
}
.yt-chip--bad {
  color: var(--danger);
}
.yt-chip--none {
  color: var(--text-faint);
}
.yt-chip__viewers {
  color: var(--text-muted);
}

/* now-playing + elapsed bar */
.nowplaying {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 12px;
  color: var(--text-muted);
}
.nowplaying__title {
  flex: 0 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40ch;
}
.nowplaying__bar {
  flex: 1;
  height: 6px;
  min-width: 80px;
  border-radius: 999px;
  background: var(--bg-inset);
  overflow: hidden;
}
.nowplaying__fill {
  display: block;
  height: 100%;
  /* Width comes from the --fill custom property set by the x-fill directive
     (app.js) via the CSSOM — never an inline style attribute (§7). */
  width: var(--fill, 0%);
  background: var(--accent);
}
.nowplaying--lg {
  font-size: 13px;
}
.stream-row__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.mediacount {
  display: flex;
  gap: var(--space-3);
  font-size: 12px;
  color: var(--text-muted);
}
.stream-row__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.row-menu {
  position: relative;
}
.menu--row {
  min-width: 160px;
}

/* --- stream detail: header + tabs ---------------------------------------- */
.stream-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.stream-head__back {
  font-size: 18px;
  color: var(--text-muted);
}
.stream-head__chan {
  color: var(--text-faint);
  font-size: 13px;
}
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-4);
  overflow-x: auto;
}
.tab {
  padding: var(--space-2) var(--space-4);
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover {
  color: var(--text);
}
.tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.tab--disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.tab-panel {
  animation: none;
}

/* --- overview cards ------------------------------------------------------ */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-4);
}
.card {
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}
.card__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.card__title {
  margin: 0 0 var(--space-3);
  font-size: 14px;
}
.card__muted {
  color: var(--text-faint);
}
.card__reason {
  color: var(--warn);
  font-size: 13px;
}
.card__pill {
  margin-bottom: var(--space-3);
}
.statgrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2) var(--space-4);
  margin: 0;
}
.statgrid dt {
  color: var(--text-faint);
  font-size: 11px;
}
.statgrid dd {
  margin: 0;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.yt-issue {
  margin: var(--space-1) 0 0;
  font-size: 12px;
  color: var(--text-muted);
}
.yt-issue--error {
  color: var(--danger);
}
.yt-issue--warning {
  color: var(--warn);
}
.rangeset {
  display: flex;
  gap: var(--space-1);
}

/* --- config editor ------------------------------------------------------- */
.cfg-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.cfg-form__bar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  background: var(--bg);
}
.cfg-form__actions {
  display: flex;
  gap: var(--space-2);
}
.cfg-form__dirty {
  color: var(--warn);
  font-size: 12px;
  font-weight: 600;
}
.cfg-form__error {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger);
  font-size: 13px;
}
.cfg-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
}
.cfg-group legend {
  font-weight: 700;
  padding: 0 var(--space-2);
}
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}
.field--inline {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: 0;
}
.field--check {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
}
.field__label {
  font-size: 12px;
  color: var(--text-muted);
}
.field__help {
  color: var(--accent);
  cursor: help;
}
.field__input {
  padding: var(--space-2) var(--space-3);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.field__input:invalid {
  border-color: var(--danger);
}
.field__input--color {
  width: 48px;
  height: 32px;
  padding: 2px;
}
.field__note {
  margin: var(--space-1) 0 0;
  font-size: 11px;
  color: var(--text-faint);
}
.field--secret {
  gap: var(--space-2);
}
.secret-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.secret-hint {
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.badge-restart {
  display: inline-block;
  margin-left: var(--space-2);
  padding: 1px var(--space-2);
  border-radius: 999px;
  background: var(--bg-inset);
  color: var(--warn);
  font-size: 10px;
  font-weight: 600;
  vertical-align: middle;
}
.dest-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.dest-table th,
.dest-table td {
  padding: var(--space-2);
  border-bottom: 1px solid var(--border);
  text-align: left;
}

/* --- media manager ------------------------------------------------------- */
.media-manager {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--space-4);
}
.media-stage__title {
  margin: 0 0 var(--space-2);
  font-size: 13px;
  color: var(--text-muted);
}
.media-pane {
  margin-bottom: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  padding: var(--space-3);
}
.media-pane__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.media-pane__title {
  margin: 0;
  flex: 1;
  font-size: 13px;
}
.media-pane__count {
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.media-pane__path {
  margin: var(--space-2) 0 0;
  font-size: 11px;
  color: var(--text-faint);
  word-break: break-all;
}
.dropzone {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  text-align: center;
  color: var(--text-faint);
  cursor: pointer;
  margin-bottom: var(--space-2);
}
.dropzone.is-hover {
  border-color: var(--accent);
  color: var(--accent);
}
.dropzone__label {
  margin: 0;
  font-size: 12px;
}
.upload-row,
.filerow {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) 0;
  font-size: 12px;
}
.upload-row__name,
.filerow__name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-row__bar,
.filerow__bar {
  flex: 0 0 80px;
  height: 6px;
  border-radius: 999px;
  background: var(--bg-inset);
  overflow: hidden;
}
.upload-row__fill,
.filerow__fill {
  display: block;
  height: 100%;
  /* Width driven by the --fill custom property (x-fill directive), not an
     inline style attribute (§7). */
  width: var(--fill, 0%);
  background: var(--accent);
}
.filelist {
  list-style: none;
  margin: 0;
  padding: 0;
}
.filerow__meta,
.filerow__state {
  color: var(--text-faint);
}
.filerow__err {
  color: var(--danger);
}
.filerow__actions {
  display: flex;
  gap: var(--space-2);
}
.filerow__act {
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.filerow__act--danger {
  color: var(--danger);
}
.filelist__empty {
  color: var(--text-faint);
  padding: var(--space-2) 0;
}
.filerow.is-failed .filerow__state {
  color: var(--danger);
}

/* --- log view ------------------------------------------------------------ */
.logview {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.logview__bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.logview__status {
  color: var(--warn);
  font-size: 12px;
}
.logview__pane {
  margin: 0;
  max-height: 60vh;
  overflow: auto;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
}
.logline__ts {
  color: var(--text-faint);
}
.logline__lvl {
  color: var(--text-muted);
  text-transform: uppercase;
}
.logline--warning .logline__lvl {
  color: var(--warn);
}
.logline--error .logline__lvl {
  color: var(--danger);
}
.logview__empty {
  color: var(--text-faint);
}

/* htmx request indicators (§7). htmx normally injects these as an inline
   <style>, which the strict style-src blocks; that injection is turned off via
   <meta name="htmx-config" content='{"includeIndicatorStyles":false}'> in the
   templates, so the rules it would have added live here instead. An element
   with .htmx-indicator is hidden until an htmx request it participates in is in
   flight (htmx adds .htmx-request to the element or its configured target). */
.htmx-indicator {
  opacity: 0;
  transition: opacity 200ms ease-in;
}
.htmx-request .htmx-indicator {
  opacity: 1;
}
.htmx-request.htmx-indicator {
  opacity: 1;
}

/* System-resource sparklines on the Metrics page (§4.7). */
.section__sub {
  font-size: 0.8em;
  font-weight: 400;
  margin-left: var(--space-2);
}
.sysres-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
}
.sysres {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
}
.sysres__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}
.sysres__label {
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted, #8b949e);
}
.sysres__value {
  font-size: 1.4rem;
  font-weight: 600;
}
.sysres__unit {
  font-size: 0.7em;
  font-weight: 400;
  margin-left: 2px;
  color: var(--text-muted, #8b949e);
}
.sysres__chart {
  width: 100%;
  height: 48px;
  display: block;
}
.sysres__empty {
  margin: 0;
  font-size: 0.85rem;
  min-height: 48px;
  display: flex;
  align-items: center;
}

/* Alerts page list (§4.8). */
.alert-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.alert-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
}
.alert-item.is-acked {
  opacity: 0.55;
}
.alert-item__title {
  margin: 0;
  font-weight: 600;
}
.alert-item__msg,
.alert-item__meta {
  margin: 2px 0 0;
  font-size: 0.9rem;
}
.alert-item__actions {
  white-space: nowrap;
}

/* Media library tree (§4.3). */
.media-tree {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.media-tree__channel {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  padding: var(--space-2) var(--space-3);
}
.media-tree__channel-head,
.media-tree__stream-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  cursor: pointer;
  list-style: none;
}
.media-tree__channel-head::-webkit-details-marker,
.media-tree__stream-head::-webkit-details-marker {
  display: none;
}
.media-tree__channel-name {
  font-weight: 600;
}
.media-tree__caret {
  display: inline-block;
  transition: transform var(--dur) var(--ease);
  color: var(--text-faint);
}
details[open] > summary .media-tree__caret {
  transform: rotate(90deg);
}
.media-tree__stream {
  margin: var(--space-2) 0 0 var(--space-4);
  padding-left: var(--space-3);
  border-left: 2px solid var(--border);
}
.media-tree__stream-name {
  font-weight: 500;
}
.media-tree__count {
  font-size: 0.85rem;
}
.media-tree__inbox {
  font-size: 0.8rem;
  color: var(--warn);
}
.media-tree__pane {
  margin: var(--space-2) 0 0 var(--space-4);
}
.media-tree__pane-label {
  margin: 0 0 var(--space-1);
  font-size: 0.85rem;
  font-weight: 500;
}
.media-tree__files {
  list-style: none;
  margin: 0;
  padding: 0;
}
.media-tree__file {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
}
.media-tree__file:hover {
  background: var(--surface-2);
}
.media-tree__file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-tree__file-size {
  flex: none;
  font-size: 0.85rem;
}
.media-tree__empty {
  margin: var(--space-1) 0 0;
  font-size: 0.85rem;
}

/* Media storage bar + thumbnails (§4.3). */
.storage-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-2);
}
.storage-bar__svg {
  width: 220px;
  height: 8px;
  flex: none;
}
.storage-bar__label {
  font-size: 0.85rem;
  margin: 0;
}
.media-tree__thumb {
  width: 48px;
  height: 27px;
  flex: none;
  object-fit: cover;
  border-radius: 3px;
  background: var(--bg-inset);
}
.media-tree__thumb--audio {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.media-tree__file {
  align-items: center;
}
.media-tree__del {
  flex: none;
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}
.media-tree__file:hover .media-tree__del,
.media-tree__del:focus-visible {
  opacity: 1;
}

/* As-run "Recently aired" panel (§4.2). */
.card--wide {
  grid-column: 1 / -1;
}
.as-run {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 320px;
  overflow-y: auto;
}
.as-run__row {
  display: flex;
  gap: var(--space-3);
  padding: 3px var(--space-2);
  border-radius: var(--radius-sm);
}
.as-run__row:nth-child(odd) {
  background: var(--surface-2);
}
.as-run__time {
  flex: none;
  font-size: 0.85rem;
}
.as-run__title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Playlist editor (§4.4). */
.card--playlist {
  margin-top: var(--space-4);
}
.playlist-editor__hint {
  font-size: 0.85rem;
  margin: 0 0 var(--space-2);
}
.playlist-editor__list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: pl;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.playlist-editor__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 4px var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  counter-increment: pl;
}
.playlist-editor__item::before {
  content: counter(pl);
  flex: none;
  min-width: 1.5em;
  text-align: right;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.playlist-editor__name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.playlist-editor__ctrls {
  flex: none;
  display: flex;
  gap: 2px;
}

/* --------------------------------------------------------------------------
 * Users → Channel access (ADR-0010): granted-channel pills with a revoke (×)
 * and the "grant a channel" inline form. Tokens only; theme-aware via --border,
 * --surface-2, --text-muted, --danger.
 * ------------------------------------------------------------------------ */
.users-table__channels {
  min-width: 220px;
}
.grant-pills {
  list-style: none;
  margin: 0 0 var(--space-2) 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}
.pill--grant {
  gap: var(--space-1);
  background: var(--surface-2);
}
.pill__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.pill__remove:hover,
.pill__remove:focus-visible {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 15%, transparent);
}

/* --------------------------------------------------------------------------
 * Bulk stream selection (dashboard): per-row checkbox, selected-row highlight,
 * and the action bar that appears when at least one stream is checked. Tokens
 * only, theme-aware. The selection state itself lives in the Alpine `selection`
 * store (app.js) so it survives htmx row/group swaps.
 * ------------------------------------------------------------------------ */
.stream-row__select {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.stream-row__select input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
.stream-row.is-selected {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: inset 3px 0 0 var(--accent);
}
.bulkbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}
.bulkbar__count {
  font-size: 13px;
}
.bulkbar__count strong {
  font-variant-numeric: tabular-nums;
}
.bulkbar__actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
 * Backup import: dry-run preview + apply-result panels (Settings → Backup).
 * ------------------------------------------------------------------------ */
.restore-io {
  margin-top: var(--space-3);
}
.restore-io__panel {
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.restore-io__title {
  margin: 0;
  font-size: 14px;
}
.restore-io__facts {
  margin: 0;
  padding-left: var(--space-4);
}
.restore-io__msg {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.restore-io__msg--ok {
  background: color-mix(in srgb, var(--ok) 15%, transparent);
  color: var(--ok);
}
.restore-io__msg--warn {
  background: color-mix(in srgb, var(--warn, #d29922) 18%, transparent);
}
.restore-io__msg--error {
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  color: var(--danger);
}

/* ==========================================================================
 * Dashboard overview (dashboard.html + _overview.html). A scannable summary:
 * live-audience headline, status tiles, and a responsive card grid. Tokens
 * only; threshold state via .is-warn / .is-critical (no inline styles — CSP).
 * ======================================================================== */
.ov-viewers {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.ov-viewers__eye {
  font-size: 22px;
}
.ov-viewers__count {
  font-size: 40px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.ov-viewers__label {
  font-size: 15px;
  color: var(--text-muted);
}
.ov-viewers__sub {
  font-size: 13px;
  color: var(--text-muted);
}
.ov-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.ov-tile {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.ov-tile__n {
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.ov-tile__l {
  font-size: 12px;
  color: var(--text-muted);
}
.ov-tile--live {
  border-color: var(--ok);
}
.ov-tile--live .ov-tile__n {
  color: var(--ok);
}
.ov-tile--failed {
  border-color: var(--danger);
}
.ov-tile--failed .ov-tile__n {
  color: var(--danger);
}
.ov-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-3);
  align-items: start;
}
.ov-card {
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.ov-card--wide {
  grid-column: 1 / -1;
}
.ov-card__title {
  margin: 0 0 var(--space-3) 0;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.ov-card__badge {
  font-size: 12px;
  padding: 0 var(--space-2);
  border-radius: 999px;
  background: var(--surface-2);
  font-variant-numeric: tabular-nums;
}
.ov-ok {
  margin: 0;
  color: var(--ok);
  font-size: 13px;
}
.ov-attn {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.ov-attn__item {
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
  padding-left: var(--space-3);
  border-left: 3px solid var(--border);
  flex-wrap: wrap;
}
.ov-attn__item--critical {
  border-left-color: var(--danger);
}
.ov-attn__item--warn {
  border-left-color: var(--warn);
}
.ov-attn__what {
  font-weight: 600;
  font-size: 13px;
}
.ov-attn__msg {
  font-size: 13px;
  color: var(--text-muted);
}
.ov-host {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.ov-host__row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-1) 0;
}
.ov-host__row dt {
  color: var(--text-muted);
  font-size: 13px;
}
.ov-host__row dd {
  margin: 0;
  font-weight: 600;
}
.ov-host__row.is-warn dd {
  color: var(--warn);
}
.ov-host__row.is-critical dd {
  color: var(--danger);
}
.ov-conv {
  display: flex;
  gap: var(--space-4);
}
.ov-conv__stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: 12px;
  color: var(--text-muted);
}
.ov-conv__n {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}
.ov-conv__stat.is-warn .ov-conv__n {
  color: var(--warn);
}
.ov-chan {
  width: 100%;
}
.ov-chan__name {
  font-weight: 500;
}
.ov-chan__count {
  text-align: right;
  color: var(--text-muted);
  font-size: 13px;
}
.ov-chan__live {
  color: var(--ok);
  font-weight: 700;
}
.ov-activity {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.ov-activity__item {
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
  flex-wrap: wrap;
  font-size: 13px;
  padding: var(--space-1) 0;
  border-bottom: 1px solid var(--border);
}
.ov-activity__item:last-child {
  border-bottom: 0;
}
.ov-activity__title {
  flex: 1;
  min-width: 200px;
}
