/* ═══════════════════════════════
   ROOT & RESET
═══════════════════════════════ */
:root {
  --bg:        #08080d;
  --bg2:       #0f0f16;
  --bg3:       #161620;
  --bg4:       #1e1e2a;
  --bg5:       #272736;
  --border:    rgba(255,255,255,.06);
  --border2:   rgba(255,255,255,.11);
  --accent:    #f0a500;
  --accent2:   #ff6535;
  --accentg:   linear-gradient(135deg,#f0a500,#ff6535);
  --text:      #eeeef8;
  --sub:       #8080a0;
  --muted:     #50506a;
  --red:       #ff4455;
  --green:     #2ecc71;
  --sidebar:   340px;
  --topbar:    56px;
  --infobar:   64px;
  --r:         10px;
  --r-sm:      7px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: 'Inter', sans-serif; overflow: hidden; -webkit-font-smoothing: antialiased; }
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-thumb { background: var(--bg5); border-radius: 99px; }

/* ═══════════════════════════════
   LAYOUT
═══════════════════════════════ */
#app  { display: flex; flex-direction: column; height: 100dvh; }
#main { display: flex; flex: 1; overflow: hidden; position: relative; }

/* ═══════════════════════════════
   TOPBAR
═══════════════════════════════ */
#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px; height: var(--topbar); flex-shrink: 0;
  background: var(--bg2); border-bottom: 1px solid var(--border); z-index: 200;
}
.logo {
  font-family: 'Syne', sans-serif; font-size: 21px; font-weight: 800;
  background: var(--accentg); -webkit-background-clip: text;
  -webkit-text-fill-color: transparent; background-clip: text;
  user-select: none; white-space: nowrap; letter-spacing: .5px; flex-shrink: 0;
}
.logo-live {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: 'JetBrains Mono', monospace; font-size: 9px; font-weight: 500;
  letter-spacing: 1px; color: var(--red); vertical-align: middle;
  margin-left: 8px; -webkit-text-fill-color: var(--red);
}
.logo-live::before {
  content: ''; display: inline-block; width: 6px; height: 6px;
  background: var(--red); border-radius: 50%; animation: blink 1.8s step-end infinite;
}
@keyframes blink { 0%,100%{opacity:1}50%{opacity:.3} }

#top-search-wrap { flex: 1; max-width: 360px; position: relative; }
#top-search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; pointer-events: none; }
#top-search {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 99px; color: var(--text); font-family: 'Inter', sans-serif;
  font-size: 13px; padding: 8px 14px 8px 34px; outline: none;
  transition: border-color .2s, background .2s;
}
#top-search:focus { border-color: var(--accent); background: var(--bg4); }
#top-search::placeholder { color: var(--muted); }
#top-search::-webkit-search-cancel-button { cursor: pointer; }

#top-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
#status-pill {
  font-size: 10px; font-family: 'JetBrains Mono', monospace;
  padding: 5px 12px; border-radius: 99px; white-space: nowrap;
  background: var(--bg3); border: 1px solid var(--border); color: var(--muted);
  max-width: 200px; overflow: hidden; text-overflow: ellipsis;
  transition: color .3s, border-color .3s;
}
#status-pill.ok  { color: var(--green); border-color: rgba(46,204,113,.2); }
#status-pill.err { color: var(--red);   border-color: rgba(255,68,85,.2); }

/* ── icon buttons ── */
.icon-btn {
  background: var(--bg3); border: 1px solid var(--border); color: var(--sub);
  border-radius: var(--r-sm); width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 16px; transition: all .15s; user-select: none; flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg4); border-color: var(--border2); color: var(--text); }
.icon-btn.active { color: var(--accent); border-color: rgba(240,165,0,.35); background: rgba(240,165,0,.08); }
#btn-menu { display: none; }

/* ═══════════════════════════════
   OVERLAY (mobile sidebar)
═══════════════════════════════ */
#overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.72); z-index: 99; backdrop-filter: blur(3px); }
#overlay.show { display: block; }

