/* ============================================================
   TvBox — STYLE
   Dark-first streaming UI with a switchable accent color.
   Organized top to bottom in the order things appear on screen.
   ============================================================ */

:root {
  --bg: #080808;
  --surface: #0f0f0f;
  --card: #161616;
  --card-hover: #1e1e1e;
  --accent: #e50914;
  --accent-dim: rgba(229, 9, 20, 0.12);
  --accent-glow: rgba(229, 9, 20, 0.35);
  --text: #ffffff;
  --text-muted: #888888;
  --text-dim: #444444;
  --border: rgba(255, 255, 255, 0.07);
  --border-bright: rgba(255, 255, 255, 0.13);
  --glass: rgba(8, 8, 8, 0.88);
  --input-bg: rgba(255, 255, 255, 0.055);
  --shadow-xl: 0 30px 60px rgba(0, 0, 0, 0.85);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.55);
  --topbar-h: 58px;
  --foot-h: 38px;
  --sidebar-w: 370px;
  --r-xl: 18px;
  --r-lg: 12px;
  --r-md: 9px;
  --r-sm: 6px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
[data-theme="light"] {
  --bg: #efefef; --surface: #ffffff; --card: #f5f5f5; --card-hover: #e8e8e8;
  --text: #0d0d0d; --text-muted: #666666; --text-dim: #aaaaaa;
  --border: rgba(0, 0, 0, 0.07); --border-bright: rgba(0, 0, 0, 0.13);
  --glass: rgba(255, 255, 255, 0.92); --input-bg: rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 30px 60px rgba(0, 0, 0, 0.12); --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  height: 100%;
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  transition: background var(--transition), color var(--transition);
  -webkit-tap-highlight-color: transparent;
}
button, input { font-family: inherit; }
a { color: inherit; }
img { max-width: 100%; }

::selection { background: var(--accent); color: #fff; }

/* Visible focus ring for keyboard / remote users, invisible for mouse */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.ch-card:focus-visible, .ch-card.kb-focus {
  outline: 3px solid var(--accent);
  outline-offset: -2px;
  z-index: 4;
}

body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none; z-index: 0; opacity: 0.5;
}
[data-theme="light"] body::before { opacity: 0.15; }

/* ===== APP SHELL ===== */
.app {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  width: 100vw; overflow: hidden;
}

/* ===== TOPBAR ===== */
.topbar {
  height: calc(var(--topbar-h) + var(--safe-t));
  padding-top: var(--safe-t);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding-left: max(16px, var(--safe-l)); padding-right: max(16px, var(--safe-r));
  background: var(--glass);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  z-index: 200; gap: 8px;
}
.topbar-left { display: flex; align-items: center; gap: 14px; flex-shrink: 0; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; user-select: none; }
.brand-icon {
  width: 34px; height: 34px; flex-shrink: 0;
  background: var(--accent); border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 18px var(--accent-glow);
  transition: box-shadow var(--transition);
}
.brand:hover .brand-icon { box-shadow: 0 0 30px var(--accent); }
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-name { font-family: 'Bebas Neue', sans-serif; font-size: 1.7rem; letter-spacing: 3px; color: var(--text); }
.brand-tag { font-size: 0.48rem; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; color: var(--accent); margin-top: 1px; }

