:root {
  /* Default: Dark Theme */
  --bg-main: #0f1115;
  --bg-sidebar: rgba(22, 25, 31, 0.7);
  --bg-card: rgba(30, 34, 42, 0.6);
  --bg-card-hover: rgba(45, 51, 63, 0.8);
  --bg-input: rgba(0, 0, 0, 0.3);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.3);

  --border-color: rgba(255, 255, 255, 0.05);
  --border-light: rgba(255, 255, 255, 0.1);

  --success: #22c55e;
  --error: #ef4444;
  --warning: #eab308;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

[data-theme="light"] {
  --bg-main: #f1f5f9;
  --bg-sidebar: rgba(255, 255, 255, 0.8);
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-hover: rgba(241, 245, 249, 1);
  --bg-input: rgba(226, 232, 240, 0.5);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --border-color: rgba(0, 0, 0, 0.05);
  --border-light: rgba(0, 0, 0, 0.1);
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-main);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  transition: background-color 0.4s ease, color 0.4s ease;
}

/* Glassmorphism utility */
.glass {
  background: var(--bg-sidebar);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border-color);
}

.app-container {
  display: flex;
  height: 100dvh;
  background: var(--bg-main);
}

/* Sidebar */
.sidebar {
  width: 320px;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar-header {
  padding: 24px 20px 16px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.sidebar-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #60a5fa, #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-header p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.hidden {
  display: none !important;
}

/* Actions */
.sidebar-actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
}

.action-btn {
  flex: 1;
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 600;
  transition: all 0.2s ease;
}

.update-btn {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-color);
}

.update-btn:hover {
  background: rgba(59, 130, 246, 0.25);
}

.clear-btn {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
}

.clear-btn:hover {
  background: rgba(239, 68, 68, 0.25);
}

/* Search */
.search-container {
  padding: 10px 20px 16px;
  position: relative;
}

.search-container svg {
  position: absolute;
  left: 35px;
  top: 45%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

#searchInput {
  width: 100%;
  padding: 12px 12px 12px 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: all 0.3s ease;
}

#searchInput:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Sidebar Tabs */
.sidebar-tabs {
  display: flex;
  padding: 0 20px 16px;
  gap: 8px;
}

.tab-btn {
  flex: 1;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 8px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.view-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.view-content.hidden {
  display: none !important;
}

/* Categories */
.categories-filter {
  padding: 0 20px 12px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  /* Firefox */
}

.categories-filter::-webkit-scrollbar {
  display: none;
  /* Chrome */
}

.filter-btn {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.filter-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.filter-btn.active {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* Channel List */
.channel-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 12px;
}

.channel-list::-webkit-scrollbar {
  width: 6px;
}

.channel-list::-webkit-scrollbar-thumb {
  background-color: var(--border-light);
  border-radius: 10px;
}

.channel-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  margin-bottom: 6px;
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.channel-item:hover {
  background: var(--bg-card);
  border-color: var(--border-color);
  transform: translateX(4px);
}

.channel-item.active {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
  border-left: 4px solid var(--accent-color);
  padding-left: 12px;
}

.channel-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.channel-name {
  font-weight: 600;
  font-size: 14px;
}

.channel-meta {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
}

.channel-type {
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
}

.health-dot.online {
  background-color: var(--success);
  box-shadow: 0 0 5px var(--success);
}

.health-dot.offline {
  background-color: var(--error);
}

.health-dot.unknown {
  background-color: var(--text-muted);
}

.fav-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), color 0.2s;
  padding: 4px;
}

.fav-btn:hover {
  transform: scale(1.2);
}

.fav-btn.active {
  color: #f59e0b;
}

/* Schedule List */
.schedule-header {
  padding: 0 20px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.schedule-header h3 {
  font-size: 14px;
  font-weight: 600;
}

.schedule-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.schedule-list::-webkit-scrollbar {
  width: 6px;
}

.schedule-list::-webkit-scrollbar-thumb {
  background-color: var(--border-light);
  border-radius: 10px;
}

.schedule-item {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border-color);
}

.schedule-time {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-color);
  margin-bottom: 4px;
}

.schedule-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  line-height: 1.3;
}