/* ═══════════════════════════════
   SIDEBAR
═══════════════════════════════ */
#sidebar {
  width: var(--sidebar); min-width: var(--sidebar);
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  transition: transform .28s cubic-bezier(.4,0,.2,1); z-index: 100;
}

/* tabs */
#tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; padding: 0 6px; }
.tab {
  flex: 1; padding: 12px 0; text-align: center; cursor: pointer;
  font-size: 11px; font-weight: 700; letter-spacing: .4px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all .16s; user-select: none;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover:not(.active) { color: var(--text); }

/* panels */
.panel { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.panel.active { display: flex; }

/* ── FILTER BAR ── */
#filter-bar { padding: 10px 10px 8px; border-bottom: 1px solid var(--border); flex-shrink: 0; display: flex; flex-direction: column; gap: 7px; }
.select-wrap { position: relative; }
.select-wrap::after { content: '▾'; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 11px; pointer-events: none; }
select {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--text); font-family: 'Inter', sans-serif;
  font-size: 12px; padding: 8px 28px 8px 10px; outline: none; cursor: pointer;
  -webkit-appearance: none; appearance: none; transition: border-color .2s;
}
select:focus { border-color: var(--accent); }
select option { background: var(--bg4); }

#pills { display: flex; gap: 5px; flex-wrap: wrap; }
.pill {
  font-size: 11px; font-weight: 600; padding: 5px 12px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 99px; color: var(--muted); cursor: pointer;
  transition: all .15s; user-select: none; white-space: nowrap;
}
.pill.active { background: var(--accent); border-color: var(--accent); color: #000; }
.pill:hover:not(.active) { border-color: var(--border2); color: var(--text); }
#ch-count { font-size: 10px; color: var(--muted); font-family: 'JetBrains Mono', monospace; }

/* ── CHANNEL SCROLL ── */
.ch-scroll { flex: 1; overflow-y: auto; padding: 5px 7px; }

.ch {
  display: flex; align-items: center; gap: 9px; padding: 8px 9px;
  border-radius: var(--r-sm); cursor: pointer; border: 1px solid transparent;
  transition: background .12s; position: relative; user-select: none;
}
.ch:hover { background: var(--bg3); }
.ch.active { background: var(--bg4); border-color: rgba(240,165,0,.25); }
.ch.active .ch-name { color: var(--accent); }
.ch.active::before {
  content: ''; position: absolute; left: 0; top: 22%; bottom: 22%;
  width: 3px; background: var(--accentg); border-radius: 0 3px 3px 0;
}
.ch-thumb {
  width: 38px; height: 38px; border-radius: 7px; flex-shrink: 0;
  object-fit: contain; background: var(--bg3); border: 1px solid var(--border);
}
.ch-ini {
  width: 38px; height: 38px; border-radius: 7px; flex-shrink: 0;
  background: var(--bg3); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Syne', sans-serif; font-size: 13px; font-weight: 700; color: var(--accent);
}
.ch-info { overflow: hidden; flex: 1; min-width: 0; }
.ch-name { font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-grp  { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.ch-flag { font-size: 13px; flex-shrink: 0; opacity: .65; }

/* skeleton */
.sk { display: flex; align-items: center; gap: 9px; padding: 8px 9px; border-radius: var(--r-sm); animation: pulse 1.5s ease-in-out infinite; }
.sk-b { width: 38px; height: 38px; border-radius: 7px; background: var(--bg4); flex-shrink: 0; }
.sk-l { flex: 1; display: flex; flex-direction: column; gap: 7px; }
.sk-line { height: 9px; border-radius: 4px; background: var(--bg4); }
.sk-line.s { width: 55%; }
@keyframes pulse { 0%,100%{opacity:.65}50%{opacity:.2} }
.no-ch { text-align: center; color: var(--muted); font-size: 13px; margin-top: 44px; line-height: 2; padding: 0 14px; }
.no-ch-icon { font-size: 30px; margin-bottom: 4px; opacity: .3; }

/* ── COUNTRY PANEL ── */
#country-head { padding: 10px 10px 8px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
#country-search-wrap { position: relative; }
#csi { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; pointer-events: none; }
#country-search {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--text); font-family: 'Inter', sans-serif;
  font-size: 13px; padding: 8px 10px 8px 32px; outline: none; transition: border-color .2s;
}
#country-search:focus { border-color: var(--accent); }
#country-search::placeholder { color: var(--muted); }
#country-back {
  display: none; align-items: center; gap: 8px; padding: 9px 12px 7px;
  cursor: pointer; color: var(--accent); font-size: 13px; font-weight: 600;
  flex-shrink: 0; user-select: none; border-bottom: 1px solid var(--border);
  transition: color .15s;
}
#country-back:hover { color: var(--text); }
#country-grid { flex: 1; overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 1px; }
.country-card {
  display: flex; align-items: center; gap: 11px; padding: 9px 10px;
  border-radius: var(--r-sm); cursor: pointer; border: 1px solid transparent;
  transition: background .12s; user-select: none;
}
.country-card:hover { background: var(--bg3); }
.country-card.active { background: var(--bg4); border-color: rgba(240,165,0,.25); }
.cc-flag { font-size: 22px; flex-shrink: 0; line-height: 1; }
.cc-name { font-size: 13px; font-weight: 500; }
.cc-code { font-size: 10px; color: var(--muted); font-family: 'JetBrains Mono', monospace; margin-top: 2px; }

/* ── FAVOURITES PANEL ── */
#p-favs .fav-empty { padding: 40px 16px; text-align: center; color: var(--muted); font-size: 13px; line-height: 2; }
#p-favs .fav-empty-icon { font-size: 36px; opacity: .3; margin-bottom: 6px; }

/* ═══════════════════════════════
   PLAYER
═══════════════════════════════ */
#player-area { flex: 1; display: flex; flex-direction: column; background: #000; overflow: hidden; position: relative; }
#video-wrap { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; background: #000; overflow: hidden; min-height: 0; }

/* ── VIDEO — NO NATIVE CONTROLS → we own them ── */
#vid { width: 100%; height: 100%; display: block; background: #000; outline: none; }

/* ── PLACEHOLDER ── */
#ph {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
.ph-tv { font-size: 56px; opacity: .12; }
#ph-text { font-family: 'Syne', sans-serif; font-size: 15px; font-weight: 700; letter-spacing: 2px; color: var(--muted); opacity: .35; }

/* ── SPINNER (z:12 above overlay z:9) ── */
#spin {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center; background: rgba(0,0,0,.45); z-index: 12;
}
#spin.show { display: flex; }
.ring {
  width: 44px; height: 44px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.08);
  border-top-color: var(--accent);
  animation: rot .8s linear infinite;
}
@keyframes rot { to { transform: rotate(360deg); } }

