:root {
  /* Core Colors - Dark Premium */
  --bg-dark: #0f1115;
  --bg-panel: #16181d;
  --bg-card: #1e2128;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --secondary: #2dd4bf;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border: #2e3340;
  
  /* Status Colors */
  --success: #10b981;
  --error: #ef4444;
  --live: #f43f5e;
  
  /* Effects */
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  /* Transitions */
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Themes */
[data-theme="amoled"] {
  --bg-dark: #000000;
  --bg-panel: #050505;
  --bg-card: #0a0a0a;
  --border: #1a1a1a;
  --primary: #8b5cf6;
  --primary-hover: #7c3aed;
}

[data-theme="midnight"] {
  --bg-dark: #09101f;
  --bg-panel: #0b1426;
  --bg-card: #152238;
  --border: #233554;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  line-height: 1.5;
  overflow: hidden; /* Prevent scrolling on main body */
  -webkit-font-smoothing: antialiased;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-family: 'Outfit', sans-serif;
  color: var(--text-main);
}

/* Utilities */
.hidden { display: none !important; }

/* Scrollbar Customization */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Buttons */
button {
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-main);
  transition: var(--transition);
  font-family: 'Inter', sans-serif;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}
.btn-primary.full { width: 100%; }

.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--text-muted);
}
.btn-secondary.sm { padding: 6px 12px; }

.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-weight: 600;
}
.btn-danger:hover { background: var(--error); color: white; }

/* ========== SPLASH SCREEN ========== */
.splash {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease;
}
.splash-logo { text-align: center; margin-bottom: 40px; }
.splash-icon {
  font-size: 64px;
  color: var(--primary);
  margin-bottom: 20px;
  animation: pulseLogo 2s infinite ease-in-out;
}
.splash-title { font-size: 3rem; font-weight: 900; letter-spacing: -1px; }
.splash-title span { color: var(--primary); }
.splash-sub { color: var(--text-muted); font-size: 1.1rem; letter-spacing: 2px; text-transform: uppercase; }

.splash-loader {
  width: 200px;
  height: 4px;
  background: var(--bg-panel);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}
.loader-bar {
  position: absolute;
  top: 0; left: 0; height: 100%;
  width: 50%;
  background: var(--primary);
  border-radius: var(--radius-full);
  animation: loadingBar 1.5s infinite ease-in-out alternate;
}

