:root {
  --bg-page: #0a0d14;
  --bg: #0e121b;
  --surface: #141924;
  --surface-raised: #1a2030;
  --surface-hover: #222a3d;
  --surface-input: #0f131d;
  --text: #eef1f6;
  --text-secondary: #c3cad6;
  --muted: #838da2;
  --primary: #6366f1;
  --primary-2: #4d8ef7;
  --primary-hover: #5457e6;
  --accent: #22d3ee;
  --success: #22c55e;
  --danger: #f43f5e;
  --warning: #f59e0b;
  --border: #222a3b;
  --border-light: #303a52;
  --radius: 10px;
  --radius-lg: 16px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1100px 520px at 12% -12%, rgba(99, 102, 241, 0.12), transparent 60%),
    radial-gradient(900px 480px at 100% 0%, rgba(34, 211, 238, 0.07), transparent 55%),
    var(--bg-page);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .page-title, .brand, .card-panel-title {
  font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
  letter-spacing: -0.02em;
}

/* Header */
.app-header {
  background: rgba(12, 16, 24, 0.82);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { font-weight: 800; font-size: 18px; color: var(--text); gap: 10px; }
.brand-icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; font-size: 0;
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.38);
}
.brand-icon svg { width: 19px; height: 19px; }
.user-pill { background: var(--surface-raised); border: 1px solid var(--border); border-radius: 999px; color: var(--text-secondary); font-weight: 600; }

/* Nav */
.nav-menu { gap: 4px; padding: 8px 2px; }
.nav-item {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 11px;
  font-weight: 600; font-size: 13.5px; color: var(--muted);
  border: 1px solid transparent;
  transition: background .16s, color .16s, box-shadow .16s;
}
.nav-item svg { width: 17px; height: 17px; stroke-width: 2.1; }
.nav-item:hover { color: var(--text); background: var(--surface-hover); }
.nav-item.active {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.32);
}
.nav-item.active svg { color: #fff; }

.nav-group {
  position: relative;
  display: inline-flex;
}
.nav-group-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 11px;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition: background .16s, color .16s, border-color .16s;
}
.nav-group-btn svg { width: 17px; height: 17px; stroke-width: 2.1; }
.nav-group-btn .nav-chevron {
  width: 14px; height: 14px; opacity: 0.7;
  transition: transform .18s ease;
}
.nav-group-btn:hover,
.nav-group-btn.open {
  color: var(--text);
  background: var(--surface-hover);
}
.nav-group-btn.open {
  border-color: rgba(99, 102, 241, 0.45);
  color: #fff;
  background: rgba(99, 102, 241, 0.18);
}
.nav-group-btn.open .nav-chevron { transform: rotate(180deg); }
.nav-group-btn.has-active {
  border-color: rgba(99, 102, 241, 0.35);
  color: #fff;
}

.nav-submenu {
  border-top: 1px solid var(--border);
  background: rgba(15, 19, 29, 0.96);
  padding: 10px 0 12px;
}
.nav-submenu[hidden] { display: none !important; }
.nav-submenu-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.nav-submenu-inner .nav-item {
  background: var(--surface);
  border: 1px solid var(--border);
}
.nav-submenu-inner .nav-item:hover {
  border-color: rgba(99, 102, 241, 0.4);
}
.nav-submenu-inner .nav-item.active {
  border-color: transparent;
}

/* Page header */
.page-header { margin-bottom: 22px; }
.page-title { font-size: 27px; font-weight: 800; color: var(--text); }
.page-sub { color: var(--muted); font-size: 14px; }

