/* ============================================================
   Relayline UI
   Type floor is 12px, all body text meets WCAG AA on its
   background, and every colour is a token so the dark theme
   is a single override block near the bottom of this file.
   ============================================================ */

:root {
  color-scheme: light;

  /* Type scale — nothing below 12px anywhere in the app. */
  --fs-xs: .75rem;      /* 12px — meta, captions        */
  --fs-sm: .8125rem;    /* 13px — table cells, controls */
  --fs-md: .875rem;     /* 14px — body copy             */
  --fs-lg: 1rem;        /* 16px — panel headings        */

  --ink: #15211d;
  --muted: #515c57;     /* 7.4:1 on white  */
  --faint: #67716c;     /* 5.1:1 on white  */
  --paper: #f5f7f4;
  --surface: #ffffff;
  --surface-sunk: #fafbf9;
  --line: #dee3de;
  --line-strong: #c3cbc5;

  --navy: #16221e;
  --navy-ink: #ffffff;
  --navy-muted: #b3bdb8;   /* 7.2:1 on --navy */
  --navy-faint: #97a29d;   /* 5.4:1 on --navy */
  --navy-line: rgba(255, 255, 255, .12);
  --navy-hover: rgba(255, 255, 255, .07);

  --green: #16694a;        /* 6.4:1 on white */
  --green-strong: #10513a;
  --green-soft: #e2efe9;
  --green-dot: #2f9068;
  --lime: #dff36d;

  --blue: #245b8c;
  --blue-soft: #e5eff8;
  --amber: #8a5310;        /* 5.6:1 on white */
  --amber-soft: #fdefd8;
  --amber-dot: #c1892b;
  --red: #a2372f;          /* 6.3:1 on white */
  --red-soft: #fbe6e3;
  --red-dot: #cc5348;

  --shadow: 0 1px 2px rgba(15, 30, 23, .05), 0 10px 30px rgba(15, 30, 23, .04);
  --shadow-lift: 0 20px 60px rgba(13, 29, 22, .22);
  --radius: 10px;

  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-size: var(--fs-md);
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin-top: 0; }
p { color: var(--muted); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

:where(button, a, input, select, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--green-dot);
  outline-offset: 2px;
  border-radius: 4px;
}

.hidden { display: none !important; }
.sports-tabs { margin: 22px 0; }
.sports-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 1fr); gap: 22px; align-items: start; }
.sports-panel { padding: 22px; }
.sports-panel > .panel-head { padding: 0 0 18px; }
.sports-panel h2 { font-size: 1.15rem; }
.sports-panel label:not(.sports-inline-check), .sports-source-search label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.sports-panel input:not([type="checkbox"]), .sports-panel select, .sports-source-search input, .sports-source-search select, .sports-override select { width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
.sports-panel label small { color: var(--muted); font-weight: 400; }
.sports-help { font-size: var(--fs-sm); color: var(--muted); margin: 10px 0; }
.sports-stack { display: grid; gap: 14px; }
.sports-card { padding: 16px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); overflow-wrap: anywhere; }
.sports-card h3 { margin: 0; font-size: var(--fs-lg); }
.sports-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sports-card-head p { margin: 0; }
.sports-badge { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 5px; color: var(--muted); background: var(--surface-sunk); font-size: var(--fs-xs); font-weight: 600; }
.sports-badge.warning { color: var(--amber); background: var(--amber-soft); }
.sports-badge.live { color: var(--green); background: var(--green-soft); }
.sports-actions, .sports-event-labels, .sports-team-basket { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.sports-actions { margin-top: 14px; }
.sports-inline-check { display: flex; flex-direction: row; gap: 9px; align-items: center; margin: 16px 0; font-weight: 600; }
.sports-inline-check input { accent-color: var(--green); width: 17px; height: 17px; }
.sports-team-chip { border: 1px solid var(--line-strong); background: var(--green-soft); color: var(--green); border-radius: 6px; padding: 6px 9px; font-size: var(--fs-sm); cursor: pointer; text-align: left; }
.sports-team-search { border-top: 1px solid var(--line); margin-top: 22px; padding-top: 20px; display: grid; gap: 12px; }
.sports-directory { max-height: 340px; overflow-y: auto; }
.sports-directory-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.sports-directory-row strong, .sports-directory-row small, .sports-slot strong, .sports-slot small { display: block; }
.sports-directory-row small, .sports-slot small { color: var(--muted); font-size: var(--fs-sm); }
.sports-directory-row .button { flex-shrink: 0; }
.sports-slot-list { display: grid; gap: 10px; }
.sports-slot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px; border-radius: 6px; background: var(--surface-sunk); }
.sports-mapping-panel { margin-top: 22px; }
.sports-settings { max-width: 780px; margin-bottom: 20px; }
.sports-settings > .button { margin-top: 14px; }
.sports-override { display: flex; align-items: center; gap: 8px; margin-left: auto; font-size: var(--fs-sm); }
.sports-override select { width: auto; }
.sports-empty { padding: 34px; text-align: center; border: 1px dashed var(--line-strong); border-radius: 8px; }
.sports-source-dialog { width: min(840px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow-y: auto; }
.sports-source-dialog h3 { margin-top: 26px; }
.sports-source-search { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(140px, 2fr) auto; align-items: end; gap: 12px; }
.sports-map-choice { grid-column: 1 / -1; }
.sports-import-link { padding: 0 22px 22px; }
#sports-legacy:not(:empty) { margin-bottom: 20px; }
#sports-enable { margin-top: 12px; }
@media (max-width: 1050px) { .sports-layout { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .sports-source-search { grid-template-columns: 1fr; } .sports-override { margin-left: 0; width: 100%; flex-wrap: wrap; } .sports-card-head, .sports-slot { flex-wrap: wrap; } .sports-panel { padding: 16px; } }
.automation-panel { max-width: 760px; }
.automation-panel hr { border: 0; border-top: 1px solid var(--line); margin: 28px 0; }
.automation-panel > label:not(.switch-row) { display: block; margin-top: 18px; }
.automation-panel > .switch-row { margin-top: 18px; }
.alignment-settings .switch-row { margin: 0 0 4px; }
.alignment-help { grid-column: 1 / -1; margin: 0; color: var(--faint); font-size: var(--fs-xs); line-height: 1.6; }
.automation-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.automation-status { padding: 12px; margin: 18px 0 0; border-radius: 8px; background: var(--surface-sunk); border: 1px solid var(--line); }
.ai-cost-estimate { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-sunk); }
.ai-cost-estimate span { color: var(--muted); font-size: var(--fs-sm); font-weight: 700; }
.ai-cost-estimate strong { color: var(--green); }
.ai-cost-estimate small { grid-column: 1 / -1; color: var(--faint); }
.sr-only {
  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; left: 12px; top: -60px; z-index: 40;
  background: var(--navy); color: var(--navy-ink);
  padding: 11px 16px; border-radius: 8px;
  font-size: var(--fs-sm); font-weight: 700; text-decoration: none;
  transition: top .15s;
}
.skip-link:focus { top: 12px; }

/* ───────────────────────────── Shell ───────────────────────────── */

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

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  padding: 24px 16px;
  background: var(--navy); color: var(--navy-ink);
}
.sidebar-head { flex: none; }
.sidebar-body { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow-y: auto; }
.menu-toggle { display: none; }
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 0 8px 24px; border-bottom: 1px solid var(--navy-line);
}
.brand-mark {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 10px; background: var(--lime); color: #16221e;
  font-weight: 900; font-size: 1.15rem;
}
.brand div { display: flex; flex-direction: column; }
.brand strong { font-size: var(--fs-md); letter-spacing: -.02em; }
.brand small { color: var(--navy-faint); font-size: var(--fs-xs); }

