/* ============================================
   LWG TV — Premium Television Design System
   ============================================ */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  user-select: none;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font: inherit; border: none; background: none; color: inherit; outline: none; }
ul, ol { list-style: none; }
img { display: block; max-width: 100%; }
video { display: block; }

::-webkit-scrollbar { width: 0; height: 0; }
* { scrollbar-width: none; }

/* --- DESIGN TOKENS --- */
:root {
  --bg-base: #050d15;
  --bg-surface: #0b1621;
  --bg-elevated: #111f2c;
  --bg-hover: #182a3a;

  --text-primary: #f0f4f8;
  --text-secondary: #8a9bb0;
  --text-muted: #4e6178;

  --accent: #1a8fd8;
  --accent-hover: #219ef5;
  --accent-subtle: rgba(26, 143, 216, 0.12);

  --live-red: #e53e3e;
  --live-red-bg: rgba(229, 62, 62, 0.15);

  --focus-ring: rgba(26, 143, 216, 0.55);

  --sidebar-w: 230px;
  --rail-gap: 18px;
  --page-px: 42px;
  --section-gap: 36px;

  --radius: 10px;
  --radius-lg: 14px;

  --transition: 220ms ease;
}

/* --- LAYOUT --- */
#app { display: flex; height: 100vh; width: 100vw; }

/* --- LOGIN --- */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-base);
  z-index: 9999;
}
.login-screen.hidden { display: none; }

.login-box { width: 100%; max-width: 400px; padding: 48px 36px; text-align: center; }

.login-logo { margin-bottom: 44px; }
.login-logo-icon {
  width: 68px; height: 68px; margin: 0 auto 18px;
  background: linear-gradient(135deg, var(--accent), #0e6db5);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800; color: #fff;
  box-shadow: 0 8px 32px rgba(26, 143, 216, 0.25);
}
.login-logo h1 { font-size: 26px; font-weight: 700; color: var(--text-primary); }
.login-logo p { font-size: 14px; color: var(--text-secondary); margin-top: 5px; }

.login-form .field { margin-bottom: 14px; text-align: left; }
.login-form label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 6px;
}
.login-form input {
  width: 100%; padding: 13px 15px;
  border: 1px solid rgba(255,255,255,0.07); border-radius: 8px;
  background: var(--bg-surface); color: var(--text-primary); font-size: 15px;
}
.login-form input::placeholder { color: var(--text-muted); }
.login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--focus-ring); }

.login-error {
  background: var(--live-red-bg); border: 1px solid var(--live-red);
  color: var(--live-red); padding: 11px; border-radius: 8px;
  font-size: 13px; margin-bottom: 14px; display: none;
}
.login-error.visible { display: block; }

.login-btn {
  width: 100%; padding: 13px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600;
  transition: background var(--transition);
}
.login-btn:hover { background: var(--accent-hover); }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.login-btn .spinner {
  display: none; width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.6s linear infinite; margin: 0 auto;
}
.login-btn.loading .btn-text { display: none; }
.login-btn.loading .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- SIDEBAR --- */
.sidebar {
  width: var(--sidebar-w); height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid rgba(255,255,255,0.04);
  display: flex; flex-direction: column; flex-shrink: 0;
  z-index: 100; overflow: hidden;
}