.net-status {
  display: flex; align-items: center; gap: 5px; font-size: 0.6rem; font-weight: 600;
  color: var(--text-muted); padding: 2px 10px 2px 6px; border-radius: 50px;
  border: 1px solid var(--border); background: var(--input-bg); flex-shrink: 0;
}
.net-dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; flex-shrink: 0; transition: background var(--transition); }
.net-dot.offline { background: #ef4444; }

.icon-btn {
  width: 36px; height: 36px; border-radius: var(--r-md);
  background: var(--input-bg); border: 1px solid var(--border); color: var(--text-muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all var(--transition); position: relative; flex-shrink: 0;
}
.icon-btn:hover { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.icon-btn svg { width: 17px; height: 17px; pointer-events: none; }
.icon-btn[data-tip]::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--border-bright); color: var(--text);
  font-size: 0.65rem; font-weight: 500; padding: 4px 10px; border-radius: var(--r-sm);
  white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity var(--transition); z-index: 9999;
}
.icon-btn[data-tip]:hover::after { opacity: 1; }
.tb-divider { width: 1px; height: 24px; background: var(--border-bright); margin: 0 2px; flex-shrink: 0; }

.theme-btn {
  display: flex; align-items: center; gap: 6px; padding: 0 12px; height: 34px;
  border-radius: var(--r-md); background: var(--input-bg); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.72rem; font-weight: 600; cursor: pointer;
  transition: all var(--transition); white-space: nowrap;
}
.theme-btn:hover { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.theme-btn svg { width: 15px; height: 15px; }

/* ===== MAIN ROW ===== */
.main-row { display: flex; flex: 1; min-height: 0; overflow: hidden; }

/* ===== PLAYER ===== */
.player-section { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #000; overflow: hidden; }
.video-wrap { flex: 1; min-height: 0; position: relative; background: radial-gradient(ellipse at center, #111 0%, #000 100%); overflow: hidden; }
#vp { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }

.loader-ov {
  position: absolute; inset: 0; background: rgba(0, 0, 0, 0.82); backdrop-filter: blur(10px);
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 30;
}
.loader-ov.show { display: flex; }
.ld-ring { width: 44px; height: 44px; border: 3px solid rgba(255, 255, 255, 0.08); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ld-txt { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }
.ld-progress { width: 160px; height: 3px; background: rgba(255, 255, 255, 0.08); border-radius: 10px; overflow: hidden; margin-top: 4px; }
.ld-progress-bar { height: 100%; background: var(--accent); border-radius: 10px; width: 0%; transition: width 0.3s; }

/* Channel unavailable overlay (all sources exhausted) */
.ch-unavailable {
  position: absolute; inset: 0; background: rgba(0, 0, 0, 0.9);
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  text-align: center; padding: 24px; z-index: 31;
}
.ch-unavailable.show { display: flex; }
.ch-unavailable svg { width: 40px; height: 40px; color: var(--accent); opacity: 0.85; }
.ch-unavailable h3 { font-size: 0.95rem; font-weight: 700; }
.ch-unavailable p { font-size: 0.72rem; color: var(--text-muted); max-width: 320px; }
.ch-unavailable .report-btn {
  margin-top: 6px; padding: 8px 18px; border-radius: 50px; border: 1px solid var(--border-bright);
  background: var(--input-bg); color: var(--text); font-size: 0.72rem; font-weight: 600; cursor: pointer;
  transition: all var(--transition);
}
.ch-unavailable .report-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Click-to-play overlay — shown whenever the video is paused (e.g. browser
   blocked sound-on autoplay) so there's always a visible way to start it. */
.play-overlay {
  position: absolute; inset: 0; z-index: 20; display: none; align-items: center; justify-content: center;
  cursor: pointer; background: rgba(0,0,0,0.25);
}
.play-overlay.show { display: flex; }
.play-overlay .po-circle {
  width: 68px; height: 68px; border-radius: 50%; background: rgba(0,0,0,0.55); border: 2px solid rgba(255,255,255,0.5);
  display: flex; align-items: center; justify-content: center; transition: transform var(--transition), background var(--transition);
}
.play-overlay:hover .po-circle { background: var(--accent); border-color: var(--accent); transform: scale(1.08); }
.play-overlay svg { width: 26px; height: 26px; margin-left: 3px; }

/* Remote number-zap overlay */
.number-overlay {
  position: absolute; top: 16px; left: 16px; z-index: 32;
  background: rgba(0,0,0,0.75); color: #fff; font-family: 'Bebas Neue', sans-serif;
  font-size: 2rem; letter-spacing: 4px; padding: 6px 18px; border-radius: var(--r-md);
  border: 1px solid var(--accent); opacity: 0; pointer-events: none; transition: opacity 0.15s;
}
.number-overlay.show { opacity: 1; }

/* Player Info Bar */
.pbar {
  min-height: 52px; flex-shrink: 0; background: var(--surface); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 6px 14px; gap: 8px;
  padding-bottom: calc(6px + var(--safe-b));
  overflow-x: auto; scrollbar-width: none;
}
.pbar::-webkit-scrollbar { display: none; }
.now-playing { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0; box-shadow: 0 0 8px var(--accent); animation: livePulse 2s ease-in-out infinite; }
@keyframes livePulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.55; transform: scale(0.8); } }
.live-badge { font-size: 0.55rem; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; background: var(--accent); color: #fff; padding: 2px 7px; border-radius: 4px; flex-shrink: 0; }
.ch-now-title { font-size: 0.9rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-now-epg { font-size: 0.68rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 1; }
.pbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; position: relative; }

/* Volume */
.vol-wrap { display: flex; align-items: center; gap: 4px; }
.vol-icon { width: 30px; height: 30px; border-radius: var(--r-sm); background: transparent; border: none; color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: color var(--transition); }
.vol-icon:hover { color: var(--accent); }
.vol-icon svg { width: 16px; height: 16px; }
.vol-slider { width: 70px; accent-color: var(--accent); cursor: pointer; }

/* Quality / Audio / CC dropdown (shared pattern) */
.qw { position: relative; }
.q-btn {
  display: flex; align-items: center; gap: 5px; height: 30px; padding: 0 9px;
  border-radius: var(--r-sm); background: var(--input-bg); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.68rem; font-weight: 600; cursor: pointer; transition: all var(--transition);
}
.q-btn:hover, .q-btn.open { border-color: var(--accent); color: var(--accent); }
.q-btn:disabled { opacity: 0.4; cursor: default; }
.q-btn svg { width: 13px; height: 13px; }
.qchev { transition: transform var(--transition); }
.q-btn.open .qchev { transform: rotate(180deg); }
.q-btn-label { display: none; }
.q-dropdown {
  position: absolute; bottom: calc(100% + 8px); right: 0; min-width: 150px; max-height: 260px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--border-bright); border-radius: var(--r-md);
  box-shadow: var(--shadow-md); padding: 5px; display: none; flex-direction: column; gap: 2px; z-index: 250;
}
.q-dropdown.open { display: flex; }
.q-opt {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: var(--r-sm);
  font-size: 0.72rem; font-weight: 500; color: var(--text-muted); cursor: pointer; transition: all var(--transition);
}
.q-opt:hover { background: var(--input-bg); color: var(--text); }
.q-opt.active { background: var(--accent-dim); color: var(--accent); font-weight: 700; }
.q-opt svg { width: 14px; height: 14px; flex-shrink: 0; }

/* Player-bar overflow menu (mobile) — desktop: `display:contents` makes the
   wrapper invisible to layout so children sit inline exactly as before.
   Mobile: becomes a popup panel opened via the ⋮ button, so a dozen
   control icons don't fight for space in one cramped row. */
.pbar-secondary { display: contents; }
.more-btn { display: none; }
.cpw { position: relative; }
.cp-dropdown {
  position: absolute; top: calc(100% + 10px); right: 0; background: var(--card); border: 1px solid var(--border-bright);
  border-radius: var(--r-md); padding: 10px; box-shadow: var(--shadow-md); display: none; z-index: 250; width: 180px;
}
.cp-dropdown.open { display: block; }
.cp-label { font-size: 0.62rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.cp-swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: all var(--transition); }
.swatch:hover { transform: scale(1.1); }
.swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px currentColor; }

/* ===== SIDEBAR ===== */
.sidebar { width: var(--sidebar-w); flex-shrink: 0; background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-tabs { display: flex; flex-shrink: 0; border-bottom: 1px solid var(--border); }
.st-tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 5px; padding: 11px 4px;
  background: none; border: none; border-bottom: 2px solid transparent; color: var(--text-muted);
  font-size: 0.72rem; font-weight: 700; cursor: pointer; transition: all var(--transition); white-space: nowrap;
}
.st-tab:hover { color: var(--text); }
.st-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.st-tab .badge { background: var(--accent-dim); color: var(--accent); font-size: 0.55rem; padding: 1px 6px; border-radius: 8px; margin-left: 4px; }

.sidebar-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.sidebar-panel { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.sidebar-panel.active { display: flex; }

.sidebar-top { flex-shrink: 0; padding: 10px 12px 0; background: var(--surface); }
.panel-title { font-size: 0.78rem; font-weight: 700; padding: 4px 0 8px; color: var(--text); }
.search-wrap { position: relative; }
.search-wrap .s-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text-muted); pointer-events: none; }
#ch-search {
  width: 100%; height: 34px; padding: 0 10px 0 34px; border-radius: 50px; border: 1px solid var(--border);
  background: var(--input-bg); color: var(--text); font-size: 0.76rem; outline: none; transition: all var(--transition);
}
#ch-search::placeholder { color: var(--text-dim); }
#ch-search:focus { border-color: var(--accent); background: var(--accent-dim); }

.cat-tabs { display: flex; gap: 4px; padding: 8px 0 10px; overflow-x: auto; scrollbar-width: none; }
.cat-tabs::-webkit-scrollbar { display: none; }
.cat-tab {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 11px; border-radius: 50px;
  font-size: 0.66rem; font-weight: 600; background: var(--input-bg); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer; white-space: nowrap; transition: all var(--transition); flex-shrink: 0;
}
.cat-tab:hover { border-color: var(--accent); color: var(--accent); }
.cat-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.cat-count { font-size: 0.55rem; background: rgba(255, 255, 255, 0.18); padding: 0 5px; border-radius: 8px; font-weight: 700; }
.cat-tab.active .cat-count { background: rgba(255, 255, 255, 0.22); }

.view-toggle { display: flex; gap: 3px; flex-shrink: 0; }
.view-btn {
  width: 28px; height: 28px; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--input-bg);
  color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all var(--transition);
}
.view-btn:hover { border-color: var(--accent); color: var(--accent); }
.view-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.view-btn svg { width: 13px; height: 13px; }