.schedule-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.schedule-link {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.schedule-link:hover {
  background: var(--accent-color);
  border-color: var(--accent-color);
}

.loading-schedule {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
  font-size: 12px;
}

/* Custom M3U */
.custom-m3u-container {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-sidebar);
  /* solid base */
}

.custom-m3u-container p {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 500;
}

.input-group {
  display: flex;
  gap: 8px;
}

#customM3uInput {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
  min-width: 0;
}

#customM3uInput:focus {
  border-color: var(--accent-color);
}

.play-custom-btn {
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.play-custom-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-main);
  background-image: radial-gradient(circle at top right, rgba(59, 130, 246, 0.05), transparent 40%);
}

.top-bar {
  padding: 24px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.top-bar h2 {
  font-size: 20px;
  font-weight: 600;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-muted);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
}

.status-indicator.loading .dot {
  background-color: var(--warning);
  animation: pulse-warning 1.5s infinite;
}

.status-indicator.playing .dot {
  background-color: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-indicator.error .dot {
  background-color: var(--error);
  box-shadow: 0 0 8px var(--error);
}

/* Player */
.player-wrapper {
  flex: 1;
  margin: 0 32px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
  position: relative;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  display: flex;
}

.player-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  z-index: 5;
}

.placeholder-content {
  text-align: center;
  color: var(--text-secondary);
}

.pulse-icon {
  width: 64px;
  height: 64px;
  background: var(--bg-card-hover);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  color: var(--text-muted);
}

.pulse-icon svg {
  width: 24px;
  height: 24px;
  margin-left: 4px;
}

.video-player,
iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: black;
  z-index: 10;
  object-fit: contain;
}

/* Hints */
.player-controls-hint {
  padding: 16px 32px 24px;
  display: flex;
  justify-content: center;
  gap: 24px;
}

.hint-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

kbd {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: inherit;
  font-weight: 600;
  color: var(--text-primary);
  box-shadow: 0 2px 0 var(--border-color);
}

/* Animations */
@keyframes pulse-warning {
  0% {
    box-shadow: 0 0 0 0 rgba(234, 179, 8, 0.4);
  }

  70% {
    box-shadow: 0 0 0 6px rgba(234, 179, 8, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(234, 179, 8, 0);
  }
}

/* Custom Video Player Overlay */
.video-container {
  width: 100%;
  height: 100%;
  position: relative;
  background: black;
}

.video-container.hidden {
  display: none !important;
}

.video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.7) 0%, transparent 20%, transparent 80%, rgba(0, 0, 0, 0.8) 100%);
  opacity: 1;
  transition: opacity 0.3s ease;
  z-index: 20;
}

.video-container.idle .video-overlay {
  opacity: 0;
  cursor: none;
}

.player-top-bar {
  padding: 16px 24px;
  display: flex;
  justify-content: flex-end;
}

.live-badge {
  background: var(--error);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  animation: pulse-live 2s infinite;
}

@keyframes pulse-live {
  0% {
    opacity: 1;
  }

  50% {
    opacity: 0.6;
  }

  100% {
    opacity: 1;
  }
}

.center-play-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 64px;
  height: 64px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  cursor: pointer;
  transition: transform 0.2s;
}

.center-play-btn:hover {
  transform: translate(-50%, -50%) scale(1.1);
}

.center-play-btn svg {
  width: 32px;
  height: 32px;
  margin-left: 4px;
}

.player-controls {
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.control-btn {
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
  transition: all 0.2s;
}

.control-btn:hover {
  opacity: 1;
  transform: scale(1.1);
}

.control-btn svg {
  width: 24px;
  height: 24px;
}

.text-btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
}

.volume-container {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 120px;
}

.volume-slider {
  width: 100%;
  cursor: pointer;
  accent-color: var(--accent-color);
}

/* Quality Menu */
.quality-selector {
  position: relative;
}

.quality-menu {
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 12px;
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  min-width: 100px;
}

.quality-option {
  background: transparent;
  border: none;
  color: white;
  padding: 8px 16px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.2s;
}

.quality-option:hover {
  background: rgba(255, 255, 255, 0.1);
}

.quality-option.active {
  color: var(--accent-color);
  font-weight: bold;
}

/* Cinema Mode */
body.cinema-active .sidebar {
  display: none !important;
}

body.cinema-active .main-content {
  background: #000 !important;
}

body.cinema-active .top-bar {
  display: none !important;
}

