/* Estilos mínimos, pensados primero para móvil (la familia usará esto
   sobre todo desde el móvil, ver docs/PROMPT.md). */

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e0e0e0;
  --accent: #2f6fed;
  --accent-fg: #ffffff;
  --card-bg: #f7f7f8;
  --error: #c0392b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --fg: #f0f0f0;
    --muted: #a0a0a0;
    --border: #2e2e2e;
    --card-bg: #1e1e1e;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 12px calc(80px + env(safe-area-inset-bottom)) 12px;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

[x-cloak] {
  display: none !important;
}

button {
  font: inherit;
}

/* --- Login --- */

.login-page {
  max-width: 420px;
  margin: 10vh auto 0 auto;
  text-align: center;
}

.login-page .hint {
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.user-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-btn {
  width: 100%;
  padding: 14px;
  font-size: 1.1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  color: var(--fg);
  cursor: pointer;
}

.user-btn:active {
  background: var(--accent);
  color: var(--accent-fg);
}

/* Login con contraseña (acceso externo por el VPS, Fase 9). */
.password-login {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.password-login label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
}

.password-login input {
  font: inherit;
  /* 16px como mínimo: en iOS, menos hace zoom al tocar el campo. */
  font-size: 1.05rem;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  color: var(--fg);
}

.password-login button {
  padding: 14px;
  font-size: 1.1rem;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
}

.password-login button:disabled {
  opacity: 0.6;
}

.error {
  color: var(--error);
  margin-top: 1rem;
}

/* --- Barra superior --- */

.topbar {
  position: sticky;
  top: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  z-index: 5;
}

.topbar h1 {
  font-size: 1.2rem;
  margin: 0;
}

.user-info {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-size: inherit;
}

/* --- Controles de búsqueda --- */

.controls {
  position: sticky;
  top: 49px;
  background: var(--bg);
  padding: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 4;
  border-bottom: 1px solid var(--border);
}

#q {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--fg);
}

.kind-filter {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 0.95rem;
}

.kind-filter label {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* --- Resultados --- */

.results {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
}

.loading,
.empty {
  color: var(--muted);
  text-align: center;
  padding: 2rem 0;
}

.notice-approx {
  color: var(--muted);
  text-align: center;
  padding: 0.5rem 0 1rem;
}

.item {
  display: flex;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  cursor: pointer;
  position: relative;
}

.item.selected {
  outline: 2px solid var(--accent);
}

.thumb {
  flex: 0 0 84px;
  height: 84px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-placeholder {
  font-size: 2rem;
}

/* Historial y listado principal: cuando la miniatura es una carátula de
   TMDB (más alta que ancha) en vez del recorte cuadrado de una miniatura
   de Telegram. */
.thumb-poster {
  flex-basis: 56px;
  width: 56px;
}

/* Listado principal: carátula propuesta automáticamente (todavía sin
   confirmar en /confirm, puede equivocarse) — borde discontinuo sutil
   para no darle la misma confianza visual que una ya confirmada. */
.thumb-poster-guess {
  outline: 2px dashed var(--muted);
  outline-offset: 2px;
}

.info {
  flex: 1;
  min-width: 0;
}

.info .name {
  margin: 0 0 2px 0;
  font-weight: 600;
  word-break: break-word;
}

.info .caption {
  margin: 0 0 4px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.info .meta {
  margin: 0 0 6px 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.badges {
  margin: 0;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--border);
}

.badge-torrent {
  background: #f0d264;
  color: #453b00;
}

.badge-video {
  background: #bcdcff;
  color: #003a6b;
}

/* Resultado de Jackett (Fase 8, extra fuera del prompt original): distingue
   un torrent encontrado en un tracker público de uno del grupo de Telegram. */
.badge-external {
  background: #cdeccb;
  color: #0d4b0a;
}

.select-box {
  align-self: flex-start;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
}

.load-more {
  width: 100%;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: none;
  color: var(--accent);
  cursor: pointer;
}

/* --- Barra de selección --- */

.selection-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 12px calc(12px + env(safe-area-inset-left)) calc(12px + env(safe-area-inset-bottom))
    calc(12px + env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.selection-bar button {
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: inherit;
}

.selection-bar button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* --- Confirmación TMDB (Fase 4) --- */

.warning {
  background: #fff3cd;
  color: #664d03;
  border: 1px solid #ffe69c;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
}

@media (prefers-color-scheme: dark) {
  .warning {
    background: #4a3b00;
    color: #ffe69c;
    border-color: #6b5400;
  }
}

.confirm-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 16px;
  background: var(--card-bg);
}

.group-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.type-toggle {
  display: flex;
  gap: 16px;
}

.type-toggle label {
  display: flex;
  align-items: center;
  gap: 4px;
}

.group-header input[type="search"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
}

.tmdb-candidates {
  margin-bottom: 10px;
}

/* --- Candidato destacado (póster grande + sinopsis) --- */

.tmdb-featured {
  display: flex;
  gap: 14px;
  margin-bottom: 12px;
}

@media (max-width: 380px) {
  .tmdb-featured {
    flex-direction: column;
  }

  .tmdb-featured-poster {
    width: 120px;
    height: 180px;
  }
}

.tmdb-featured-poster {
  flex: 0 0 140px;
  width: 140px;
  height: 210px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--border);
}

.tmdb-featured-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tmdb-featured-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.tmdb-featured-year {
  font-weight: 400;
  color: var(--muted);
}

.tmdb-featured-overview {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  overflow-y: auto;
  max-height: 8.4em;
}

.tmdb-featured-badge {
  margin: auto 0 0 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
}

/* --- Miniaturas de las otras opciones --- */

.tmdb-thumbs-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 6px 0;
}

.tmdb-thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 10px;
}

