/*
 * Paleta en oklch: los canales L (claridad), C (croma) y H (tono) se pueden
 * ajustar por separado. Para un tema oscuro con acento verde, la version clara
 * solo tiene que bajar L y subir C un poco; con hex habria que recalcular cada
 * color a mano.
 *
 * El tema se selecciona con [data-theme] en <html>, no con prefers-color-scheme
 * directamente, porque theme.js escribe la preferencia en localStorage y la
 * aplica antes del primer paint. El media query queda como default para cuando
 * no hay JS.
 */
:root {
  color-scheme: dark;

  --bg: oklch(17% 0.014 265);
  --panel: oklch(21% 0.017 265);
  --panel-2: oklch(25% 0.019 265);
  --panel-3: oklch(29% 0.021 265);
  --border: oklch(32% 0.021 265);
  --border-strong: oklch(42% 0.024 265);
  --text: oklch(93% 0.008 265);
  --muted: oklch(68% 0.017 265);
  --accent: oklch(78% 0.155 163);
  --accent-ink: oklch(20% 0.045 163);
  --accent-dim: oklch(78% 0.155 163 / 0.13);
  --danger: oklch(72% 0.16 25);
  --danger-dim: oklch(72% 0.16 25 / 0.12);
  --shadow: oklch(0% 0 0 / 0.5);
  --scrim: oklch(12% 0.01 265 / 0.75);
  --badge-bg: oklch(12% 0.01 265 / 0.7);
  --shimmer: oklch(100% 0 0 / 0.06);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  --ease: 0.16s cubic-bezier(0.2, 0, 0.2, 1);
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg: oklch(98.5% 0.003 265);
  --panel: oklch(100% 0 0);
  --panel-2: oklch(96.5% 0.005 265);
  --panel-3: oklch(93.5% 0.007 265);
  --border: oklch(90% 0.008 265);
  --border-strong: oklch(80% 0.012 265);
  --text: oklch(24% 0.015 265);
  --muted: oklch(52% 0.017 265);
  --accent: oklch(58% 0.14 163);
  --accent-ink: oklch(99% 0 0);
  --accent-dim: oklch(58% 0.14 163 / 0.1);
  --danger: oklch(56% 0.19 25);
  --danger-dim: oklch(56% 0.19 25 / 0.09);
  --shadow: oklch(40% 0.02 265 / 0.14);
  --scrim: oklch(30% 0.02 265 / 0.45);
  --badge-bg: oklch(20% 0.02 265 / 0.72);
  --shimmer: oklch(30% 0.02 265 / 0.05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 48px 24px;
  margin: 0;
}

/* ---------------- Login ---------------- */

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(60rem 40rem at 50% -10%, var(--panel-2), transparent 70%),
    var(--bg);
}

.login-wrap { width: 100%; }

.login-card {
  max-width: 380px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  display: grid;
  gap: 18px;
  box-shadow: 0 24px 60px -24px var(--shadow);
}

.login-head { display: grid; gap: 4px; margin-bottom: 2px; }

.login-title { margin: 0; font-size: 24px; letter-spacing: -0.4px; }
.login-sub { margin: 0; color: var(--muted); font-size: 13px; }

.field { display: grid; gap: 6px; }
.field span { color: var(--muted); font-size: 13px; font-weight: 500; }

input, select, button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color var(--ease), background var(--ease);
}

input::placeholder { color: var(--muted); opacity: 0.7; }

input:hover, select:hover { border-color: var(--border-strong); }

input:focus-visible, select:focus-visible, button:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-color: var(--accent);
}

.field input[aria-invalid="true"] {
  border-color: var(--danger);
  background: var(--danger-dim);
}
.field input[aria-invalid="true"]:focus-visible { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--danger); }

#submit {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
  cursor: pointer;
  padding: 11px 12px;
  transition: filter var(--ease), transform var(--ease);
}
#submit:hover:not(:disabled) { filter: brightness(1.08); }
#submit:active:not(:disabled) { transform: translateY(1px); }
#submit:disabled { opacity: 0.6; cursor: default; }

.login-msg { margin: 0; min-height: 18px; font-size: 13px; color: var(--muted); }
.login-msg[data-kind="error"] { color: var(--danger); }

/* ---------------- Topbar ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: color-mix(in oklch, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  backdrop-filter: blur(12px) saturate(140%);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; flex-direction: column; gap: 2px; }
.brand strong { letter-spacing: -0.3px; }

.stats {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* El buscador lleva el hint de "/" adentro, y se oculta al enfocarse. */
.search { position: relative; display: flex; align-items: center; }
.search input[type="search"] { min-width: 220px; padding-right: 30px; }
.search input[type="search"]::-webkit-search-cancel-button { filter: invert(0.6); cursor: pointer; }

.search-hint {
  position: absolute;
  right: 8px;
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 5px;
  pointer-events: none;
  transition: opacity var(--ease);
}
.search:focus-within .search-hint { opacity: 0; }

select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%238b94a7' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
  cursor: pointer;
}

button.ghost,
a.ghost {
  background: transparent;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease);
}
button.ghost:hover,
a.ghost:hover { background: var(--panel-2); border-color: var(--border-strong); }

button.icon { padding: 8px; width: 38px; display: grid; place-items: center; }

/* Icono de sol/luna dibujado con dos circulos y un cono, en CSS puro para no
   sumar un request ni un SVG inline (la CSP los bloquearia igual). */
.theme-icon { width: 16px; height: 16px; border-radius: 50%; position: relative; display: block; }
.theme-icon::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--text);
}
.theme-icon::after {
  content: "";
  position: absolute;
  inset: -3px -3px 5px 3px;
  border-radius: 50%;
  background: var(--panel);
  transition: transform var(--ease);
}
:root[data-theme="light"] .theme-icon::before {
  background: transparent;
  box-shadow: 0 0 0 2px var(--text);
}
:root[data-theme="light"] .theme-icon::after { transform: translateY(4px) scale(0.6); }

/* ---------------- Tabs ---------------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 12px 20px 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tabs button {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  padding: 8px 16px;
  cursor: pointer;
  color: var(--muted);
  white-space: nowrap;
  transition: color var(--ease), background var(--ease), border-color var(--ease);
}
.tabs button:hover { color: var(--text); background: color-mix(in oklch, var(--panel) 50%, transparent); }
.tabs button.active {
  color: var(--text);
  background: var(--panel);
  border-color: var(--border);
  font-weight: 500;
}
.tabs button:focus-visible { box-shadow: inset var(--ring); }

/* Transicion de cross-fade al cambiar de tab o de busqueda. El nombre va en el
   elemento que sobrevive entre estados (la grilla), no en las cards: nombrar
   cada card las sacaria a todas del snapshot y la animacion se veria como un
   borrón. Se degrada sola si el browser no soporta View Transitions. */
@media (prefers-reduced-motion: no-preference) {
  .grid { view-transition-name: grid; }

  /* El selector con * requiere Chrome 125+. Donde no exista la regla se
     descarta y queda el cross-fade por defecto, que tambien anda bien. */
  ::view-transition-old(*),
  ::view-transition-new(*) { animation-duration: 0.18s; }
}

.notice {
  margin: 12px 20px 0;
  padding: 10px 14px;
  background: var(--accent-dim);
  border: 1px solid color-mix(in oklch, var(--accent) 30%, transparent);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
}
.notice[data-kind="error"] {
  background: var(--danger-dim);
  border-color: color-mix(in oklch, var(--danger) 35%, transparent);
  color: var(--danger);
}

/* ---------------- Grilla ---------------- */

main { padding: 20px; }

/* Contador de elementos arriba de la grilla. Scoped a `main` a proposito: hay
   otra regla .stats global mas arriba que es del topbar viejo, y sin el scope
   esta le pisaria el margen. */
main .stats {
  margin: 0 0 12px;
  font-size: 13px;
}

/* Barra del catalogo: pestañas (Movies/Series/Anime/Episodes) a la izquierda,
   busqueda y orden a la derecha. Vive aca y no en el navbar porque solo aplica
   a las vistas de catalogo. */
.catalog-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 10px;
}

.catalog-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
}

/* Control segmentado: las cuatro vistas en una pastilla, la activa resaltada. */
.catalog-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  overflow-x: auto;
  scrollbar-width: none;
}
.catalog-tabs::-webkit-scrollbar { display: none; }

.catalog-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 16px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--ease), background var(--ease);
}
.catalog-tab:hover { color: var(--text); background: var(--panel-3); }
.catalog-tab.active { color: var(--accent); background: var(--accent-dim); font-weight: 600; }
.catalog-tab:focus-visible { outline: none; box-shadow: var(--ring); }

