:root {
  --bg: #12141a;
  --surface: #1b1e27;
  --surface-2: #242832;
  --text: #e8e9ee;
  --muted: #9498a5;
  --accent: #6c8cff;
  --accent-secondary: #6c8cff;
  --accent-text: #ffffff;
  --news: #ff8a3d;
  --danger: #ff5c5c;
  --radius: 10px;
  --cover-image: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

/* El fondo difuminado de portada queda contenido dentro del propio header:
   se ajusta a su alto real (incluso si el buscador ocupa 2 filas en pantallas
   angostas) y nunca se mete en la zona donde se listan los posters. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  padding: 12px 16px;
  border-bottom: 1px solid #2a2e3a;
  overflow: hidden;
  transition: padding-bottom 0.3s ease, background 0.4s ease, border-color 0.4s ease;
}

.topbar::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--cover-image);
  background-size: cover;
  background-position: center 20%;
  filter: blur(20px) brightness(0.45) saturate(1.15);
  /* clip-path stops the blur from bleeding past the header's own box —
     without it, filter blur paints outside the box edges regardless of
     overflow:hidden on the ancestor. */
  clip-path: inset(0);
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: 0;
}

.topbar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(18, 20, 26, 0) 40%, var(--surface) 100%);
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: 0;
}

.topbar.has-cover {
  padding-bottom: 30px;
  background: transparent;
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.topbar.has-cover::before,
.topbar.has-cover::after {
  opacity: 1;
}

.topbar > * {
  position: relative;
  z-index: 1;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

h1 {
  font-size: 1.3rem;
  margin: 0;
  letter-spacing: 0.02em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logout-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid #333846;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}

.logout-btn:hover { color: var(--text); border-color: var(--accent); }

.news-badge {
  background: var(--news);
  color: #1a1200;
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.search-form {
  display: flex;
  gap: 8px;
}

select, input, button {
  font-size: 0.95rem;
  border-radius: 8px;
  border: 1px solid #333846;
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 10px;
}

.search-form select { flex: 0 0 auto; }
.search-form input { flex: 1 1 auto; min-width: 0; }

.search-results {
  margin-top: 8px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface-2);
  border-radius: var(--radius);
}

.result-row {
  display: flex;
  gap: 10px;
  padding: 8px;
  border-bottom: 1px solid #2a2e3a;
  align-items: center;
}

.result-row img {
  width: 40px;
  height: 58px;
  object-fit: cover;
  border-radius: 4px;
  background: #333;
  flex-shrink: 0;
}

.result-row .info { flex: 1; min-width: 0; }
.result-row .info strong { display: block; font-size: 0.9rem; }
.result-row .info span { color: var(--muted); font-size: 0.8rem; }

.result-row button {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  cursor: pointer;
  white-space: nowrap;
}

main {
  padding: 16px;
  min-height: calc(100vh - 60px);
  background-repeat: no-repeat;
  transition: background-image 0.3s ease;
}

/* Fondo nítido (sin blur) del poster de portada en la zona donde se listan
   los títulos — separado del banner difuminado del header. Se ancla al
   viewport (background-attachment: fixed) para no deformarse cuando la
   grilla crece más alto que la pantalla. */
main.has-cover {
  background-image: linear-gradient(rgba(18, 20, 26, 0.82), rgba(18, 20, 26, 0.93)), var(--cover-image);
  background-size: cover;
  background-position: center top;
  background-attachment: fixed;
}

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

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

.card {
  position: relative;
  cursor: pointer;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  transition: transform 0.1s ease;
}

.card:active { transform: scale(0.97); }

.card img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  display: block;
  background: #333;
}

.card .title {
  padding: 6px 8px;
  font-size: 0.82rem;
  line-height: 1.2;
}

.card .news-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--news);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.4);
}

.card .type-tag {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 999px;
  text-transform: uppercase;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  margin-top: 40px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

.overlay[hidden] {
  display: none;
}

.detail-card {
  position: relative;
  background: var(--surface);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding-bottom: 20px;
}

.detail-card img {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  display: block;
}

.detail-body { padding: 14px 16px; }
.detail-body h2 { margin: 0 0 4px; font-size: 1.2rem; }
.detail-body p { color: var(--muted); font-size: 0.9rem; line-height: 1.4; }

.news-note {
  color: var(--news) !important;
  font-weight: 600;
}

.providers-section {
  margin-top: 12px;
}

.providers-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 8px;
}

.providers-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.provider-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px 10px 4px 4px;
  font-size: 0.8rem;
}

.provider-chip img {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  object-fit: cover;
}

.providers-note {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 6px;
}

.children-section {
  margin-top: 16px;
  border-top: 1px solid #2a2e3a;
  padding-top: 12px;
}

.children-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 8px;
}

/* Grid with fixed areas so every row lays out identically regardless of title
   length — the title truncates with an ellipsis instead of wrapping and
   pushing the button/checkbox around. */
.child-row {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  grid-template-areas:
    "poster info    watched"
    "poster promote promote";
  column-gap: 10px;
  row-gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid #22252e;
}

.child-row:last-child { border-bottom: none; }

.child-row img {
  grid-area: poster;
  width: 40px;
  height: 58px;
  object-fit: cover;
  border-radius: 4px;
  background: #333;
}

.child-row .info {
  grid-area: info;
  min-width: 0;
  align-self: center;
}

.child-row .info strong {
  display: block;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.child-row .info span { color: var(--muted); font-size: 0.78rem; }

.promote-btn {
  grid-area: promote;
  justify-self: start;
  background: transparent;
  color: var(--muted);
  border: 1px solid #333846;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.72rem;
  cursor: pointer;
  white-space: nowrap;
}

.promote-btn:hover { color: var(--text); border-color: var(--accent); }

.child-row.pending .info strong::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--news);
  margin-right: 6px;
}

.watched-toggle {
  grid-area: watched;
  align-self: center;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}

.watched-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.detail-actions button {
  flex: 1 1 120px;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  padding: 10px;
  border-radius: 8px;
}

.detail-actions button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

.close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  z-index: 1;
}

@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .overlay { align-items: center; }
  .detail-card { border-radius: 16px; }
}
