/* Keeper dashboard. Dark theme by default; colors chosen for WCAG AA. */
:root {
  --bg: #0e1014;
  --surface: #161920;
  --surface-2: #1d2129;
  --border: #2c313b;
  --text: #e8eaee;
  --muted: #a4abb6;          /* 7.6:1 on --surface */
  --accent: #8b6cf0;
  --accent-strong: #6d4ee0;  /* white text 5.6:1 */
  --accent-text: #ffffff;
  --focus: #ffd166;
  --ok: #4ade80;
  --ok-bg: #11301f;
  --warn: #fbbf24;
  --warn-bg: #33270a;
  --bad: #f87171;
  --bad-bg: #3a1618;
  --danger: #c62828;         /* white text 5.6:1 */
  --danger-hover: #a91f1f;
  --go: #15803d;             /* white text 5.0:1 */
  --go-hover: #116a33;
  --neutral-bg: #262b34;
  --shadow: 0 8px 24px rgba(0, 0, 0, .35);
  --radius: 12px;
  --content-max: 1360px;
  --gap: 16px;
  --fs-body: 15px;   /* body text never below 14px */
  --fs-help: 13px;   /* helper / meta text never below 13px */
  --topbar-h: 56px;
  --mobile-bar-h: 0px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f7;
    --surface: #ffffff;
    --surface-2: #f6f7f9;
    --border: #d7dbe2;
    --text: #15181d;
    --muted: #535b67;
    --accent: #5b3fd1;
    --accent-strong: #5b3fd1;
    --focus: #b45309;
    --ok: #166534;
    --ok-bg: #dcfce7;
    --warn: #854d0e;
    --warn-bg: #fef3c7;
    --bad: #b91c1c;
    --bad-bg: #fee2e2;
    --neutral-bg: #eceff3;
    --shadow: 0 8px 24px rgba(15, 20, 30, .12);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: calc(var(--topbar-h) + 12px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-body)/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--mobile-bar-h) + env(safe-area-inset-bottom, 0px));
}
body.has-savebar { padding-bottom: calc(var(--mobile-bar-h) + 72px); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; margin-bottom: 12px; }
h2 { font-size: 15px; font-weight: 650; letter-spacing: .01em; }
h3.sub { font-size: 14px; margin: 20px 0 8px; color: var(--text); }
code { font-size: 13px; background: var(--neutral-bg); padding: 1px 5px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 100; background: var(--surface); color: var(--text); padding: 8px 12px; border-radius: 8px; }
.skip-link:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main:focus { outline: none; }
.muted { color: var(--muted); }

/* ----- top bar ----- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--content-max); margin: 0 auto; min-height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px; padding: 8px 16px;
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.who { color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto; }
.indicators { display: flex; gap: 6px; flex: 0 0 auto; }
.ind {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); font-size: 13px; font-weight: 600; white-space: nowrap;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.ind.ok .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.ind.warn .dot { background: var(--warn); }
.ind.bad .dot { background: var(--bad); }

.error-banner {
  position: fixed; top: calc(var(--topbar-h) + 8px); left: 50%; transform: translateX(-50%);
  z-index: 40; width: min(680px, calc(100% - 24px));
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  background: var(--bad-bg); color: var(--text); border: 1px solid var(--bad);
  border-radius: 10px; padding: 8px 12px; box-shadow: var(--shadow); font-size: 14px;
}

/* ----- layout ----- */
main { max-width: var(--content-max); margin: 0 auto; padding: var(--gap); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; min-height: 34px; }

/* One 12-column grid for the whole page. Desktop: main column 7/12, side column 5/12,
   settings full width, so every card edge lines up. Both columns stretch to the
   same height; the slack goes into the bitrate chart (left) and the switch log (right)
   instead of empty space under a card. */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); align-items: stretch; }
.dash-col { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
@media (min-width: 900px) {
  .dash-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .dash-col-main { grid-column: 1 / span 7; }
  .dash-col-side { grid-column: 8 / span 5; }
  .dash-grid > .settings-card, .dash-grid > .connect-card { grid-column: 1 / -1; }
  .feed-card { flex: 1 1 auto; display: flex; flex-direction: column; }
  .feed-card .spark-wrap { flex: 1 1 96px; max-height: 260px; }
  .card-fill { flex: 1 1 auto; display: flex; flex-direction: column; }
  .card-fill .fill-scroll { flex: 1 1 0px; min-height: 160px; overflow: auto; }
}
.login-card { max-width: 400px; margin: 48px auto; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.detail { color: var(--muted); font-size: var(--fs-help); margin: 6px 0 0; }
#feed-detail { min-height: 1.45em; } /* one line reserved: no shift when it changes */
#autostop-status:empty, .reason:empty { display: none; }
.reason { color: var(--warn); font-size: var(--fs-help); margin: 10px 0 0; }
/* fixed height so the resume button / countdown never shifts the cards below */
.status-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 38px; }
.status-row .detail { margin: 0; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* ----- chips & badges ----- */
.chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 84px; padding: 3px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 650; background: var(--neutral-bg); color: var(--text); white-space: nowrap;
}
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.badges { display: flex; gap: 6px; }
/* Status pills: plain text with a dot, no fill/border/shadow, so they never read as buttons.
   "Stop stream" stays the only solid red element. */
.status-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px;
  font-size: var(--fs-help); font-weight: 700; white-space: nowrap; cursor: default; user-select: none;
}
.status-air { color: var(--bad); }
.status-rec { color: var(--text); }
.status-rec .rec-dot { background: var(--bad); }
.pulse, .rec-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.status-air .pulse { box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 25%, transparent); }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .pulse, .spinner { animation: none !important; } }