@keyframes pulseLogo {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes loadingBar {
  0% { left: 0; width: 30%; }
  100% { left: 70%; width: 30%; }
}

/* ========== MODAL ========== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: var(--transition);
}
.modal-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 500px;
  padding: 30px;
  position: relative;
  box-shadow: var(--shadow-lg);
  animation: modalEnter 0.3s ease-out;
}
@keyframes modalEnter {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-close {
  position: absolute;
  top: 20px; right: 20px;
  background: var(--bg-card);
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--error); }

.modal-header { text-align: center; margin-bottom: 30px; }
.modal-icon {
  width: 60px; height: 60px;
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  margin: 0 auto 15px;
}
.modal-header h2 { margin-bottom: 5px; }
.modal-header p { color: var(--text-muted); font-size: 0.9rem; }

.modal-tabs {
  display: flex;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 25px;
}
.mtab {
  flex: 1; padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 500;
  color: var(--text-muted);
}
.mtab.active { background: var(--bg-panel); color: var(--text-main); box-shadow: var(--shadow-sm); }

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease; }

.input-group {
  position: relative; margin-bottom: 20px;
}
.input-group i {
  position: absolute; left: 15px; top: 15px;
  color: var(--text-muted);
}
.input-group input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 14px 15px 14px 45px;
  border-radius: var(--radius-md);
  font-family: inherit; font-size: 0.95rem;
  transition: var(--transition);
}
.input-group input:focus { border-color: var(--primary); outline: none; }

.file-drop-zone {
  border: 2px dashed var(--border);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 20px;
}
.file-drop-zone:hover { border-color: var(--primary); background: rgba(99, 102, 241, 0.05); }
.file-drop-zone i { font-size: 40px; color: var(--primary); margin-bottom: 15px; }
.file-drop-zone span { display: block; margin-top: 10px; font-size: 0.8rem; color: var(--text-muted); }

.demo-info {
  background: rgba(45, 212, 191, 0.1);
  color: var(--secondary);
  padding: 10px 15px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 20px;
  display: flex; gap: 10px; align-items: flex-start;
}
.demo-list { display: flex; flex-direction: column; gap: 10px; }
.demo-item {
  display: flex; align-items: center; gap: 15px;
  background: var(--bg-card);
  padding: 15px; border-radius: var(--radius-md);
  border: 1px solid var(--border);
  text-align: left;
}
.demo-item:hover { border-color: var(--primary); transform: translateX(5px); }
.demo-item i:first-child { font-size: 24px; color: var(--primary); width: 30px; text-align: center; }
.demo-item div { flex: 1; }
.demo-item strong { display: block; font-size: 1rem; }
.demo-item span { color: var(--text-muted); font-size: 0.8rem; }

/* ========== APP LAYOUT ========== */
.app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* SIDEBAR */
.sidebar {
  width: 320px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  z-index: 100;
}
.sidebar.collapsed { margin-left: -320px; }

.sidebar-header {
  padding: 20px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 10px; font-family: 'Outfit'; font-size: 1.5rem; font-weight: 700; color: var(--text-main); }
.logo i { color: var(--primary); }
.logo b { color: var(--primary); font-weight: 900; }

.sidebar-toggle {
  background: var(--bg-card);
  width: 36px; height: 36px; border-radius: var(--radius-sm);
}
.sidebar-toggle:hover { background: var(--border); }

/* Search in Sidebar */
.search-wrap {
  padding: 15px 20px;
  position: relative;
}
.search-wrap i { position: absolute; left: 35px; top: 27px; color: var(--text-muted); font-size: 0.9rem; }
.search-wrap input {
  width: 100%;
  background: var(--bg-dark); border: 1px solid var(--border);
  padding: 10px 35px 10px 40px; border-radius: var(--radius-full);
  color: var(--text-main); font-size: 0.9rem;
}
.search-wrap input:focus { border-color: var(--primary); outline: none; }
.search-clear {
  position: absolute; right: 25px; top: 22px;
  width: 24px; height: 24px; background: var(--bg-panel); border-radius: 50%;
}

/* Categories List */
.categories-wrap { padding: 0 20px 10px; border-bottom: 1px solid var(--border); }
.categories-wrap h4 { font-size: 0.75rem; color: var(--text-muted); letter-spacing: 1px; margin-bottom: 10px; }
.categories { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 5px; }
.categories::-webkit-scrollbar { height: 4px; }
.cat-badge {
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: var(--radius-full);
  font-size: 0.8rem; white-space: nowrap; cursor: pointer;
  transition: var(--transition);
}
.cat-badge:hover, .cat-badge.active {
  background: var(--primary); border-color: var(--primary); color: white;
}

/* Channel List */
.channels-wrap { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.channels-header {
  padding: 15px 20px;
  display: flex; justify-content: space-between; align-items: center;
}
.channels-header h4 { font-size: 0.85rem; font-weight: 600; text-transform: uppercase; }
.badge { background: var(--bg-card); padding: 2px 8px; border-radius: var(--radius-full); font-size: 0.75rem; font-weight: 700; color: var(--text-muted); }

.channel-list {
  flex: 1; overflow-y: auto; padding: 0 10px 20px;
}
.channel-item {
  display: flex; align-items: center; gap: 15px;
  padding: 12px 15px; margin-bottom: 8px;
  background: transparent; border-radius: var(--radius-md);
  cursor: pointer; transition: var(--transition); border: 1px solid transparent;
  width: 100%; text-align: left;
}
.channel-item:hover { background: rgba(255, 255, 255, 0.03); }
.channel-item.active { background: var(--bg-card); border-color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }

.ci-logo {
  width: 40px; height: 40px; background: var(--bg-dark); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0;
}
.ci-logo img { width: 100%; height: 100%; object-fit: contain; }
.ci-logo i { color: var(--text-muted); font-size: 16px; }

.ci-info { flex: 1; overflow: hidden; }
.ci-name { font-size: 0.95rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.ci-cat { font-size: 0.75rem; color: var(--text-muted); display: block; margin-top: 2px; }

/* Sidebar Footer */
.sidebar-footer {
  padding: 15px; border-top: 1px solid var(--border);
  display: flex; gap: 10px;
}
.sf-btn {
  flex: 1; padding: 10px; background: var(--bg-card); border-radius: var(--radius-sm);
  font-size: 0.85rem; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.sf-btn:hover { background: var(--border); }
.sf-btn:first-child { color: var(--primary); }

/* MAIN CONTENT */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
  position: relative;
  overflow: hidden;
}

/* Topbar */
.topbar {
  height: 70px; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(15, 17, 21, 0.8); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 20px; }

.sidebar-toggle-mobile {
  display: none; width: 40px; height: 40px; background: var(--bg-panel); border-radius: var(--radius-sm);
}

.now-playing-info { display: flex; flex-direction: column; }
.np-label { font-size: 0.7rem; color: var(--text-muted); font-weight: 700; letter-spacing: 1px; }
.np-name { font-family: 'Outfit'; font-weight: 600; font-size: 1.1rem; }

.topbar-right { display: flex; align-items: center; gap: 15px; }
.quality-badge { background: var(--primary); color: white; padding: 4px 8px; border-radius: 4px; font-size: 0.75rem; font-weight: 700; letter-spacing: 1px; }
.tb-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-panel); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 1rem;
}
.tb-btn:hover { background: var(--border); color: var(--primary); }
.tb-btn.active { color: var(--live); } /* Heart active */

/* PLAYER SECTION */
.player-section {
  flex: 1;
  margin-top: 70px;
  position: relative;
  display: flex; flex-direction: column;
  padding: 20px; gap: 20px;
}

.video-container {
  flex: 1;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
#mainPlayer { width: 100%; height: 100%; object-fit: contain; outline: none; background: #000; }

.player-placeholder {
  position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--bg-panel), var(--bg-dark));
  display: flex; align-items: center; justify-content: center;
  z-index: 2;
}
.ph-content { text-align: center; max-width: 400px; }
.ph-icon { font-size: 80px; color: rgba(99, 102, 241, 0.2); margin-bottom: 20px; }
.pulse-anim { animation: pulseLogo 3s infinite ease-in-out; }
.ph-content h2 { margin-bottom: 10px; font-size: 2rem; }
.ph-content p { color: var(--text-muted); margin-bottom: 30px; }