/* ── ERROR (z:13) ── */
#err-box {
  position: absolute; inset: 0; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 11px;
  background: rgba(0,0,0,.82); z-index: 13; backdrop-filter: blur(6px);
}
#err-box.show { display: flex; }
.err-icon { font-size: 38px; }
#err-msg { font-size: 12px; color: var(--red); font-family: 'JetBrains Mono', monospace; text-align: center; padding: 0 20px; max-width: 380px; word-break: break-all; line-height: 1.8; }
.err-actions { display: flex; gap: 8px; margin-top: 4px; }
.err-btn {
  border: none; font-family: 'Inter', sans-serif; font-weight: 700; font-size: 12px;
  padding: 9px 20px; border-radius: 99px; cursor: pointer; transition: filter .15s;
}
.err-btn.primary { background: var(--accent); color: #000; }
.err-btn.secondary { background: var(--bg4); color: var(--text); border: 1px solid var(--border2); }
.err-btn:hover { filter: brightness(1.12); }

/* ══════════════════════════════════════════
   CUSTOM VIDEO CONTROLS OVERLAY
   z-index: 9 (below spinner:12, error:13)
   pointer-events: none by default so clicks
   pass through to the video element itself
   ONLY the control bar gets pointer-events
══════════════════════════════════════════ */
#vc-overlay {
  position: absolute; inset: 0; z-index: 9;
  pointer-events: none;             /* pass-through to <video> */
  display: flex; flex-direction: column;
  opacity: 0; transition: opacity .28s;
}
#vc-overlay.vis { opacity: 1; }