/* Header row: type tabs (left) + search/sort (right) */
.catalog-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.catalog-type-nav {
  display: inline-flex;
  gap: 4px;
  flex-shrink: 0;
}

.catalog-type-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  transition: color var(--ease), background var(--ease);
}
.catalog-type-tab i { font-size: 12px; }
.catalog-type-tab:hover { color: var(--text); background: var(--panel-2); }
.catalog-type-tab.active { color: var(--accent); background: var(--accent-dim); font-weight: 600; }
.catalog-type-tab:focus-visible { outline: none; box-shadow: var(--ring); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px 16px;
}

.grid[aria-busy="true"] { opacity: 0.55; transition: opacity var(--ease); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  color: inherit;
  font: inherit;
  transition: transform var(--ease), border-color var(--ease), box-shadow var(--ease);
}
.card:hover, .card:focus-visible {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 14px 28px -14px var(--shadow);
  outline: none;
}
.card:focus-visible { box-shadow: var(--ring), 0 14px 28px -14px var(--shadow); }

.poster {
  position: relative;
  aspect-ratio: 2 / 3;
  background: var(--panel-2);
  overflow: hidden;
}
.poster.small { width: 56px; border-radius: 6px; overflow: hidden; flex: none; }

.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Overlay con el titulo: en cards de 150px el .card-title ya esta, asi que
   esto solo aparece en pantallas grandes o con teclado. Se oculta por
   defecto y aparece en hover/focus. */
.card-overlay {
  position: absolute;
  inset: auto 0 0 0;
  padding: 26px 10px 10px;
  background: linear-gradient(to top, var(--scrim), transparent);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--ease), transform var(--ease);
  pointer-events: none;
}
.card:hover .card-overlay, .card:focus-visible .card-overlay {
  opacity: 1;
  transform: translateY(0);
}

.no-poster {
  width: 100%;
  height: 100%;
  background:
    radial-gradient(120% 80% at 50% 0%, var(--panel-3), transparent 70%),
    linear-gradient(160deg, var(--panel-2), var(--panel));
}
.no-poster.thumb { width: 90px; height: 135px; border-radius: var(--radius-sm); }

.badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  max-width: calc(100% - 12px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--badge-bg);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  color: var(--text);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  transition: opacity var(--ease);
}
/* El overlay y el badge se pisan: en hover solo se ve el titulo. */
.card:hover .badge, .card:focus-visible .badge { opacity: 0; }

/* Boton "+" (agregar a playlist) de cada card del catalogo, y su espejo "x"
 * (quitar) en la grilla de detalle de una playlist — mismo estilo circular
 * arriba a la derecha, para no competir con el badge (abajo a la izquierda)
 * ni con el overlay del titulo (abajo, en hover). z-index porque el overlay
 * tambien ocupa esa esquina al crecer en hover. */
.card-add-btn, .card-remove-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 1;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: var(--badge-bg);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background var(--ease), transform var(--ease);
}
.card-add-btn:hover, .card-remove-btn:hover { background: var(--accent); color: var(--accent-ink); }
.card-add-btn:active, .card-remove-btn:active { transform: scale(0.92); }
.card-add-btn:focus-visible, .card-remove-btn:focus-visible { outline: none; box-shadow: var(--ring); }

.card-title {
  padding: 10px 10px 2px;
  font-size: 14px;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  min-height: 2.6em;
}

.card-meta {
  padding: 0 10px 10px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sentinel { height: 1px; }

/* ---------------- Skeletons ---------------- */

.skeleton { pointer-events: none; }
.skeleton .poster, .skeleton .line { background: var(--panel-2); }
.skeleton .line { height: 12px; border-radius: 4px; margin: 10px 10px 0; }
.skeleton .line:last-child { width: 55%; margin-bottom: 12px; }
.skeleton .poster::after, .skeleton .line::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--shimmer), transparent);
  animation: shimmer 1.4s infinite;
}
.skeleton .line { position: relative; overflow: hidden; }
.skeleton .poster { position: relative; overflow: hidden; }

@keyframes shimmer { 100% { transform: translateX(100%); } }

/* ---------------- Preview del addon de Stremio (pagina /stremio) ---------------- */

/* Hermana del .pw-box, no hija: comparte el ancho con la grilla de /movies
   (ver stremio.ejs). Replica el ritmo vertical que daba el gap del .pw-box,
   sin su padding. minmax(0,1fr) para que la grilla anidada mida contra el
   ancho real del contenedor y no contra su max-content. */
.stremio-preview {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.stremio-preview-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stremio-preview-tab {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}

.stremio-preview-tab:hover { border-color: var(--border-strong); }

.stremio-preview-tab.active {
  background: var(--accent);
  color: var(--accent-contrast, #fff);
  border-color: transparent;
}

/* Sin max-height ni scroll propio: una card de esta grilla mide ~300px de
   alto (poster 2/3 + titulo + meta), asi que un cajon de 360px mostraba una
   fila y cortaba la siguiente al medio. Fluye como la grilla de /movies y
   scrollea la pagina. min-height reserva el lugar mientras carga. */
.stremio-preview-grid {
  min-height: 80px;
}

/* Cards de preview: mismo look que la grilla principal, pero sin la
   interaccion (no abren el modal de detalle — un meta de Stremio no trae el
   shape completo de un item del catalogo, solo id/name/poster/releaseInfo). */
.stremio-preview-grid .card { cursor: default; }

/* Spinner de los botones de Sync mientras un job esta corriendo. */
@keyframes spin { to { transform: rotate(360deg); } }
.spin-icon {
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

/* ---------------- Modal ---------------- */

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  padding: 0;
  max-width: 760px;
  width: calc(100% - 32px);
  max-height: 84vh;
  box-shadow: 0 30px 80px -20px var(--shadow);
}
.modal::backdrop { background: var(--scrim); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }

/* El dialog es una columna: la barra queda fija arriba y solo el cuerpo
   scrollea, asi los botones nunca tapan contenido. */
.modal[open] { display: flex; flex-direction: column; overflow: hidden; }
.modal-body {
  padding: 4px 24px 24px;
  display: grid;
  align-content: start;
  gap: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1;
  min-height: 0;
}

/* Barra del modal: volver a la izquierda (con el nombre del nivel al que
   vuelve) y cerrar a la derecha. 40px de alto: target tactil comodo. */
.modal-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 6px;
  flex: none;
}

.modal-back,
.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 40px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
}
.modal-back:hover,
.modal-close:hover { background: var(--panel-2); border-color: var(--border); color: var(--text); }
.modal-back:focus-visible,
.modal-close:focus-visible { outline: none; box-shadow: var(--ring); color: var(--text); }
.modal-back:active,
.modal-close:active { transform: scale(0.96); }

.modal-back { padding: 0 14px 0 8px; max-width: 70%; }
.modal-back[hidden] { display: none; }
.modal-back span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* margin-left:auto para que quede a la derecha aunque volver este oculto. */
.modal-close { width: 40px; padding: 0; margin-left: auto; }

.detail-head { display: flex; gap: 16px; align-items: flex-start; }
.detail-head img, .detail-head .no-poster { width: 90px; aspect-ratio: 2 / 3; border-radius: var(--radius-sm); flex: none; }
.detail-head h2 { margin: 0 0 4px; font-size: 18px; overflow-wrap: anywhere; }

.detail-row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
}
.detail-row .card-title, .detail-row .card-meta { padding: 0 0 2px; min-height: 0; }
.detail-row .card-title { -webkit-line-clamp: 1; line-clamp: 1; }


/* T drill-down: temporadas -> episodios -> fuentes */
.drill-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  margin-top: 4px;
}

/* Episodios: lista vertical de una columna, tipo indice. Un grid de tiles
   obliga a saltar la vista entre columnas para leer E01 -> E50; en una sola
   columna el recorrido es de arriba hacia abajo. Las temporadas, que son pocas,
   siguen en grid porque ahi el grid ocupa menos alto. */
.ep-list { display: grid; gap: 2px; margin-top: 4px; }

.ep-tile {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease);
}
.ep-tile:hover { background: var(--panel-3); border-color: var(--border-strong); }
.ep-tile:focus-visible { outline: none; box-shadow: var(--ring); }

.ep-kicker {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.ep-body { display: grid; gap: 4px; min-width: 0; }
.ep-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ep-meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.ep-badges { display: flex; flex-wrap: wrap; gap: 4px; }

.drill-tile {
  display: grid;
  gap: 3px;
  align-content: start;
  text-align: left;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease);
}
.drill-tile:hover { background: var(--panel-3); border-color: var(--border-strong); }
.drill-tile:focus-visible { outline: none; box-shadow: var(--ring); }