.sidebar-logo {
  padding: 22px 18px 16px;
  display: flex; align-items: center; gap: 11px;
}
.sidebar-logo-icon {
  width: 38px; height: 38px; min-width: 38px;
  background: linear-gradient(135deg, var(--accent), #0e6db5);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff;
}
.sidebar-logo-text { font-size: 17px; font-weight: 700; letter-spacing: -0.2px; }

.sidebar-clock { padding: 4px 18px 8px; }
.clock-time { font-size: 13px; font-weight: 600; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.clock-date { font-size: 11px; color: var(--text-muted); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav-section { margin-bottom: 4px; }
.nav-section-title {
  font-size: 10px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px; padding: 10px 8px 5px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  font-size: 14px; font-weight: 500; color: var(--text-secondary);
  transition: all var(--transition); cursor: pointer; position: relative;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item:focus-visible {
  outline: none; background: var(--bg-hover); color: var(--text-primary);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.nav-item.active {
  background: var(--accent-subtle); color: var(--accent); font-weight: 600;
}
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; background: var(--accent); border-radius: 0 2px 2px 0;
}
.nav-item-icon { width: 20px; text-align: center; font-size: 15px; flex-shrink: 0; }

.sidebar-user {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.04);
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--bg-hover);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: var(--accent); flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.user-role { font-size: 11px; color: var(--text-muted); }

/* --- MAIN CONTENT --- */
.main-content {
  flex: 1; height: 100vh;
  overflow-y: auto; overflow-x: hidden;
  scroll-behavior: smooth;
  background: var(--bg-base);
}

/* --- HERO --- */
.hero {
  position: relative;
  height: clamp(340px, 42vh, 580px);
  min-height: 340px;
  overflow: hidden;
  display: flex; align-items: flex-end;
}

.hero-backdrop {
  position: absolute; inset: 0;
  transition: background-image 0.8s ease, background-color 0.8s ease;
}

.hero-backdrop::after {
  content: ''; position: absolute; inset: 0;
  background:
    linear-gradient(to right, var(--bg-base) 0%, rgba(5,13,21,0.88) 30%, rgba(5,13,21,0.35) 60%, transparent 100%),
    linear-gradient(to top, var(--bg-base) 0%, rgba(5,13,21,0.7) 35%, transparent 65%);
}

.hero-content {
  position: relative; z-index: 2;
  padding: 0 var(--page-px) 44px;
  max-width: 600px;
}

.hero-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px; border-radius: 4px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.7px;
  margin-bottom: 14px;
}
.hero-badge.live { background: var(--live-red-bg); color: var(--live-red); }
.hero-badge.featured { background: var(--accent-subtle); color: var(--accent); }

.hero-title {
  font-size: clamp(32px, 4vw, 52px);
  font-weight: 800; line-height: 1.08; letter-spacing: -0.8px;
  margin-bottom: 10px;
  text-shadow: 0 2px 24px rgba(0,0,0,0.5);
}

.hero-meta {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px; font-size: 13px; color: var(--text-secondary);
}
.hero-meta .dot {
  width: 3px; height: 3px; border-radius: 50%; background: var(--text-muted);
}

.hero-description {
  font-size: 14px; line-height: 1.55; color: var(--text-secondary);
  margin-bottom: 22px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

.hero-actions { display: flex; gap: 10px; }

.btn-hero {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 12px 26px; border-radius: 8px;
  font-size: 14px; font-weight: 600;
  transition: all var(--transition);
}
.btn-hero:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--focus-ring); transform: scale(1.03); }
.btn-hero.primary { background: var(--accent); color: #fff; }
.btn-hero.primary:hover { background: var(--accent-hover); }
.btn-hero.secondary {
  background: var(--bg-elevated); color: var(--text-primary);
  border: 1px solid rgba(255,255,255,0.07);
}
.btn-hero.secondary:hover { background: var(--bg-hover); }

/* --- CONTENT RAILS --- */
.content-section { padding: 0 0 var(--section-gap); }

.section-header {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 0 var(--page-px) 14px;
}
.section-title { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.section-more {
  font-size: 13px; color: var(--text-muted); cursor: pointer;
  transition: color var(--transition);
}
.section-more:hover { color: var(--accent); }

.rail {
  display: flex; gap: var(--rail-gap);
  padding: 0 var(--page-px);
  overflow-x: auto; scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

/* --- LIVE CHANNEL CARD --- */
.card-live {
  flex: 0 0 290px;
  scroll-snap-align: start;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-surface);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  position: relative;
}
.card-live:hover { transform: translateY(-3px); box-shadow: 0 6px 24px rgba(0,0,0,0.4); }
.card-live:focus-visible {
  outline: none;
  transform: scale(1.05);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 2px var(--accent);
  z-index: 10;
}

.card-live-thumb {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  overflow: hidden;
}
.card-live-thumb .thumb-bg {
  width: 100%; height: 100%;
  object-fit: contain;
  background: var(--bg-elevated);
}
.card-live-thumb .thumb-gradient {
  width: 100%; height: 100%;
}
.card-live-thumb .logo-overlay {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  max-width: 60%; max-height: 55%;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.4));
}

.live-badge {
  position: absolute; top: 8px; left: 8px;
  display: flex; align-items: center; gap: 4px;
  padding: 3px 7px; border-radius: 4px;
  background: var(--live-red); color: #fff;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.live-badge::before {
  content: ''; width: 5px; height: 5px; border-radius: 50%; background: #fff;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.card-live-quality {
  position: absolute; top: 8px; right: 8px;
  padding: 2px 6px; border-radius: 3px;
  background: rgba(0,0,0,0.55); color: var(--text-secondary);
  font-size: 10px; font-weight: 600;
}

.card-live-info { padding: 12px 14px 14px; }
.card-live-name {
  font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 3px;
}
.card-live-program {
  font-size: 12px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-live-progress {
  margin-top: 8px; height: 3px;
  background: rgba(255,255,255,0.06); border-radius: 2px; overflow: hidden;
}
.card-live-progress-bar {
  height: 100%; background: var(--accent); border-radius: 2px;
}

/* --- CATEGORY PILLS --- */
.category-bar {
  display: flex; gap: 8px;
  padding: 0 var(--page-px) 20px;
  overflow-x: auto;
}
.category-pill {
  flex-shrink: 0; padding: 7px 16px; border-radius: 20px;
  font-size: 13px; font-weight: 500;
  background: var(--bg-surface); color: var(--text-secondary);
  border: 1px solid transparent; cursor: pointer;
  transition: all var(--transition);
}
.category-pill:hover { background: var(--bg-hover); color: var(--text-primary); }
.category-pill:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--focus-ring); }
.category-pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* --- LIVE TV GRID --- */
.live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 18px;
  padding: 0 var(--page-px) 40px;
}

