:root {
  --bg-0: #0b0f1e;
  --bg-1: #131a33;
  --bg-2: #1a2140;
  --card: #161d38;
  --card-2: #1d2547;
  --border: #2a3357;
  --text: #e7eaf6;
  --muted: #98a0c0;
  --accent: #8b5cf6;
  --accent-2: #6366f1;
  --blue: #3b82f6;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(99, 102, 241, 0.25), transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, rgba(139, 92, 246, 0.22), transparent 55%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1) 55%, #10142b);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* ---------- Vista de login ---------- */
.view {
  min-height: 100vh;
}

.login-card {
  width: min(420px, calc(100vw - 40px));
  margin: 12vh auto 0;
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-logo {
  font-size: 48px;
}

.login-card h1 {
  margin: 12px 0 4px;
  font-size: 28px;
  letter-spacing: 0.5px;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 24px;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

label {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
}

input[type="text"],
input[type="password"],
input[type="search"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-1);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.25);
}

/* ---------- Botones ---------- */
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--card-2);
  transition: transform 0.08s, filter 0.15s;
}

.btn:hover {
  filter: brightness(1.12);
}

.btn:active {
  transform: translateY(1px);
}

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

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
}

#login-btn {
  margin-top: 20px;
  padding: 13px;
  font-size: 16px;
}

/* ---------- Cabecera ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 15, 30, 0.6);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand-logo {
  font-size: 26px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
}

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

#username-label {
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Navegación ---------- */
nav {
  display: flex;
  gap: 4px;
  padding: 10px 20px 0;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 15, 30, 0.4);
}

.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 12px 18px;
  font-size: 15px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ---------- Paneles ---------- */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fade 0.2s ease;
}

@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Buscador ---------- */
.search-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-bottom: 20px;
}

.type-toggle {
  display: flex;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}

.chip {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.chip.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}

.search-bar {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 260px;
}

.search-bar input {
  flex: 1;
}

/* ---------- Tarjetas ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card h3 {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

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

.result-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.poster {
  position: relative;
  aspect-ratio: 2 / 3;
  background: var(--bg-1);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

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

.poster-placeholder {
  font-size: 40px;
  opacity: 0.5;
}

.card-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}

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

.badge {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--card-2);
  color: var(--muted);
}

.badge.ok {
  background: rgba(52, 211, 153, 0.15);
  color: var(--ok);
}

.badge.pending {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warn);
}

.card-overview {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-actions {
  margin-top: auto;
  padding-top: 10px;
}

.card-actions .btn {
  width: 100%;
}

/* ---------- Listas (biblioteca / cola) ---------- */
.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  flex-wrap: wrap;
}

.list-item .info {
  flex: 1;
  min-width: 160px;
}

.list-item .title {
  font-weight: 600;
  font-size: 15px;
}

.list-item .sub {
  font-size: 13px;
  color: var(--muted);
}

/* Barra de progreso */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 160px;
  flex: 1;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-1);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--blue));
  border-radius: 999px;
  transition: width 0.4s ease;
}

.progress-label {
  font-size: 13px;
  color: var(--muted);
  min-width: 42px;
  text-align: right;
}

/* ---------- Estado ---------- */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}

.service-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

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

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }

.service-name {
  font-size: 14px;
  flex: 1;
}

.service-url {
  font-size: 12px;
  color: var(--accent-2);
  text-decoration: none;
}

.service-url:hover {
  text-decoration: underline;
}

.indexer {
  padding: 6px 0;
  font-size: 14px;
}

/* ---------- Pie ---------- */
footer {
  text-align: center;
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.conn::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warn);
}

.conn.ok::before { background: var(--ok); }
.conn.down::before { background: var(--bad); }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 15, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-card {
  width: min(440px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.season-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.season-row:hover {
  background: var(--card-2);
}

.season-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.season-info {
  font-size: 14px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  justify-content: flex-end;
}

/* ---------- Mensajes ---------- */
.error {
  color: var(--bad);
  font-size: 14px;
  margin-top: 12px;
}

.warn {
  color: var(--warn);
  font-size: 14px;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 40px 0;
  font-size: 15px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 60;
  max-width: calc(100vw - 40px);
}

.toast.error {
  border-color: rgba(248, 113, 113, 0.5);
  color: var(--bad);
}

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  header {
    padding: 12px 16px;
  }

  nav {
    padding: 8px 8px 0;
    justify-content: space-between;
  }

  .tab {
    padding: 10px 12px;
    font-size: 14px;
    flex: 1;
    text-align: center;
  }

  main {
    padding: 16px;
  }

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

  .user {
    gap: 8px;
  }

  #username-label {
    display: none;
  }
}
