/* Always dark, like the apps. */
:root {
  --bg: #0a1020;
  --surface: #0f172a;
  --surface-2: #17213a;
  --text: #e6ecf5;
  --muted: #8d99ae;
  --border: #223050;
  --accent: #5fe0cc;
  --accent-text: #04201c;
  --danger: #ff7a6e;
  --ok: #6fd69c;
  --ok-bg: #173225;
  --warn-bg: #3a1d1a;
  --now-line: #f07a8a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 14px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; font-size: 1.1rem; letter-spacing: -0.01em; }
.topbar-right { display: flex; gap: 12px; align-items: center; color: var(--muted); }

main { max-width: 860px; margin: 24px auto; padding: 0 16px; }
/* The guide uses the whole width of the window, like a TV guide. */
main:has(> #guide-view:not([hidden])) { max-width: 1600px; padding: 0 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.narrow { max-width: 420px; margin: 40px auto; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

h1 { font-size: 1.4rem; margin: 0 0 8px; }
h2 { font-size: 1.1rem; margin: 0; }

form { display: grid; gap: 14px; margin-top: 16px; }

label { display: grid; gap: 4px; font-weight: 500; }
label small { font-weight: 400; }

input:not([type="radio"], [type="checkbox"]) {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}

input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

fieldset.segmented { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 16px; }
fieldset.segmented legend { font-weight: 500; margin-bottom: 4px; }
fieldset.segmented label { display: flex; align-items: center; gap: 6px; font-weight: 400; }

button {
  font: inherit;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

button.secondary { background: transparent; color: var(--accent); }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 500; }
button.danger { color: var(--danger); }
button:disabled { opacity: 0.6; cursor: progress; }

.actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.actions .danger { margin-left: auto; }

.muted, .hint { color: var(--muted); }
.hint { margin: 0; font-size: 0.9rem; }

.error, .success { margin: 0; padding: 8px 12px; border-radius: 8px; }
.error { color: var(--danger); background: var(--warn-bg); }
.success { color: var(--ok); background: var(--ok-bg); }

.badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--danger);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 16px 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

table.libraries { width: 100%; border-collapse: collapse; margin-top: 12px; }
.libraries th, .libraries td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.libraries th { color: var(--muted); font-weight: 500; font-size: 0.9rem; }
.libraries td.paths { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }

.topbar { gap: 24px; }
.topbar-right { grid-column: 3; justify-self: end; }
.mainnav { display: flex; gap: 20px; }
.mainnav a, .subnav a { color: var(--muted); text-decoration: none; font-weight: 500; }
.mainnav a { font-size: 1.05rem; }
.mainnav a:hover { color: var(--text); }
.mainnav a.active { color: var(--accent); }
.mainnav a:focus-visible, .subnav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

main h1 { margin-bottom: 16px; }
h3 { font-size: 1rem; margin: 0; }
h4 { font-size: 0.9rem; margin: 20px 0 0; }

select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}

.picker-intro { margin: 0; }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.checklist label { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; font-weight: 400; }
.checklist input { margin-top: 4px; }
.checklist small { display: block; color: var(--muted); overflow-wrap: anywhere; }
.checklist .unsupported { color: var(--muted); }

#library-index { display: grid; gap: 12px; margin-top: 12px; }
.scan-status { margin: 0; color: var(--muted); }
.scan-status.running { color: var(--accent); font-weight: 500; }
#libraries-excluded { margin: 0; }
.table-scroll { overflow-x: auto; }
.libraries .num { text-align: right; font-variant-numeric: tabular-nums; }
.libraries td.warn { color: var(--danger); }

.wizard { max-width: 640px; margin: 0 auto; }
.steps { display: flex; flex-wrap: wrap; gap: 8px 24px; list-style: none; margin: 0 0 20px; padding: 0; counter-reset: step; }
.steps li { color: var(--muted); counter-increment: step; }
.steps li::before { content: counter(step) ". "; }
.steps li.current { color: var(--text); font-weight: 600; }
.steps li.done { color: var(--ok); }
#wizard-scan { display: grid; gap: 12px; }
#wizard-scan h2, #wizard-scan p { margin: 0; }
#wizard-progress { width: 100%; accent-color: var(--accent); }
#wizard-view #conn-summary, #wizard-view #disconnect-btn { display: none; }

a.button {
  display: inline-block;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  text-decoration: none;
}
a.button.secondary { background: transparent; color: var(--accent); }
a.button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.narrow-page { max-width: 720px; margin: 0 auto; }
.back-link { display: inline-block; margin-bottom: 12px; color: var(--muted); text-decoration: none; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.brand span { color: var(--accent); }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 1rem; }