.drill-kicker {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
}
.drill-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.drill-meta { font-size: 12px; color: var(--muted); }

.drill-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.badge-chip {
  font-size: 11px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
  background: var(--panel-3);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;}

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .tabs { padding: 10px 12px 0; }
  .notice { margin: 10px 12px 0; }
  main { padding: 12px; }
  .tools { width: 100%; }
  .search { flex: 1 1 100%; }
  .search input[type="search"] { min-width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; }
  .card-overlay { display: none; }
  /* Sin una columna para el contador, este baja debajo del titulo. */
  .ep-tile { grid-template-columns: 40px minmax(0, 1fr); }
  .ep-meta { grid-column: 2; }

  /* Barra del catalogo en phone: pestañas a todo el ancho, debajo busqueda y
     orden en una sola fila, y el contador como linea secundaria. */
  .catalog-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 12px;
  }
  .catalog-tools {
    flex: none;
    gap: 8px;
  }
  .catalog-tools .catalog-search { flex: 1; min-width: 0; max-width: none; }
  /* 16px evita que iOS haga zoom al enfocar; 44px es el target tactil minimo. */
  .catalog-tools .catalog-search input,
  .catalog-tools select {
    font-size: 16px;
    min-height: 44px;
  }
  .catalog-tools select { flex: none; max-width: 42%; }
  .catalog-tabs { width: 100%; }
  .catalog-tab { flex: 1; min-height: 40px; padding: 0 10px; }
  main .stats { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------------------------------------------------------------- */
/* Descargas                                                        */
/* ---------------------------------------------------------------- */

/* El boton de descarga vive al final de la fila de fuente, no pegado al
   texto: el click tiene que caer en un blanco comodo y no sobre el titulo,
   que es lo que el usuario todavia esta leyendo. */
.dl-btn {
  align-self: center;
  flex: 0 0 auto;
  margin-left: auto;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.8125rem;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.dl-btn:hover { background: var(--panel-3); border-color: var(--accent); }
.dl-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* En la lista de fuentes es la accion principal del modal: va rellena. */
.dl-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  padding: 10px 16px;
}
.dl-btn.primary:hover { background: var(--accent); filter: brightness(1.08); }

/* Servidor sin conexion directa en este momento: no hay URL de descarga. */
.dl-btn.disabled {
  color: var(--muted);
  cursor: default;
  font-size: 0.8125rem;
  white-space: nowrap;
  text-align: center;
}

/* ---------------- Modal: fuentes de un episodio / versiones ---------------- */

.detail-text { min-width: 0; }
.detail-kicker {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.src-list { display: grid; gap: 8px; margin-top: 4px; }

.src-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  transition: border-color var(--ease);
}
.src-row:hover { border-color: var(--border-strong); }

.src-info { display: grid; gap: 6px; min-width: 0; flex: 1; }
.src-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.src-provider {
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text);
  background: var(--panel-3);
}
/* Color fijo por proveedor, para reconocerlo de un vistazo entre filas. */
.src-provider[data-provider="jellyfin"] {
  background: color-mix(in oklch, oklch(62% 0.17 300) 22%, var(--panel-2));
  border-color: color-mix(in oklch, oklch(62% 0.17 300) 55%, transparent);
}
.src-provider[data-provider="plex"] {
  background: color-mix(in oklch, oklch(78% 0.15 80) 22%, var(--panel-2));
  border-color: color-mix(in oklch, oklch(78% 0.15 80) 55%, transparent);
}

.src-file {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text);
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.src-meta { font-size: 12px; color: var(--muted); }

@media (max-width: 640px) {
  .modal-body { padding: 4px 14px 16px; }
  .modal-bar { padding: 8px 8px 6px; }
  .detail-head img, .detail-head .no-poster, .detail-head .poster.small { width: 64px; }
  /* En phone el boton baja a su propia linea a todo el ancho: target tactil
     grande y el nombre de archivo no queda apretado. */
  .src-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .src-row .dl-btn.primary { margin-left: 0; text-align: center; padding: 12px 16px; font-size: 15px; }
  .src-file { white-space: normal; overflow-wrap: anywhere; }
}

.dl-wrap { position: relative; }

.dl-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  width: min(340px, calc(100vw - 32px));
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 12px 32px rgb(0 0 0 / 28%);
}

/* El panel no gestiona el archivo: lo baja el browser. Decirlo evita que el
   usuario busque un boton de pausa aca que no existe. */
.dl-hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

.dl-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }

.dl-row {
  display: grid;
  gap: 2px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.dl-row:first-child { padding-top: 0; border-top: 0; }

.dl-name {
  color: var(--text);
  font-size: 0.8125rem;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.dl-name:hover { color: var(--accent); text-decoration: underline; }
.dl-meta { color: var(--muted); font-size: 0.75rem; }

/* ---------------- Sidebar ---------------- */

:root {
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 64px;
}

.main-content {
  margin-left: var(--sidebar-w);
  transition: margin-left var(--ease);
}

body.sidebar-collapsed .main-content { margin-left: var(--sidebar-w-collapsed); }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  z-index: 50;
  transition: width var(--ease);
  overflow: hidden;
}

body.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .sidebar-link-label,
body.sidebar-collapsed .sidebar-brand-text,
body.sidebar-collapsed .sidebar-dropdown-toggle .sidebar-link-label,
body.sidebar-collapsed .sidebar-theme-toggle .sidebar-link-label { display: none; }
body.sidebar-collapsed .sidebar-collapse-toggle i { transform: rotate(180deg); }
body.sidebar-collapsed .sidebar-header { justify-content: center; }
body.sidebar-collapsed .sidebar-header .sidebar-brand { display: none; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  flex-shrink: 0;
}

.sidebar-collapse-toggle {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--ease), color var(--ease);
}
.sidebar-collapse-toggle:hover { background: var(--panel-2); color: var(--text); }
.sidebar-collapse-toggle i { transition: transform var(--ease); }
.sidebar-collapse-toggle:focus-visible { outline: none; box-shadow: var(--ring); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  overflow: hidden;
  flex-shrink: 0;
}
.sidebar-brand strong { color: var(--accent); white-space: nowrap; font-size: 1.05rem; }
.sidebar-brand-mark { color: var(--accent); font-weight: 700; font-size: 1.1rem; flex-shrink: 0; }
.sidebar-brand-text { white-space: nowrap; }

.sidebar-mobile-close { display: none; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-group {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-group-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 4px;
}

/* Secciones del menu (Explorar, Mi servidor, Sistema). Contraido, el titulo
   se vuelve una linea corta: sigue marcando donde empieza cada grupo. */
.sidebar-section + .sidebar-section { margin-top: 14px; }
.sidebar-section-label {
  margin: 0 0 4px;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.sidebar-collapsed .sidebar-section-label {
  height: 1px;
  margin: 0 10px 8px;
  padding: 0;
  background: var(--border);
  color: transparent;
  opacity: 1;
}
body.sidebar-collapsed .sidebar-section:first-child .sidebar-section-label { display: none; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  transition: color 0.15s ease, background 0.15s ease;
}
.sidebar-link:hover { color: var(--text); background: var(--panel-2); }
.sidebar-link { position: relative; }
.sidebar-link.active { color: var(--accent); background: var(--accent-dim); }
/* Barrita a la izquierda del activo: se ve tambien con el menu contraido. */
.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.sidebar-link.active:hover { color: var(--accent); }

.sidebar-link-icon {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  font-size: 1rem;
}

.sidebar-link-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.sidebar-theme-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  width: 100%;
  text-align: left;
  transition: color 0.15s ease, background 0.15s ease;
}
.sidebar-theme-toggle:hover { background: var(--panel-2); color: var(--text); }
.sidebar-theme-toggle:focus-visible { outline: none; box-shadow: var(--ring); }
.sidebar-theme-toggle .theme-icon { flex-shrink: 0; }

.sidebar-dropdown { position: relative; }

.sidebar-dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-align: left;
  transition: color 0.15s ease, background 0.15s ease;
}
.sidebar-dropdown-toggle:hover { background: var(--panel-2); color: var(--text); }
.sidebar-dropdown-toggle:focus-visible { outline: none; box-shadow: var(--ring); }

.sidebar-dropdown-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 8px;
  right: 8px;
  z-index: 60;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgb(0 0 0 / 28%);
  list-style: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}
.sidebar-dropdown-toggle[aria-expanded="true"] + .sidebar-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

body.sidebar-collapsed .sidebar-dropdown-menu {
  left: calc(var(--sidebar-w-collapsed) + 8px);
  right: auto;
  width: 220px;
  bottom: 8px;
}