body.cinema-active .player-wrapper {
  margin: 0;
  border-radius: 0;
  border-right: none;
  height: 100dvh;
}

/* Mobile Bottom Navigation */
.bottom-nav {
  display: none;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  padding: 8px 15px 15px;
  /* Increased bottom padding visually */
  justify-content: space-around;
  align-items: center;
  z-index: 50;
  padding-bottom: calc(env(safe-area-inset-bottom, 16px) + 7px);
  /* Pushes icons up to avoid home indicator */
}

.nav-item {
  flex: 1;
  /* Take up equal horizontal space */
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  padding: 8px 0;
  /* Remove horizontal padding so flex handles centering */
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.nav-item svg {
  width: 24px;
  height: 24px;
}

.nav-item span {
  font-size: 10px;
  font-weight: 600;
}

.nav-item.active {
  color: var(--accent-color);
}

.nav-item:active {
  background: rgba(255, 255, 255, 0.05);
}

/* Mobile Search Overlay */
.search-overlay {
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(12px);
  padding: 12px 16px;
  display: none;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
  /* Margin between search and player box */
  animation: slideDown 0.2s ease-out;
}

.search-overlay.open {
  display: flex;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.search-overlay input {
  flex: 1;
  background: transparent;
  border: none;
  color: white;
  font-size: 16px;
  outline: none;
}

.search-overlay .search-icon {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
}

.search-overlay button {
  background: transparent;
  border: none;
  color: var(--accent-color);
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}

/* Double Tap Overlay */
.double-tap-indicator {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 40%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-weight: bold;
  font-size: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 30;
}

.double-tap-indicator.left {
  left: 0;
  border-radius: 0 50% 50% 0;
}

.double-tap-indicator.right {
  right: 0;
  border-radius: 50% 0 0 50%;
}

.double-tap-indicator.show {
  opacity: 1;
  animation: ripple 0.5s ease-out;
}

@keyframes ripple {
  0% {
    transform: scale(1);
    opacity: 1;
  }

  100% {
    transform: scale(1.1);
    opacity: 0;
  }
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex: 1;
    min-height: 0;
    /* allows flex container to shrink and trigger child scroll */
    border-right: none;
    display: flex;
    flex-direction: column;
    order: 2;
    /* places it below the player */
  }

  .sidebar-header {
    display: none;
    /* Hide the big logo header on mobile to save space */
  }

  .sidebar-actions {
    padding: 16px 20px 16px;
    /* give some breathing room from the video */
    margin-top: 0;
  }

  .search-container {
    display: none;
    /* Hide the main search bar since we have the mobile overlay */
  }

  .categories-filter,
  .schedule-header {
    margin-top: 16px;
    margin-bottom: 16px;
    /* Give some breathing room from the player box */
    padding: 0 16px;
  }

  .channel-item {
    padding: 16px 20px;
    /* larger tap targets for thick thumbs */
  }

  .custom-m3u-container {
    display: none;
    /* Hide custom m3u input on mobile to save space */
  }

  .sidebar-tabs {
    display: none;
    /* Hide the top tabs since we use bottom nav */
  }

  .bottom-nav {
    display: flex;
    order: 3;
  }

  /* Make view contents fill the screen except nav */
  .main-content {
    flex: none;
    /* Do not expand to fill the screen */
    order: 1;
    overflow-y: visible;
  }

  body.video-playing .main-content {
    justify-content: center;
    background: black;
  }

  .top-bar {
    padding: 16px;
  }

  .player-wrapper {
    margin: 0;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    min-height: 250px;
    height: 35vh;
    /* fill a portion of screen */
    flex: none;
  }

  /* When rotated to landscape */
  @media (orientation: landscape) {
    .player-wrapper {
      height: 100dvh;
      position: fixed;
      top: 0;
      left: 0;
      width: 100vw;
      z-index: 100;
    }

    .top-bar,
    .bottom-nav,
    .player-controls-hint {
      display: none !important;
    }
  }

  .player-controls {
    padding: 12px;
  }

  .volume-container {
    display: none;
    /* hide volume slider on mobile, use physical buttons */
  }

  .player-controls-hint {
    display: none;
    /* Hide hints on mobile */
  }

  /* PWA overrides */
  body {
    -webkit-tap-highlight-color: transparent;
  }
}