.player-loading {
  position: absolute; inset: 0; z-index: 3;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(5px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 15px;
}
.loading-spinner {
  width: 50px; height: 50px;
  border: 4px solid rgba(255,255,255,0.1); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.player-error {
  position: absolute; inset: 0; z-index: 3;
  background: rgba(0,0,0,0.8);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px;
}
.player-error i { font-size: 50px; color: var(--error); margin-bottom: 15px; }
.player-error p { color: var(--text-muted); margin-bottom: 20px; max-width: 400px; }
.error-actions { display: flex; gap: 10px; }

/* Custom Video Controls */
.player-controls {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 5;
  padding: 20px;
  display: flex; flex-direction: column; justify-content: flex-end;
  opacity: 0; transition: opacity 0.3s;
}
.video-container:hover .player-controls, .video-container.controls-active .player-controls { opacity: 1; }
.controls-gradient {
  position: absolute; bottom: 0; left: 0; right: 0; height: 150px;
  background: linear-gradient(to top, rgba(0,0,0,0.9), transparent); z-index: -1; pointer-events: none;
}
.controls-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.ctrl-channel-name { font-weight: 600; font-size: 1.1rem; text-shadow: 0 2px 4px rgba(0,0,0,0.8); }
.live-badge { background: var(--live); color: white; padding: 4px 8px; border-radius: 4px; font-size: 0.7rem; font-weight: 700; display: flex; align-items: center; gap: 5px; }
.live-badge i { font-size: 8px; animation: blink 1.5s infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.controls-bottom { display: flex; justify-content: space-between; align-items: center; }
.ctrl-left, .ctrl-right { display: flex; align-items: center; gap: 15px; }
.ctrl-btn {
  color: white; font-size: 1.2rem; width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: rgba(255,255,255,0.1); backdrop-filter: blur(4px);
}
.ctrl-btn:hover { background: var(--primary); transform: scale(1.1); }
.main-btn { width: 50px; height: 50px; font-size: 1.5rem; background: var(--primary); }

.volume-wrap { display: flex; align-items: center; gap: 10px; width: 120px; opacity: 0; transition: var(--transition); transform: translateX(-10px); }
.ctrl-left:hover .volume-wrap { opacity: 1; transform: translateX(0); }
.volume-slider { width: 100%; height: 4px; cursor: pointer; accent-color: var(--primary); }

.live-dot { font-size: 0.8rem; font-weight: 600; display: flex; align-items: center; gap: 6px; color: rgba(255,255,255,0.5); }
.live-dot i { color: var(--live); font-size: 8px; }

/* Info Bar Below Video */
.channel-info-bar {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 20px;
  display: flex; align-items: center; gap: 20px;
}
.cib-logo {
  width: 60px; height: 60px; background: var(--bg-dark); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.cib-logo img { width: 100%; height: 100%; object-fit: contain; }
.cib-logo i { font-size: 24px; color: var(--text-muted); }

.cib-details { flex: 1; }
.cib-details h3 { font-size: 1.5rem; margin-bottom: 5px; }
.cib-meta { display: flex; gap: 15px; font-size: 0.85rem; color: var(--text-muted); }
.cib-meta span { display: flex; align-items: center; gap: 5px; }
.cib-actions { display: flex; gap: 10px; }

/* Bottom Panels (Optional extensions like EPG or similar) */
.bottom-panels { display: none; } /* Hidden by default, can be toggled */

/* ========== SETTINGS PANEL ========== */
.settings-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 350px;
  background: var(--bg-panel); border-left: 1px solid var(--border);
  z-index: 100;
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -10px 0 30px rgba(0,0,0,0.5);
}
.settings-panel:not(.hidden) { transform: translateX(0); }

.settings-header {
  padding: 20px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.settings-header h3 { display: flex; align-items: center; gap: 10px; font-size: 1.2rem; }
.settings-header button { width: 32px; height: 32px; background: var(--bg-card); border-radius: 50%; }

.settings-body { padding: 20px; flex: 1; overflow-y: auto; }
.setting-group { margin-bottom: 30px; }
.setting-group h4 { font-size: 0.8rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 15px; letter-spacing: 1px; }

.setting-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.setting-item:last-child { border-bottom: none; }
.setting-item label { font-size: 0.95rem; }

.setting-slider { width: 100px; accent-color: var(--primary); }
.setting-select {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text-main);
  padding: 6px 10px; border-radius: var(--radius-sm); outline: none; font-size: 0.9rem;
}

/* Toggle Switch */
.toggle-switch {
  width: 44px; height: 24px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; position: relative; cursor: pointer; transition: var(--transition);
}
.toggle-switch.active { background: var(--primary); border-color: var(--primary); }
.toggle-knob {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  background: white; border-radius: 50%; transition: var(--transition);
}
.toggle-switch.active .toggle-knob { left: 22px; }

/* Util */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--bg-panel); border-left: 4px solid var(--primary);
  padding: 12px 20px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); color: var(--text-main);
  animation: slideIn 0.3s ease forwards;
  display: flex; align-items: center; gap: 10px; min-width: 250px;
}
.toast.error { border-left-color: var(--error); }
.toast.success { border-left-color: var(--success); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ========== RESPONSIVE ========== */
@media (max-width: 992px) {
  .player-section { padding: 10px; }
  .channel-info-bar { flex-direction: column; text-align: center; }
  .cib-meta { justify-content: center; }
}

@media (max-width: 768px) {
  .sidebar { position: fixed; inset: 0 0 0 -100%; top: 70px; width: 100%; z-index: 50; }
  .sidebar.mobile-open { left: 0; margin: 0; }
  .sidebar-toggle { display: none; }
  .sidebar-toggle-mobile { display: flex; align-items: center; justify-content: center; }
  
  .controls-bottom { flex-wrap: wrap; justify-content: center; gap: 15px; }
  .volume-wrap { display: none; } /* Hide volume slider on mobile */
  
  .settings-panel { width: 100%; }
}
