/* ════════════════════════════════════════
   DESIGN SYSTEM — StalkerBridge
   ════════════════════════════════════════ */
:root {
  --bg:          #070b14;
  --bg-2:        #0b1120;
  --surface:     #0f1729;
  --surface-2:   #141e30;
  --surface-3:   #1a2540;
  --border:      rgba(255,255,255,0.07);
  --border-2:    rgba(255,255,255,0.12);

  --primary:         #3b82f6;
  --primary-dark:    #2563eb;
  --primary-glow:    rgba(59,130,246,0.18);
  --indigo:          #6366f1;
  --cyan:            #06b6d4;
  --purple:          #a855f7;

  --success:    #10b981;
  --success-bg: rgba(16,185,129,0.12);
  --error:      #ef4444;
  --error-bg:   rgba(239,68,68,0.12);
  --warning:    #f59e0b;
  --warning-bg: rgba(245,158,11,0.12);
  --info:       #3b82f6;
  --info-bg:    rgba(59,130,246,0.12);

  --text:      #e2e8f0;
  --text-dim:  #94a3b8;
  --text-muted:#64748b;

  --sidebar-w: 240px;
  --topbar-h:  60px;
  --radius:    14px;
  --radius-sm: 9px;
  --radius-xs: 6px;
  --transition: 0.18s ease;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 10px rgba(0,0,0,0.3);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
}

a { text-decoration: none; color: inherit; }
code {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  background: var(--surface-3);
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  color: #93c5fd;
}
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; display: inline-block; }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ══════════════════════════════════════
   LOGIN SCREEN
   ══════════════════════════════════════ */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  background: var(--bg);
}
.login-bg {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(59,130,246,0.12), transparent),
              radial-gradient(ellipse 60% 40% at 80% 100%, rgba(99,102,241,0.08), transparent);
  pointer-events: none;
}
.login-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 20px;
  padding: 40px;
  width: 400px;
  max-width: 95vw;
  box-shadow: 0 32px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
  animation: fadeUp 0.3s ease;
}
.login-logo {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 32px;
}
.login-logo-icon { flex-shrink: 0; }
.login-title { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.login-sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

/* ══════════════════════════════════════
   APP SHELL
   ══════════════════════════════════════ */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: width var(--transition), transform var(--transition);
  overflow: hidden;
  z-index: 100;
}
.sidebar.collapsed { width: 64px; }
.sidebar.mobile-open { transform: translateX(0) !important; }

.sidebar-header {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-logo-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  white-space: nowrap;
  background: linear-gradient(135deg, #60a5fa, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  transition: opacity var(--transition);
}
.sidebar.collapsed .sidebar-logo-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-user-info { opacity: 0; width: 0; overflow: hidden; }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
  overflow-x: hidden;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 13.5px;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  white-space: nowrap;
  margin-bottom: 2px;
  position: relative;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.nav-item.active {
  background: var(--primary-glow);
  color: #93c5fd;
  border: 1px solid rgba(59,130,246,0.25);
}
.nav-item.active .nav-icon { color: var(--primary); }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-label { flex: 1; }
.nav-badge {
  background: var(--primary);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  min-width: 22px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}
.sidebar-user {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}
.sidebar-avatar {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--primary), var(--indigo));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.sidebar-username { font-weight: 600; font-size: 13px; display: block; white-space: nowrap; }
.sidebar-role { color: var(--text-muted); font-size: 11px; display: block; }
.sidebar-user-info { overflow: hidden; transition: opacity var(--transition); }
.btn-logout {
  width: 34px; height: 34px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.btn-logout:hover { background: var(--error-bg); border-color: rgba(239,68,68,0.3); color: var(--error); }

/* ── MAIN WRAP ── */
.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── TOPBAR ── */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  flex-shrink: 0;
  z-index: 50;
}
.topbar-menu-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px 8px;
  display: flex; align-items: center;
  transition: background var(--transition);
}
.topbar-menu-btn:hover { background: var(--surface-3); }
.topbar-title { font-size: 15px; font-weight: 600; flex: 1; }
.topbar-status { display: flex; align-items: center; gap: 8px; }

.conn-indicator {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-muted);
}
.conn-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background var(--transition);
}
.conn-dot.ok    { background: var(--success); box-shadow: 0 0 6px rgba(16,185,129,0.5); animation: pulse 2s infinite; }
.conn-dot.error { background: var(--error); }
.conn-dot.loading { background: var(--warning); animation: pulse 0.8s infinite; }