.ch-info-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px 4px; flex-shrink: 0; }
.ch-info-label { font-size: 0.62rem; color: var(--text-dim); font-weight: 500; }
.ch-info-count { font-size: 0.62rem; color: var(--accent); font-weight: 700; }

/* Channel Grid */
.ch-grid {
  flex: 1; overflow-y: auto; padding: 6px 10px 12px; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(95px, 1fr)); gap: 7px; align-content: start;
  padding-bottom: max(12px, var(--safe-b));
}
.ch-grid::-webkit-scrollbar { width: 3px; }
.ch-grid::-webkit-scrollbar-track { background: transparent; }
.ch-grid::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 2px; }
.ch-grid.list-view { grid-template-columns: 1fr; gap: 4px; }
.ch-grid.list-view .ch-card { display: flex; align-items: center; gap: 10px; padding: 6px 10px; text-align: left; border-radius: var(--r-md); min-height: 0; }
.ch-grid.list-view .ch-card .ch-logo-wrap { width: 40px; height: 40px; margin: 0; flex-shrink: 0; }
.ch-grid.list-view .ch-card .ch-name { font-size: 0.72rem; -webkit-line-clamp: 1; flex: 1; }
.ch-grid.list-view .ch-card .ch-play { display: none; }
.ch-grid.list-view .ch-card .ch-num { display: block; font-size: 0.6rem; color: var(--text-dim); font-weight: 700; min-width: 22px; }
.ch-grid.list-view .ch-card .ch-fav { position: static; margin-left: auto; background: none; opacity: 0.6; }
.ch-grid.list-view .ch-card .src-badge { position: static; margin-left: 2px; }