/* The program picked in the guide, shown large above it. */
.guide-hero { min-height: 172px; margin: 4px 0 18px; display: flex; align-items: flex-start; gap: 20px; }
.hero-text { flex: 1; min-width: 0; display: grid; align-content: start; gap: 4px; }
.guide-hero p { margin: 0; }
/* The selected program's poster, 2:3. The placeholder keeps its size while it loads, or without one. */
.hero-poster { flex: none; width: 116px; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.hero-poster img { display: block; width: 100%; height: 100%; object-fit: cover; }
/* The channel line takes the channel's color, or the accent without one. */
.hero-eyebrow { color: var(--channel, var(--accent)); font-weight: 600; }
.hero-title { margin: 0; font-size: clamp(1.6rem, 4vw, 2.4rem); line-height: 1.15; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.hero-subtitle { color: var(--text); font-size: 1.05rem; }
.hero-meta { color: var(--muted); font-size: 1.05rem; }
.hero-overview {
  max-width: 70ch; color: var(--text); opacity: 0.85; line-height: 1.5;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden;
  transition: opacity 0.15s;
}
.hero-overview.loading { opacity: 0.4; }
@media (max-width: 640px) { .hero-overview { -webkit-line-clamp: 4; line-clamp: 4; } }
.hero-watch {
  justify-self: start;
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-weight: 600;
  font-size: 1.05rem;
  text-decoration: none;
}
.hero-watch svg { width: 12px; height: 12px; fill: currentColor; }
.hero-watch:hover span { text-decoration: underline; }

.guide-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 10px; }
.guide-toolbar .actions { margin: 0; }
.guide-date { margin: 0; }
button.small, a.button.small { padding: 4px 12px; font-size: 0.9rem; }

.guide-scroll { overflow-x: auto; position: relative; padding-bottom: 6px; }
.guide-inner { position: relative; }
.guide-row { display: flex; }
.guide-channel {
  position: sticky;
  left: 0;
  z-index: 3;
  flex: none;
  width: var(--guide-label);
  padding: 0 12px 0 0;
  background: var(--bg);
  color: #fff;
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
/* Each channel cell sits on a wash of its color: as light as the programs around the one on air,
   or as strong as the on-air one while a program in its row is picked. */
.guide-row:not(.guide-times) .guide-channel { padding-left: 12px; }
.guide-row:not(.guide-times) .guide-channel::before {
  content: "";
  position: absolute;
  inset: 4px 6px 4px 0;
  z-index: -1;
  border-radius: 8px;
  background: color-mix(in srgb, var(--channel-tint) var(--wash-off), var(--bg));
}
.guide-row.picked .guide-channel::before { background: color-mix(in srgb, var(--channel-tint) var(--wash-on), var(--bg)); }
.guide-channel b {
  color: #fff;
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
/* The name sits under the number, as in the apps, and may take two lines before it's cut off. */
.guide-channel span {
  font-weight: 400;
  font-size: 0.85rem;
  line-height: 1.25;
  color: #fff;
  overflow: hidden;
  overflow-wrap: break-word;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
.guide-watch { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; color: #fff; text-decoration: none; }
.guide-watch:hover span { text-decoration: underline; }
.guide-edit { flex: none; color: color-mix(in srgb, #fff 70%, transparent); text-decoration: none; padding: 2px 4px; }
.guide-edit:hover, .guide-edit:focus-visible { color: var(--accent); }
@media (hover: hover) {
  .guide-edit { opacity: 0; }
  .guide-row:hover .guide-edit, .guide-edit:focus-visible { opacity: 1; }
}
.guide-track { position: relative; flex: none; height: 76px; }
.guide-times .guide-track { height: 30px; }
.guide-times .guide-channel { color: var(--muted); font-size: 0.95rem; }
.guide-time { position: absolute; top: 4px; font-size: 0.85rem; color: var(--muted); white-space: nowrap; }

/* Every program takes a wash of its channel's color, with a border and a stripe down the left:
   strong for the one on air, light for those before and after it. Channels without a color are gray. */
.guide-row { --channel-tint: var(--channel, #8e8e93); --wash-on: 23%; --wash-off: 8%; }
.guide-program {
  position: absolute;
  top: 4px;
  bottom: 4px;
  margin: 0;
  padding: 6px 14px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 1px;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: color-mix(in srgb, var(--channel-tint) var(--wash-off), var(--bg));
  border: 1px solid color-mix(in srgb, var(--channel-tint) 18%, var(--bg));
  box-shadow: inset 3px 0 0 color-mix(in srgb, var(--channel-tint) 40%, var(--bg));
  border-radius: 8px;
  overflow: hidden;
  white-space: nowrap;
  cursor: pointer;
}
.guide-program.on-air {
  background: color-mix(in srgb, var(--channel-tint) var(--wash-on), var(--bg));
  border-color: color-mix(in srgb, var(--channel-tint) 65%, var(--bg));
  box-shadow: inset 3px 0 0 var(--channel-tint);
}
.guide-program.past { opacity: 0.6; }
/* The picked program keeps its own colors and gets a white outline; so does keyboard focus. */
.guide-program.picked, .guide-program:focus-visible { outline: 2px solid #fff; outline-offset: -1px; opacity: 1; }
.guide-program:hover:not(.picked) { outline: 1px solid color-mix(in srgb, #fff 45%, transparent); outline-offset: -1px; }
.guide-program strong, .guide-program small { display: block; overflow: hidden; text-overflow: ellipsis; }
.guide-program strong { font-weight: 600; font-size: 0.95rem; line-height: 1.3; }
.guide-program small { color: var(--muted); font-size: 0.8rem; line-height: 1.3; }
.guide-none { position: absolute; left: 12px; top: 26px; color: var(--muted); }
.guide-now-line { position: absolute; top: 30px; bottom: 6px; width: 2px; margin-left: -1px; background: var(--now-line); z-index: 2; pointer-events: none; }

.suggestion-group { margin-bottom: 20px; }
.suggestion-group h2 { margin-bottom: 8px; }
.suggestion { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.suggestion:last-child { border-bottom: 0; }
.suggestion small { display: block; color: var(--muted); }

.editor { display: grid; gap: 16px; margin-top: 0; }
.editor-section { display: grid; gap: 14px; }
.field-row { display: flex; flex-wrap: wrap; gap: 12px; }
.field-row label { flex: 1 1 140px; }
.field-row label.grow { flex: 3 1 220px; }
.field-row label.short { flex: 1 1 100px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chips label { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; }
.chips label:has(input:checked) { border-color: var(--accent); color: var(--accent); }
.chips small { color: var(--muted); }
.title-list { max-height: 340px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 2px 12px; }
.preview { margin: 0; color: var(--muted); }

.guide-empty { display: grid; justify-items: center; gap: 16px; padding: 48px 20px; }
.guide-empty p { margin: 0; }
.tv { width: min(420px, 100%); height: auto; fill: none; stroke: var(--muted); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }

:root { --guide-label: 168px; }

.settings { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 24px; }
.subnav { display: grid; align-content: start; gap: 4px; }
.subnav a { padding: 6px 10px; border-radius: 8px; }
.subnav a.active { color: var(--text); background: var(--surface); border: 1px solid var(--border); }
.server-version { margin: 16px 0 0; padding: 0 10px; color: var(--muted); font-size: 0.8rem; }
.section-title { margin-bottom: 12px; }
.task-description { margin: 4px 0 0; }
.task-form { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 16px; }
.check { display: flex; align-items: center; gap: 8px; }
.interval { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 360px; }
.runs { min-width: 520px; }
.runs td { font-size: 0.9rem; }

@media (max-width: 560px) {
  .settings { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .topbar { display: flex; flex-wrap: wrap; gap: 12px; padding: 12px 16px; }
  .topbar-right { margin-left: auto; }
  .libraries:not(.runs) { min-width: 480px; }
  :root { --guide-label: 108px; }
  /* Narrow labels give the name the full width; the edit button sits beside the number instead. */
  .guide-row:not(.guide-times) .guide-channel { align-items: stretch; }
  .guide-watch { justify-content: flex-start; padding-top: 10px; }
  .guide-edit { position: absolute; top: 10px; right: 8px; padding: 0 4px; line-height: 1.2; }
  .guide-hero { min-height: 150px; gap: 14px; }
  .hero-poster { width: 84px; }
  .clock { display: none; }
}

[hidden] { display: none !important; }

.color-field { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.color-field .segmented { margin: 0; }
.color-swatch { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border); }
input[type="color"].color-input { width: 56px; height: 36px; padding: 2px; }

.player-head { display: flex; align-items: center; gap: 16px; margin: 8px 0 16px; }
.player-head h1 { margin: 0; }
.player-head p { margin: 2px 0 0; }
.player-channel { flex: none; color: var(--muted); font-weight: 500; }
.player-frame { background: #000; border-radius: var(--radius); overflow: hidden; }
.player-frame video { display: block; width: 100%; max-height: 72vh; }
#player-view .actions { margin-top: 12px; }
#player-view .error { margin-top: 12px; }

.player-info { margin-top: 12px; display: grid; gap: 8px; }
.player-info h2, .player-info h3, .player-info p, .player-info dl { margin: 0; }
.player-info h3 { margin-top: 8px; }
.player-info-episode { font-weight: 500; }
.player-info-tagline { font-style: italic; color: var(--muted); }

.devices-hint { margin-top: 4px; }
.device-list { list-style: none; margin: 8px 0 0; padding: 0; }
.device-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.device-list li:last-child { border-bottom: 0; }
.device-list small { display: block; color: var(--muted); }
#link-view p { margin: 0 0 12px; }
#link-confirm .actions { margin-top: 4px; }
#login-code small { display: block; margin-top: 6px; font-weight: 400; color: var(--muted); }
#twofa-card { margin-top: 16px; }
#twofa-card form, #twofa-codes { margin-top: 12px; }
.twofa-qr { width: 200px; max-width: 100%; margin: 0 0 12px; }
.twofa-qr svg { display: block; width: 100%; height: auto; border-radius: 8px; }
.twofa-key { margin: 0 0 12px; }
.twofa-key summary { cursor: pointer; font-weight: 500; }
.twofa-key code { word-break: break-all; font-size: 0.95rem; }
.recovery-codes { columns: 2; gap: 24px; margin: 0 0 12px; padding-left: 1.6em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.recovery-codes li { padding: 2px 0; }
.code-entry { display: flex; align-items: center; gap: 6px; margin-top: 6px; font: 600 1.25rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.08em; }
.code-entry input { width: 7ch; font: inherit; letter-spacing: inherit; text-transform: uppercase; }
#link-rest small { display: block; margin-top: 6px; font-weight: 400; color: var(--muted); }

.more-filters { border-top: 1px solid var(--border); padding-top: 12px; }
.more-filters summary { cursor: pointer; font-weight: 500; }
.more-filters > .editor-section { margin-top: 14px; }
.inline-input { margin-top: 8px; }
.short-field { max-width: 240px; }

/* Settings -> Streams */
#settings-streams .card + .card { margin-top: 16px; }
.numbering-auto { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.numbering-auto label.short { flex: 0 1 170px; }
.numbering-list { list-style: none; margin: 8px 0 0; padding: 0; }
.numbering-row {
  display: grid; grid-template-columns: 90px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.numbering-row:last-child { border-bottom: 0; }
.numbering-number { width: 100%; }
.numbering-name { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; white-space: nowrap; }
.numbering-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
@media (max-width: 560px) {
  .numbering-row { grid-template-columns: 76px minmax(0, 1fr); }
  .numbering-kind { grid-column: 2; justify-self: start; }
}

.stream-list, .stream-history { list-style: none; margin: 8px 0 0; padding: 0; }
.stream {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  margin-top: 10px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--channel, var(--accent));
  border-radius: 8px;
  background: var(--surface-2);
}
.stream-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stream-channel { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stream-channel b { color: color-mix(in srgb, var(--channel, var(--muted)) 75%, var(--text)); font-variant-numeric: tabular-nums; }
.stream-state { font-size: 0.8rem; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.stream-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.stream-state.playing { color: var(--ok); }
.stream-body { display: grid; gap: 4px; min-width: 0; }
.stream-title { font-size: 1.15rem; font-weight: 600; overflow-wrap: anywhere; }
.stream-subtitle { color: var(--muted); }
.stream-progress { display: flex; align-items: center; gap: 10px; margin: 4px 0; }
.stream-progress small { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stream-progress .bar { flex: 1; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.stream-progress .bar span { display: block; height: 100%; background: var(--channel, var(--accent)); }
.stream-who { margin: 0; color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }
.stream-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.tag { font-size: 0.8rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.tag.delivery.transcode { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.tag.delivery.direct-stream, .tag.delivery.direct-play { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.stream-actions { display: flex; justify-content: flex-end; }
.stream-history li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.stream-history li:last-child { border-bottom: 0; }
.history-main { display: grid; gap: 2px; min-width: 0; }
.history-title { display: flex; gap: 10px; min-width: 0; }
.history-title > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-main small { color: var(--muted); }
.history-side { display: grid; justify-items: end; gap: 4px; flex: none; }
@media (max-width: 560px) {
  .stream-history li { align-items: start; flex-direction: column; }
  .history-side { justify-items: start; display: flex; gap: 8px; align-items: center; }
}
