/* Azul noche con acento ámbar (el color de las luces de sala). A propósito lejos del rojo y
   negro de Netflix: con aquellos colores Google marcaba el sitio como imitación. */
:root {
  --bg: #0e1424;
  --surface: #161e33;
  --surface-2: #1f2942;
  --border: #2c3854;
  --text: #edf0f7;
  --muted: #9aa6c0;
  --accent: #f5b544;
  --accent-hover: #ffc75f;
  --on-accent: #1a1405;
  --ok: #4cc38a;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

a { color: inherit; text-decoration: none; }

/* Foco bien visible: en la tele se navega con el control remoto. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

button, select, input {
  font: inherit;
  color: inherit;
}

.btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }

input[type="text"], input[type="password"], select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  min-width: 0;
}

/* ---- Encabezado ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1rem;
  background: rgba(14, 20, 36, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: 0.01em;
  color: var(--text);
}
.logo img { display: block; border-radius: 22%; }
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--muted); font-size: 0.9rem; }

main { max-width: 1400px; margin: 0 auto; padding: 1rem; }

h2 { font-size: 1.1rem; margin: 1.5rem 0 0.75rem; color: var(--muted); font-weight: 600; }

/* ---- Migas de pan ---- */
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; font-size: 1.05rem; }
.breadcrumbs a { padding: 0.3rem 0.5rem; border-radius: 6px; color: var(--muted); }
.breadcrumbs a:hover { background: var(--surface-2); color: var(--text); }
.breadcrumbs a.current { color: var(--text); font-weight: 600; }
.breadcrumbs .sep { color: var(--border); }

/* ---- Grillas ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.75rem;
}
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  overflow: hidden;
}
.card:hover { background: var(--surface-2); }
.card .title { font-weight: 600; overflow-wrap: anywhere; }
.card .sub { color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; overflow-wrap: anywhere; }
.folder .title::before { content: "📁 "; }

.bar { height: 4px; background: var(--border); border-radius: 2px; margin-top: 0.6rem; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }

/* ---- Buscador ---- */
.topbar .search {
  flex: 1;
  max-width: 34rem;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  min-width: 0;
}
.topbar .search:focus { border-color: var(--accent); outline: none; }