.sidebar nav { display: flex; flex-direction: column; gap: 4px; padding: 22px 0; }
.nav-section-label {
  margin: 14px 0 2px; padding: 0 12px;
  color: var(--navy-faint); font-size: var(--fs-xs); font-weight: 800;
  letter-spacing: .1em; text-transform: uppercase;
}
.nav-section-label:first-child { margin-top: 0; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  border: 0; background: transparent; color: var(--navy-muted);
  border-radius: 8px; padding: 11px 12px;
  font-size: var(--fs-sm); text-align: left; cursor: pointer;
}
.nav-icon { width: 19px; height: 19px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-item > .nav-icon { color: var(--navy-faint); }
.nav-item:hover { background: var(--navy-hover); color: var(--navy-ink); }
.nav-item.active { background: rgba(223, 243, 109, .14); color: var(--lime); font-weight: 700; }
.nav-item.active > .nav-icon { color: var(--lime); }
.nav-badge {
  margin-left: auto; background: var(--lime); color: #16221e;
  border-radius: 99px; padding: 2px 7px; font-size: var(--fs-xs); font-weight: 800;
}

.sidebar-foot { margin-top: auto; border-top: 1px solid var(--navy-line); padding: 16px 8px 0; }
.system-state { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.system-state > i {
  flex: none; width: 9px; height: 9px; border-radius: 50%;
  background: var(--navy-faint); box-shadow: 0 0 0 4px rgba(255, 255, 255, .06);
}
.system-state.online > i { background: var(--lime); box-shadow: 0 0 0 4px rgba(223, 243, 109, .12); }
.system-state.offline > i { background: #e2705f; box-shadow: 0 0 0 4px rgba(226, 112, 95, .16); }
.system-state div { display: flex; flex-direction: column; min-width: 0; }
.system-state strong { font-size: var(--fs-xs); }
.system-state small { color: var(--navy-faint); font-size: var(--fs-xs); }

.sidebar-links { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.theme-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; background: transparent; color: var(--navy-muted);
  padding: 0; font-size: var(--fs-xs); cursor: pointer;
}
.theme-toggle:hover { color: var(--navy-ink); }
.theme-icon { font-size: var(--fs-md); }
.sidebar-links a { color: var(--navy-muted); font-size: var(--fs-xs); text-decoration: none; }
.sidebar-links a:hover { color: var(--navy-ink); text-decoration: underline; }
.sidebar-links .text-button { color: var(--navy-muted); padding: 0; }

/* ───────────────────────────── Top bar ───────────────────────────── */

.main { min-width: 0; padding: 0 36px 64px; }
.topbar {
  min-height: 144px; display: flex; align-items: center; justify-content: space-between;
  gap: 24px; padding-block: 26px; border-bottom: 1px solid var(--line); margin-bottom: 24px;
}
.topbar > div:first-child { min-width: 0; }
.kicker, .context-label {
  margin: 0 0 6px; color: var(--green);
  font-size: var(--fs-xs); font-weight: 800; letter-spacing: .12em;
}
h1 {
  margin-bottom: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 500;
  font-size: clamp(1.9rem, 3vw, 2.5rem); letter-spacing: -.04em;
}
h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; letter-spacing: -.03em; }
.page-description { margin: 8px 0 0; max-width: 70ch; font-size: var(--fs-sm); color: var(--muted); line-height: 1.6; }

.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; flex: none; flex-wrap: wrap; max-width: 45%; }
.top-actions .button { white-space: nowrap; }
.refresh-state { white-space: nowrap; }
.section-tabs { display: flex; align-items: stretch; gap: 24px; margin: -8px 0 24px; padding: 0; border-bottom: 1px solid var(--line); }
.section-tab { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 12px 0; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; cursor: pointer; }
.section-tab:hover { color: var(--ink); border-bottom-color: var(--line-strong); }
.section-tab.active { color: var(--green); border-bottom-color: var(--green); }
.tab-badge { border-radius: 99px; padding: 1px 6px; background: var(--surface-sunk); color: var(--muted); font-size: var(--fs-xs); }
.section-tab.active .tab-badge { background: var(--green-soft); color: var(--green); }
.refresh-state { display: flex; align-items: center; gap: 8px; color: var(--faint); font-size: var(--fs-xs); }
.icon-refresh {
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 8px; font-size: var(--fs-md); cursor: pointer;
}
.icon-refresh:hover { border-color: var(--line-strong); color: var(--ink); }
.icon-refresh.spinning span { display: inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────────────────────── Buttons ───────────────────────────── */

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 8px; padding: 10px 15px;
  font-size: var(--fs-sm); font-weight: 700; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, transform .15s;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.button.dark { background: var(--navy); color: var(--navy-ink); }
.button.dark:hover:not(:disabled) { background: #223029; }
.button.light { background: var(--lime); color: #16221e; }
.button.ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.button.ghost:hover:not(:disabled) { border-color: var(--faint); }
.button.danger { background: var(--red); color: #fff; }
.button.busy { cursor: progress; }

.text-button {
  border: 0; background: transparent; color: var(--green);
  padding: 4px 2px; font-size: var(--fs-xs); font-weight: 700; cursor: pointer;
}
.text-button:hover { text-decoration: underline; }
.text-button.muted { color: var(--muted); }
.text-button.danger { color: var(--red); }

/* ───────────────────────────── Views & banners ───────────────────────────── */

.view { display: none; }
.view.active { display: block; animation: view-in .2s ease; }
.view:focus { outline: none; }
@keyframes view-in { from { opacity: 0; transform: translateY(3px); } }

.banner {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: 16px; padding: 16px 20px; margin-bottom: 16px; border-radius: var(--radius);
}
.banner strong { font-size: var(--fs-md); display: block; }
.banner p { margin: 3px 0 0; font-size: var(--fs-sm); }
.banner-icon {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 9px; font-size: var(--fs-lg); font-weight: 800;
}
.banner.setup { background: var(--navy); color: var(--navy-ink); }
.banner.setup p { color: var(--navy-muted); }
.banner.setup .banner-icon { background: rgba(223, 243, 109, .14); color: var(--lime); }
.banner.attention { background: var(--amber-soft); border: 1px solid #eccd96; color: #4a3211; }
.banner.attention p { color: #6b4a1c; }
.banner.attention .banner-icon { background: #f3dcae; color: var(--amber); }
.banner.attention .button.light { background: var(--amber); color: #fff; }
.banner.offline { background: var(--red-soft); border: 1px solid #eeb9b2; color: #58201b; }
.banner.offline p { color: #74332c; }
.banner.offline .banner-icon { background: #f2c9c3; color: var(--red); }
.banner.offline .button.light { background: var(--red); color: #fff; }

/* ───────────────────────────── Metrics ───────────────────────────── */

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric {
  min-height: 128px; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.metric-label {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  color: var(--muted); font-size: var(--fs-xs); font-weight: 700;
}
.live-pill {
  color: var(--green); background: var(--green-soft);
  padding: 3px 6px; border-radius: 5px; font-size: var(--fs-xs); font-weight: 800;
}
.live-pill.stale { color: var(--amber); background: var(--amber-soft); }
.metric > strong { margin-top: 14px; font: 500 2rem Georgia, serif; letter-spacing: -.04em; }
.metric > small { margin-top: auto; color: var(--faint); font-size: var(--fs-xs); }
.metric.alert-metric.is-alerting {
  background: var(--red-soft); border-color: #eeb9b2; cursor: pointer;
}
.metric.alert-metric.is-alerting .metric-label { color: var(--red); }
.metric.alert-metric.is-alerting > strong { color: var(--red); }
.metric.alert-metric.is-alerting > small { color: #74332c; }

/* ───────────────────────────── Panels ───────────────────────────── */

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
#view-players > .panel + .panel, #view-security > .panel + .panel { margin-top: 16px; }
.panel-head {
  min-height: 74px; display: flex; align-items: center; justify-content: space-between;
  gap: 18px; padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.panel-head.compact { min-height: 66px; }
.panel-head h2 { font: 700 var(--fs-lg) Inter, sans-serif; letter-spacing: -.015em; margin: 0 0 3px; }
.panel-head p { margin: 0; font-size: var(--fs-sm); }

.handoff-panel {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; padding: 18px 20px; margin-bottom: 16px; flex-wrap: wrap;
}
.handoff-copy h2 { font: 700 var(--fs-lg) Inter, sans-serif; margin: 0 0 3px; letter-spacing: -.015em; }
.handoff-copy p { margin: 0; font-size: var(--fs-sm); max-width: 60ch; }
.copy-field { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.copy-field code {
  background: var(--surface-sunk); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; font-size: var(--fs-sm);
  color: var(--ink); overflow-wrap: anywhere;
}

/* ───────────────────────────── Toolbar & filters ───────────────────────────── */

.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.search-field { position: relative; flex: 1 1 240px; max-width: 320px; }
.search-field > span { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search-field input { padding-left: 31px; }
.filter-tabs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.filter-tabs button {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 7px 11px; border-radius: 7px; font-size: var(--fs-xs); font-weight: 600; cursor: pointer;
}
.filter-tabs button:hover { background: var(--surface-sunk); border-color: var(--line); }
.filter-tabs button b { margin-left: 5px; font-weight: 800; }
.filter-tabs button.active {
  background: var(--green-soft); color: var(--green-strong);
  border-color: transparent; font-weight: 800;
}

.bulk-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 44px; padding: 6px 16px; flex-wrap: wrap;
  background: var(--surface-sunk); border-bottom: 1px solid var(--line);
  color: var(--muted); font-size: var(--fs-xs);
}
.bulk-bar b { color: var(--ink); font-size: var(--fs-sm); }
.bulk-bar > div { display: flex; gap: 14px; flex-wrap: wrap; }

/* ───────────────────────────── Tables ───────────────────────────── */

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-sunk); color: var(--muted);
  font-size: var(--fs-xs); letter-spacing: .04em; text-align: left;
  padding: 11px 15px; font-weight: 800; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
td { border-top: 1px solid var(--line); padding: 12px 15px; font-size: var(--fs-sm); vertical-align: middle; }
tbody tr:hover { background: var(--surface-sunk); }
.num-col { text-align: right; }
td.num-col { font-variant-numeric: tabular-nums; }
.check-col { width: 42px; }
.check-col input { width: 16px; height: 16px; accent-color: var(--green-dot); cursor: pointer; }

.data-table { min-width: 940px; }
.channel-cell { display: flex; flex-direction: column; gap: 3px; min-width: 170px; }
.channel-cell strong { font-size: var(--fs-md); }
.channel-cell small { color: var(--faint); font-size: var(--fs-xs); }
tr.is-paused .channel-cell strong { color: var(--faint); }

/* Plain-language channel status */
.status-chip {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  padding: 5px 10px; border-radius: 99px;
  font-size: var(--fs-xs); font-weight: 800;
  background: var(--surface-sunk); color: var(--muted);
}
.status-chip i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.status-chip.live { background: var(--green-soft); color: var(--green); }
.status-chip.failing { background: var(--amber-soft); color: var(--amber); }
.status-chip.down { background: var(--red-soft); color: var(--red); }
.status-chip.paused { background: var(--surface-sunk); color: var(--faint); }
.status-chip.idle { background: var(--surface-sunk); color: var(--muted); }
.status-chip.starting { background: var(--blue-soft); color: var(--blue); }
@media (prefers-reduced-motion: no-preference) {
  .status-chip.live i { animation: pulse 2.4s ease-in-out infinite; }
}
@keyframes pulse { 50% { opacity: .35; } }

/* Per-source health cell */
.source-health { display: flex; flex-direction: column; gap: 3px; min-width: 140px; }
.source-line { display: flex; align-items: center; gap: 7px; font-weight: 650; }
.source-line .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.source-line.healthy .dot { background: var(--green-dot); }
.source-line.starting .dot { background: var(--blue); }
.source-line.stalled .dot, .source-line.error .dot { background: var(--red-dot); }
.source-line.disabled .dot, .source-line.idle .dot { background: var(--line-strong); }
.source-health small { color: var(--faint); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.source-health .on-air-tag {
  align-self: flex-start; margin-top: 2px;
  background: var(--green-soft); color: var(--green);
  border-radius: 4px; padding: 1px 5px; font-size: var(--fs-xs); font-weight: 800;
}

/* On-air segmented control */
.source-toggle { display: inline-flex; padding: 3px; background: var(--surface-sunk); border: 1px solid var(--line); border-radius: 8px; gap: 2px; }
.source-toggle button {
  border: 0; background: transparent; color: var(--muted);
  min-width: 44px; height: 30px; padding: 0 10px;
  border-radius: 6px; font-size: var(--fs-xs); font-weight: 800; cursor: pointer;
}
.source-toggle button:hover:not(:disabled):not(.active) { background: var(--line); color: var(--ink); }
.source-toggle button.active { color: #fff; background: var(--green); }
.source-toggle button:disabled { opacity: .45; cursor: not-allowed; }

.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.icon-button {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  font-size: var(--fs-xs); font-weight: 600; padding: 6px 9px; border-radius: 6px; cursor: pointer;
}
.icon-button:hover { background: var(--surface-sunk); border-color: var(--line); color: var(--ink); }
.icon-button.danger:hover { background: var(--red-soft); border-color: #eeb9b2; color: var(--red); }
.icon-button[aria-expanded="true"] { background: var(--green-soft); color: var(--green-strong); }

/* Expandable diagnostics row */
tr.detail-row > td { padding: 0; border-top: 0; background: var(--surface-sunk); }
tr.detail-row:hover { background: var(--surface-sunk); }
.detail-inner { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; padding: 18px 16px 20px; border-top: 1px dashed var(--line-strong); }
.detail-block { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 14px; }
.detail-block h4 { margin: 0 0 10px; font-size: var(--fs-sm); display: flex; align-items: center; gap: 8px; }
.detail-block h4 span { color: var(--faint); font-weight: 500; }
.detail-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: var(--fs-xs); }
.detail-list dt { color: var(--faint); }
.detail-list dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.detail-error {
  margin-top: 10px; padding: 9px 11px; border-radius: 7px;
  background: var(--red-soft); color: #58201b; font-size: var(--fs-xs); overflow-wrap: anywhere;
}
.detail-url { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.detail-url code {
  flex: 1; min-width: 0; background: var(--surface-sunk); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 9px; font-size: var(--fs-xs);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Skeletons & empty states */
.skeleton-cell { height: 14px; border-radius: 5px; background: linear-gradient(90deg, var(--line) 25%, var(--surface-sunk) 50%, var(--line) 75%); background-size: 200% 100%; }
@media (prefers-reduced-motion: no-preference) {
  .skeleton-cell { animation: shimmer 1.3s linear infinite; }
}
@keyframes shimmer { to { background-position: -200% 0; } }

.empty-state {
  display: none; min-height: 240px; text-align: center;
  align-items: center; justify-content: center; flex-direction: column; padding: 36px;
}
.empty-state.show { display: flex; }
.empty-state.standalone { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.empty-symbol {
  width: 46px; height: 46px; display: grid; place-items: center;
  background: var(--green-soft); color: var(--green); border-radius: 50%;
  margin-bottom: 12px; font-size: 1.2rem;
}
.empty-state strong { font-size: var(--fs-lg); }
.empty-state p { font-size: var(--fs-sm); margin: 6px 0 16px; max-width: 46ch; }

/* ───────────────────────────── Overview lower panels ───────────────────────────── */

.overview-lower { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.provider-summary-row {
  min-height: 64px; display: grid; grid-template-columns: auto 1fr auto;
  align-items: center; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--line);
}
.provider-summary-row:first-child { border-top: 0; }
.provider-mini-letter {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px;
  background: var(--green-soft); color: var(--green); font-size: var(--fs-xs); font-weight: 900;
}
.provider-summary-row.slot-b .provider-mini-letter { background: var(--blue-soft); color: var(--blue); }
.provider-summary-row > div { display: flex; flex-direction: column; min-width: 0; }
.provider-summary-row strong { font-size: var(--fs-sm); }
.provider-summary-row small { color: var(--faint); font-size: var(--fs-xs); overflow-wrap: anywhere; }
.provider-summary-row small.capacity-line { color: var(--green); font-weight: 700; }
.configured-pill {
  color: var(--green); background: var(--green-soft); white-space: nowrap;
  font-size: var(--fs-xs); font-weight: 800; border-radius: 99px; padding: 4px 9px;
}
.configured-pill.missing { color: var(--amber); background: var(--amber-soft); }
.provider-summary-empty { padding: 26px 18px; color: var(--faint); font-size: var(--fs-sm); }

.event-rows { max-height: 208px; overflow: auto; }
.event-row {
  min-height: 64px; display: grid; grid-template-columns: auto 1fr auto;
  align-items: center; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--line);
}
.event-row:first-child { border-top: 0; }
.event-arrow { color: var(--green); font-weight: 800; font-size: var(--fs-xs); white-space: nowrap; }
.event-row > div { display: flex; flex-direction: column; min-width: 0; }
.event-row strong { font-size: var(--fs-sm); }
.event-row small { color: var(--faint); font-size: var(--fs-xs); }
.event-row time { color: var(--faint); font-size: var(--fs-xs); white-space: nowrap; }
.event-empty { color: var(--faint); font-size: var(--fs-sm); padding: 26px 18px; }

/* ───────────────────────────── Provider management ───────────────────────────── */

.provider-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.provider-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.provider-card-head {
  min-height: 76px; display: grid; grid-template-columns: auto 1fr auto auto;
  align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.provider-letter {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 9px;
  background: var(--green-soft); color: var(--green); font-size: var(--fs-md); font-weight: 900; flex: none;
}
.provider-card-head p { margin: 0 0 2px; font-size: var(--fs-xs); color: var(--faint); font-weight: 800; letter-spacing: .1em; }
.provider-card-head h3 { margin: 0; font-size: var(--fs-md); }
.provider-name-input {
  height: auto; padding: 3px 6px; margin: -3px -6px;
  border: 1px solid transparent; background: transparent; font-weight: 700;
}
.provider-name-input:hover, .provider-name-input:focus { border-color: var(--line-strong); background: var(--surface); }
.provider-card-head .remove-provider { white-space: nowrap; }
.provider-add-row { display: flex; align-items: center; gap: 14px; margin-top: 16px; flex-wrap: wrap; }
.provider-limit-note { margin: 0; color: var(--faint); font-size: var(--fs-xs); }
.connection-result {
  color: var(--muted); background: var(--surface-sunk); border-radius: 99px;
  padding: 6px 10px; font-size: var(--fs-xs); font-weight: 700; white-space: nowrap;
}
.connection-result.success { color: var(--green); background: var(--green-soft); }
.connection-result.error { color: var(--red); background: var(--red-soft); }
.connection-result.testing { color: var(--blue); background: var(--blue-soft); }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 18px; }
label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: var(--fs-sm); font-weight: 700; }
label.wide { grid-column: 1 / -1; }
label small { color: var(--faint); font-size: var(--fs-xs); font-weight: 450; line-height: 1.45; }
.inline-hint { display: inline; font-weight: 450; color: var(--faint); }
input, select {
  width: 100%; height: 42px; padding: 9px 11px;
  border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: 8px; color: var(--ink); font-size: var(--fs-sm); outline: 0;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus { border-color: var(--green-dot); box-shadow: 0 0 0 3px rgba(47, 144, 104, .16); }
input[aria-invalid="true"] { border-color: var(--red); }
input[type="search"] { -webkit-appearance: none; }

.password-field { position: relative; display: block; }
.password-field input { padding-right: 62px; }
.reveal-password {
  position: absolute; right: 6px; top: 6px; height: 30px; padding: 0 8px;
  border: 0; border-radius: 6px; background: transparent;
  color: var(--green); font-size: var(--fs-xs); font-weight: 700; cursor: pointer;
}
.reveal-password:hover { background: var(--green-soft); }
.saved-password { min-height: 1em; color: var(--green) !important; }

.field-error { margin: 0; padding: 0 18px; color: var(--red); font-size: var(--fs-xs); font-weight: 650; }
.field-error:empty { display: none; }

.test-button {
  width: 100%; min-height: 50px; display: flex; align-items: center; justify-content: space-between;
  border: 0; border-top: 1px solid var(--line); background: var(--surface-sunk);
  color: var(--ink); padding: 0 18px; font-size: var(--fs-sm); font-weight: 800; cursor: pointer;
}
.test-button:hover:not(:disabled) { background: var(--green-soft); color: var(--green-strong); }
.test-button:disabled { opacity: .6; cursor: progress; }

.helper { margin-top: 14px; font-size: var(--fs-sm); }
.helper summary { color: var(--green); font-weight: 700; cursor: pointer; }
.helper p { margin: 10px 0 8px; font-size: var(--fs-xs); }
.helper pre {
  margin: 0; padding: 11px 13px; border-radius: 8px; overflow-x: auto;
  background: var(--surface-sunk); border: 1px solid var(--line);
  font-size: var(--fs-xs); color: var(--ink);
}
.file-drop {
  position: relative;
  min-height: 78px; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto;
  column-gap: 12px; align-content: center; padding: 13px 15px; cursor: pointer;
  border: 1px dashed var(--line-strong); border-radius: 9px;
}
.file-drop:hover, .file-drop.has-file { border-color: var(--green-dot); background: var(--green-soft); }
.file-drop input { position: absolute; top: 0; left: 0; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.file-drop:focus-within { outline: 2px solid var(--green-dot); outline-offset: 2px; }
.file-icon {
  grid-row: 1 / 3; align-self: center; width: 32px; height: 32px;
  display: grid; place-items: center; border-radius: 7px;
  background: var(--green-soft); color: var(--green); font-size: var(--fs-lg);
}
.file-drop strong { color: var(--ink); font-size: var(--fs-sm); }
.file-drop small { margin-top: 3px; }
.threshold-control > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.threshold-control label { color: var(--muted); font-size: var(--fs-sm); }
.threshold-control output { color: var(--green); font-size: var(--fs-sm); font-weight: 800; white-space: nowrap; }
.threshold-control small { display: block; margin-top: 4px; color: var(--faint); font-size: var(--fs-xs); }
input[type="range"] { height: 22px; padding: 0; border: 0; background: none; accent-color: var(--green-dot); box-shadow: none; }

.switch-row { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 12px; cursor: pointer; }
.switch-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-row > span {
  width: 38px; height: 22px; flex: none; position: relative;
  background: var(--line-strong); border-radius: 99px; transition: background .18s;
}
.switch-row > span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform .18s;
}
.switch-row input:checked + span { background: var(--green); }
.switch-row input:checked + span::after { transform: translateX(16px); }
.switch-row input:focus-visible + span { outline: 2px solid var(--green-dot); outline-offset: 2px; }
.switch-row > div { display: flex; flex-direction: column; }
.switch-row strong { color: var(--ink); font-size: var(--fs-sm); }
.switch-row small { color: var(--faint); font-size: var(--fs-xs); font-weight: 450; }

.scan-button {
  grid-column: 1 / -1; margin: 24px -26px 0; min-height: 72px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border: 0; background: var(--navy); color: var(--navy-ink);
  padding: 0 26px; text-align: left; cursor: pointer;
}
.scan-button:hover:not(:disabled) { background: #223029; }
.scan-button:disabled { opacity: .8; cursor: progress; }
.scan-button span { display: flex; flex-direction: column; gap: 3px; }
.scan-button b { font-size: var(--fs-md); }
.scan-button small { color: var(--navy-muted); font-size: var(--fs-xs); }
.scan-button i {
  flex: none; width: 36px; height: 36px; display: grid; place-items: center;
  background: var(--lime); color: #16221e; border-radius: 50%; font-style: normal; font-weight: 900;
}

/* ───────────────────────────── Source matching ───────────────────────────── */

.match-body { padding: 22px 26px 6px; display: flex; flex-direction: column; gap: 18px; }
.match-providers-summary { display: flex; flex-wrap: wrap; gap: 10px; }
.provider-chip {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface-sunk); min-width: 160px;
}
.provider-chip strong { font-size: var(--fs-sm); }
.provider-chip small { color: var(--faint); font-size: var(--fs-xs); overflow-wrap: anywhere; }
.match-empty-note { margin: 0; color: var(--amber); font-size: var(--fs-sm); font-weight: 700; }
.match-wanted-summary { margin: 0; font-size: var(--fs-sm); }
.match-panel .scan-button { width: 100%; grid-column: unset; margin: 8px 0 0; }

/* ───────────────────────────── Review ───────────────────────────── */

.scan-summary {
  display: flex; flex-wrap: wrap; align-items: center;
  background: var(--navy); border-radius: var(--radius); color: var(--navy-ink);
  margin-bottom: 16px; padding: 14px 20px; gap: 14px;
}
.scan-provider { display: flex; align-items: center; gap: 12px; min-width: 0; }
.scan-provider-letter {
  flex: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px;
  background: rgba(223, 243, 109, .16); color: var(--lime); font-size: var(--fs-xs); font-weight: 900;
}
.scan-provider > div { display: flex; flex-direction: column; min-width: 0; }
.scan-provider strong { font-size: var(--fs-sm); }
.scan-provider small { color: var(--navy-muted); font-size: var(--fs-xs); }
.scan-link { color: var(--navy-faint); font-size: var(--fs-xs); letter-spacing: .16em; white-space: nowrap; }

.review-scroll { max-height: 62vh; overflow: auto; }
.review-table { min-width: 1040px; }
.review-table td { padding-top: 11px; padding-bottom: 11px; }
.review-table tr.needs-review-row { background: #fffbf3; }
.review-table tr.unmatched-row td { color: var(--faint); }
.review-table tr.is-selected { background: var(--green-soft); }
.name-input { min-width: 170px; height: 38px; font-weight: 650; }
.candidate-cell { min-width: 270px; }
.candidate-cell select { height: 38px; max-width: 280px; }
.same-provider-warning { margin: 6px 0 0; color: var(--amber); font-size: var(--fs-xs); font-weight: 700; }
.epg-form { display: grid; grid-template-columns: 1fr 2fr auto; gap: 14px; align-items: end; margin: 24px 0; }
.epg-sources { display: grid; gap: 10px; }
.epg-source { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); }
.epg-source > div:first-child { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.epg-source small { color: var(--faint); overflow: hidden; text-overflow: ellipsis; }
.epg-actions { display: flex; gap: 8px; flex-shrink: 0; }
@media (max-width: 760px) { .epg-form { grid-template-columns: 1fr; } .epg-source { align-items: flex-start; flex-direction: column; } }
.candidate-meta { min-height: 18px; display: flex; align-items: center; gap: 7px; color: var(--faint); font-size: var(--fs-xs); margin-top: 6px; }
.score-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--amber-dot); flex: none; }
.score-dot.high { background: var(--green-dot); }
.assessment {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 5px 10px; border-radius: 99px;
  background: var(--green-soft); color: var(--green); font-size: var(--fs-xs); font-weight: 800;
}
.assessment.needs-review { color: var(--amber); background: var(--amber-soft); }
.assessment.unmatched { color: var(--red); background: var(--red-soft); }
.assessment.reviewed { color: var(--blue); background: var(--blue-soft); }
.load-more {
  width: 100%; border: 0; border-top: 1px solid var(--line); background: var(--surface);
  color: var(--green); padding: 14px; font-size: var(--fs-sm); font-weight: 800; cursor: pointer;
}
.load-more:hover { background: var(--green-soft); }
.review-footer {
  position: sticky; bottom: 0;
  min-height: 74px; display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding: 14px 18px; border-top: 1px solid var(--line); background: var(--surface);
}
.review-footer > div { display: flex; flex-direction: column; gap: 2px; }
.review-footer strong { font-size: var(--fs-sm); }
.review-footer small { color: var(--faint); font-size: var(--fs-xs); }

/* ───────────────────────────── Wanted channels ───────────────────────────── */

.wanted-status-line {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 9px;
  background: var(--green-soft); color: var(--green-strong);
}
.wanted-status-icon {
  width: 30px; height: 30px; display: grid; place-items: center; flex: none;
  border-radius: 7px; background: var(--surface); font-size: var(--fs-md);
}
.wanted-status-line strong { display: block; font-size: var(--fs-sm); color: var(--ink); }
.wanted-status-line small { color: var(--muted); font-size: var(--fs-xs); }
.wanted-status-line.is-empty { background: var(--amber-soft); }
.wanted-status-line.is-empty .wanted-status-icon { color: var(--amber); }

.quick-add-row { display: flex; align-items: center; gap: 8px; flex: 1 1 260px; max-width: 360px; }
.quick-add-row input { flex: 1; }
.quick-add-row .button { flex: none; }

.match-source-note { margin: -8px 0 16px; font-size: var(--fs-xs); color: var(--faint); }

.wanted-import-form { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 12px; }
.wanted-import-form textarea {
  width: 100%; min-height: 120px; resize: vertical; padding: 10px 12px;
  border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: 8px; color: var(--ink); font: var(--fs-xs) ui-monospace, monospace; line-height: 1.5;
}
.wanted-import-form textarea:focus { border-color: var(--green-dot); box-shadow: 0 0 0 3px rgba(47, 144, 104, .16); }
.wanted-import-row { display: flex; align-items: stretch; gap: 12px; }
.file-drop.compact { flex: 1; min-height: 58px; padding: 9px 12px; }
.file-drop.compact .file-icon { width: 26px; height: 26px; font-size: .85rem; }
.wanted-import-row .button { flex: none; align-self: center; }

.catalog-browser { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 12px; }
.catalog-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.catalog-toolbar .search-field { flex: 1 1 200px; max-width: none; }
#catalog-provider-toggle button { min-width: 40px; padding: 0 12px; }
.catalog-toggle-empty { padding: 0 10px; color: var(--faint); font-size: var(--fs-xs); }
.catalog-status { margin: 0; font-size: var(--fs-xs); color: var(--faint); }
.catalog-status.is-error { color: var(--red); }
.catalog-scroll { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 9px; }
.catalog-scroll .data-table { min-width: 0; }
.catalog-scroll th { position: sticky; top: 0; }
.catalog-add-button {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--green-strong);
  padding: 6px 11px; border-radius: 6px; font-size: var(--fs-xs); font-weight: 700; cursor: pointer;
}
.catalog-add-button:hover:not(:disabled) { background: var(--green-soft); border-color: transparent; }
.catalog-add-button:disabled { border-color: transparent; background: var(--green-soft); color: var(--green); cursor: default; opacity: .85; }

/* ───────────────────────────── Dialogs ───────────────────────────── */

dialog {
  width: min(600px, calc(100% - 24px)); padding: 0;
  border: 1px solid var(--line-strong); border-radius: 12px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lift);
}
dialog::backdrop { background: rgba(12, 23, 19, .55); backdrop-filter: blur(3px); }
#channel-form { padding: 24px; }
.dialog-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  border-bottom: 1px solid var(--line); margin: -24px -24px 20px; padding: 20px 24px 16px;
}
.dialog-head h2 { margin: 0; font-size: 1.45rem; }
.dialog-close {
  border: 0; background: transparent; color: var(--muted);
  width: 34px; height: 34px; border-radius: 8px; font-size: 1.5rem; line-height: 1; cursor: pointer;
}
.dialog-close:hover { background: var(--surface-sunk); color: var(--ink); }
.dialog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.enabled-check { grid-column: 1 / -1; display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 12px; cursor: pointer; }
.enabled-check input { position: absolute; opacity: 0; width: 0; height: 0; }
.enabled-check > span {
  width: 38px; height: 22px; position: relative;
  background: var(--line-strong); border-radius: 99px; transition: background .18s;
}
.enabled-check > span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform .18s;
}
.enabled-check input:checked + span { background: var(--green); }
.enabled-check input:checked + span::after { transform: translateX(16px); }
.enabled-check input:focus-visible + span { outline: 2px solid var(--green-dot); outline-offset: 2px; }
.enabled-check > div { display: flex; flex-direction: column; }
.enabled-check strong { color: var(--ink); font-size: var(--fs-sm); }
.enabled-check small { color: var(--faint); font-size: var(--fs-xs); font-weight: 450; }
#channel-form .field-error { padding: 12px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ───────────────────────── Catalog picker dialog ───────────────────────── */

/* Wider and taller than the form dialogs: this one is for reading a list of
   thousands of channels, so the room goes to the list. */
dialog.picker {
  width: min(1040px, calc(100% - 24px));
  height: min(720px, calc(100vh - 48px));
  display: flex; flex-direction: column; overflow: hidden;
}
dialog.picker:not([open]) { display: none; }
.picker .dialog-head { margin: 0; padding: 18px 22px 14px; }
.picker .dialog-head h2 { font-size: 1.25rem; }

.picker-providers {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 12px 22px; border-bottom: 1px solid var(--line); background: var(--surface-sunk);
}
.picker-providers button {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted);
  padding: 6px 12px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 650; cursor: pointer;
}
.picker-providers button:hover { color: var(--ink); border-color: var(--green-dot); }
.picker-providers button.active {
  background: var(--green-soft); border-color: transparent; color: var(--green-strong);
}

.picker-body { flex: 1; display: grid; grid-template-columns: 258px 1fr; min-height: 0; }

.picker-rail {
  border-right: 1px solid var(--line); background: var(--surface-sunk);
  display: flex; flex-direction: column; min-height: 0;
}
.picker-rail-search { padding: 12px; border-bottom: 1px solid var(--line); }
.picker-rail-search input { width: 100%; }
.picker-sections { overflow-y: auto; padding: 8px; flex: 1; }
.picker-section {
  width: 100%; text-align: left; border: 0; background: transparent; cursor: pointer;
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 7px 10px; border-radius: 7px; color: var(--muted); font-size: var(--fs-sm);
}
.picker-section:hover { background: var(--surface); color: var(--ink); }
.picker-section.active { background: var(--green-soft); color: var(--green-strong); font-weight: 650; }
.picker-section-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-section-count { color: var(--faint); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; flex: none; }
.picker-section.active .picker-section-count { color: var(--green); }
.picker-rail-empty { padding: 14px 12px; color: var(--faint); font-size: var(--fs-xs); }

.picker-main { display: flex; flex-direction: column; min-height: 0; padding: 14px 18px 0; }
.picker-search { display: flex; gap: 8px; }
.picker-search input { flex: 1; }
.picker-status { margin: 10px 2px; color: var(--faint); font-size: var(--fs-xs); }
.picker-status.is-error { color: var(--red); }
.picker-results-wrap { flex: 1; overflow-y: auto; min-height: 0; border-top: 1px solid var(--line); }
.picker-results { list-style: none; margin: 0; padding: 0; }

.picker-result {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px;
  width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line);
  background: transparent; cursor: pointer; padding: 11px 12px; color: inherit;
}
.picker-result:hover, .picker-result:focus-visible { background: var(--surface-sunk); outline: none; }
.picker-result:focus-visible { box-shadow: inset 3px 0 0 var(--green-dot); }
.picker-result.is-current { background: var(--green-soft); }
.picker-result-name { font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
.picker-result-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 3px; }
.picker-result-meta span { color: var(--faint); font-size: var(--fs-xs); }
.picker-pick {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--green-strong);
  padding: 6px 12px; border-radius: 6px; font-size: var(--fs-xs); font-weight: 700; flex: none;
}
.picker-result:hover .picker-pick { background: var(--green-soft); border-color: transparent; }
.picker-result.is-current .picker-pick { background: transparent; border-color: transparent; color: var(--green); }

.picker-flag {
  border-radius: 4px; padding: 1px 6px; font-size: var(--fs-xs); font-weight: 700;
  background: var(--amber-soft); color: var(--amber);
}
.picker-single-provider { margin: 0; color: var(--faint); font-size: var(--fs-xs); font-weight: 650; }
/* The same flag reused on a review row, where it follows running text. */
.candidate-meta .picker-flag { margin-left: 6px; }

.picker-more { margin: 12px auto; }
.picker-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 22px; border-top: 1px solid var(--line); background: var(--surface-sunk);
}
.picker-hint { margin: 0; color: var(--faint); font-size: var(--fs-xs); }
.picker-empty { padding: 28px 12px; text-align: center; color: var(--faint); font-size: var(--fs-sm); }

.browse-button { width: 100%; margin-top: 8px; }

@media (max-width: 820px) {
  dialog.picker { height: min(760px, calc(100vh - 24px)); }
  .picker-body { grid-template-columns: 1fr; }
  .picker-rail { border-right: 0; border-bottom: 1px solid var(--line); max-height: 190px; }
}

.confirm-body { padding: 26px; }
.confirm-icon {
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%;
  background: var(--red-soft); color: var(--red); font-size: 1.3rem; font-weight: 800; margin-bottom: 14px;
}
.confirm-body h2 { margin: 0 0 8px; font-size: 1.35rem; }
.confirm-body > p { margin: 0; font-size: var(--fs-sm); }
.confirm-notes { margin: 14px 0 0; padding-left: 20px; color: var(--muted); font-size: var(--fs-sm); }
.confirm-notes:empty { display: none; }
.confirm-notes li { margin-bottom: 5px; }

/* ───────────────────────────── Toasts ───────────────────────────── */

#toast-stack {
  position: fixed; z-index: 30; bottom: 22px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column-reverse; gap: 8px;
  width: min(460px, calc(100% - 24px));
}
.toast {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--navy); color: var(--navy-ink);
  padding: 13px 15px; border-radius: 9px; box-shadow: var(--shadow-lift);
  font-size: var(--fs-sm); font-weight: 600;
}
.toast.error { background: var(--red); }
.toast.error strong { display: block; margin-bottom: 2px; }
.toast p { margin: 0; color: inherit; opacity: .92; font-weight: 450; }
.toast-close {
  margin-left: auto; flex: none; border: 0; background: transparent; color: inherit;
  opacity: .7; font-size: 1.2rem; line-height: 1; padding: 0 2px; cursor: pointer;
}
.toast-close:hover { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in .18s ease; }
  @keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
}

/* ───────────────────────────── Dark theme ───────────────────────────── */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #e7eee9;
    --muted: #a9b4af;
    --faint: #8e9994;
    --paper: #0e1411;
    --surface: #161d19;
    --surface-sunk: #1b231e;
    --line: #26302a;
    --line-strong: #35413a;

    --navy: #0a0f0c;
    --navy-muted: #b3bdb8;
    --navy-faint: #929d98;

    --green: #58c194;
    --green-strong: #7ad3ad;
    --green-soft: #14312492;
    --green-dot: #43b183;

    --blue: #7fb6e6;
    --blue-soft: #16283796;
    --amber: #e0ae62;
    --amber-soft: #33260f96;
    --amber-dot: #d69b45;
    --red: #ef8377;
    --red-soft: #3a1a1696;
    --red-dot: #d9695c;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .25);
    --shadow-lift: 0 20px 60px rgba(0, 0, 0, .5);
  }
  :root:not([data-theme="light"]) .banner.attention { background: var(--amber-soft); border-color: #5b451c; color: #f0d5a6; }
  :root:not([data-theme="light"]) .banner.attention p { color: #d8bc8c; }
  :root:not([data-theme="light"]) .banner.attention .banner-icon { background: #4a3817; color: var(--amber); }
  :root:not([data-theme="light"]) .banner.attention .button.light { background: var(--amber); color: #221803; }
  :root:not([data-theme="light"]) .banner.offline { background: var(--red-soft); border-color: #6a2f28; color: #f4bdb5; }
  :root:not([data-theme="light"]) .banner.offline p { color: #dda49c; }
  :root:not([data-theme="light"]) .banner.offline .banner-icon { background: #55231d; color: var(--red); }
  :root:not([data-theme="light"]) .banner.offline .button.light { background: var(--red); color: #2a0e0a; }
  :root:not([data-theme="light"]) .metric.alert-metric.is-alerting { border-color: #6a2f28; }
  :root:not([data-theme="light"]) .metric.alert-metric.is-alerting > small { color: #dda49c; }
  :root:not([data-theme="light"]) .detail-error { background: var(--red-soft); color: #f4bdb5; }
  :root:not([data-theme="light"]) .review-table tr.needs-review-row { background: #241d0f7a; }
  :root:not([data-theme="light"]) .source-toggle button.active,
  :root:not([data-theme="light"]) .status-chip.live { color: #0d1a14; }
  :root:not([data-theme="light"]) .source-toggle button.active { background: var(--green-dot); }
  :root:not([data-theme="light"]) .status-chip.live { background: var(--green-dot); }
  :root:not([data-theme="light"]) .button.danger,
  :root:not([data-theme="light"]) .toast.error { background: var(--red-dot); color: #2a0e0a; }
  :root:not([data-theme="light"]) .switch-row > span::after,
  :root:not([data-theme="light"]) .enabled-check > span::after { background: #0e1411; }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e7eee9;
  --muted: #a9b4af;
  --faint: #8e9994;
  --paper: #0e1411;
  --surface: #161d19;
  --surface-sunk: #1b231e;
  --line: #26302a;
  --line-strong: #35413a;

  --navy: #0a0f0c;
  --navy-muted: #b3bdb8;
  --navy-faint: #929d98;

  --green: #58c194;
  --green-strong: #7ad3ad;
  --green-soft: #14312492;
  --green-dot: #43b183;

  --blue: #7fb6e6;
  --blue-soft: #16283796;
  --amber: #e0ae62;
  --amber-soft: #33260f96;
  --amber-dot: #d69b45;
  --red: #ef8377;
  --red-soft: #3a1a1696;
  --red-dot: #d9695c;

  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .25);
  --shadow-lift: 0 20px 60px rgba(0, 0, 0, .5);
}
:root[data-theme="dark"] .banner.attention { background: var(--amber-soft); border-color: #5b451c; color: #f0d5a6; }
:root[data-theme="dark"] .banner.attention p { color: #d8bc8c; }
:root[data-theme="dark"] .banner.attention .banner-icon { background: #4a3817; color: var(--amber); }
:root[data-theme="dark"] .banner.attention .button.light { background: var(--amber); color: #221803; }
:root[data-theme="dark"] .banner.offline { background: var(--red-soft); border-color: #6a2f28; color: #f4bdb5; }
:root[data-theme="dark"] .banner.offline p { color: #dda49c; }
:root[data-theme="dark"] .banner.offline .banner-icon { background: #55231d; color: var(--red); }
:root[data-theme="dark"] .banner.offline .button.light { background: var(--red); color: #2a0e0a; }
:root[data-theme="dark"] .metric.alert-metric.is-alerting { border-color: #6a2f28; }
:root[data-theme="dark"] .metric.alert-metric.is-alerting > small { color: #dda49c; }
:root[data-theme="dark"] .detail-error { background: var(--red-soft); color: #f4bdb5; }
:root[data-theme="dark"] .review-table tr.needs-review-row { background: #241d0f7a; }
:root[data-theme="dark"] .source-toggle button.active { background: var(--green-dot); color: #0d1a14; }
:root[data-theme="dark"] .status-chip.live { background: var(--green-dot); color: #0d1a14; }
:root[data-theme="dark"] .button.danger,
:root[data-theme="dark"] .toast.error { background: var(--red-dot); color: #2a0e0a; }
:root[data-theme="dark"] .switch-row > span::after,
:root[data-theme="dark"] .enabled-check > span::after { background: #0e1411; }

/* ───────────────────────────── Responsive ───────────────────────────── */

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 208px minmax(0, 1fr); }
  .main { padding-inline: 24px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .provider-grid, .overview-lower { grid-template-columns: 1fr; }
  .scope-card { grid-template-columns: 1fr; row-gap: 22px; }
}

@media (max-width: 780px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; padding: 14px; }
  .sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .sidebar-head .brand { padding: 0; border: 0; }
  .menu-toggle { display: inline-flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--navy-line); border-radius: 8px; background: transparent; color: var(--navy-ink); font-size: var(--fs-sm); cursor: pointer; }
  .menu-toggle[aria-expanded="true"] { color: var(--lime); background: var(--navy-hover); }
  .sidebar-body { display: none; }
  .sidebar.navigation-open .sidebar-body { display: flex; }
  .sidebar nav { padding-top: 18px; }
  .nav-item { padding: 12px; }
  .sidebar-foot { padding-top: 14px; }
  .sidebar-foot .system-state { margin-bottom: 10px; }
  .sidebar-links { flex-direction: row; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
  .main { padding: 0 14px 48px; }
  .topbar { min-height: 0; margin-bottom: 20px; padding-block: 22px; align-items: stretch; flex-direction: column; gap: 16px; }
  .top-actions { max-width: none; justify-content: flex-start; }
  .section-tabs { gap: 18px; overflow-x: auto; }
  .banner { grid-template-columns: auto 1fr; }
  .banner .button { grid-column: 1 / -1; }
  .handoff-panel { flex-direction: column; align-items: stretch; }
  .copy-field code { flex: 1 1 100%; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .quick-add-row { flex: none; max-width: none; }
  .quick-add-row input { min-width: 0; }
  .search-field { flex: none; max-width: none; }
  .filter-tabs { overflow-x: auto; padding-bottom: 2px; }
  .scan-summary { flex-direction: column; align-items: stretch; }
  .scan-link { display: none; }
  .review-footer { align-items: stretch; flex-direction: column; }
  .save-pairs { width: 100%; }
  /* Keep the channel name visible while scrolling wide tables sideways. */
  .data-table th:nth-child(2), .data-table td:nth-child(2) {
    position: sticky; left: 0; z-index: 1; background: var(--surface);
  }
  .data-table th:nth-child(2) { z-index: 3; background: var(--surface-sunk); }
  .data-table tbody tr:hover td:nth-child(2) { background: var(--surface-sunk); }
}

@media (max-width: 560px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { padding: 14px; }
  .metric-label { flex-wrap: wrap; }
  .metric:last-child { grid-column: 1 / -1; }
  .panel-head { flex-wrap: wrap; }
  .panel-head > .button { flex: none; }
  .field-grid, .dialog-grid { grid-template-columns: 1fr; }
  label.wide { grid-column: auto; }
  .provider-card-head { grid-template-columns: auto 1fr; }
  .connection-result { grid-column: 1 / -1; justify-self: start; }
  .section-tabs { gap: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
  .section-tab { margin: 0; padding: 11px 6px; font-size: var(--fs-xs); border: 0; }
  .section-tab.active { background: var(--green-soft); }
  .topbar { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .button:hover:not(:disabled) { transform: none; }
}

/* Administrator access, player credentials, and channel curation. */
.auth-gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(100%, 500px); padding: 30px; }
.auth-card .brand { color: var(--ink); padding: 0 0 24px; }
.auth-card .brand small { color: var(--muted); }
.auth-card h1 { font-size: 1.8rem; margin: 0 0 12px; }
.auth-card > p { margin: 0 0 18px; }
.auth-card > .button { width: 100%; }
.auth-form { display: grid; gap: 14px; margin-top: 18px; }
.auth-form label, .account-create-form label, .channel-source-card label { display: grid; gap: 7px; font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
.auth-enrollment { border-top: 1px solid var(--line); margin-top: 24px; padding-top: 18px; }
.auth-enrollment summary { cursor: pointer; font-size: var(--fs-sm); font-weight: 600; }
.auth-enrollment p { font-size: var(--fs-sm); margin-bottom: 0; }
#auth-retry { margin-top: 18px; }
.account-create-form { display: flex; align-items: end; gap: 16px; padding: 20px; flex-wrap: wrap; }
.account-create-form label { flex: 1 1 180px; }
.account-create-form small { font-weight: 400; color: var(--muted); }
.account-create-form .button { flex: none; }
.account-list { padding: 0 20px 20px; }
.account-row { padding: 16px 0; border-bottom: 1px solid var(--line); }
.account-row:last-child { border-bottom: 0; }
.account-row-head { display: flex; gap: 12px; justify-content: space-between; flex-wrap: wrap; align-items: center; }
.account-row-head > div { display: grid; gap: 4px; }
.account-row-head small, .account-row > p, .account-empty { color: var(--muted); font-size: var(--fs-sm); }
.account-row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: end; }
.account-row-actions label { font-size: var(--fs-xs); display: grid; gap: 5px; max-width: 180px; }
.account-row-actions input { width: 100%; }
.panel-message { padding: 0 20px; }
.credentials-body { padding: 24px; }
.credentials-body > p { font-size: var(--fs-sm); }
.credential-fields { display: grid; gap: 16px; }
.credential-field { display: grid; gap: 6px; }
.credential-field > strong { font-size: var(--fs-sm); }
.credential-field .copy-field { padding: 0; }
.credential-field code { word-break: break-all; overflow-wrap: anywhere; white-space: normal; }
.channel-source-editor { grid-column: 1 / -1; display: grid; gap: 14px; }
.channel-source-card { border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: grid; gap: 10px; }
.channel-source-card h3 { font-size: var(--fs-sm); margin: 0; }
.channel-source-current { margin: 0; color: var(--muted); font-size: var(--fs-xs); }
.channel-source-search { display: flex; gap: 8px; }
.channel-source-search input { flex: 1; min-width: 0; }
.channel-source-results { max-height: 180px; overflow-y: auto; }
.channel-source-results .picker-result { padding: 8px; }
.inline-check { display: flex; gap: 10px; align-items: center; }
.inline-check input { width: auto; }
.channel-logo { width: 32px; height: 32px; object-fit: contain; align-self: start; }
.guide-state { font-size: var(--fs-xs); color: var(--muted); }
.guide-state.is-error { color: var(--amber); }
@media (max-width: 560px) {
  .auth-gate { padding: 12px; }
  .auth-card { padding: 22px; }
  .account-create-form { flex-direction: column; align-items: stretch; }
  .account-create-form label { flex-basis: auto; }
}

.channel-source-options { grid-column: 1 / -1; padding: 13px 0; border-block: 1px solid var(--line); }
.channel-source-options > summary { cursor: pointer; color: var(--ink); font-size: var(--fs-sm); font-weight: 650; }
.channel-source-fields { display: grid; gap: 16px; margin-top: 16px; }
.channel-source-fields label { display: grid; gap: 7px; }
.channel-source-fields label.inline-check { display: flex; }