/* top bar: channel name + volume */
#vc-top {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 0;
  background: linear-gradient(to bottom, rgba(0,0,0,.75) 0%, transparent 100%);
  pointer-events: auto;
}
#vc-live-badge {
  font-size: 9px; font-family: 'JetBrains Mono', monospace; font-weight: 700;
  letter-spacing: 1px; padding: 3px 8px; background: var(--red);
  border-radius: 4px; color: #fff; flex-shrink: 0;
  animation: blink 1.8s step-end infinite; display: none;
}
#vc-ch-name { font-size: 13px; font-weight: 600; color: #fff; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: none; }

/* volume row */
#vc-vol-wrap { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
#vc-vol-icon { font-size: 14px; cursor: pointer; color: rgba(255,255,255,.8); pointer-events: auto; user-select: none; }
#vc-vol {
  -webkit-appearance: none; appearance: none;
  width: 72px; height: 3px; border-radius: 99px; outline: none; cursor: pointer;
  background: rgba(255,255,255,.25); accent-color: var(--accent);
  pointer-events: auto;
}
#vc-vol::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%; background: var(--accent); cursor: pointer; }

/* middle centre: big play/pause on click */
#vc-mid {
  flex: 1; display: flex; align-items: center; justify-content: center;
  pointer-events: auto; cursor: pointer;
}
.vc-play-icon {
  font-size: 52px; opacity: 0;
  transition: opacity .18s, transform .18s;
  transform: scale(.8); color: rgba(255,255,255,.9);
  pointer-events: none; text-shadow: 0 2px 24px rgba(0,0,0,.8);
}
.vc-play-icon.flash { opacity: 1; transform: scale(1); }

/* bottom control bar */
#vc-bar {
  display: flex; align-items: center; gap: 8px; padding: 0 14px 14px;
  background: linear-gradient(to top, rgba(0,0,0,.82) 0%, transparent 100%);
  pointer-events: auto;
}
.vc-btn {
  background: rgba(255,255,255,.1); border: none; color: rgba(255,255,255,.9);
  width: 34px; height: 34px; border-radius: 50%; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(6px); transition: background .14s, transform .1s; flex-shrink: 0;
}
.vc-btn:hover { background: rgba(255,255,255,.22); transform: scale(1.08); }
.vc-btn:active { transform: scale(.94); }
#vc-spacer { flex: 1; }

/* quality badge */
#vc-quality {
  font-size: 9px; font-family: 'JetBrains Mono', monospace; font-weight: 600;
  padding: 3px 7px; border-radius: 4px; background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.7); letter-spacing: .5px; display: none;
}

