:root {
  --bg-base: #0a0b0e;
  --bg-surface: #12141a;
  --bg-card: #181b24;
  --bg-card-hover: #222634;
  --bg-card-active: #2a3044;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #6366f1;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: rgba(99, 102, 241, 0.15);
  --live-color: #ef4444;
  --badge-clearkey: #10b981;
  --badge-dash: #06b6d4;
  --badge-hls: #f59e0b;
  --sidebar-width: 380px;
  --topbar-height: 64px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-base);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* TOP NAVIGATION BAR */
.topbar {
  height: var(--topbar-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 20px;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 200px;
}

.logo-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.5px;
}

.brand-accent {
  color: #818cf8;
}

.brand-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

.search-wrapper {
  flex: 1;
  max-width: 520px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  height: 42px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 0 40px 0 42px;
  color: var(--text-main);
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

#search-input:focus {
  outline: none;
  border-color: var(--border-focus);
  background-color: #1e222e;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.clear-btn {
  position: absolute;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.switch {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #475569;
  transition: .3s;
  border-radius: 18px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--accent);
}

input:checked + .slider:before {
  transform: translateX(14px);
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover {
  background-color: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

/* MAIN LAYOUT */
.main-layout {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--topbar-height));
  position: relative;
  overflow: hidden;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s ease, margin-left 0.3s ease;
  z-index: 50;
}

.sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-width));
}

.filter-controls-wrapper {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  width: 60px;
  flex-shrink: 0;
}

.control-row .select-box {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.select-chevron {
  position: absolute;
  right: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

#source-select, #category-select {
  width: 100%;
  height: 36px;
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0 28px 0 10px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
}

#source-select:hover, #category-select:hover {
  background-color: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.15);
}

#source-select:focus, #category-select:focus {
  border-color: var(--border-focus);
  background-color: #1a1e2a;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

#source-select option, #category-select option {
  background-color: #141722;
  color: var(--text-main);
  padding: 8px;
}

.channel-list-header {
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.text-btn {
  background: none;
  border: none;
  color: #818cf8;
  font-size: 0.75rem;
  cursor: pointer;
}

.channel-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.channel-card {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.18s ease;
  gap: 12px;
  user-select: none;
}

.channel-card:hover {
  background-color: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

.channel-card.active {
  background-color: var(--bg-card-active);
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.2);
}

.channel-logo-wrap {
  width: 44px;
  height: 44px;
  background: #111319;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.channel-logo-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.channel-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ch-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ch-meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.badge-dash {
  background: rgba(6, 182, 212, 0.15);
  color: #22d3ee;
}

.badge-hls {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.badge-drm {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.badge-group {
  background: rgba(255, 255, 255, 0.08);
  color: #cbd5e1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.playing-indicator {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}

.playing-indicator span {
  background: var(--accent);
  width: 3px;
  border-radius: 1px;
  animation: bounce 0.8s infinite alternate ease-in-out;
}
.playing-indicator span:nth-child(2) { animation-delay: 0.25s; }
.playing-indicator span:nth-child(3) { animation-delay: 0.5s; }

@keyframes bounce {
  from { height: 4px; }
  to { height: 16px; }
}

/* STAGE & PLAYER */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: #060709;
  position: relative;
  overflow: hidden;
}

.player-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #000;
}

#player-container {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background-color: #000;
}

/* Shaka Player UI customization */
.shaka-video-container {
  width: 100% !important;
  height: 100% !important;
}

/* Overlays */
.stream-overlay {
  position: absolute;
  top: 20px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(10, 11, 14, 0.75);
  backdrop-filter: blur(8px);
  padding: 8px 16px;
  border-radius: 30px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 10;
  pointer-events: none;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--live-color);
  letter-spacing: 0.5px;
}

.live-badge .dot {
  width: 8px;
  height: 8px;
  background-color: var(--live-color);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--live-color);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}

.overlay-channel-info {
  display: flex;
  flex-direction: column;
}

#overlay-ch-name {
  font-size: 0.85rem;
  font-weight: 600;
}

#overlay-ch-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.player-loading-overlay, .player-error-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
  text-align: center;
}

.spinner, .spinner-large {
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s infinite linear;
}

.spinner { width: 24px; height: 24px; margin-bottom: 8px; }
.spinner-large { width: 48px; height: 48px; margin-bottom: 16px; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.player-error-overlay .error-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.player-error-overlay h3 {
  font-size: 1.25rem;
  margin-bottom: 8px;
  color: #f87171;
}

.player-error-overlay p {
  font-size: 0.88rem;
  color: var(--text-muted);
  max-width: 400px;
  margin-bottom: 20px;
}

.error-actions {
  display: flex;
  gap: 12px;
}

.btn-retry, .btn-next {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.btn-retry {
  background: var(--accent);
  color: white;
}
.btn-retry:hover { background: var(--accent-hover); }

.btn-next {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}
.btn-next:hover { background: rgba(255, 255, 255, 0.2); }

/* FOOTER BAR */
.channel-footer {
  height: 76px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 20px;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.current-logo {
  width: 52px;
  height: 52px;
  background: #111319;
  border-radius: 10px;
  object-fit: contain;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.channel-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.channel-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

#current-title {
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-tag {
  background: var(--accent-light);
  color: #a5b4fc;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
}

.channel-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.channel-meta a {
  color: #818cf8;
  text-decoration: none;
}

.footer-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.sources-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sources-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sources-chips {
  display: flex;
  gap: 6px;
}

.source-chip {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.source-chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn-round {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn-round:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

/* RESPONSIVE */
@media (max-width: 900px) {
  :root {
    --sidebar-width: 320px;
  }
  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    height: 100%;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
}

@media (max-width: 600px) {
  :root {
    --sidebar-width: 100%;
    --topbar-height: 56px;
  }
  .search-wrapper {
    max-width: 180px;
  }
  .brand-subtitle, .mode-toggle span {
    display: none;
  }
  .channel-footer {
    height: 64px;
    padding: 0 12px;
  }
  .current-logo {
    width: 40px;
    height: 40px;
  }
}