/* ── PAGES ── */
.pages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}
.page { display: none; }
.page.active { display: block; animation: fadeUp 0.2s ease; }

.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.4px; }
.page-sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ── CARDS ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-badge { font-size: 12px; color: var(--text-muted); }

/* ── STATS GRID ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition);
}
.stat-card:hover { border-color: var(--border-2); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-blue   { background: rgba(59,130,246,0.12); color: #60a5fa; }
.stat-purple { background: rgba(168,85,247,0.12); color: #c084fc; }
.stat-green  { background: rgba(16,185,129,0.12); color: #34d399; }
.stat-cyan   { background: rgba(6,182,212,0.12);  color: #22d3ee; }
.stat-value { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline {
  background: transparent;
  border-color: var(--border-2);
  color: var(--text-dim);
}
.btn-outline:hover:not(:disabled) { background: var(--surface-3); color: var(--text); border-color: rgba(255,255,255,0.2); }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-full { width: 100%; justify-content: center; padding: 12px; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--surface-3); color: var(--text); border-color: var(--border-2); }
.btn-icon.copied { color: var(--success); border-color: rgba(16,185,129,0.4); }

.card-header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.add-toggle-btn { flex-shrink: 0; }
.add-toggle-btn svg { transition: transform var(--transition); }
.add-toggle-btn[aria-expanded="true"] svg { transform: rotate(45deg); }
.add-form-collapsible { margin-top: 16px; padding-top: 4px; }
.list-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.list-header .text-muted { font-size: 13px; }

/* ── FORMS ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 7px;
}
.required { color: var(--error); }
.form-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 14px;
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-input:focus {
  border-color: rgba(59,130,246,0.6);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}
.form-input::placeholder { color: var(--text-muted); }
.form-input[readonly] { opacity: 0.7; cursor: default; }
.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; display: block; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.input-with-copy { position: relative; display: flex; align-items: center; gap: 8px; }
.input-with-copy .form-input { flex: 1; }
.input-action-row { display: flex; gap: 8px; align-items: center; }
.input-action-row .form-input { flex: 1; }

/* ── ADVANCED BLOCK ── */
.advanced-block {
  margin-top: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
}
.advanced-summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  transition: color var(--transition);
}
.advanced-summary:hover { color: var(--text); }
details[open] .advanced-summary svg { transform: rotate(90deg); }
.advanced-summary svg { transition: transform var(--transition); }