/* ── INFO BAR ── */
#info-bar {
  background: var(--bg2); border-top: 1px solid var(--border);
  padding: 0 14px; height: var(--infobar);
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-shrink: 0;
}
.np-left { display: flex; align-items: center; gap: 10px; overflow: hidden; }
#np-flag { font-size: 20px; flex-shrink: 0; }
#np-name {
  font-family: 'Syne', sans-serif; font-size: 17px; font-weight: 700;
  background: var(--accentg); -webkit-background-clip: text;
  -webkit-text-fill-color: transparent; background-clip: text;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px;
}
#np-grp { font-size: 10px; color: var(--muted); font-family: 'JetBrains Mono', monospace; margin-top: 2px; }
.np-right { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.cb {
  background: var(--bg3); border: 1px solid var(--border); color: var(--sub);
  border-radius: var(--r-sm); width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 14px; transition: all .14s; user-select: none;
}
.cb:hover { background: var(--bg4); border-color: var(--border2); color: var(--text); }
.cb.on { color: var(--accent); border-color: rgba(240,165,0,.35); background: rgba(240,165,0,.07); }

/* ── MINI EPG / NOW PLAYING TICKER ── */
#now-ticker {
  background: var(--bg3); border-top: 1px solid var(--border);
  padding: 5px 14px; flex-shrink: 0;
  display: flex; align-items: center; gap: 8px; overflow: hidden;
}
#now-ticker .ticker-label { font-size: 9px; font-family: 'JetBrains Mono', monospace; color: var(--accent); letter-spacing: 1px; white-space: nowrap; font-weight: 600; }
#ticker-text { font-size: 11px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }

/* ── SLEEP TIMER BADGE ── */
#sleep-badge {
  display: none; align-items: center; gap: 5px;
  font-size: 10px; font-family: 'JetBrains Mono', monospace; color: var(--sub);
  background: var(--bg3); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 99px; white-space: nowrap;
}
#sleep-badge.show { display: flex; }
#sleep-badge .sb-icon { color: var(--accent); }

/* ── TOAST ── */
#toast {
  position: fixed; bottom: 82px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--bg4); border: 1px solid var(--border2); color: var(--text);
  font-size: 12.5px; padding: 9px 20px; border-radius: 99px;
  opacity: 0; pointer-events: none; transition: opacity .22s, transform .22s;
  z-index: 999; white-space: nowrap; box-shadow: 0 8px 28px rgba(0,0,0,.45);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── SLEEP TIMER MODAL ── */
#sleep-modal {
  display: none; position: fixed; inset: 0; z-index: 300;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,.7); backdrop-filter: blur(6px);
}
#sleep-modal.show { display: flex; }
.modal-box {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--r); padding: 24px; min-width: 260px; max-width: 320px; width: 90%;
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
}
.modal-title { font-family: 'Syne', sans-serif; font-size: 16px; font-weight: 700; margin-bottom: 16px; color: var(--text); }
.modal-options { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.modal-opt {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: var(--r-sm); border: 1px solid var(--border); cursor: pointer;
  transition: background .12s; font-size: 13px; color: var(--sub);
}
.modal-opt:hover { background: var(--bg4); color: var(--text); }
.modal-opt.active { border-color: var(--accent); background: rgba(240,165,0,.08); color: var(--accent); }
.modal-opt-icon { font-size: 16px; flex-shrink: 0; }
.modal-close { width: 100%; background: var(--bg4); border: 1px solid var(--border); color: var(--sub); padding: 9px; border-radius: var(--r-sm); cursor: pointer; font-size: 13px; font-family: 'Inter', sans-serif; transition: all .14s; }
.modal-close:hover { color: var(--text); border-color: var(--border2); }

/* ═══════════════════════════════
   RESPONSIVE
═══════════════════════════════ */
@media (max-width: 768px) {
  :root { --sidebar: 300px; }
  #btn-menu { display: flex; }
  #top-search-wrap { max-width: 160px; }
  #sidebar {
    position: fixed; inset: 0 auto 0 0;
    transform: translateX(-110%); z-index: 100;
    width: 86vw; max-width: 320px; min-width: 260px;
  }
  #sidebar.open { transform: translateX(0); }
  #np-name { font-size: 14px; max-width: 140px; }
  #info-bar { padding: 0 10px; }
  .cb { width: 31px; height: 31px; font-size: 13px; }
  .np-right { gap: 4px; }
  #vc-vol-wrap { display: none; }
}
@media (max-width: 420px) {
  #np-flag { display: none; }
  #top-search-wrap { display: none; }
  #status-pill { max-width: 120px; font-size: 9px; }
}
