/* Relay — application styles. Light by default; dark via prefers-color-scheme
   or an explicit [data-theme]. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --accent: #059669;
  --accent-hover: #047857;
  --accent-contrast: #ffffff;
  --success: #059669;
  --success-bg: #d1fae5;
  --success-fg: #065f46;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --danger-fg: #991b1b;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d11;
    --surface: #161a21;
    --surface-2: #12151b;
    --border: #20242c;
    --border-strong: #2a2f3a;
    --text: #f3f4f6;
    --text-muted: #8b94a3;
    --accent: #10b981;
    --accent-hover: #34d399;
    --accent-contrast: #06231a;
    --success: #34d399;
    --success-bg: #064e3b;
    --success-fg: #a7f3d0;
    --danger: #f87171;
    --danger-bg: #4c1d1d;
    --danger-fg: #fecaca;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

:root[data-theme="dark"] {
  --bg: #0b0d11;
  --surface: #161a21;
  --surface-2: #12151b;
  --border: #20242c;
  --border-strong: #2a2f3a;
  --text: #f3f4f6;
  --text-muted: #8b94a3;
  --accent: #10b981;
  --accent-hover: #34d399;
  --accent-contrast: #06231a;
  --success: #34d399;
  --success-bg: #064e3b;
  --success-fg: #a7f3d0;
  --danger: #f87171;
  --danger-bg: #4c1d1d;
  --danger-fg: #fecaca;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden; /* contain the full-bleed player breakout */
}

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

h1, h2, h3 { line-height: 1.25; }

.section-label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin: 0 0 .5rem;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: .65rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; display: block; }
.brand-name { font-weight: 700; font-size: 1.05rem; }

.nav { display: flex; gap: 1rem; }
.nav a {
  color: var(--text-muted);
  font-size: .9rem;
  padding: .35rem 0;
  border-bottom: 2px solid transparent;
}
.nav a:hover { color: var(--text); text-decoration: none; }
.nav a.active { color: var(--text); border-bottom-color: var(--accent); }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.user-menu { display: flex; align-items: center; gap: .6rem; }
.user-name { font-size: .9rem; color: var(--text-muted); }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1;
  padding: .35rem .45rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

#theme-toggle::before { content: "\263E"; } /* moon */
:root[data-theme="dark"] #theme-toggle::before { content: "\2600"; } /* sun */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-toggle::before { content: "\2600"; }
}

.nav-toggle { display: none; }

/* ---------- Layout ---------- */
.main { max-width: 980px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-size: .88rem;
  font-weight: 600;
  padding: .5rem .9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }
.btn-block { display: block; width: 100%; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--danger); border-color: var(--border-strong); background: var(--surface); }
.btn-danger:hover { background: var(--danger-bg); color: var(--danger-fg); }

.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.inline-form { display: inline; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: .85rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field-label {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted);
}
input[type="text"], input[type="password"], input:not([type]) {
  font: inherit;
  padding: .5rem .6rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus-visible, .btn:focus-visible, a:focus-visible, .icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Alerts ---------- */
.alert { padding: .55rem .75rem; border-radius: var(--radius-sm); font-size: .88rem; margin: 0 0 1rem; }
.alert-error { background: var(--danger-bg); color: var(--danger-fg); }

/* ---------- Cards & stat tiles ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.tiles { display: flex; gap: .75rem; margin-bottom: 1rem; }
.tile {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
}
.tile-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.tile-value { font-size: 1.25rem; font-weight: 700; margin-top: .2rem; }
.tile-value.ok { color: var(--success); }

.block { margin-bottom: 1.75rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; background: var(--surface); }
table.data th, table.data td {
  text-align: left; padding: .6rem .75rem; font-size: .88rem;
  border-bottom: 1px solid var(--border);
}
table.data thead th {
  background: var(--surface-2); color: var(--text-muted);
  font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data td.actions { vertical-align: middle; }
code, .mono { font-family: var(--mono); font-size: .82em; color: var(--text-muted); }
.muted { color: var(--text-muted); }

/* Upstream row actions + edit/add forms: keep inputs compact (the global
   input width:100% otherwise stretches them and bloats the table rows). */
.row-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.up-edit, .up-add { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: 0; }
.up-edit .in-name, .up-add .in-name { width: 9rem; }
.up-edit .in-url, .up-add .in-url { width: 18rem; max-width: 100%; flex: 1 1 18rem; }

/* ---------- Status pills ---------- */
.pill {
  display: inline-block; font-size: .72rem; font-weight: 600;
  padding: .15rem .55rem; border-radius: 999px;
}
.pill-active { background: var(--success-bg); color: var(--success-fg); }
.pill-suspended { background: var(--danger-bg); color: var(--danger-fg); }

/* ---------- Viewer list ---------- */
.viewers { list-style: none; margin: 0; padding: .5rem .25rem; }
.viewers li {
  display: flex; align-items: center; gap: .5rem;
  font-size: .88rem; padding: .35rem .5rem;
}
.viewers li:not(.empty)::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--success); flex: none;
}
.viewers .muted { color: var(--text-muted); margin-left: auto; font-size: .82rem; }
.empty { color: var(--text-muted); font-size: .88rem; padding: .5rem; }