.sidebar-dropdown-label {
  display: block;
  padding: 6px 12px;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: default;
}

.sidebar-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s ease;
}
.sidebar-dropdown-item:hover { background: var(--panel-2); }
.sidebar-dropdown-item.danger:hover { background: var(--danger-dim); color: var(--danger); }

.sidebar-divider-menu {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
  border: none;
}

.sidebar-mobile-bar {
  display: none;
}

.sidebar-scrim {
  display: none;
}

.catalog-search {
  position: relative;
  flex: 1;
  max-width: 320px;
  min-width: 180px;
}

.catalog-search input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.catalog-search input::placeholder { color: var(--muted); opacity: 0.7; }
.catalog-search input:hover { border-color: var(--border-strong); }
.catalog-search input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.catalog-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

@media (max-width: 768px) {
  .sidebar-mobile-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    position: sticky;
    top: 0;
    z-index: 55;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
  }

  .sidebar-mobile-toggle {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
  }
  .sidebar-mobile-toggle:hover { background: var(--panel-2); }

  .sidebar-mobile-bar .sidebar-brand { font-size: 1rem; }
  .sidebar-mobile-bar .sidebar-brand strong { color: var(--accent); }

  .sidebar {
    width: 260px;
    transform: translateX(-100%);
    transition: transform var(--ease);
    z-index: 70;
  }
  body.sidebar-mobile-open .sidebar { transform: translateX(0); }

  body.sidebar-collapsed .sidebar { width: 260px; }
  body.sidebar-collapsed .sidebar-link-label,
  body.sidebar-collapsed .sidebar-brand-text,
  body.sidebar-collapsed .sidebar-dropdown-toggle .sidebar-link-label,
  body.sidebar-collapsed .sidebar-theme-toggle .sidebar-link-label { display: inline; }
  body.sidebar-collapsed .sidebar-collapse-toggle i { transform: none; }
  body.sidebar-collapsed .sidebar-section-label {
    height: auto;
    margin: 0 0 4px;
    padding: 0 12px;
    background: none;
    color: var(--muted);
    opacity: 0.75;
  }
  body.sidebar-collapsed .sidebar-section:first-child .sidebar-section-label { display: block; }

  .sidebar-collapse-toggle { display: none; }

  .sidebar-mobile-close {
    display: grid;
    place-items: center;
    margin-left: auto;
    width: 28px;
    height: 28px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--muted);
    cursor: pointer;
    flex-shrink: 0;
  }
  .sidebar-mobile-close:hover { background: var(--panel-2); color: var(--text); }

  .main-content { margin-left: 0; }

  .sidebar-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--scrim);
    z-index: 65;
  }
  body.sidebar-mobile-open .sidebar-scrim { display: block; }
}

/* ---------------- Admin ---------------- */

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

.admin-badge {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid color-mix(in oklch, var(--accent) 30%, transparent);
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 2px 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.admin-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-main { padding: 20px; }

.admin-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.admin-head { display: grid; gap: 6px; margin-bottom: 18px; }

.admin-head h1 { margin: 0; font-size: 22px; letter-spacing: -0.3px; }

.admin-sub {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.admin-sub code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.85em;
}

.admin-form { display: grid; gap: 12px; margin-bottom: 24px; }

/* El form de crear usuario: campo + boton en una fila en vez de apilados,
   que es lo que hacia .admin-form a secas (pensado para formularios de un
   solo campo apilable, como el de reset). */
.admin-form-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 10px;
}
.admin-form-row .field { flex: 1 1 220px; }
.admin-form-row button { flex: none; }

.field-hint { color: var(--muted); font-size: 12px; }

/* Input con icono adelante, mismo patron que .catalog-search. Generico (lo
   usan el campo de usuario y el buscador de la tabla), por eso no lleva
   ningun ancho fijo — eso lo decide el contenedor. */
.input-icon { position: relative; display: flex; }
.input-icon svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.input-icon input { width: 100%; padding-left: 34px; }
.input-icon:focus-within svg { color: var(--accent); }

.users-filter-wrap { min-width: 200px; }

.admin-msg { margin: 0; min-height: 18px; font-size: 13px; color: var(--muted); }
.admin-msg[data-kind="error"] { color: var(--danger); }
.admin-msg[data-kind="success"] { color: color-mix(in oklch, var(--accent) 70%, var(--text)); }

/* --- Vista /admin: tabla de usuarios --------------------------------- */

.users-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 20px 0 12px;
}

/* En phone la tabla scrollea dentro de su caja en vez de desbordar la pagina
   (mismo patron que .lib-table-wrap y .snap-table-wrap). */
.users-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.users-table-wrap table tbody tr:last-child td { border-bottom: 0; }

.users-by { color: var(--muted); font-size: 0.85em; }

/* Gap explicito entre Resetear y Borrar: antes dependian del espacio en
   blanco que quedaba entre los dos <button> en el markup. Un div adentro del
   td, no el td mismo: display:flex en un <td> lo saca del layout de tabla y
   puede desalinear el ancho de la columna contra el resto de las filas. */
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
/* Boton con icono (ver playlists.js): alinea el svg con el texto igual que
   button.primary ya hace — sin esto quedan pegados sin separacion. */
.row-actions .ghost { display: inline-flex; align-items: center; gap: 5px; }

/* --- Vista /library ------------------------------------------------- */

.lib-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

/* El resumen va a la izquierda y crece; los botones no se estiran con el texto
   largo que aparece cuando estan marcadas todas las librerias. */
.lib-toolbar .admin-msg { flex: 1 1 220px; }

.lib-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.lib-actions button { white-space: nowrap; }

.admin-table .lib-check {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

.admin-table .lib-check:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

/* Fila de una libreria que no se puede sincronizar: se ve, pero apagada, para
   que el admin sepa que existe y que la decision fue "no esta". */
.admin-table tr.lib-off td {
  color: var(--muted);
  opacity: 0.7;
}

/* Columna "Servidor" de la tabla de Plex: propio/compartido y su estado. */
.lib-own { color: var(--muted); font-size: 0.85em; }
.lib-kind { padding: 4px 28px 4px 8px; font-size: 0.9em; min-width: 0; width: auto; }
.lib-off-badge,
.lib-relay-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.75em;
  white-space: nowrap;
}
.lib-off-badge { background: color-mix(in oklch, var(--danger) 18%, transparent); color: var(--danger); }
.lib-relay-badge { background: var(--panel-3); color: var(--muted); }

.admin-table td:nth-child(4) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.admin-table thead {
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.admin-table th,
.admin-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.admin-table tbody tr:hover { background: var(--panel-2); }

.admin-table tbody tr.loading td,
.admin-table tbody tr.empty td,
.admin-table tbody tr.error td {
  text-align: center;
  color: var(--muted);
  font-style: italic;
}

.admin-table tbody tr.error td { color: var(--danger); }

/* --- Vista /admin/snapshot ------------------------------------------ */

.snap-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.snap-card {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.snap-card-empty { color: var(--muted); font-size: 13px; }

.snap-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.snap-card-total { font-size: 13px; color: var(--muted); }
.snap-card-total strong { font-size: 20px; color: var(--text); font-variant-numeric: tabular-nums; }

.snap-card-list { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0; font-size: 13px; }
.snap-card-list div { display: flex; gap: 6px; }
.snap-card-list dt { color: var(--muted); }
.snap-card-list dd { margin: 0; }

.snap-card-counts { margin: 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.snap-card-last-by { margin: 0; font-size: 12px; color: var(--muted); }

.snap-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

/* Las pestañas de /movies son <a>; aca son <button> y hay que sacarles el
   chrome que les pone la regla global de button. */
button.catalog-tab,
button.catalog-type-tab { border: 0; background: transparent; font: inherit; font-size: 0.9rem; cursor: pointer; }

/* En phone la tabla scrollea dentro de su caja en vez de desbordar la pagina. */
.snap-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.snap-table { min-width: 760px; }
.snap-table tbody tr:last-child td { border-bottom: 0; }
.snap-table th.num,
.snap-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.snap-table td:first-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
.snap-kind {
  cursor: help;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
  border: 1px solid var(--border-strong);
  background: var(--panel-3);
}
/* Antes el tipo (rapido/completo) solo se veia como un emoji sin texto: solo
   se distinguian pasando el mouse por el title. Ahora llevan la palabra al
   lado, y el color es la misma logica que .snap-table .delta-up/.delta-down
   (completo = reescanea todo, es la operacion "grande"; se lo marca como tal). */
.snap-kind-incremental { color: color-mix(in oklch, var(--accent) 70%, var(--text)); border-color: color-mix(in oklch, var(--accent) 45%, var(--border-strong)); }
.snap-kind-full { color: var(--text); border-color: var(--border-strong); background: var(--panel-2); }

.snap-table .delta-up { color: color-mix(in oklch, var(--accent) 80%, var(--text)); font-weight: 600; }
.snap-table .delta-down { color: var(--danger); font-weight: 600; }
.snap-table .delta-zero,
.snap-table .delta-none { color: var(--muted); }
/* Cambio de cada columna, al lado del conteo (ver countCell en snapshot.js). */
.snap-delta {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 18px;
  background: var(--panel-3);
  border: 1px solid var(--border-strong);
}

@media (max-width: 640px) {
  .admin-card { padding: 16px; }
  .admin-main { padding: 12px; }
  .snap-toolbar .catalog-tabs { width: 100%; }
  .snap-toolbar .catalog-tab { flex: 1; min-height: 40px; }
  .admin-form-row { flex-direction: column; align-items: stretch; }
  .admin-form-row button { width: 100%; }
  .users-filter-wrap { min-width: 0; width: 100%; }
}

/* Resetear/Borrar de una fila: mismo tamaño para los dos (antes Resetear
   usaba el .ghost generico — mas grande, sin font-size propio — y quedaba
   visiblemente mas grande que Borrar al lado). Cada uno colorea distinto en
   hover/foco: acento el que no es destructivo, rojo el que si. */
.reset-btn.ghost,
.delete-btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.reset-btn.ghost:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.reset-btn.ghost:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}
.delete-btn.ghost:hover {
  background: var(--danger-dim);
  border-color: var(--danger);
  color: var(--danger);
}
.delete-btn.ghost:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--danger);
}