/* Channel Card */
.ch-card {
  background: var(--card); border-radius: var(--r-lg); cursor: pointer; padding: 8px 6px 8px;
  text-align: center; border: 2px solid transparent; transition: all var(--transition); position: relative;
  display: flex; flex-direction: column; min-height: 108px;
}
.ch-card:hover { background: var(--card-hover); transform: translateY(-2px) scale(1.02); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45); }
.ch-card.active { border-color: var(--accent); background: var(--accent-dim); box-shadow: 0 4px 18px var(--accent-glow); }
.ch-card .live-pip { display: none; position: absolute; top: 5px; right: 5px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent); animation: livePulse 2s ease-in-out infinite; z-index: 3; }
.ch-card.active .live-pip { display: block; }
.ch-card .ch-play {
  position: absolute; left: 6px; right: 6px; top: 8px; height: 58px; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center; z-index: 2; opacity: 0;
  background: rgba(0,0,0,0.45); transition: opacity var(--transition); pointer-events: none;
}
.ch-card:hover .ch-play, .ch-card.locked .ch-play, .ch-card.unavailable .ch-play { opacity: 1; }
.ch-card .ch-play svg { width: 26px; height: 26px; }
.ch-card .ch-logo-wrap {
  width: 100%; height: 58px; border-radius: var(--r-md); background: rgba(255, 255, 255, 0.08); margin: 0 0 6px;
  overflow: hidden; display: flex; align-items: center; justify-content: center; border: 1px solid var(--border-bright);
  transition: border-color var(--transition); position: relative; flex-shrink: 0;
}
[data-theme="light"] .ch-card .ch-logo-wrap { background: rgba(0, 0, 0, 0.05); }
.ch-card.active .ch-logo-wrap { border-color: var(--accent); }
.ch-card .ch-logo { width: 100%; height: 100%; object-fit: contain; padding: 6px; display: block; }
.ch-card .ch-name {
  font-size: 0.62rem; font-weight: 600; color: var(--text); display: -webkit-box; flex: 1;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.32; transition: color var(--transition);
}
.ch-card.active .ch-name { color: var(--accent); }
.ch-card .ch-num { display: none; }
.ch-card .ch-fav {
  position: absolute; top: 4px; left: 4px; z-index: 3; opacity: 0.85; transition: opacity var(--transition);
  cursor: pointer; background: rgba(0, 0, 0, 0.55); border-radius: 50%; padding: 4px; border: none; color: #fbbf24;
}
.ch-card .ch-fav:hover { opacity: 1; }
.ch-card .ch-fav svg { width: 12px; height: 12px; pointer-events: none; fill: currentColor; }
.ch-card .ch-fav.active { opacity: 1; color: #fbbf24; }
.ch-card .src-badge {
  position: absolute; top: 4px; right: 4px; z-index: 3; background: rgba(0,0,0,0.6); color: #fff;
  font-size: 0.54rem; font-weight: 700; padding: 1px 5px; border-radius: 8px; border: 1px solid var(--border-bright);
}
.ch-card.locked { filter: grayscale(0.4); }
.ch-card.locked .ch-logo { opacity: 0.5; }

.empty-state { grid-column: 1/-1; padding: 40px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-state svg { width: 40px; height: 40px; opacity: 0.3; color: var(--text-muted); }
.empty-state p { font-size: 0.78rem; color: var(--text-muted); }

.grid-sentinel { grid-column: 1 / -1; height: 1px; }

/* ===== FOOTER ===== */
.footer {
  min-height: var(--foot-h); flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  gap: 6px; font-size: 0.62rem; color: var(--text-dim); border-top: 1px solid var(--border); background: var(--surface);
  padding: 4px 0; padding-bottom: calc(4px + var(--safe-b)); padding-left: var(--safe-l); padding-right: var(--safe-r);
}
.footer a { color: var(--accent); text-decoration: none; font-weight: 600; }
.footer a:hover { text-decoration: underline; }

/* ===== GENERIC OVERLAY / MODAL ===== */
.modal-overlay, .epg-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 900;
  opacity: 0; pointer-events: none; transition: opacity var(--transition); padding: 16px;
}
.modal-overlay.open, .epg-overlay.open { opacity: 1; pointer-events: auto; }
.modal-panel {
  background: var(--surface); border: 1px solid var(--border-bright); border-radius: var(--r-xl);
  width: 100%; max-width: 420px; max-height: 82vh; overflow-y: auto; box-shadow: var(--shadow-xl);
  transform: translateY(10px) scale(0.98); transition: transform var(--transition);
}
.modal-overlay.open .modal-panel { transform: translateY(0) scale(1); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal-head h3 { font-size: 0.95rem; font-weight: 700; }
.modal-close { width: 30px; height: 30px; border-radius: 50%; border: none; background: var(--input-bg); color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: var(--accent-dim); color: var(--accent); }
.modal-close svg { width: 15px; height: 15px; }
.modal-body { padding: 16px 18px 20px; display: flex; flex-direction: column; gap: 18px; }
.settings-section { display: flex; flex-direction: column; gap: 8px; }
.settings-section h4 { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.settings-hint { font-size: 0.66rem; color: var(--text-dim); line-height: 1.5; }

.pill-row { display: flex; flex-wrap: wrap; gap: 6px; }
.sleep-opt {
  padding: 7px 14px; border-radius: 50px; border: 1px solid var(--border); background: var(--input-bg);
  color: var(--text-muted); font-size: 0.72rem; font-weight: 600; cursor: pointer; transition: all var(--transition);
}
.sleep-opt:hover { border-color: var(--accent); color: var(--accent); }
.sleep-status { font-size: 0.68rem; color: var(--accent); font-weight: 700; }

.pin-row { display: flex; gap: 8px; }
.pin-row input {
  flex: 1; height: 38px; padding: 0 12px; border-radius: var(--r-md); border: 1px solid var(--border);
  background: var(--input-bg); color: var(--text); font-size: 0.85rem; letter-spacing: 3px; outline: none;
}
.pin-row input:focus { border-color: var(--accent); }
.btn-solid {
  padding: 0 16px; height: 38px; border-radius: var(--r-md); border: none; background: var(--accent);
  color: #fff; font-size: 0.75rem; font-weight: 700; cursor: pointer; transition: all var(--transition); white-space: nowrap;
}
.btn-solid:hover { filter: brightness(1.12); }
.btn-outline {
  padding: 8px 16px; border-radius: var(--r-md); border: 1px solid var(--border-bright); background: var(--input-bg);
  color: var(--text); font-size: 0.75rem; font-weight: 700; cursor: pointer; transition: all var(--transition);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.lock-cat-list { display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r-md); padding: 6px; }
.lock-row { display: flex; align-items: center; justify-content: space-between; padding: 7px 8px; border-radius: var(--r-sm); font-size: 0.74rem; }
.lock-row:hover { background: var(--input-bg); }
.lock-row input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }
.lock-row input:disabled { opacity: 0.35; cursor: not-allowed; }

.cp-row { display: flex; gap: 8px; }
.cp-row input {
  flex: 1; min-width: 0; height: 38px; padding: 0 12px; border-radius: var(--r-md); border: 1px solid var(--border);
  background: var(--input-bg); color: var(--text); font-size: 0.75rem; outline: none;
}
.cp-row input:focus { border-color: var(--accent); }
.custom-playlist-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 8px; border-radius: var(--r-sm); font-size: 0.7rem; }
.custom-playlist-row:hover { background: var(--input-bg); }
.custom-playlist-row .cp-url { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); direction: ltr; }
.custom-playlist-row .cp-remove {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%; border: none; background: var(--input-bg);
  color: var(--text-muted); cursor: pointer; font-size: 0.68rem; display: flex; align-items: center; justify-content: center; transition: all var(--transition);
}
.custom-playlist-row .cp-remove:hover { background: var(--accent-dim); color: var(--accent); }