/* Cards / panels */
.card, .card-panel {
  background: linear-gradient(180deg, var(--surface-raised), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
}
.card:hover { border-color: var(--border-light); }
.card h2, .card-panel-title { font-weight: 700; font-size: 17px; color: var(--text); }
.muted { color: var(--muted); }

/* Buttons */
.btn {
  border-radius: 10px; font-weight: 600; letter-spacing: 0.01em;
  transition: filter .15s, background .15s, transform .05s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border: none; color: #fff;
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.35);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--surface-raised); border: 1px solid var(--border); color: var(--text-secondary); }
.btn.ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn.danger { background: linear-gradient(135deg, #f43f5e, #e11d48); border: none; color: #fff; }

/* Inputs */
input, select, textarea {
  border-radius: 10px !important;
  background: var(--surface-input) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.22) !important;
  outline: none !important;
}

/* Tables */
table, .tbl { width: 100%; border-collapse: collapse; }
.tbl th, table th {
  color: var(--muted); font-weight: 700; text-align: left;
  text-transform: uppercase; font-size: 11px; letter-spacing: 0.05em;
  padding: 11px 12px; border-bottom: 1px solid var(--border);
}
.tbl td, table td { padding: 12px; border-bottom: 1px solid var(--border); color: var(--text-secondary); }
.tbl tbody tr, table tbody tr { transition: background .12s; }
.tbl tbody tr:hover, table tbody tr:hover { background: var(--surface-hover); }

/* Badge */
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 11px;
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.01em;
  border: 1px solid var(--border-light);
  background: var(--surface-hover);
  color: var(--text-secondary);
}
.badge.direct { background: rgba(77, 142, 247, 0.16); border-color: rgba(77, 142, 247, 0.45); color: #a8c6fb; }
.badge.extracted { background: rgba(124, 109, 240, 0.18); border-color: rgba(124, 109, 240, 0.55); color: #cbbdfb; }
.badge.iptv { background: rgba(245, 158, 11, 0.16); border-color: rgba(245, 158, 11, 0.5); color: #fbd38d; }
.badge.ok { background: rgba(34, 197, 94, 0.16); border-color: rgba(34, 197, 94, 0.5); color: #86efac; }
.badge.off { background: rgba(244, 63, 94, 0.16); border-color: rgba(244, 63, 94, 0.5); color: #fca5a5; }

/* Nav tab icons on the fly (dashboard cards etc.) */
.card-panel-title { letter-spacing: -0.01em; }

/* Dashboard stat cards */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(180deg, var(--surface-raised), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
  transition: transform .12s, border-color .12s;
}
.stat::before { display: none; }
.stat:hover { transform: translateY(-2px); border-color: var(--border-light); }
.stat-ico {
  width: 46px; height: 46px; flex: 0 0 46px;
  display: grid; place-items: center; border-radius: 13px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.3);
}
.stat-ico svg { width: 22px; height: 22px; color: #fff; }
.stat .label {
  color: var(--muted); font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.stat .value {
  font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
  font-size: 30px; font-weight: 800; color: var(--text); line-height: 1.05; margin-top: 3px;
}
.stat-channels .stat-ico { background: linear-gradient(135deg, #6366f1, #4d8ef7); }
.stat-extracted .stat-ico { background: linear-gradient(135deg, #8b5cf6, #a855f7); }
.stat-direct .stat-ico { background: linear-gradient(135deg, #22d3ee, #3698ee); }
.stat-iptv .stat-ico { background: linear-gradient(135deg, #f59e0b, #f97316); }
.stat-users .stat-ico { background: linear-gradient(135deg, #22c55e, #16a34a); }
.stat-premium .stat-ico { background: linear-gradient(135deg, #f43f5e, #ec4899); }

/* Quick-access cards */
.card-panel-title { margin-bottom: 14px; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

.detect-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.detect-form label { flex: 1 1 420px; display: flex; flex-direction: column; gap: 6px; }
.detect-form button { flex: 0 0 auto; }
.detect-status { margin-top: 12px; font-size: 14px; line-height: 1.5; }
.detect-status.ok { color: #34d399; }
.detect-status.error { color: #f87171; }
.detect-results { display: flex; flex-direction: column; gap: 16px; margin-top: 16px; }
.detect-candidates { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }

.cand {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  background: var(--surface-raised);
  transition: border-color .15s ease;
}
.cand:hover { border-color: var(--border-light); }
.cand-primary { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface-raised)); }
.cand-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.cand-url {
  display: block;
  word-break: break-all;
  font-size: 12.5px;
  color: var(--text-secondary);
  background: var(--surface-input);
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 10px;
}
.cand-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cand-actions .btn { display: inline-flex; align-items: center; gap: 5px; }
.cand-actions .btn i { width: 15px; height: 15px; }
.cand-preview {
  margin-top: 10px;
  padding: 10px;
  background: var(--surface-input);
  border-radius: 8px;
  font-size: 11.5px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 160px;
  overflow: auto;
}
.cand-test { margin-left: auto; }
.inline-check { display: flex; flex-direction: row; align-items: center; gap: 8px; margin: 10px 0; }
.inline-check input { width: auto; }

.detect-status.loading { display: flex; align-items: center; gap: 12px; color: var(--text); }
.detect-loader-txt { font-size: 14px; line-height: 1.4; }
.detect-timer { color: var(--muted); font-variant-numeric: tabular-nums; }
.detect-spinner {
  flex: 0 0 auto;
  width: 20px; height: 20px;
  border: 2.5px solid var(--border-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: detspin .7s linear infinite;
}
@keyframes detspin { to { transform: rotate(360deg); } }
.detect-save-hint { font-size: 12px; margin: -4px 0 12px; line-height: 1.4; }
.cand-blocked { border-color: #f43f5e; background: color-mix(in srgb, #f43f5e 6%, var(--surface-raised)); padding: 14px 16px; }

.dt-picker input[type="date"]::-webkit-calendar-picker-indicator,
.dt-picker input[type="time"]::-webkit-calendar-picker-indicator,
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(1.6);
  opacity: 0.85;
  cursor: pointer;
}

/* Mini switch (ej. columna "Pro" en tabla de canales) */
.mini-switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex: 0 0 auto;
  vertical-align: middle;
}
.mini-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.mini-switch .track {
  position: absolute;
  inset: 0;
  background: var(--surface-input);
  border: 1px solid var(--border-light);
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.mini-switch .track::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: var(--text);
  border-radius: 50%;
  transition: transform .15s ease;
}
.mini-switch input:checked + .track {
  background: var(--warning);
  border-color: var(--warning);
}
.mini-switch input:checked + .track::before {
  transform: translateX(16px);
  background: #1a1206;
}
.mini-switch input:disabled + .track {
  opacity: 0.5;
  cursor: not-allowed;
}