/* --- GUIDE --- */
.guide-container { display: flex; flex-direction: column; height: 100%; }
.guide-time-header {
  display: flex; align-items: center;
  padding: 14px var(--page-px);
  background: var(--bg-surface);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  gap: 20px; position: sticky; top: 0; z-index: 10;
}
.guide-time-header .time-slot { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.guide-time-header .time-slot.now { color: var(--accent); font-weight: 700; }
.guide-channels-list { flex: 1; overflow-y: auto; }
.guide-channel-row {
  display: flex; align-items: stretch;
  border-bottom: 1px solid rgba(255,255,255,0.04); min-height: 68px;
}
.guide-channel-info {
  width: 180px; min-width: 180px; padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  border-right: 1px solid rgba(255,255,255,0.04);
}
.guide-channel-logo {
  width: 36px; height: 36px; border-radius: 6px; overflow: hidden;
  background: var(--bg-elevated); flex-shrink: 0;
}
.guide-channel-logo img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.guide-channel-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.guide-programs { flex: 1; display: flex; overflow-x: auto; }
.guide-program {
  flex-shrink: 0; padding: 10px 14px;
  border-right: 1px solid rgba(255,255,255,0.02);
  cursor: pointer; transition: background var(--transition);
  display: flex; flex-direction: column; justify-content: center;
}
.guide-program:hover { background: var(--bg-hover); }
.guide-program:focus-visible { outline: none; background: var(--bg-elevated); box-shadow: inset 0 0 0 2px var(--accent); }
.guide-program.current { background: var(--accent-subtle); border-left: 3px solid var(--accent); }
.guide-program-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.guide-program-time { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* --- SEARCH --- */
.search-container { padding: 28px var(--page-px); }
.search-input-wrap { position: relative; max-width: 560px; margin-bottom: 28px; }
.search-input-wrap .search-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 17px; pointer-events: none;
}
.search-input {
  width: 100%; padding: 14px 18px 14px 44px;
  border: 1px solid rgba(255,255,255,0.07); border-radius: 12px;
  background: var(--bg-surface); color: var(--text-primary); font-size: 17px;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--focus-ring); }

