:root {
  --bg: #07090d;
  --bg-elev: #10141c;
  --bg-card: #141924;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef2f7;
  --muted: #8b95a8;
  --accent: #39d98a;
  --accent-dim: rgba(57, 217, 138, 0.14);
  --air: #ff3b4e;
  --warn: #f5c15c;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --font: "Barlow", "Segoe UI", sans-serif;
  --cond: "Barlow Condensed", "Arial Narrow", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color-scheme: dark;
}
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(57, 217, 138, 0.08), transparent 50%),
    radial-gradient(900px 400px at 100% 0%, rgba(255, 59, 78, 0.06), transparent 45%),
    var(--bg);
  color: var(--text);
  letter-spacing: 0.01em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.app {
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.top {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 9, 13, 0.95);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 1px solid var(--accent);
  display: grid;
  place-items: center;
  color: var(--accent);
  position: relative;
  background: #0c1118;
}
.live-dot {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--air);
  box-shadow: 0 0 8px var(--air);
}
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-text strong {
  font-family: var(--cond);
  font-size: 28px;
  letter-spacing: 0.12em;
  font-weight: 700;
}
.brand-text small {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.22em;
  margin-top: 3px;
}

.search {
  display: grid;
  grid-template-columns: repeat(5, minmax(100px, 1fr)) auto;
  gap: 8px;
  align-items: center;
}
.search.search-filters {
  flex: 1 1 auto;
  min-width: 0;
}
.search input,
.search select,
.sheet input,
.sheet select,
select.btn {
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background-color: #1e1e1e;
  color: #ffffff;
  padding: 0 12px;
  font: inherit;
  color-scheme: dark;
  min-width: 0;
}
.search input:focus,
.search select:focus,
.sheet input:focus,
.sheet select:focus,
select.btn:focus {
  outline: 2px solid rgba(57, 217, 138, 0.45);
  border-color: transparent;
}
select {
  color: #ffffff !important;
  background-color: #1e1e1e !important;
  color-scheme: dark;
}
select option,
select optgroup {
  color: #ffffff !important;
  background-color: #1e1e1e !important;
}
/* Windows/Chrome: el desplegable nativo a veces ignora el fondo; forzar contraste */
@supports (-webkit-appearance: none) {
  select option {
    color: #ffffff;
    background-color: #1e1e1e;
  }
}
select option:checked,
select option:hover,
select option:focus {
  color: #ffffff !important;
  background-color: #2a2f3a !important;
}

.btn {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 0 14px;
  cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-accent {
  background: var(--accent);
  color: #062114;
  border-color: transparent;
}
.btn-ghost { background: transparent; }
.btn-logout {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
  font-size: 12px;
  padding: 0 10px;
  min-width: 0;
}
.btn-logout:hover { color: var(--text); }
.btn-export { min-width: 150px; }
body.auth-locked .app {
  pointer-events: none;
  user-select: none;
  filter: blur(2px);
  opacity: 0.45;
}
.btn-tiny {
  height: 28px;
  font-size: 12px;
  padding: 0 8px;
}
.top-actions { display: flex; gap: 8px; }
a.mod-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  color: var(--text);
  text-decoration: none;
  font-family: var(--cond);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}
a.mod-nav-btn:hover {
  border-color: rgba(57, 217, 138, 0.45);
  color: #9fe8c8;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 0 0 1px rgba(57, 217, 138, 0.16),
    0 8px 20px rgba(0, 0, 0, 0.28);
}

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  padding: 20px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

