/* ==========================================================================
   IPTV & Movie Streaming Web App - Modern 3D Cyber Theme
   ========================================================================== */

:root {
  --bg-main: #0b0f19;
  --bg-card: #151d30;
  --bg-card-hover: #1b2640;
  --bg-surface: #101626;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-bright: rgba(0, 212, 255, 0.3);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent-cyan: #00d4ff;
  --accent-purple: #8b5cf6;
  --accent-gradient: linear-gradient(135deg, #00d4ff 0%, #7928ca 100%);
  --btn-3d-bg: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  --btn-3d-border: #334155;
  --btn-3d-shadow: 0 5px 0 #070b13, 0 8px 18px rgba(0,0,0,0.5);
  --btn-3d-active-shadow: 0 2px 0 #070b13, 0 3px 6px rgba(0,0,0,0.4);
  --badge-dead: #ef4444;
  --badge-live: #10b981;
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --navbar-height: 64px;
}

[data-theme="light"] {
  --bg-main: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-surface: #e2e8f0;
  --border-color: rgba(0, 0, 0, 0.08);
  --border-bright: rgba(0, 150, 255, 0.4);
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;
  --btn-3d-bg: linear-gradient(180deg, #ffffff 0%, #e2e8f0 100%);
  --btn-3d-border: #cbd5e1;
  --btn-3d-shadow: 0 4px 0 #94a3b8, 0 8px 16px rgba(0,0,0,0.12);
  --btn-3d-active-shadow: 0 2px 0 #94a3b8, 0 3px 6px rgba(0,0,0,0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* ---------------- Navbar ---------------- */
.navbar {
  position: sticky;
  top: 0;
  height: var(--navbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  text-decoration: none;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-links {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  transition: all 0.2s;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.nav-link:hover, .nav-link.active {
  color: var(--accent-cyan);
  background: rgba(0, 212, 255, 0.08);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

.btn-icon:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

/* ---------------- Sticky Filter & Search Bar ---------------- */
.control-bar {
  background: var(--bg-main);
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}

.search-box-wrap {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.search-input {
  flex: 1;
  min-height: 44px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-main);
  padding: 0 1rem;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.15);
}

.category-chips {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  white-space: nowrap;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.category-chips::-webkit-scrollbar {
  display: none;
}

.chip-3d {
  background: var(--btn-3d-bg);
  color: var(--text-muted);
  border: 1px solid var(--btn-3d-border);
  padding: 0.45rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 20px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--border-color);
  transition: all 0.15s ease;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chip-3d:hover {
  color: var(--text-main);
  border-color: var(--accent-cyan);
}

.chip-3d.active {
  background: var(--accent-gradient);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 3px 0 #4c1d95;
  transform: translateY(-1px);
}

/* ---------------- Layout & Main Container (Req 1 & 2) ---------------- */
.app-container {
  padding: 0;
  max-width: 100%;
  margin: 0 auto;
}

/* Desktop layout (>= 1024px): 2 columns, left column 65%, right column 35% */
.tv-main-layout {
  display: flex;
  flex-direction: column;
  width: 100%;
}

@media (min-width: 1024px) {
  .tv-main-layout {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
  }

  .player-column {
    flex: 0 0 65%;
    width: 65%;
    max-width: 65%;
    position: sticky;
    top: var(--navbar-height);
    height: calc(100vh - var(--navbar-height));
    overflow-y: auto;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    z-index: 50;
    display: flex;
    flex-direction: column;
  }

  .grid-column {
    flex: 0 0 35%;
    width: 35%;
    max-width: 35%;
    padding: 1.25rem;
    overflow-y: auto;
    min-height: calc(100vh - var(--navbar-height));
  }
}

/* Mobile layout (< 1024px): Player sticky at top, 100% viewport width */
@media (max-width: 1023px) {
  .player-column {
    position: sticky;
    top: 0;
    width: 100%;
    z-index: 50;
    background: #000000;
    box-shadow: 0 10px 25px rgba(0,0,0,0.8);
  }

  .grid-column {
    width: 100%;
    padding: 1rem;
  }
}

/* ---------------- Video Player Element (Req 1: 100% width, aspect-ratio 16/9, contain) ---------------- */
.player-video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.player-video-wrap video {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: contain !important;
  background: #000000;
  display: block;
}

/* Tap to unmute banner overlay */
.unmute-overlay {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  color: #00d4ff;
  border: 1px solid rgba(0, 212, 255, 0.4);
  padding: 0.5rem 1rem;
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  z-index: 10;
  display: none;
  align-items: center;
  gap: 0.5rem;
  animation: pulse 1.5s infinite;
}

.unmute-overlay.active {
  display: inline-flex;
}

.player-meta {
  padding: 1rem 1.25rem;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.player-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.player-title {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(16, 185, 129, 0.15);
  color: var(--badge-live);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 50px;
  border: 1px solid rgba(16, 185, 129, 0.3);
  white-space: nowrap;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.player-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.btn-action {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.45rem 0.85rem;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  transition: all 0.2s;
}

.btn-action:hover {
  background: var(--accent-gradient);
  color: #fff;
  border-color: transparent;
}

/* ---------------- 3D Channel Button Grid (Req 4: 48px Logo & Initials fallback) ---------------- */
.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 1rem;
}

@media (min-width: 640px) {
  .channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1.1rem;
  }
}

.btn-channel-3d {
  position: relative;
  background: var(--btn-3d-bg);
  border: 2px solid var(--btn-3d-border);
  border-radius: 14px;
  padding: 0.85rem 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 115px;
  cursor: pointer;
  box-shadow: var(--btn-3d-shadow);
  transform: translateY(0);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.15s ease;
  user-select: none;
  text-align: center;
  outline: none;
}

.btn-channel-3d:hover {
  border-color: var(--accent-cyan);
  transform: translateY(-2px);
  box-shadow: 0 7px 0 #070b13, 0 12px 20px rgba(0,0,0,0.6);
}

.btn-channel-3d:active, .btn-channel-3d.pressed {
  transform: translateY(3px);
  box-shadow: var(--btn-3d-active-shadow);
}

.btn-channel-3d.active-channel {
  border-color: var(--accent-cyan);
  background: linear-gradient(180deg, #1e3a5f 0%, #0c1a2e 100%);
  box-shadow: 0 0 16px rgba(0, 212, 255, 0.4), var(--btn-3d-shadow);
}

/* Logo container with fallback avatar */
.channel-logo-wrap {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}

.channel-logo {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

/* Fallback initial circle */
.channel-avatar-fallback {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: 800;
  color: #ffffff;
  background: var(--accent-gradient);
  text-transform: uppercase;
}

.channel-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-cat-tag {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.badge-dead-channel {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--badge-dead);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.5);
}

/* ---------------- Movie Grid ---------------- */
.movie-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1.5rem;
}

@media (min-width: 640px) {
  .movie-grid {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  }
}

.movie-card-3d {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  transform: translateY(0);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.movie-card-3d:hover {
  transform: translateY(-5px);
  border-color: var(--accent-cyan);
  box-shadow: 0 16px 36px rgba(0, 212, 255, 0.15), 0 8px 16px rgba(0,0,0,0.4);
}

.movie-poster-wrap {
  width: 100%;
  aspect-ratio: 2 / 3;
  position: relative;
  background: #111827;
  overflow: hidden;
}

.movie-poster {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.movie-badges {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.movie-chip {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.movie-chip.quality {
  background: var(--accent-gradient);
  border: none;
}

.movie-info {
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.movie-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.movie-sub {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---------------- Toast Notification ---------------- */
.toast-msg {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--accent-cyan);
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 9999;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 640px) {
  .navbar {
    padding: 0 1rem;
  }
  .nav-brand span {
    display: none;
  }
}