/* --- EMPTY / LOADING --- */
.empty-state { text-align: center; padding: 72px 36px; color: var(--text-muted); }
.empty-state-icon { font-size: 44px; margin-bottom: 14px; opacity: 0.3; }
.empty-state h3 { font-size: 17px; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p { font-size: 14px; }

.loading-spinner { display: flex; align-items: center; justify-content: center; padding: 36px; }
.loading-spinner::after {
  content: ''; width: 30px; height: 30px;
  border: 3px solid var(--bg-elevated); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}

/* --- VIEW TOGGLE --- */
.view { display: none; }
.view.active { display: block; }

/* --- PLAYER OVERLAY --- */
.player-overlay {
  position: fixed; inset: 0; background: #000;
  z-index: 1000; display: flex; flex-direction: column;
}
.player-overlay.hidden { display: none; }
.player-video-wrap { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; background: #000; }
#video-player { width: 100%; height: 100%; }
.player-controls {
  position: absolute; top: 0; left: 0; right: 0;
  padding: 18px 28px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
  display: flex; align-items: center; justify-content: space-between;
  transition: opacity var(--transition); pointer-events: auto;
}
.player-controls.hidden { opacity: 0; pointer-events: none; }
.player-btn-back {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 14px; border-radius: 8px;
  background: rgba(255,255,255,0.1); color: var(--text-primary);
  font-size: 13px; cursor: pointer; transition: background var(--transition);
}
.player-btn-back:hover { background: rgba(255,255,255,0.18); }
.player-now-name { font-size: 14px; font-weight: 600; }
.player-now-program { font-size: 12px; color: var(--text-secondary); }
.player-overlay-info {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 56px var(--page-px) 28px;
  background: linear-gradient(to top, rgba(0,0,0,0.88), transparent);
  transition: opacity var(--transition); pointer-events: none;
}
.player-overlay-info.hidden { opacity: 0; }
.player-overlay-channel { font-size: 13px; color: var(--accent); font-weight: 600; margin-bottom: 5px; }
.player-overlay-title { font-size: 22px; font-weight: 700; margin-bottom: 3px; }
.player-overlay-time { font-size: 12px; color: var(--text-secondary); }
.player-error { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; color: var(--text-secondary); }
.player-error p { margin-bottom: 14px; font-size: 16px; }

/* --- MOBILE --- */
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  z-index: 99; display: none;
}
.sidebar-backdrop.open { display: block; }

.mobile-header {
  display: none; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--bg-surface);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  position: sticky; top: 0; z-index: 100;
}
.mobile-menu-btn {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; border-radius: 8px;
}
.mobile-menu-btn:hover { background: var(--bg-hover); }

.mobile-bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  height: 56px; background: var(--bg-surface);
  border-top: 1px solid rgba(255,255,255,0.04);
  z-index: 200; align-items: center; justify-content: space-around; padding: 0 6px;
}
.mobile-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 5px 10px; border-radius: 8px;
  color: var(--text-muted); font-size: 10px; font-weight: 500; cursor: pointer;
}
.mobile-nav-item .nav-icon { font-size: 19px; }
.mobile-nav-item.active { color: var(--accent); }

@media (max-width: 1024px) {
  :root { --sidebar-w: 190px; --page-px: 30px; }
  .hero-title { font-size: clamp(26px, 3.5vw, 40px); }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: -250px; top: 0; bottom: 0;
    z-index: 9000; transition: left var(--transition); width: 250px;
  }
  .sidebar.open { left: 0; }
  .mobile-header { display: flex !important; }
  .mobile-bottom-nav { display: flex !important; }
  :root { --page-px: 16px; --section-gap: 24px; }
  .hero { height: clamp(240px, 38vh, 360px); min-height: 240px; }
  .hero-title { font-size: 24px; }
  .hero-content { padding: 0 16px 20px; max-width: 100%; }
  .hero-description { font-size: 13px; -webkit-line-clamp: 2; }
  .section-title { font-size: 18px; }
  .card-live { flex: 0 0 230px; }
  .live-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
  .guide-channel-info { width: 130px; min-width: 130px; }
  .player-overlay-info { padding: 36px 16px 16px; }
  .player-overlay-title { font-size: 17px; }
}

@media (min-width: 1600px) {
  :root { --sidebar-w: 260px; --page-px: 52px; }
  .hero { height: clamp(400px, 45vh, 640px); }
  .hero-title { font-size: 56px; }
  .card-live { flex: 0 0 320px; }
}