.main {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.status {
  flex: 0 0 auto;
}

.lede {
  color: var(--muted);
  margin: 0 0 14px;
  max-width: 62ch;
}
.lede code {
  color: var(--accent);
  font-size: 0.95em;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  border: 1px solid var(--line);
  background: var(--accent-dim);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  font: inherit;
}
.chips button:hover { border-color: var(--accent); }

.status-msg {
  color: var(--muted);
  margin: 8px 0 16px;
}
.status-msg.error { color: #ff8b96; }

.scan-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 13px;
  color: var(--muted);
}
.scan-metrics[hidden] { display: none !important; }
.scan-metric strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  margin-right: 4px;
}
.scan-metric.ok strong { color: #6dcea0; }
.scan-metric.warn strong { color: #e6b35c; }

.grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  align-content: start;
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.card:hover,
.card:focus-visible {
  border-color: var(--accent);
  transform: translateY(-1px);
  outline: none;
}
.card.in-list { border-color: rgba(57, 217, 138, 0.55); }
.card.playing { box-shadow: 0 0 0 1px var(--accent), var(--shadow); }

.logo {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  background: #0c1118;
  object-fit: contain;
  padding: 6px;
}
.logo-fallback {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #0c1118;
  color: var(--accent);
  font-family: var(--cond);
  font-size: 22px;
  letter-spacing: 0.06em;
}

.card h3 {
  margin: 0 0 4px;
  font-size: 16px;
  line-height: 1.25;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}
.flag { font-size: 16px; }
.tag {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
}
.tag.warn {
  color: var(--warn);
  border-color: rgba(245, 193, 92, 0.35);
}
.card-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
}
.card-actions .btn { height: 34px; flex: 1; font-size: 13px; }

.dock {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}
.player-card,
.list-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.player-card { flex: 0 0 auto; }
.list-card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.player-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 200px;
  background: #000;
  overflow: hidden;
}
.player-frame video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
  z-index: 1;
}
.player-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  color: var(--muted);
  background:
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,0.015) 3px),
    #05070a;
  pointer-events: none;
}
.player-overlay[hidden] {
  display: none !important;
}
.player-overlay p { margin: 0; letter-spacing: 0.08em; text-transform: uppercase; font-size: 12px; }
.on-air {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 3;
  background: var(--air);
  color: #fff;
  font-family: var(--cond);
  letter-spacing: 0.16em;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
}
.on-air[hidden] {
  display: none !important;
}
.now {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 10px;
  align-items: center;
  padding: 12px 14px 0;
}
.now img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: #0c1118;
  border-radius: 8px;
}
.now h2 { margin: 0; font-size: 18px; }
.now p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
#now-epg {
  color: #c8d4e0;
  font-size: 12px;
  line-height: 1.35;
}
.player-error {
  margin: 8px 14px 0;
  color: #ff8b96;
  font-size: 13px;
}
.now-actions {
  display: flex;
  gap: 8px;
  padding: 12px 14px 14px;
}

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px 0;
}
.list-head-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.list-head h2 {
  margin: 0;
  font-family: var(--cond);
  letter-spacing: 0.08em;
  font-size: 18px;
}
.custom-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0 8px 12px;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.custom-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.custom-list button {
  height: 30px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.custom-list button:hover { color: var(--text); }
.list-empty {
  color: var(--muted);
  padding: 8px 14px 16px;
  font-size: 14px;
}

.sheet {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg-elev);
  color: var(--text);
  color-scheme: dark;
  padding: 0;
  width: min(480px, 92vw);
}
/* No forzar display:block: rompe el top-layer del <dialog> modal en algunos navegadores. */
.sheet::backdrop { background: rgba(0, 0, 0, 0.72); }
.sheet form { padding: 20px; display: grid; gap: 12px; position: relative; }
.sheet h2 { margin: 0; font-family: var(--cond); letter-spacing: 0.06em; padding-right: 28px; }
.sheet p { margin: 0; color: var(--muted); }
.sheet menu { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 0; margin: 0; }
#export-filter-dialog {
  width: min(480px, 94vw);
  max-height: min(92vh, 720px);
  overflow: hidden;
}
#export-filter-form {
  display: flex;
  flex-direction: column;
  max-height: min(92vh, 720px);
  gap: 0;
  margin: 0;
}
#export-filter-form .export-filter-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 20px 8px;
  display: grid;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}
#export-filter-form menu.export-filter-actions {
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  z-index: 2;
  justify-content: stretch;
  gap: 10px;
  margin: 0;
  padding: 12px 20px 20px;
  background: linear-gradient(180deg, rgba(16, 20, 28, 0) 0%, rgba(16, 20, 28, 0.88) 28%, var(--bg-elev) 100%);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 -14px 32px rgba(0, 0, 0, 0.38);
}
#export-filter-form menu.export-filter-actions .btn-ghost {
  flex: 0 0 auto;
}
#export-confirm {
  flex: 1 1 auto;
  min-height: 44px;
  box-shadow: 0 10px 28px rgba(57, 217, 138, 0.22);
}
#export-filter-dialog label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
#export-filter-dialog input[type="checkbox"] {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}
#export-filter-dialog .export-block {
  margin: 12px 0 4px;
}
#export-filter-dialog .export-block h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 600;
}
#export-filter-dialog .export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0 4px;
}
#export-countries-container.is-locked,
#export-languages-container.is-locked {
  opacity: 0.45;
}
.sheet input,
.sheet select { width: 100%; }
.sort-label {
  margin: 4px 0 -6px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.sheet-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.login-sheet {
  width: min(380px, 92vw);
  max-width: 92vw;
  margin: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg-elev);
  color: var(--text);
  color-scheme: dark;
  padding: 0;
}
dialog.login-sheet[open] {
  position: fixed;
  inset: 0;
  margin: auto;
  height: fit-content;
  z-index: 10050;
}
.login-sheet h2 { padding-right: 0; }
.login-error {
  color: #ff8f8f !important;
  font-size: 13px;
}

@media (max-width: 980px) {
  .top {
    grid-template-columns: 1fr;
  }
  .search {
    grid-template-columns: 1fr 1fr;
  }
  .search.search-filters button[type="submit"] {
    grid-column: 1 / -1;
  }
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
  }
  .main {
    min-height: 0;
    overflow: hidden;
  }
  .dock {
    order: -1;
    max-height: 46vh;
    overflow: hidden;
  }
  .list-card {
    max-height: 120px;
  }
}
