/* ============================================
   PinoyTV — Premium Cable TV Experience
   ============================================ */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a26;
  --bg-card-hover: #222235;
  --bg-sidebar: #0e0e16;
  --bg-topbar: rgba(10, 10, 15, 0.92);
  --bg-player: #000;
  --text-primary: #f0f0f5;
  --text-secondary: #8888a0;
  --text-muted: #555570;
  --accent: #e63946;
  --accent-glow: rgba(230, 57, 70, 0.3);
  --accent-secondary: #ff6b6b;
  --border: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.1);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --sidebar-width: 220px;
  --topbar-height: 60px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button {
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
}

input {
  border: none;
  outline: none;
  background: none;
  color: inherit;
  font-family: inherit;
}

/* =================== TOPBAR =================== */

#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-topbar);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-center {
  flex: 1;
  max-width: 400px;
  margin: 0 20px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.logo-icon {
  font-size: 1.5rem;
}

.logo-text {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.logo-accent {
  color: var(--accent);
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: var(--transition);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.icon-btn.active {
  color: var(--accent);
}

.search-box {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  height: 38px;
  padding: 0 14px 0 38px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.87rem;
  color: var(--text-primary);
  transition: var(--transition);
}

#search-input::placeholder {
  color: var(--text-muted);
}

#search-input:focus {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#clock {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 70px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* =================== SIDEBAR =================== */

#sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 10px;
  z-index: 900;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#sidebar::-webkit-scrollbar {
  width: 4px;
}

#sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

#categories {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cat-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.87rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition);
  text-align: left;
}

.cat-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.cat-btn.active {
  background: linear-gradient(135deg, var(--accent), #c0392b);
  color: white;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.cat-btn svg {
  flex-shrink: 0;
}

/* =================== MAIN CONTENT =================== */

#main {
  margin-left: var(--sidebar-width);
  margin-top: var(--topbar-height);
  padding: 24px;
  min-height: calc(100vh - var(--topbar-height));
}

/* =================== NOW PLAYING =================== */

#now-playing {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(135deg, rgba(230, 57, 70, 0.15), rgba(230, 57, 70, 0.05));
  border: 1px solid rgba(230, 57, 70, 0.2);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.now-playing-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.live-badge {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  animation: pulse-live 2s infinite;
  letter-spacing: 0.5px;
}

@keyframes pulse-live {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#now-playing-channel {
  font-weight: 600;
  font-size: 0.9rem;
}

/* =================== VIDEO PLAYER =================== */

#player-container {
  margin-bottom: 28px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-player);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

#player-wrapper {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  background: #000;
}

#video-player {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
}

#player-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  transition: opacity var(--transition);
  pointer-events: none;
}

#player-overlay.hidden {
  opacity: 0;
}

#player-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-secondary);
}

#player-loading p {
  font-size: 0.9rem;
}

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

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

#player-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  text-align: center;
}

#player-error p {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

#player-error span {
  font-size: 0.8rem;
  opacity: 0.7;
}

#channel-switch-overlay {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  padding: 14px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  text-align: right;
  animation: fadeInOut 2s ease forwards;
}

.channel-switch-number {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.channel-switch-name {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

@keyframes fadeInOut {
  0% { opacity: 0; transform: translateY(-8px); }
  15% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* Player Controls Bar */
#player-controls-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.player-nav-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: var(--transition);
}

.player-nav-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

#current-channel-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

#current-channel-number {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent);
  min-width: 30px;
}

#current-channel-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* =================== CHANNEL GRID =================== */

#channel-grid-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 18px;
}

#grid-title {
  font-size: 1.3rem;
  font-weight: 700;
}

#channel-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

#channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.channel-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 14px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  overflow: hidden;
}

.channel-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(230, 57, 70, 0.05));
  opacity: 0;
  transition: var(--transition);
}

.channel-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.channel-card:hover::before {
  opacity: 1;
}

.channel-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 20px var(--accent-glow);
}

.channel-card-number {
  position: absolute;
  top: 8px;
  left: 10px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
}

.channel-logo-wrapper {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.channel-logo-wrapper img {
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.channel-logo-placeholder {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.channel-card-name {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

.channel-card-category {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.channel-card-fav {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-muted);
  transition: var(--transition);
  z-index: 2;
}

.channel-card-fav:hover {
  background: rgba(255, 255, 255, 0.1);
}

.channel-card-fav.is-fav {
  color: var(--accent);
}

.channel-card-fav svg {
  width: 14px;
  height: 14px;
}

/* =================== EMPTY STATE =================== */

#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  gap: 16px;
  color: var(--text-muted);
}

#empty-state p {
  font-size: 1rem;
}

/* =================== UTILITY =================== */

.hidden {
  display: none !important;
}

/* =================== SCROLLBAR =================== */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* =================== RESPONSIVE =================== */

@media (max-width: 900px) {
  :root {
    --sidebar-width: 0px;
  }

  #sidebar {
    transform: translateX(-100%);
    width: 260px;
    z-index: 1100;
    box-shadow: var(--shadow-lg);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1050;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
  }

  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: all;
  }

  #main {
    margin-left: 0;
    padding: 16px;
  }

  #channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }

  .channel-card {
    padding: 14px 10px;
  }

  .channel-logo-wrapper {
    width: 56px;
    height: 56px;
  }

  .channel-logo-wrapper img {
    width: 42px;
    height: 42px;
  }
}

@media (max-width: 600px) {
  #topbar {
    padding: 0 12px;
  }

  .topbar-center {
    margin: 0 10px;
  }

  #clock {
    display: none;
  }

  #main {
    padding: 12px;
  }

  #channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
  }

  .channel-card {
    padding: 12px 8px;
  }

  .channel-logo-wrapper {
    width: 48px;
    height: 48px;
  }

  .channel-logo-wrapper img {
    width: 36px;
    height: 36px;
  }

  .channel-card-name {
    font-size: 0.75rem;
  }

  .channel-card-category {
    display: none;
  }

  #player-controls-bar {
    padding: 8px 12px;
  }
}

@media (max-width: 380px) {
  #channel-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* =================== FULLSCREEN =================== */

#player-container.fullscreen-mode {
  position: fixed;
  inset: 0;
  z-index: 2000;
  margin: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
}

#player-container.fullscreen-mode #player-wrapper {
  flex: 1;
  padding-top: 0;
}

#player-container.fullscreen-mode #video-player {
  position: relative;
  width: 100%;
  height: 100%;
}

/* =================== ANIMATIONS =================== */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.channel-card {
  animation: fadeIn 0.3s ease backwards;
}

.channel-card:nth-child(1) { animation-delay: 0.02s; }
.channel-card:nth-child(2) { animation-delay: 0.04s; }
.channel-card:nth-child(3) { animation-delay: 0.06s; }
.channel-card:nth-child(4) { animation-delay: 0.08s; }
.channel-card:nth-child(5) { animation-delay: 0.1s; }
.channel-card:nth-child(6) { animation-delay: 0.12s; }
.channel-card:nth-child(7) { animation-delay: 0.14s; }
.channel-card:nth-child(8) { animation-delay: 0.16s; }
.channel-card:nth-child(9) { animation-delay: 0.18s; }
.channel-card:nth-child(10) { animation-delay: 0.2s; }