.tmdb-thumb {
  flex: 0 0 auto;
  cursor: pointer;
  border-radius: 6px;
  border: 2px solid transparent;
  line-height: 0;
}

.tmdb-thumb.selected {
  border-color: var(--accent);
}

.tmdb-thumb input {
  display: none;
}

.tmdb-thumb img,
.poster-placeholder {
  width: 60px;
  height: 90px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--border);
}

.poster-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.tmdb-featured-poster.poster-placeholder {
  width: 140px;
  height: 210px;
  font-size: 2.5rem;
  border-radius: 8px;
}

.group-files-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 6px 0;
}

.group-files {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.group-file {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.9rem;
}

.group-file .file-name {
  flex: 1;
  min-width: 140px;
  word-break: break-word;
}

.group-file input[type="number"] {
  width: 60px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

.confirm-btn {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
}

.confirm-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.group-status {
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.2em;
}

/* --- Cola de descargas (Fase 5) --- */

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
}

.queue-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--card-bg);
}

.queue-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.queue-item-header strong {
  word-break: break-word;
}

.queue-item-file {
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-word;
  margin-bottom: 6px;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 4px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}

.queue-item-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.queue-item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.queue-item-added {
  font-size: 0.75rem;
  color: var(--muted);
}

.queue-item-actions {
  display: flex;
  gap: 8px;
}

.queue-item-actions button {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  font-size: 0.8rem;
}

.queue-item-actions .link-btn {
  font-size: 0.8rem;
}

/* --- Mapeo de archivos de un torrent (Fase 6) --- */

.torrent-file {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: var(--card-bg);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.torrent-file-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  cursor: pointer;
}

.torrent-file-name {
  flex: 1;
  min-width: 160px;
  word-break: break-word;
  font-size: 0.9rem;
}

.torrent-file-size {
  font-size: 0.8rem;
  color: var(--muted);
}

.torrent-file-episode {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  padding-left: 26px;
}

.torrent-file-episode input {
  width: 55px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

/* --- Admin (Fase 7) --- */

.admin-new-user {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin: 12px 0;
  background: var(--card-bg);
}

.admin-new-user h2 {
  margin-top: 0;
  font-size: 1rem;
}

.admin-new-user form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-new-user input,
.admin-new-user select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
}

.admin-new-user input {
  flex: 1;
  min-width: 140px;
}

.admin-new-user button {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
}

.quota-form,
.password-form {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.quota-input {
  width: 70px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.85rem;
}

.password-input {
  flex: 1 1 160px;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
}

.quota-form button,
.password-form button {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  font-size: 0.8rem;
}