/* ---- Tarjetas con miniatura ---- */
.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--surface-2) url("/static/icons/icon.svg") center / 28% no-repeat;
  overflow: hidden;
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.9rem;
}
.media-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(240px, 300px);
  gap: 0.9rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  scroll-snap-type: x proximity;
}
/* Sección secundaria del inicio (Agregado recientemente): separada y más chica. */
section.secondary {
  margin-top: 2.25rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
section.secondary h2 { font-size: 0.95rem; }
.media-row.compact { grid-auto-columns: minmax(180px, 220px); }
.media-row.compact .card-body { padding: 0.5rem 0.65rem 0.6rem; }
.media-row.compact .title { font-size: 0.9rem; }

.media-card-wrap { position: relative; scroll-snap-align: start; min-width: 0; }
/* Corazón de favoritos: sutil hasta que se marca. */
.heart {
  position: absolute;
  right: 0.4rem;
  bottom: 0.35rem;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  opacity: 0.55;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: opacity 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.heart:hover, .heart:focus-visible { opacity: 1; color: var(--text); }
.heart[aria-pressed="true"] { opacity: 0.95; color: var(--accent); }
.heart:active { transform: scale(0.85); }
/* ✕ para sacar de "Seguir viendo": sobre la miniatura, discreta. */
.card-dismiss {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 1.7rem;
  height: 1.7rem;
  border: 0;
  border-radius: 50%;
  background: rgba(5, 8, 16, 0.6);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  opacity: 0.6;
}
.card-dismiss:hover, .card-dismiss:focus-visible { opacity: 1; background: rgba(5, 8, 16, 0.85); }
@media (hover: hover) {
  .card-dismiss { opacity: 0; }
  .media-card-wrap:hover .card-dismiss { opacity: 0.8; }
}
.media-card-wrap .card-body { padding-right: 2.2rem; }
.player-bar .heart { position: static; flex: none; opacity: 0.8; color: var(--text); }
.player-bar .heart[aria-pressed="true"] { color: var(--accent); }
.media-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  scroll-snap-align: start;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.media-card:hover, .media-card:focus-visible { transform: translateY(-2px); border-color: var(--accent); }
.media-card .card-body { padding: 0.65rem 0.8rem 0.8rem; }
.media-card .title { font-weight: 600; overflow-wrap: anywhere; }
.media-card .sub { color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; overflow-wrap: anywhere; }

/* ---- Lista de videos ---- */
.videos { display: flex; flex-direction: column; gap: 0.5rem; }
.video-row {
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.video-row:hover { background: var(--surface-2); }
.video-row .play { flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.9rem; }
.video-row .thumb { flex: none; width: 168px; }
.video-row .info { min-width: 0; padding: 0.6rem 0.3rem 0.6rem 0; }
.video-row .title { font-weight: 600; overflow-wrap: anywhere; }
.video-row .sub { color: var(--muted); font-size: 0.85rem; margin-top: 0.15rem; overflow-wrap: anywhere; }
.video-row .watched-btn {
  border: 0;
  border-left: 1px solid var(--border);
  background: transparent;
  padding: 0 1rem;
  cursor: pointer;
  color: var(--border);
  font-size: 1.3rem;
}
.video-row .watched-btn:hover { color: var(--muted); }
.video-row.watched .watched-btn { color: var(--ok); }
.video-row.watched .title { color: var(--muted); }

.empty, .error { color: var(--muted); padding: 2rem 0; text-align: center; }
.error { color: #ff8a8a; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-box {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.login-box .logo { font-size: 1.8rem; justify-content: center; margin-bottom: 0.5rem; }
.login-wrap {
  background:
    radial-gradient(ellipse at top, rgba(245, 181, 68, 0.12), transparent 60%),
    var(--bg);
}
.login-box label { display: flex; flex-direction: column; gap: 0.3rem; color: var(--muted); font-size: 0.9rem; }
.form-error { color: #ff8a8a; min-height: 1.2em; font-size: 0.9rem; margin: 0; }

/* ---- Reproductor ---- */
/* Fijo a la pantalla visible: con height 100dvh, en la web app instalada el alto calculado era
   mayor que la pantalla y la parte de abajo del video (subtítulos y controles) quedaba afuera. */
body.player-page {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #000;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
/* Barra superpuesta al video, semitransparente; se esconde sola mientras reproduce
   (clase .idle en el escenario, la pone player.js). */
.player-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.5rem 0.75rem 1.25rem;
  background: linear-gradient(to bottom, rgba(5, 8, 16, 0.85), rgba(5, 8, 16, 0.45) 70%, transparent);
  transition: opacity 0.25s ease;
}
.player-bar .btn { background: rgba(22, 30, 51, 0.7); }
.player-stage.idle .player-bar,
.player-stage.idle .next-hint { opacity: 0; pointer-events: none; }
.player-stage.idle { cursor: none; }
.btn-icon { font-size: 1.1rem; line-height: 1; padding: 0.3rem 0.5rem; }
.player-bar .title { flex: 1; min-width: 8rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-bar label { display: flex; align-items: center; gap: 0.35rem; color: var(--muted); font-size: 0.85rem; }
.player-bar select { padding: 0.4rem 0.5rem; max-width: 46vw; }
.player-stage { position: relative; flex: 1; min-height: 0; background: #000; }
.player-stage video { width: 100%; height: 100%; background: #000; display: block; }
.player-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.6);
  pointer-events: none;
  white-space: pre-line;
}
.player-status[hidden] { display: none; }

/* Enviar a Chromecast: botón del SDK de Google y panel de control remoto. */
google-cast-launcher {
  width: 2.2rem;
  height: 2.2rem;
  padding: 0.3rem;
  cursor: pointer;
  --disconnected-color: var(--text);
  --connected-color: var(--accent);
}
.cast-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 1rem;
  background: var(--bg);
  text-align: center;
}
.cast-debug {
  flex: none;
  max-height: 40vh;
  overflow: auto;
  margin: 0;
  padding: 0.5rem;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.7rem;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: text;
}
.cast-device { margin: 0; color: var(--muted); }
.cast-seek { display: flex; align-items: center; gap: 0.75rem; width: min(100%, 40rem); font-variant-numeric: tabular-nums; }
.cast-seek input { flex: 1; min-width: 0; accent-color: var(--accent); }
.cast-buttons { display: flex; gap: 0.75rem; }
.cast-buttons .btn { min-width: 5.5rem; padding: 0.8rem 1rem; font-size: 1.05rem; }
video::cue { background: rgba(0, 0, 0, 0.6); }

/* Audio y subtítulos: botón bien visible y panel con opciones grandes (dedo o control remoto). */
.track-selects { display: none; }
.btn-tracks { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.sheet {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(5, 8, 16, 0.6);
}
.sheet-inner {
  width: min(100%, 46rem);
  max-height: 85%;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: 1rem 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.sheet-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; }
.sheet-col h3 { margin: 0 0 0.5rem; font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.options { display: flex; flex-direction: column; gap: 0.35rem; }
.option {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  cursor: pointer;
}
.option:hover { background: var(--surface-2); }
.option[aria-checked="true"] { border-color: var(--accent); background: var(--surface-2); font-weight: 600; }
.option[aria-checked="true"]::before { content: "✓ "; color: var(--accent); }

.toast {
  position: absolute;
  top: 3.75rem; /* debajo de la barra superpuesta */
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 2rem);
  padding: 0.6rem 1rem;
  background: rgba(22, 30, 51, 0.95);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.9rem;
  text-align: center;
  z-index: 5;
}

.toast-action {
  margin-left: 0.75rem;
  background: none;
  border: 0;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
  padding: 0.1rem 0.2rem;
}

/* Siguiente episodio. Antes del final, un botón chico y translúcido arriba a la derecha (abajo
   están los controles y los subtítulos); al terminar, una tarjeta chica. */
.next-hint {
  position: absolute;
  bottom: 4.5rem; /* arriba de los controles nativos */
  right: 0.75rem;
  z-index: 3;
  transition: opacity 0.25s ease;
  padding: 0.35rem 0.8rem;
  background: rgba(14, 20, 36, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--text);
  backdrop-filter: blur(4px);
}
.next-hint:hover, .next-hint:focus-visible { background: rgba(14, 20, 36, 0.85); border-color: var(--accent); }
.next-card {
  position: absolute;
  bottom: 4.5rem;
  right: 0.75rem;
  z-index: 5;
  max-width: min(16rem, calc(100% - 1.5rem));
  padding: 0.55rem 0.7rem;
  background: rgba(22, 30, 51, 0.9);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.85rem;
}
.next-label { color: var(--accent); font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.next-title { font-weight: 600; margin: 0.15rem 0 0.45rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.next-actions { display: flex; gap: 0.4rem; }

.sync-box { margin-top: 0.6rem; padding: 0 0.8rem; }
.sync-box .hint { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.78rem; }

/* Cómo instalar la app en el iPhone (no hay aviso automático como en Android). */
.ios-install {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(22rem, calc(100% - 2rem));
  padding: 0.9rem 1rem;
  background: rgba(22, 30, 51, 0.97);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.9rem;
  z-index: 20;
}
.ios-install p { margin: 0 0 0.4rem; }
.ios-install ol { margin: 0 0 0.7rem; padding-left: 1.2rem; }
.ios-install li { margin: 0.2rem 0; }

/* Interruptor del panel de opciones. */
.toggle { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0.8rem; cursor: pointer; }
.toggle input { width: 1.2rem; height: 1.2rem; accent-color: var(--accent); }

/* Celular apaisado: la barra se achica para dejarle alto al video. */
@media (orientation: landscape) and (max-height: 500px) {
  .player-bar { padding: 0.25rem 0.75rem 0.9rem; gap: 0.4rem 0.6rem; }
  .player-bar .btn-small { padding: 0.2rem 0.55rem; font-size: 0.8rem; }
  .player-bar .title { font-size: 0.9rem; }
  google-cast-launcher { width: 1.8rem; height: 1.8rem; padding: 0.2rem; }
}

/* ---- Admin ---- */
.status-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 0.75rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.8rem 1rem; }
.stat-value { font-size: 1.15rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }
.subhead { font-size: 0.9rem; color: var(--muted); margin: 1.1rem 0 0.4rem; }
.muted { color: var(--muted); }
.line { padding: 0.35rem 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.job-line { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
td.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

@media (max-width: 600px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
  .media-row { grid-auto-columns: 72%; }
  .media-row.compact { grid-auto-columns: 52%; }
  .video-row .thumb { width: 112px; }
  main { padding: 0.75rem; }
  .topbar { flex-wrap: wrap; gap: 0.6rem; }
  .topbar .search { order: 5; flex-basis: 100%; max-width: none; }
  .topbar .logo { margin-right: auto; }
  .topbar .logo span { font-size: 1.1rem; }
  .topbar .user { display: none; }
  .player-bar label { flex: 1; min-width: 0; }
  .player-bar select { flex: 1; max-width: none; width: 100%; }
}

/* Pantallas grandes vistas de lejos (tele). */
@media (min-width: 1800px) {
  html { font-size: 20px; }
}