/* ----- buttons ----- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--accent-strong); background: var(--accent-strong); color: var(--accent-text);
  transition: background-color .12s, border-color .12s;
}
.btn:hover { filter: brightness(1.08); }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: var(--fs-help); }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-go { background: var(--go); border-color: var(--go); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn .rec-dot { background: var(--bad); }
.btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; filter: none; }
.btn.busy { cursor: progress; }
.btn.busy .btn-label { opacity: .7; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: #fff; animation: pulse 1.4s ease-in-out infinite; }

/* ----- live control ----- */
.current-scene { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.label { font-size: var(--fs-help); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.current-scene-name { font-size: 30px; font-weight: 750; line-height: 1.15; overflow-wrap: anywhere; min-height: 1.15em; }
.scene-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.scene-btn {
  font: inherit; cursor: pointer; text-align: left;
  min-height: 64px; padding: 10px 12px; border-radius: 10px;
  background: var(--surface-2); color: var(--text); border: 2px solid var(--border);
  display: flex; flex-direction: column; justify-content: center; gap: 2px; min-width: 0;
}
.scene-btn:hover { border-color: var(--accent); }
.scene-btn .scene-top { display: flex; align-items: center; justify-content: space-between; gap: 4px 8px; flex-wrap: wrap; min-width: 0; }
.scene-btn .scene-key { font-weight: 750; font-size: 15px; letter-spacing: .03em; overflow-wrap: anywhere; }
.scene-btn .scene-name { font-size: var(--fs-help); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scene-btn.active { border-color: var(--ok); background: var(--ok-bg); }
.scene-active { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-help); font-weight: 700; color: var(--ok); white-space: nowrap; }
.scene-active::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.scene-btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; border-style: dashed; }
.scene-grid-small .scene-btn { min-height: 48px; }
.other-scenes { margin-top: 12px; }
.other-scenes summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 6px 0; }
.action-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.offline-panel { background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px; padding: 16px; }
.offline-panel h3 { font-size: 17px; margin-bottom: 6px; }
.offline-panel ul { margin: 8px 0 0; padding-left: 20px; }
.offline-panel li { margin: 6px 0; }