.admin-dialog {
  max-width: 480px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  padding: 0;
}

.pw-box { display: grid; gap: 14px; padding: 24px; }

/* Dialogo de resetear contraseña: mismo padding que pw-box, el h2 va arriba
   sin su propio wrapper porque no hace falta separarlo del form. */
#reset-dialog h2 { margin: 24px 24px 0; font-size: 18px; }
#reset-form { padding: 14px 24px 24px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }

.pw-warning { margin: 0; font-size: 13px; color: var(--muted); }
.pw-warning strong { color: var(--danger); }

.pw-row { display: flex; align-items: center; gap: 10px; }

.pw-value {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  letter-spacing: 0.03em;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.pw-copy.ghost {
  flex: 0 0 auto;
  padding: 8px 12px;
  white-space: nowrap;
}

.pw-done.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.pw-done.primary:hover { filter: brightness(1.08); }
.pw-done.primary:active { transform: translateY(1px); }
.pw-done.primary:focus-visible { outline: none; box-shadow: var(--ring); }

/* Boton primario para el form de alta */
button.primary, a.primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  font-weight: 600;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: filter 0.15s ease, transform 0.15s ease;
}
button.primary:hover:not(:disabled), a.primary:hover { filter: brightness(1.08); }
button.primary:active:not(:disabled), a.primary:active { transform: translateY(1px); }
button.primary:disabled, a.primary[aria-disabled="true"] { opacity: 0.6; cursor: default; pointer-events: none; }
button.primary:focus-visible, a.primary:focus-visible { outline: none; box-shadow: var(--ring); }

/* .pw-box es grid: sin esto el boton se estira a lo ancho de la columna. */
#stremio-install { justify-self: start; }

/* Link crudo de /stremio: colapsado por default, el boton "Instalar en
   Stremio" (stremio://...) ya cubre el caso comun. */
.stremio-link-details { margin-top: 4px; }
.stremio-link-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  padding: 4px 0;
}
.stremio-link-details[open] summary { margin-bottom: 10px; }

/* ---------------- Playlists (/playlists y el dialogo "Agregar a playlist") ---------------- */

.playlists-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.playlists-list-empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