/* ---------- Player (full-bleed, edge to edge) ---------- */
.player-wrap {
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  margin-top: -1.25rem; /* cancel .main top padding so the video meets the header */
}
#video {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 8rem); /* keep the controls in view on tall/ultrawide screens */
  object-fit: contain;
  background: #000;
  border: none;
  border-radius: 0;
}
.player-bar { display: flex; align-items: center; gap: .5rem; max-width: 980px; margin: .85rem auto 0; padding: 0 1rem; }
.status { font-size: .85rem; color: var(--text-muted); margin-left: auto; }
.status.live { color: var(--success); }
.status.error { color: var(--danger); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.login-card {
  width: 100%; max-width: 340px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 1.75rem;
}
.login-brand { display: flex; align-items: center; justify-content: center; gap: .55rem; margin-bottom: 1.4rem; }
.login-brand img { width: 40px; height: 40px; }
.login-brand .brand-name { font-size: 1.5rem; }

.toolbar { display: flex; align-items: center; margin-bottom: .75rem; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .nav {
    display: none;
    position: absolute; top: 52px; left: 0; right: 0;
    flex-direction: column; gap: 0;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: .5rem 1rem;
  }
  .nav.open { display: flex; }
  .nav a { padding: .6rem 0; border-bottom: none; }
  .nav a.active { border-bottom: none; color: var(--accent); }
  .nav-toggle { display: inline-flex; }
  .topbar { position: relative; }
  .user-name { display: none; }
  .tiles { flex-direction: column; }
}

/* ---------- Browse channels ---------- */
.browse { display: flex; gap: 1rem; align-items: flex-start; }
.browse-groups {
  flex: 0 0 240px; position: sticky; top: 1rem;
  max-height: calc(100vh - 5rem); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .75rem;
}
.group-list { list-style: none; margin: 0; padding: 0; }
.group-item {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  width: 100%; text-align: left; font: inherit; font-size: .9rem;
  padding: .5rem .6rem; border: none; background: transparent; color: var(--text);
  border-radius: var(--radius-sm); cursor: pointer;
}
.group-item:hover { background: var(--surface-2); }
.group-item.active { background: var(--surface-2); color: var(--accent); font-weight: 600; }
.group-item .pill { background: var(--surface-2); color: var(--text-muted); }
.group-item.active .pill { background: var(--success-bg); color: var(--success-fg); }

.browse-channels { flex: 1 1 auto; min-width: 0; }
.browse-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .85rem; }
.chan-search { flex: 1 1 auto; }
.browse-back { display: none; }

.chan-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
.chan-card {
  display: flex; align-items: center; gap: .6rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .55rem .65rem;
}
.chan-card.is-active { border-color: var(--accent); }
.chan-logo { width: 40px; height: 40px; object-fit: contain; flex: none; background: var(--surface-2); border-radius: 6px; }
.chan-name { flex: 1 1 auto; min-width: 0; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan-star { border: none; background: transparent; color: var(--text-muted); font-size: 1.1rem; cursor: pointer; line-height: 1; padding: .2rem; }
.chan-star.on { color: #f59e0b; }
.chan-default { border: none; background: transparent; color: var(--text-muted); font-size: 1rem; cursor: pointer; line-height: 1; padding: .2rem; }
.chan-default.on { color: var(--accent); }
.chan-more { display: flex; justify-content: center; margin: 1rem 0; }

/* small logo used on the dashboard active tile + player chip */
.chan-logo-sm { width: 24px; height: 24px; object-fit: contain; border-radius: 4px; background: var(--surface-2); }

@media (max-width: 640px) {
  .browse { display: block; }
  .browse-groups { flex: none; width: auto; position: static; max-height: none; }
  /* drill-in: show groups OR channels, toggled by .show-channels */
  .browse-channels { display: none; }
  .browse.show-channels .browse-groups { display: none; }
  .browse.show-channels .browse-channels { display: block; }
  .browse-back { display: inline-flex; }
  .chan-grid { grid-template-columns: 1fr; }
}

/* ---------- Player channel chip ---------- */
.chan-chip { display: flex; align-items: center; gap: .5rem; margin-right: .5rem; min-width: 0; }
.chan-chip-name { font-size: .9rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 14rem; }
@media (max-width: 640px) {
  .player-bar { flex-wrap: wrap; }
  .chan-chip { flex: 1 1 100%; margin: 0 0 .25rem; }
}

/* ---------- NRL fixtures table ---------- */
.nrl-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.nrl-table th, .nrl-table td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--border); }
.nrl-table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.nrl-table tbody tr:last-child td { border-bottom: 0; }
.nrl-table tr.nrl-next td { background: var(--success-bg); color: var(--success-fg); }
.nrl-table tr.nrl-next td:first-child { border-left: 3px solid var(--accent); }

/* EPG guide */
.epg-days { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: .75rem; }
.epg-day { background: none; border: none; border-bottom: 2px solid transparent; color: var(--text-muted); padding: .5rem .75rem; cursor: pointer; white-space: nowrap; font: inherit; }
.epg-day.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.epg-list { display: flex; flex-direction: column; gap: .5rem; }
.epg-row { display: flex; align-items: center; gap: .6rem; padding: .6rem; background: var(--surface); border: 1px solid transparent; border-radius: 10px; }
.epg-row.is-active { border-color: var(--accent); }
.epg-meta { flex: 1; min-width: 0; }
.epg-name { font-weight: 600; }
.epg-now { color: var(--accent); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.epg-next { color: var(--text-muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.epg-bar { height: 3px; background: var(--border); border-radius: 2px; margin: .2rem 0; }
.epg-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.epg-expand { background: none; border: none; color: var(--text-muted); font-size: 1.1rem; cursor: pointer; padding: .2rem .4rem; }
.epg-timeline { padding: .25rem .5rem .5rem 3rem; }
.epg-tl { display: flex; gap: .6rem; padding: .3rem 0; border-bottom: 1px solid var(--border); font-size: .85rem; }
.epg-tl-time { color: var(--text-muted); width: 4.5rem; flex: none; }
.epg-tl.live .epg-tl-prog { color: var(--accent); font-weight: 600; }
.chan-now { display: block; color: var(--text-muted); font-size: .75rem; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chan-chip-now { color: var(--text-muted); font-size: .8rem; margin-left: .5rem; }