/* ----- feed ----- */
.kbps-row { display: flex; align-items: baseline; gap: 8px; }
.kbps { font-size: 46px; font-weight: 750; font-variant-numeric: tabular-nums; min-width: 4.2ch; line-height: 1.05; }
.kbps-unit { color: var(--muted); font-weight: 600; }
.spark-wrap { position: relative; height: 96px; min-height: 96px; margin-top: 10px; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.spark { display: block; width: 100%; height: 100%; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark-th { stroke-width: 1; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
.spark-th-low { stroke: var(--warn); }
.spark-th-off { stroke: var(--bad); }
/* Threshold labels sit on their lines: LOW at the right end, OFFLINE at the left end. */
.spark-label {
  position: absolute; padding: 0 5px; border-radius: 4px; line-height: 18px;
  font-size: var(--fs-help); font-weight: 700; font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--surface-2) 85%, transparent); pointer-events: none; white-space: nowrap;
}
.spark-label.above { transform: translateY(calc(-100% - 1px)); }
.spark-label.below { transform: translateY(1px); }
.spark-label-low { right: 4px; color: var(--warn); }
.spark-label-off { left: 4px; color: var(--bad); }
.spark-legend { display: flex; justify-content: space-between; font-size: var(--fs-help); color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }

/* ----- switches ----- */
.switch { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; min-height: 44px; padding: 6px 0; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  flex: 0 0 auto; width: 42px; height: 24px; border-radius: 999px; margin-top: 1px;
  background: var(--neutral-bg); border: 1px solid var(--border); position: relative; transition: background-color .15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--muted); transition: transform .15s, background-color .15s;
}
.switch input:checked + .track { background: var(--accent-strong); border-color: var(--accent-strong); }
.switch input:checked + .track::after { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .track { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch-text { display: flex; flex-direction: column; font-weight: 600; }
.switch-text small { font-weight: 400; color: var(--muted); font-size: var(--fs-help); }

/* ----- lists & tables ----- */
.list { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); min-width: 0; }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.list .mono { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.list .empty { color: var(--muted); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--muted); font-size: var(--fs-help); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; white-space: nowrap; }
.table td { white-space: nowrap; }
.commands-table td:first-child { white-space: normal; min-width: 180px; }
.commands-table .cmd-name { font-weight: 700; }
.commands-table .cmd-help { display: block; color: var(--muted); font-size: var(--fs-help); }
.commands-table input[type="number"] { width: 84px; }
.commands-table input[type="text"] { width: 140px; }
.commands-table select { width: 150px; }
.commands-table .field-error { margin: 2px 0 0; white-space: normal; }

/* ----- settings ----- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs [role="tab"] {
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  background: none; color: var(--muted); border: 0; border-bottom: 3px solid transparent;
  padding: 10px 14px; min-height: 44px;
}
.tabs [role="tab"][aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs [role="tab"]:hover { color: var(--text); }
.panel { padding-top: 4px; }
/* Settings use a fixed 3-column grid (one column on phones) so fields line up in
   rows and no field wraps onto a row of its own. */
.field-grid, .toggle-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px 24px; }
.toggle-grid { gap: 4px 24px; margin-top: 16px; }
@media (min-width: 700px) { .field-grid, .toggle-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.field-wide { grid-column: 1 / -1; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; min-height: 42px;
}
textarea { width: 100%; resize: vertical; }
.field > input:not([type]), .field > select, .field > input[type="password"] { width: 100%; max-width: 360px; }
.input-narrow { width: 80px !important; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--bad); }
.input-unit { display: flex; align-items: center; gap: 8px; }
.input-unit input { width: 120px; font-variant-numeric: tabular-nums; }
.unit { color: var(--muted); font-size: 14px; }
.help { color: var(--muted); font-size: var(--fs-help); margin: 6px 0 0; }
.field-error { color: var(--bad); font-size: var(--fs-help); margin: 4px 0 0; min-height: 0; }
.field-error:empty { display: none; }
.field-warn { color: var(--warn); font-size: var(--fs-help); margin: 4px 0 0; }
.field-warn:empty { display: none; }
/* ----- Connect OBS card ----- */
.connect-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px 24px; }
@media (min-width: 900px) { .connect-grid { grid-template-columns: 5fr 7fr; } }
.connect-col { min-width: 0; }
.connect-col > h3.sub:first-child { margin-top: 0; }
.connect-status { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0 0 4px; }
.connect-status div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.connect-status dt { font-size: var(--fs-help); color: var(--muted); }
.connect-status dd { margin: 2px 0 0; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
#connect-generate { margin-top: 10px; }
.connect-empty { font-size: 14px; color: var(--muted); background: var(--surface-2); border: 1px dashed var(--border); border-radius: 8px; padding: 12px; margin: 0; }
.connect-fields { margin-bottom: 4px; }
@media (min-width: 700px) { .connect-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.connect-fields input[type="number"] { width: 120px; }
.connect-link { width: 100%; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 14px; }
.connect-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.connect-countdown { margin: 0; font-variant-numeric: tabular-nums; }
.connect-help { margin: 12px 0 0; padding-left: 18px; }
.connect-help li + li { margin-top: 2px; }
@media (max-width: 599px) { .connect-status { grid-template-columns: minmax(0, 1fr); } }

.password-form { margin-top: 8px; }
.password-form .btn { margin-top: 14px; }

/* ----- save bar ----- */
.save-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--mobile-bar-h) + env(safe-area-inset-bottom, 0px)); z-index: 25;
  background: var(--surface); border-top: 1px solid var(--accent); box-shadow: var(--shadow);
}
.save-bar-inner { max-width: var(--content-max); margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.save-actions { display: flex; gap: 8px; }
#save-msg.error { color: var(--bad); }

/* ----- toasts ----- */
.toasts {
  position: fixed; right: 16px; bottom: calc(var(--mobile-bar-h) + 16px + env(safe-area-inset-bottom, 0px)); z-index: 50;
  display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100% - 32px)); pointer-events: none;
}
body.has-savebar .toasts { bottom: calc(var(--mobile-bar-h) + 84px); }
.toast {
  pointer-events: auto; background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-left: 4px solid var(--ok); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); font-size: 14px;
}
.toast.error { border-left-color: var(--bad); }

/* ----- dialogs ----- */
.dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; width: min(420px, calc(100% - 32px)); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dialog h2 { font-size: 17px; margin-bottom: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.sheet .scene-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 8px; }

/* ----- mobile ----- */
.mobile-bar { display: none; }
@media (max-width: 899px) {
  body.in-app { --mobile-bar-h: 68px; }
  :root { --gap: 12px; }
  .card { padding: 14px; }
  .who { display: none; }
  .topbar-inner { gap: 8px; padding: 6px 12px; }
  .indicators { flex: 1 1 auto; justify-content: flex-end; }
  .ind { padding: 4px 8px; }
  .scene-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .action-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .current-scene-name { font-size: 24px; }
  .kbps { font-size: 40px; }
  .spark-wrap { height: 88px; min-height: 88px; }
  .mobile-bar:not([hidden]) {
    display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: 8px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 26;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: var(--shadow);
  }
  .mobile-bar .btn { min-height: 48px; }
}
@media (max-width: 599px) {
  .scene-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .action-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 420px) {
  .topbar-inner { gap: 6px; padding: 6px 10px; }
  .indicators { gap: 4px; }
  .ind { padding: 4px 7px; gap: 5px; }
  .brand { font-size: 15px; }
}