.playlists-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
}
.playlists-sort-handle { display: flex; flex-direction: column; gap: 1px; flex-shrink: 0; }
.icon-btn {
  display: grid; place-items: center;
  width: 22px; height: 22px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color var(--ease), background var(--ease);
}
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.playlists-list-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.playlists-list-name { font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stremio-badge { display: inline-flex; align-items: center; color: var(--accent); opacity: 0.8; flex-shrink: 0; }
.playlists-list-meta { color: var(--muted); font-size: 12px; }

/* Checkboxes de playlists del dialogo "Agregar a playlist" (ver app.js). */
/* Legacy picker (kept for snapshot.ejs provider filter) */
.playlist-picker-item label { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 0; }

/* ── Add-to-playlist dialog ──────────────────────────────────────── */
/* ── Add-to-playlist dialog ──────────────────────────────────────── */
.pick-dialog {
  width: 360px;
  max-width: min(360px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  padding: 0;
}
.pick-dialog[open] { display: flex; flex-direction: column; max-height: min(520px, calc(100vh - 80px)); }
.pick-dialog::backdrop { background: rgb(0 0 0 / 60%); }

.pick-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.pick-dialog-title { margin: 0; font-size: 14px; font-weight: 600; }
.pick-dialog-close {
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border-radius: var(--radius);
  color: var(--muted);
  background: transparent;
  border: 0;
  cursor: pointer;
  transition: color var(--ease), background var(--ease);
}
.pick-dialog-close:hover { color: var(--text); background: var(--panel-2); }

.playlist-picker {
  list-style: none;
  margin: 0;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  flex: 1;
  min-height: 60px;
}

.pick-empty { padding: 20px 8px; text-align: center; color: var(--muted); font-size: 13px; }

.pick-item { border-radius: var(--radius); }
.pick-item-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background var(--ease);
  user-select: none;
}
.pick-item-label:hover { background: var(--panel-2); }
.pick-item--on .pick-item-label { background: var(--accent-dim); }
.pick-item--loading .pick-item-label { opacity: 0.5; pointer-events: none; }

/* Native checkbox hidden, custom box shown */
.pick-item-cb { appearance: none; -webkit-appearance: none; margin: 0; flex-shrink: 0; }

.pick-item-check {
  width: 17px; height: 17px;
  flex-shrink: 0;
  border-radius: 4px;
  border: 1.5px solid var(--border);
  background: var(--panel-3);
  display: grid; place-items: center;
  pointer-events: none;
  transition: background var(--ease), border-color var(--ease);
}
.pick-item-check svg { opacity: 0; transition: opacity var(--ease); }
.pick-item--on .pick-item-check {
  background: var(--accent);
  border-color: var(--accent);
}
.pick-item--on .pick-item-check svg { opacity: 1; }

.pick-item-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-item-count { font-size: 12px; color: var(--muted); flex-shrink: 0; background: var(--panel-3); padding: 1px 7px; border-radius: 999px; }
.pick-item--on .pick-item-count { background: var(--accent-dim); color: var(--accent); }

.pick-dialog-footer {
  border-top: 1px solid var(--border);
  padding: 10px;
  flex-shrink: 0;
}
.pick-new-form { display: flex; gap: 6px; }
.pick-new-input {
  flex: 1;
  padding: 6px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  min-width: 0;
}
.pick-new-input::placeholder { color: var(--muted); }
.pick-new-input:focus { outline: none; border-color: var(--accent); }
.pick-new-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.pick-new-btn:hover { filter: brightness(1.1); }
.pick-msg { margin: 8px 0 0; font-size: 12px; color: var(--danger); }

/* Grilla de contenido de una playlist abierta en /playlists: hermana del
   .admin-card de arriba, no su hija — mismo motivo que .stremio-preview en
   stremio.ejs (el padding de un contenedor angosta la grilla contra /movies). */
.playlist-detail { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.playlist-detail-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.playlist-detail-head h2 { margin: 0; font-size: 18px; }

/* Item de un import de TMDB sin match en el catalogo propio (ver tmdb.js):
   se muestra igual, pero atenuado — no hay nada que reproducir todavia. */
.card.unavailable .poster { opacity: 0.55; }
.badge.unavailable { background: var(--danger-dim); color: var(--danger); }
.card.unavailable:hover .badge.unavailable,
.card.unavailable:focus-visible .badge.unavailable { opacity: 1; }

@media (max-width: 640px) {
  .admin-topbar { padding: 10px 12px; flex-wrap: wrap; }
  .admin-main { padding: 12px; }
  .admin-card { padding: 16px; }
  .admin-table th,
  .admin-table td { padding: 10px 12px; font-size: 13px; }
  .pw-box { padding: 18px; }
}

/* --- Vista /library cards ------------------------------------------- */

.lib-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.lib-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  overflow: hidden;
}

/* La tabla tiene 7 columnas: en una card angosta (mobile, o el layout de dos
   columnas en viewports medianos) el texto de Registros/Hora se aprieta y
   parte feo. Mejor que la tabla scrollee horizontal dentro de su propia
   card que lastimar las columnas para que entren. */
.lib-table-wrap {
  overflow-x: auto;
}

.lib-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.lib-head h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.lib-toolbar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.lib-msg {
  margin: 0;
  padding: 0.5rem 1rem;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.lib-msg[data-kind="error"] { color: var(--danger); }
.lib-msg[data-kind="success"] { color: color-mix(in oklch, var(--accent) 70%, var(--text)); }

.lib-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.lib-table thead {
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lib-table th,
.lib-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.lib-table tbody tr:hover { background: var(--panel-2); }

.lib-table tbody tr.loading td,
.lib-table tbody tr.empty td,
.lib-table tbody tr.error td {
  text-align: center;
  color: var(--muted);
  font-style: italic;
}

.lib-table tbody tr.error td { color: var(--danger); }

.lib-table tr.lib-off td {
  color: var(--muted);
  opacity: 0.7;
}

/* Items (6ª col en tabla unificada: Fuente|Check|Servidor|Librería|Tipo|Items) */
.lib-table td:nth-child(6) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Registros y hora del ultimo sync: antes vivian en una sola celda
   ("lib-last") apiladas en dos lineas; ahora son dos columnas, cada una con
   su propio estado/placeholder. */
.lib-table td.lib-counts,
.lib-table td.lib-time {
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
}

.lib-counts .lib-ok { color: color-mix(in oklch, var(--accent) 70%, var(--text)); }
.lib-counts .lib-fail { color: var(--danger); }
.lib-counts .lib-run { color: var(--muted); }

.lib-time .lib-ago {
  color: var(--muted);
  font-size: 12px;
}

/* La columna de acciones es la ultima: con el selector por posicion cada
   columna nueva obligaba a renumerar. */
.lib-table td:last-child {
  text-align: center;
  white-space: nowrap;
}

.lib-table .lib-sync-btn {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.lib-table .lib-sync-btn:hover:not(:disabled) {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.lib-table .lib-sync-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.lib-table .lib-sync-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

/* Boton chico al lado de Sync: fuerza un sync completo de esa libreria sola,
   sin duplicar el ancho de la columna con dos botones de texto. */
.lib-table .lib-sync-full-btn {
  margin-left: 4px;
  padding: 4px 6px;
  font-size: 11px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.lib-table .lib-sync-full-btn:hover:not(:disabled) {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.lib-table .lib-sync-full-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.lib-table .lib-sync-full-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

.lib-table .lib-check {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

.lib-table .lib-check:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.lib-toolbar button { white-space: nowrap; }

/* Historial de syncs. Va plegado por default: es la referencia, no el estado
   actual, y en un server con muchas librerias el <details> abierto empujaba
   la tabla fuera de pantalla. */
.lib-history {
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}

.lib-history > summary {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  list-style-position: inside;
}

.lib-history > summary:hover { color: var(--text); }

.lib-history > summary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

.lib-history .lib-none {
  margin: 0;
  padding: 0 14px 14px;
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
}

.lib-hist {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.lib-hist thead {
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lib-hist th,
.lib-hist td {
  padding: 8px 14px;
  text-align: left;
  border-top: 1px solid var(--border);
}

.lib-hist td.lib-st {
  white-space: nowrap;
}

.lib-hist td.lib-st.completed { color: color-mix(in oklch, var(--accent) 70%, var(--text)); }
.lib-hist td.lib-st.failed { color: var(--danger); }
.lib-hist td.lib-st.running,
.lib-hist td.lib-st.pending { color: var(--muted); }

/* Status y conteo alineados a la derecha para que las cifras formen columna. */
.lib-hist td:nth-child(3),
.lib-hist td:nth-child(4) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.lib-hist td:nth-child(5) {
  text-align: right;
  white-space: nowrap;
  color: var(--muted);
}

/* --- Vista /admin/analytics ------------------------------------------ */

/* Colores por tipo de contenido (movies/series/anime/episodes), fijos y en
   ese orden: no hay mapeo previo para esto en la app (a diferencia de
   Jellyfin/Plex, que ya tienen su color en .src-provider y se reusa tal
   cual abajo). Valores tomados de la paleta categorica validada del skill de
   dataviz (slots 1/2/3/4: blue/orange/aqua/yellow), en hex porque son un
   valor documentado, no algo que convenga recalcular a mano en oklch. */
:root {
  --content-movies: #3987e5;
  --content-series: #d95926;
  --content-anime: #199e70;
  --content-episodes: #c98500;
  /* Mismo hue que .src-provider (sin el color-mix con el panel): para usar
     como fill solido en los graficos, no solo como fondo de badge. */
  --provider-jellyfin: oklch(62% 0.17 300);
  --provider-plex: oklch(78% 0.15 80);
}
:root[data-theme="light"] {
  --content-movies: #2a78d6;
  --content-series: #eb6834;
  --content-anime: #1baf7a;
  --content-episodes: #eda100;
}

.an-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.an-stat {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.an-stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.an-stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.an-stat-empty { color: var(--muted); font-size: 13px; }

.an-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
@media (min-width: 900px) {
  .an-grid { grid-template-columns: 1fr 1fr; }
}

.an-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.an-card:last-child { margin-bottom: 0; }
.an-card h2 { margin: 0 0 12px; font-size: 15px; }
.an-card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.an-card-head h2 { margin: 0; }
.an-range { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

.an-chart-wrap { position: relative; }
.an-loading { color: var(--muted); font-size: 13px; text-align: center; padding: 30px 0; }
.an-chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }

.an-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 12px 0 0; padding: 0; list-style: none; font-size: 12px; color: var(--muted); }
.an-legend li { display: flex; align-items: center; gap: 6px; }
.an-legend .sw { width: 10px; height: 10px; border-radius: 2px; flex: none; }

/* Tooltip compartido por los dos graficos: un solo div reusado, posicionado
   cerca del cursor en vez de uno por marca (igual al patron de hover de
   interaction.md). */
.an-tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--panel-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 4px 14px var(--shadow);
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--ease);
}
.an-tooltip.show { opacity: 1; }
.an-tooltip b { font-variant-numeric: tabular-nums; }

.an-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.an-jobs-table, .an-servers-table, .an-activity-table { min-width: 480px; }
.an-jobs-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.an-status { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.an-status .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.an-status.ok { color: color-mix(in oklch, var(--accent) 75%, var(--text)); }
.an-status.ok .dot { background: var(--accent); }
.an-status.failed { color: var(--danger); }
.an-status.failed .dot { background: var(--danger); }
.an-status.pending { color: var(--muted); }
.an-status.pending .dot { background: var(--muted); }

.an-chart-label { dominant-baseline: middle; }
.an-grid-line { stroke: var(--border); stroke-width: 1; }
.an-axis-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.an-crosshair { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.an-tip-date { color: var(--muted); margin-bottom: 4px; }

@media (max-width: 640px) {
  .an-card { padding: 12px; }
}

/* ------------------------------------------------------------------ */
/* History page                                                        */
/* ------------------------------------------------------------------ */

.hist-page { display: flex; flex-direction: column; gap: 20px; }

.hist-hero { display: flex; align-items: flex-start; justify-content: space-between; }
.hist-title { font-size: 24px; font-weight: 700; margin: 0 0 4px; }
.hist-sub { color: var(--muted); font-size: 14px; margin: 0; }

/* stat cards */
.hist-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.hist-stat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.hist-stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  flex-shrink: 0;
  font-size: 15px;
}
.hist-stat-val { font-size: 20px; font-weight: 700; line-height: 1.2; }
.hist-stat-label { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* card wrapper */
.hist-card { padding: 16px; }

/* toolbar */
.hist-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

/* range toggle */
.hist-range {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.hist-range-btn {
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
}
.hist-range-btn:first-child { border-left: none; }
.hist-range-btn:hover:not(.active) { background: var(--panel-2); color: var(--text); }
.hist-range-btn.active { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }

/* filters row */
.hist-filters { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }

.hist-search-wrap { position: relative; min-width: 200px; flex: 1; max-width: 380px; }
.hist-search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

.hist-input {
  padding: 7px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  width: 100%;
}
.hist-input--search { padding-left: 28px; }
.hist-select {
  padding: 7px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  min-width: 150px;
  width: auto;
  flex-shrink: 0;
}
.hist-input:focus,
.hist-select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.hist-count { font-size: 13px; color: var(--muted); white-space: nowrap; margin-left: auto; }

/* table columns */
.hist-col-date { width: 120px; }
.hist-col-user { width: 140px; }
.hist-col-source { width: 120px; }

.hist-date-main { font-size: 13px; font-weight: 500; }
.hist-date-time { font-size: 11px; color: var(--muted); }

.hist-user-name { font-size: 13px; font-weight: 500; }
.hist-user-ip { font-size: 11px; color: var(--muted); font-family: monospace; }

/* content cell */
.hist-content-row { display: flex; align-items: center; gap: 8px; }
.hist-kind-icon { color: var(--muted); font-size: 13px; flex-shrink: 0; width: 14px; }
.hist-content-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; display: block; }

/* source tag */
.hist-src {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.hist-src--jf  { background: color-mix(in srgb, #a78bfa 12%, transparent); color: #a78bfa; }
.hist-src--plex { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }

.hist-empty { text-align: center; color: var(--muted); padding: 40px !important; }

/* pagination */
.hist-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 16px;
  justify-content: center;
}
.hist-page-btn {
  padding: 5px 10px;
  min-width: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
}
.hist-page-btn:hover:not(:disabled):not(.active) { background: var(--panel); }
.hist-page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.hist-page-btn:disabled { opacity: .35; cursor: default; }
.hist-page-gap { padding: 5px 4px; color: var(--muted); font-size: 13px; }

@media (max-width: 640px) {
  .hist-stats { grid-template-columns: 1fr 1fr; }
  .hist-stats .hist-stat-card:last-child { grid-column: span 2; }
  .hist-toolbar { flex-direction: column; align-items: stretch; }
  .hist-count { margin-left: 0; }
}

/* Playlist: el badge lista los servidores ("Jellyfin + Plex + ChangPlex +
   Hallownest"); con 3-4 nombres en una sola linea quedaba cortado con "…".
   Hasta dos lineas, y el title del span tiene el texto completo. */
.badge.badge-servers {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.3;
}

/* Playlist: mover items. Los botones van arriba a la izquierda (la "x" esta
   arriba a la derecha y el badge abajo); se ven en hover o con foco, y
   siempre en pantallas tactiles, donde no hay hover ni drag de HTML5. */
.card-move {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 1;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--ease);
}
.card:hover .card-move, .card-move:focus-within { opacity: 1; }
@media (hover: none) { .card-move { opacity: 1; } }
.card-move-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: var(--badge-bg);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.card-move-btn:hover { background: var(--accent); color: var(--accent-ink); }
.card-move-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.card[draggable="true"] { cursor: grab; }
.card.dragging { opacity: 0.4; }

/* Chip "Estrenadas recientemente" (catalogo y Mi Plex, solo Movies). Toggle:
   .active / aria-pressed cuando el filtro esta prendido. */
.recent-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease);
}
.recent-chip:hover { border-color: var(--accent); }
.recent-chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: color-mix(in oklch, var(--accent) 80%, var(--text));
}
.recent-chip:focus-visible { outline: none; box-shadow: var(--ring); }

/* /admin/sonarr y /admin/radarr (vista compartida, ver public/arr.js) */
.arr-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.arr-filters .search input[type="search"] { min-width: 200px; }
.arr-table { min-width: 900px; }
.arr-table td { vertical-align: middle; }
.arr-title { display: flex; align-items: center; gap: 10px; min-width: 240px; }
.arr-title strong { font-weight: 600; }
.arr-title .badge-chip { margin-left: 6px; font-size: 11px; }
.arr-thumb {
  flex: none;
  width: 36px;
  aspect-ratio: 2 / 3;
  border-radius: 4px;
  overflow: hidden;
  background: var(--panel-3);
}
.arr-poster { display: block; width: 100%; height: 100%; object-fit: cover; }
.arr-sub { font-size: 12px; color: var(--muted); }
.arr-status[data-status="continuing"] { color: color-mix(in oklch, var(--accent) 80%, var(--text)); }
.arr-status[data-status="ended"] { color: var(--muted); }
.arr-status[data-status="downloaded"] { color: color-mix(in oklch, var(--accent) 80%, var(--text)); }
.arr-status[data-status="missing"] { color: var(--danger); }
.arr-status[data-status="upcoming"] { color: var(--muted); }
.arr-progress { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.arr-bar { flex: 1; height: 6px; border-radius: 999px; background: var(--panel-3); overflow: hidden; }
.arr-bar > span { display: block; height: 100%; background: var(--accent); }
.arr-progress[data-kind="partial"] .arr-bar > span { background: color-mix(in oklch, var(--danger) 55%, var(--accent)); }
.arr-eps { font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.arr-eps em { font-style: normal; color: var(--danger); }
.arr-next { color: color-mix(in oklch, var(--accent) 80%, var(--text)); white-space: nowrap; }
.arr-prev { color: var(--muted); white-space: nowrap; }
.arr-actions { width: 1%; white-space: nowrap; text-align: right; }
button.arr-del {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid color-mix(in oklch, var(--danger) 55%, transparent);
  background: var(--danger-dim);
  color: var(--danger);
  font-weight: 600;
}
button.arr-del:hover { border-color: var(--danger); background: color-mix(in oklch, var(--danger) 22%, transparent); }
.arr-confirm { display: flex; align-items: center; justify-content: flex-end; gap: 8px; white-space: normal; min-width: 280px; }
.arr-confirm span { font-size: 12px; color: var(--danger); text-align: left; }
.arr-confirm .danger {
  padding: 6px 12px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: var(--danger-dim);
  color: var(--danger);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.arr-confirm .danger:hover { background: color-mix(in oklch, var(--danger) 22%, transparent); }
.arr-link { color: inherit; text-decoration: none; }
.arr-link:hover strong { color: var(--accent); text-decoration: underline; }

/* /movies/:key — pagina de una pelicula */
.movie-page { display: grid; gap: 24px; max-width: 1200px; }
.movie-back { color: var(--muted); text-decoration: none; font-size: 14px; display: inline-flex; gap: 8px; align-items: center; width: fit-content; }
.movie-back:hover { color: var(--text); }
.movie-hero {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.movie-backdrop {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center top;
  opacity: 0.35;
}
.movie-backdrop::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--panel-2) 15%, color-mix(in oklch, var(--panel-2) 55%, transparent) 60%, transparent),
    linear-gradient(0deg, var(--panel-2), transparent 45%);
}
.movie-hero-inner {
  position: relative;
  display: grid;
  grid-template-columns: minmax(140px, 240px) 1fr;
  gap: 28px;
  padding: 28px;
}
.movie-poster img,
.movie-poster .no-poster {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: var(--radius-sm, 8px);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.45);
}
.movie-info { display: grid; gap: 10px; align-content: start; min-width: 0; }
.movie-info h1 { margin: 0; font-size: clamp(1.5rem, 3.2vw, 2.4rem); line-height: 1.15; }
.movie-original { margin: 0; color: var(--muted); font-size: 15px; }
.movie-meta { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.movie-tagline { margin: 0; font-style: italic; color: color-mix(in oklch, var(--accent) 60%, var(--text)); }
.movie-genres { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.movie-overview { margin: 0; max-width: 70ch; line-height: 1.6; }
.movie-credits { display: flex; flex-wrap: wrap; gap: 6px 24px; margin: 0; font-size: 14px; }
.movie-credits div { display: flex; gap: 6px; }
.movie-credits dt { color: var(--muted); }
.movie-credits dd { margin: 0; }
.movie-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.movie-actions a.ghost { padding: 8px 14px; text-decoration: none; }
.movie-section h2 { margin: 0 0 12px; font-size: 1.1rem; }
.movie-cast {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.movie-cast-item { display: grid; gap: 4px; font-size: 13px; }
.movie-cast-item img,
.movie-cast-nophoto { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: var(--radius-sm, 8px); background: var(--panel-3); }
.movie-cast-item span { color: var(--muted); }
@media (max-width: 640px) {
  .movie-hero-inner { grid-template-columns: 1fr; padding: 18px; }
  .movie-poster { max-width: 180px; }
}
.arr-path {
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.85;
}
.movie-page .season {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
  margin-bottom: 10px;
}
.movie-page .season > summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
}
.movie-page .season > summary::-webkit-details-marker { display: none; }
.movie-page .season > summary::before {
  content: '▸';
  color: var(--muted);
  transition: transform var(--ease);
}
.movie-page .season[open] > summary::before { transform: rotate(90deg); }
.movie-page .season > summary .season-name { flex: 1; }
.season-meta { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.episode-list { display: grid; gap: 14px; padding: 0 16px 16px; }
.episode-title { margin: 0 0 6px; font-size: 14px; font-weight: 600; }
.episode-code { color: var(--accent); font-variant-numeric: tabular-nums; margin-right: 4px; }

/* /library: animacion mientras corre un sync. Barra indeterminada bajo el
   titulo de la tarjeta, fila que late, y puntos que avanzan en "sincronizando". */
@keyframes lib-sweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}
@keyframes lib-pulse {
  0%, 100% { background-color: transparent; }
  50% { background-color: var(--accent-dim); }
}
@keyframes lib-dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}
.lib-card { position: relative; }
.lib-card.lib-card-syncing::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 40%;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: lib-sweep 1.4s ease-in-out infinite;
}
.lib-table tr.lib-syncing td { animation: lib-pulse 1.8s ease-in-out infinite; }
.lib-table tr.lib-syncing td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.lib-counts .lib-run { color: color-mix(in oklch, var(--accent) 80%, var(--text)); font-weight: 600; }
.lib-dots { display: inline-block; width: 1.2em; text-align: left; }
.lib-dots::after { content: ''; animation: lib-dots 1.2s steps(1) infinite; }
@media (prefers-reduced-motion: reduce) {
  .lib-card.lib-card-syncing::before,
  .lib-table tr.lib-syncing td,
  .lib-dots::after,
  .lib-run .spin-icon { animation: none; }
  .lib-card.lib-card-syncing::before { width: 100%; opacity: 0.6; }
}
.lib-progress {
  display: block;
  width: 100%;
  min-width: 120px;
  height: 4px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--panel-3);
  overflow: hidden;
}
.lib-progress > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.6s ease;
}
.lib-counts .lib-run { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Tabla unificada JF+Plex */
.lib-head-unified {
  justify-content: space-between;
}

.lib-head-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.lib-toggle-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.lib-toggle-label:hover { color: var(--text); }

.lib-toggle-label input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.lib-toolbar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}

.lib-toolbar-row + .lib-toolbar-row {
  border-top: none;
}

.lib-src-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
  min-width: 2.6em;
  justify-content: center;
}

.lib-src-jf {
  background: color-mix(in oklch, #7b7bff 20%, transparent);
  color: #a0a0ff;
  border: 1px solid color-mix(in oklch, #7b7bff 40%, transparent);
}

.lib-src-plex {
  background: color-mix(in oklch, #e5a00d 18%, transparent);
  color: #e5a00d;
  border: 1px solid color-mix(in oklch, #e5a00d 35%, transparent);
}

/* Badge en toolbar (emoji + label) */
.lib-toolbar-row .lib-src-badge {
  font-size: 13px;
  padding: 3px 10px;
  margin-right: 4px;
}

/* Mensaje inline bajo cada toolbar */
.lib-msg-inline {
  border-bottom: none;
  padding-top: 4px;
  padding-bottom: 4px;
  min-height: 1.4em;
}

.lib-msg-inline:empty { display: none; }

/* Columna Fuente: primera col, no muy ancha */
.lib-table td:first-child,
.lib-table th:first-child {
  width: 3.5rem;
  text-align: center;
  padding-left: 8px;
  padding-right: 8px;
}

/* Separador visual entre filas de distintas fuentes */
.lib-table tr[data-src="plex"]:first-of-type td {
  border-top: 2px solid var(--border);
}

/* Botón Actualizar */
#lib-refresh {
  align-self: flex-start;
  margin-left: auto;
}

/* ------------------------------------------------------------------ */
/* /admin/config                                                       */
/* ------------------------------------------------------------------ */

.cfg { max-width: 860px; }
.cfg-groups { display: grid; gap: 16px; }
.cfg-loading { color: var(--muted); margin: 0; }

.cfg-group {
  margin: 0;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 18px 16px;
  display: grid;
  gap: 14px;
  background: var(--panel);
}
.cfg-group legend {
  padding: 0 8px;
  margin-left: -8px;
  font-weight: 600;
  font-size: 15px;
}
.cfg-group legend i { color: var(--accent); }

.cfg-field { display: grid; gap: 6px; }
.cfg-field > label { font-size: 13px; font-weight: 500; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.cfg-field input[type="url"],
.cfg-field input[type="password"] { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.cfg-field.dirty input[type="url"],
.cfg-field.dirty input[type="password"] { border-color: var(--accent); }
.cfg-help { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }

.cfg-set {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 999px;
  padding: 1px 8px;
}

.cfg-source { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 11px; color: var(--muted); opacity: 0.85; }
button.cfg-reset {
  background: none;
  border: 0;
  padding: 0;
  font-size: 11px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cfg-bool {
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.cfg-bool-text { display: grid; gap: 4px; }
.cfg-bool-text label { font-weight: 500; font-size: 14px; color: var(--text); cursor: pointer; }
.cfg-group > .cfg-bool:first-of-type { border-top: 0; padding-top: 0; }
.cfg-field.cfg-bool.dirty .cfg-bool-text label::after { content: ' •'; color: var(--accent); }

/* Switch: un checkbox con apariencia propia, sigue siendo un input nativo
   (teclado, form, lector de pantalla con role=switch). */
input.cfg-switch {
  appearance: none;
  width: 42px;
  height: 24px;
  padding: 0;
  margin: 2px 0 0;
  border-radius: 999px;
  background: var(--panel-3);
  border: 1px solid var(--border-strong);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}
input.cfg-switch::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform var(--ease), background var(--ease);
}
input.cfg-switch:checked { background: var(--accent); border-color: transparent; }
input.cfg-switch:checked::before { transform: translateX(18px); background: var(--accent-ink); }

.cfg-test-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
button.cfg-test { padding: 7px 12px; font-size: 13px; }
.cfg-test-result { font-size: 13px; color: var(--muted); }
.cfg-test-result[data-kind="ok"] { color: var(--accent); }
.cfg-test-result[data-kind="error"] { color: var(--danger); }

.cfg-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin: 16px -24px -24px;
  padding: 14px 24px calc(14px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in oklch, var(--panel) 92%, transparent);
  backdrop-filter: blur(6px);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.cfg-status { margin: 0 auto 0 0; font-size: 13px; color: var(--muted); }
.cfg-status[data-kind="ok"] { color: var(--accent); }
.cfg-status[data-kind="error"] { color: var(--danger); }
.cfg-status[data-kind="pending"] { color: var(--text); }
button.cfg-save {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
  cursor: pointer;
}
button.cfg-save:disabled,
.cfg-bar button:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 600px) {
  .cfg-group { padding: 4px 12px 14px; }
  .cfg-bar { margin: 16px -16px -16px; padding-inline: 16px; }
}

/* /admin/sonarr y /admin/radarr en phone: la tabla de 7-8 columnas pide
   ~900px y obligaba a scrollear de costado. Debajo de 700px cada fila es una
   tarjeta: titulo arriba, los datos en grilla de 2 con su etiqueta
   (data-label, la pone arr.js) y el borrar abajo a lo ancho. */
@media (max-width: 700px) {
  .arr-toolbar { align-items: stretch; }
  .arr-toolbar .catalog-tabs { width: 100%; }
  .arr-filters { width: 100%; }
  .arr-filters .search { flex: 1 1 100%; }
  .arr-filters .search input[type="search"] { min-width: 0; width: 100%; }
  .arr-filters select { flex: 1 1 0; min-width: 0; }
  .arr-filters #arr-refresh { flex: 1 1 100%; }

  .arr-toolbar ~ .snap-table-wrap { border: 0; overflow: visible; }
  .arr-table { min-width: 0; width: 100%; }
  .arr-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .arr-table,
  .arr-table tbody { display: block; }
  .arr-table tbody { display: grid; gap: 10px; }

  .arr-table tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 14px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
  }
  .arr-table tr.loading,
  .arr-table tr.empty,
  .arr-table tr.error { display: block; }

  .arr-table td {
    display: block;
    padding: 0;
    border: 0;
    min-width: 0;
    white-space: normal;
    text-align: left;
  }
  /* Le gana a .admin-table td:nth-child(4) y a .snap-table td.num. */
  .arr-table tr > td:nth-child(n) { text-align: left; }
  .arr-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .arr-table td.arr-title-cell { grid-column: 1 / -1; white-space: normal; }
  .arr-title { min-width: 0; align-items: flex-start; }
  .arr-title > div { min-width: 0; }
  .arr-thumb { width: 52px; }
  .arr-progress { min-width: 0; }
  .arr-next,
  .arr-prev { white-space: normal; }

  .arr-table td.arr-actions { grid-column: 1 / -1; width: auto; text-align: left; }
  button.arr-del { width: 100%; justify-content: center; }
  .arr-confirm { min-width: 0; flex-wrap: wrap; justify-content: stretch; }
  .arr-confirm span { flex: 1 1 100%; }
  .arr-confirm button { flex: 1 1 0; }
}