/* ── ALERTS ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
}
.alert-success { background: var(--success-bg); border-color: rgba(16,185,129,0.3); color: #6ee7b7; }
.alert-error   { background: var(--error-bg);   border-color: rgba(239,68,68,0.3);  color: #fca5a5; }
.alert-warning { background: var(--warning-bg); border-color: rgba(245,158,11,0.3); color: #fcd34d; }
.alert-info    { background: var(--info-bg);    border-color: rgba(59,130,246,0.3); color: #93c5fd; }

/* ── CHIPS ── */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.chip-blue    { background: rgba(59,130,246,0.15);  color: #93c5fd; border: 1px solid rgba(59,130,246,0.3); }
.chip-success { background: rgba(16,185,129,0.15);  color: #6ee7b7; border: 1px solid rgba(16,185,129,0.3); }
.chip-info    { background: rgba(6,182,212,0.15);   color: #67e8f9; border: 1px solid rgba(6,182,212,0.3); }
.chip-purple  { background: rgba(168,85,247,0.15);  color: #d8b4fe; border: 1px solid rgba(168,85,247,0.3); }
.chip-gray    { background: var(--surface-3);        color: var(--text-dim); border: 1px solid var(--border); }

/* ── SOURCE STATUS (Xtream/Stalker expiry) ── */
.source-status {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.source-status-active   { background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3); }
.source-status-expired  { background: rgba(239,68,68,0.15);  color: #f87171; border: 1px solid rgba(239,68,68,0.3); }
.source-status-unknown  { background: var(--surface-3);      color: var(--text-dim); border: 1px solid var(--border); }

/* ── CONN LIST (Dashboard) ── */
.conn-list { display: flex; flex-direction: column; gap: 1px; }
.conn-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
}
.conn-key {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  width: 80px;
  flex-shrink: 0;
}
.conn-val {
  flex: 1;
  color: #93c5fd;
  font-size: 12.5px;
  background: transparent;
  padding: 0;
  max-width: 0;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── CONN CARDS (Links page) ── */
.conn-card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.conn-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
}
.conn-card-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.conn-card-value {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.conn-card-value code {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

/* ── QUICK ACTIONS ── */
.link-selection-note {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid rgba(59,130,246,0.25);
  border-radius: var(--radius-sm);
  background: rgba(59,130,246,0.07);
  color: var(--text-dim);
  font-size: 12px;
}
.link-selection-note > strong { color: var(--text); }
.link-selection-note p { margin-top: 7px; color: var(--text-muted); }
.link-selection-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 8px;
}
.link-selection-summary span { color: #bfdbfe; }

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.quick-btn { justify-content: center; }

.loop-dashboard-card .card-header {
  align-items: flex-start;
}
.loop-dashboard-card .text-muted {
  margin-top: 4px;
  font-size: 12px;
}
.loop-config-grid {
  display: grid;
  grid-template-columns: 110px minmax(160px, 0.8fr) minmax(260px, 1.6fr) minmax(140px, 0.8fr) minmax(160px, 0.9fr);
  gap: 12px;
  align-items: end;
}
.loop-config-grid .form-group {
  margin-bottom: 0;
}
.loop-toggle {
  height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
}
.loop-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}
.loop-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.loop-meta-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.loop-meta-item span {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.loop-meta-item strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 13px;
  overflow-wrap: anywhere;
}

/* ── CATEGORIES ── */

/* ── CATEGORY TABS ── */
.cats-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: -1px;
  position: relative;
  z-index: 5;
}
.cats-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}
.cats-tab:hover { color: var(--text); background: var(--surface-2); }
.cats-tab.active {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-2);
  border-bottom-color: var(--surface);
}
.cats-tab.active[data-tab="live"]   { color: #60a5fa; }
.cats-tab.active[data-tab="vod"]    { color: #c084fc; }
.cats-tab.active[data-tab="series"] { color: #34d399; }
.tab-badge {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 99px;
  min-width: 20px;
  text-align: center;
}
.cats-tab.active .tab-badge {
  background: var(--primary-glow);
  border-color: rgba(59,130,246,0.3);
  color: #93c5fd;
}

.cats-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 18px;
  margin-bottom: 0;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.cats-toolbar-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.cats-toolbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.search-box {
  position: relative;
  flex: 1;
  max-width: 320px;
}
.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 12px 8px 34px;
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-input:focus {
  border-color: rgba(59,130,246,0.6);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}
.cats-stat { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.cats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
  padding: 16px 0;
}
.cat-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 132px;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}
.cat-item:hover { border-color: var(--border-2); background: var(--surface-2); }
.cat-item.selected {
  border-color: rgba(59,130,246,0.5);
  background: rgba(59,130,246,0.08);
}
.cat-item.selected .cat-name { color: #93c5fd; }
.cat-check {
  width: 18px; height: 18px;
  border: 2px solid var(--border-2);
  border-radius: 5px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  background: transparent;
}
.cat-item.selected .cat-check {
  background: var(--primary);
  border-color: var(--primary);
}
.cat-check svg { display: none; }
.cat-item.selected .cat-check svg { display: block; }
.cat-info { flex: 1; min-width: 0; }
.cat-name {
  font-size: 14px;
  line-height: 1.35;
  font-weight: 650;
  overflow-wrap: anywhere;
}
.cat-source-line {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  margin-top: 9px;
}
.cat-source-name {
  min-width: 0;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.cat-source-url {
  margin-top: 6px;
  color: #7dd3fc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10.5px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.cat-source-local {
  color: var(--text-muted);
  font-family: inherit;
}
.cat-id {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 7px;
}
.cat-source {
  padding: 1px 6px;
  font-size: 9px;
  letter-spacing: 0.3px;
}

.save-bar {
  position: sticky;
  bottom: -24px;
  margin: 0 -24px -24px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 20;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.3);
  animation: slideUp 0.2s ease;
}
.save-bar-text { font-size: 13px; color: var(--text-dim); }

/* ── LOADING / EMPTY STATES ── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state p { font-size: 14px; }

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border-2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── API TABLE ── */
.api-table { display: flex; flex-direction: column; gap: 6px; }
.api-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  flex-wrap: wrap;
}
.api-method {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  text-transform: uppercase;
  flex-shrink: 0;
}
.api-method.get   { background: rgba(16,185,129,0.15); color: #6ee7b7; }
.api-method.redir { background: rgba(245,158,11,0.15);  color: #fcd34d; }
.api-path {
  flex: 1;
  font-size: 12px;
  background: transparent;
  padding: 0;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.api-desc { font-size: 11.5px; color: var(--text-muted); flex-shrink: 0; }

/* ── DEBUG RESULT ── */
.custom-playlist-list { display: flex; flex-direction: column; gap: 12px; }
.custom-category-block {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  overflow: hidden;
}
.custom-category-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.custom-category-head > div { display: flex; align-items: center; gap: 10px; }
.custom-streams { display: flex; flex-direction: column; }
.custom-stream-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}
.custom-stream-row:last-child { border-bottom: 0; }
.custom-stream-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.custom-stream-main strong { font-size: 13px; }
.custom-stream-main span, .custom-empty { font-size: 11.5px; color: var(--text-muted); }
.custom-stream-main { flex: 1; }
.custom-stream-title, .custom-stream-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.custom-stream-url {
  display: block;
  max-width: 100%;
  overflow: hidden;
  color: #93c5fd;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.custom-empty { padding: 14px; }

.loop-links-list { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.loop-link-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.loop-link-order { flex: 0 0 auto; font-weight: 700; }
.loop-link-url { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loop-add-link-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.loop-add-link-row .form-input { flex: 1; }

/* ── WEB PLAYER ── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.player-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.9fr);
  gap: 16px;
}
.player-panel,
.player-list-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.player-video-wrap {
  position: relative;
  background: #020617;
  aspect-ratio: 16 / 9;
}
.player-video {
  width: 100%;
  height: 100%;
  display: block;
  background: #020617;
}
.player-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}
.player-placeholder.hidden { display: none; }
.player-now {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}
.player-now > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.player-now strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-panel .alert {
  margin: 0 16px 16px;
}
.player-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.player-tab {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.player-tab:hover,
.player-tab.active {
  color: var(--text);
  border-color: rgba(59, 130, 246, 0.55);
  background: rgba(59, 130, 246, 0.12);
}
.player-category-row {
  padding: 0 14px 14px;
  border-bottom: 1px solid var(--border);
}
.player-list-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}
.player-list-head .form-input { flex: 1; }
.player-channel-list {
  max-height: 560px;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.player-channel {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.player-channel:hover,
.player-channel.active {
  background: rgba(59, 130, 246, 0.1);
}
.player-channel-logo {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  object-fit: contain;
  border-radius: var(--radius-xs);
  background: var(--bg);
  border: 1px solid var(--border);
}
.player-channel-logo.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}
.player-channel-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.player-channel-title {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-channel-meta {
  color: var(--text-muted);
  font-size: 11.5px;
}
.player-series-title {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
}

/* ── TOASTS ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  box-shadow: var(--shadow);
  pointer-events: all;
  animation: toastIn 0.25s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: 380px;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--error); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-info    { border-left: 3px solid var(--primary); }
.toast.out     { animation: toastOut 0.2s ease forwards; }

/* ── TEXT HELPERS ── */
.text-muted { color: var(--text-muted); font-size: 13px; }

/* ══════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* ══════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════ */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .conn-card-grid { grid-template-columns: 1fr; }
  .loop-config-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .form-grid-3 { grid-template-columns: 1fr; }
  .quick-actions { grid-template-columns: 1fr; }
  .loop-config-grid { grid-template-columns: 1fr; }
  .player-layout { grid-template-columns: 1fr; }
  .player-channel-list { max-height: 420px; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 240px;
    transform: translateX(-100%);
    z-index: 200;
    box-shadow: 8px 0 32px rgba(0,0,0,0.5);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
  }
  .pages { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .cats-toolbar { position: relative; }
  .loop-meta-grid { grid-template-columns: 1fr; }
  .save-bar { margin: 0 -16px -16px; bottom: -16px; }
}

@media (max-width: 480px) {
  .login-box { padding: 28px 20px; }
  .stats-grid { grid-template-columns: 1fr; }
  .cats-toolbar { flex-direction: column; align-items: stretch; }
  .cats-toolbar-left { flex-direction: column; }
  .cats-toolbar-right { flex-wrap: wrap; }
  .search-box { max-width: none; }
}