.about-block { font-size: 0.7rem; color: var(--text-muted); line-height: 1.7; }
.about-block b { color: var(--text); }

/* PIN prompt (small, focused) */
#pinPromptOverlay .modal-panel { max-width: 300px; text-align: center; }
#pinPromptOverlay .modal-body { align-items: center; }
.pin-lock-icon { width: 40px; height: 40px; color: var(--accent); margin: 0 auto; }
#pinPromptInput { text-align: center; font-size: 1.1rem; }

/* Install banner */
.install-banner {
  position: fixed; left: 50%; bottom: 16px; transform: translate(-50%, 140%);
  width: min(92vw, 420px); background: var(--card); border: 1px solid var(--border-bright);
  border-radius: var(--r-lg); box-shadow: var(--shadow-xl); padding: 12px 14px; display: flex;
  align-items: center; gap: 10px; z-index: 800; transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1);
  margin-bottom: var(--safe-b);
}
.install-banner.show { transform: translate(-50%, 0); }
.install-banner .ib-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--accent); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.install-banner .ib-icon svg { width: 20px; height: 20px; color: #fff; }
.install-banner .ib-text { flex: 1; min-width: 0; }
.install-banner .ib-title { font-size: 0.78rem; font-weight: 700; }
.install-banner .ib-sub { font-size: 0.64rem; color: var(--text-muted); }
.install-banner .ib-actions { display: flex; gap: 6px; flex-shrink: 0; }
.ib-btn { padding: 7px 12px; border-radius: var(--r-sm); border: none; background: var(--accent); color: #fff; font-size: 0.68rem; font-weight: 700; cursor: pointer; }
.ib-dismiss { width: 26px; height: 26px; border-radius: 50%; border: none; background: var(--input-bg); color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ===== EPG PANEL ===== */
.epg-overlay .modal-panel, .epg-overlay .epg-panel {
  background: var(--surface); border: 1px solid var(--border-bright); border-radius: var(--r-xl);
  width: 100%; max-width: 480px; max-height: 78vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-xl);
}
.epg-list { overflow-y: auto; padding: 8px 10px 16px; display: flex; flex-direction: column; gap: 6px; }
.epg-item { display: flex; gap: 12px; padding: 10px 10px; border-radius: var(--r-md); transition: background var(--transition); }
.epg-item.now { background: var(--accent-dim); border: 1px solid var(--accent); }
.epg-time { font-size: 0.66rem; font-weight: 700; color: var(--text-muted); white-space: nowrap; padding-top: 2px; min-width: 78px; }
.epg-item.now .epg-time { color: var(--accent); }
.epg-info { flex: 1; min-width: 0; }
.epg-prog { font-size: 0.78rem; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.epg-desc { font-size: 0.68rem; color: var(--text-muted); line-height: 1.4; }
.epg-empty { padding: 30px; text-align: center; color: var(--text-muted); font-size: 0.78rem; }

/* ===== TOAST ===== */
#toastWrap {
  position: fixed; top: calc(16px + var(--safe-t)); right: max(16px, var(--safe-r)); z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; max-width: min(90vw, 340px);
}
.toast {
  display: flex; align-items: center; gap: 9px; background: var(--card); border: 1px solid var(--border-bright);
  border-radius: var(--r-md); padding: 11px 14px; box-shadow: var(--shadow-md); font-size: 0.76rem; font-weight: 600;
  color: var(--text); animation: tIn 0.28s cubic-bezier(0.34,1.56,0.64,1);
}
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
.toast.success { border-color: rgba(34,197,94,0.4); }
.toast.success svg { color: #22c55e; }
.toast.error { border-color: rgba(239,68,68,0.4); }
.toast.error svg { color: #ef4444; }
.toast.info svg { color: var(--accent); }
@keyframes tIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: translateX(0); } }
@keyframes tOut { to { opacity: 0; transform: translateX(24px); } }

/* ===== GLOBAL LOADER ===== */
#global-loader {
  position: fixed; inset: 0; background: var(--bg); z-index: 9998; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; transition: opacity 0.4s;
}
#global-loader .gl-logo { font-family: 'Bebas Neue', sans-serif; font-size: 2.4rem; letter-spacing: 5px; color: var(--text); }
#global-loader .gl-logo span { color: var(--accent); }

/* Accessibility helpers */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link {
  position: absolute; left: 8px; top: -60px; background: var(--accent); color: #fff; padding: 10px 16px;
  border-radius: var(--r-sm); z-index: 99999; font-size: 0.78rem; font-weight: 700; transition: top 0.2s;
}
.skip-link:focus { top: 8px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
  :root { --sidebar-w: 320px; }
}

@media (max-width: 992px) {
  .main-row { flex-direction: column; }
  .sidebar { width: 100%; height: 50vh; min-height: 340px; border-left: none; border-top: 1px solid var(--border); }
  .video-wrap { min-height: 120px; }
  .ch-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}

/* Shorter phones (older/smaller devices, or any short viewport): the
   sidebar's min-height above can demand more room than a short screen
   actually has, leaving too little for the player. Ease it down so both
   areas stay usable instead of fighting for space. */
@media (max-width: 992px) and (max-height: 700px) {
  .sidebar { min-height: 220px; height: 42vh; }
  .video-wrap { min-height: 90px; }
}
@media (max-width: 992px) and (max-height: 600px) {
  .sidebar { min-height: 180px; height: 38vh; }
}

@media (max-width: 768px) {
  .topbar { padding-left: max(10px, var(--safe-l)); padding-right: max(10px, var(--safe-r)); gap: 4px; }
  .brand-name { font-size: 1.4rem; letter-spacing: 2px; }
  .brand-icon { width: 30px; height: 30px; }
  .net-status span.net-label-txt { display: none; }
  .theme-btn span { display: none; }
  .theme-btn { padding: 0 8px; width: 34px; justify-content: center; }
  .tb-divider { display: none; }
  .pbar { padding: 6px 8px; padding-bottom: calc(6px + var(--safe-b)); gap: 6px; overflow: visible; }
  .vol-slider { width: 58px; }
  .now-playing { gap: 6px; }
  .ch-now-epg { display: none; }
  .modal-panel { max-width: 94vw; }

  /* Overflow "more" menu replaces the long row of secondary controls */
  .more-btn { display: flex; }
  .pbar-secondary {
    display: none; position: absolute; bottom: calc(100% + 10px); right: 8px; z-index: 260;
    background: var(--card); border: 1px solid var(--border-bright); border-radius: var(--r-md);
    box-shadow: var(--shadow-md); padding: 6px; flex-direction: column; gap: 2px;
    width: min(240px, calc(100vw - 24px)); max-height: 60vh; overflow-y: auto;
  }
  .pbar-secondary.open { display: flex; }
  .pbar-secondary .icon-btn {
    width: 100%; height: 40px; justify-content: flex-start; gap: 12px; padding: 0 10px; background: none; border: none;
  }
  .pbar-secondary .icon-btn svg { flex-shrink: 0; }
  .pbar-secondary .icon-btn:hover { background: var(--input-bg); }
  .pbar-secondary .icon-btn[data-tip]::after {
    content: attr(data-tip); position: static; opacity: 1; transform: none; left: auto; bottom: auto;
    background: none; border: none; padding: 0; font-size: 0.74rem; font-weight: 500; color: var(--text); white-space: normal;
  }
  .pbar-secondary .qw, .pbar-secondary .cpw { width: 100%; }
  .pbar-secondary .q-btn { width: 100%; justify-content: flex-start; height: 40px; background: none; border: none; gap: 12px; }
  .pbar-secondary .q-btn svg:first-child { flex-shrink: 0; }
  .pbar-secondary .q-btn-label { display: inline; }
  .pbar-secondary .qchev { margin-left: auto; }
  .pbar-secondary .q-dropdown, .pbar-secondary .cp-dropdown { position: fixed; bottom: auto; right: 16px; left: 16px; width: auto; }
}

@media (max-width: 480px) {
  .brand-tag { display: none; }
  .icon-btn { width: 32px; height: 32px; }
  .icon-btn svg { width: 15px; height: 15px; }
  .ch-grid { grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 8px; padding: 6px 8px 10px; }
  .ch-card .ch-logo-wrap { height: 52px; }
  .cat-tab { font-size: 0.62rem; padding: 3px 9px; }
  .st-tab { font-size: 0.66rem; padding: 9px 2px; }
  .modal-body { padding: 14px; gap: 14px; }
  .install-banner { padding: 10px; gap: 8px; }
  .install-banner .ib-title { font-size: 0.72rem; }
  .install-banner .ib-sub { font-size: 0.6rem; }
  .epg-time { min-width: 62px; font-size: 0.6rem; }
  .live-badge { display: none; }
}

@media (max-width: 360px) {
  .net-status { padding: 2px 6px; }
  .search-wrap .s-icon { left: 9px; }
  #ch-search { font-size: 0.7rem; }
  .ch-grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; }
  .ch-card { min-height: 96px; padding: 6px 5px 6px; }
  .ch-card .ch-logo-wrap { height: 46px; }
  .ch-card .ch-name { font-size: 0.58rem; }
  .pin-row { flex-direction: column; }
  .pin-row .btn-solid { width: 100%; }
}

/* Short-height landscape phones: keep player+sidebar side by side so the
   video never gets crushed into a sliver. */
@media (max-height: 500px) and (orientation: landscape) {
  .main-row { flex-direction: row; }
  .sidebar { width: 260px; height: auto; min-height: 0; border-top: none; border-left: 1px solid var(--border); }
  .topbar { height: calc(42px + var(--safe-t)); }
  .brand-tag, .footer { display: none; }
  .video-wrap { min-height: 0; }
  .ch-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

@media print {
  .app { display: none; }
}
