/* ============================================================
   IPTV Browser — cable-box stylesheet
   Greyscale palette. No accent colors. High contrast. Flat.
   ============================================================ */

/* --- design tokens --- */
:root {
  /* surfaces (dark → light) */
  --bg:        #0a0a0a;
  --surface-1: #141414;   /* panels, overlays            */
  --surface-2: #1c1c1c;   /* inputs, raised rows         */
  --surface-3: #262626;   /* hover / active states       */
  --surface-4: #303030;   /* pressed / strong highlight  */

  /* borders */
  --border:    #2a2a2a;
  --border-2:  #3a3a3a;

  /* text */
  --text:      #e8e8e8;
  --text-2:    #a0a0a0;   /* secondary                   */
  --text-3:    #666;      /* muted / placeholder         */

  /* functional (all greyscale — no chromatic accents) */
  --on:        #e8e8e8;   /* enabled / active indicator  */
  --off:       #555;      /* disabled / idle             */
}

/* --- reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: var(--bg); overscroll-behavior: none; }
body {
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

/* --- type scale --- */
/* xs=11  sm=13  base=15  lg=18  xl=24  (all via direct font-size) */

/* ============================================================
   VIDEO
   ============================================================ */
video#video {
  position: fixed; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #000; z-index: 1;
}

/* ============================================================
   EMPTY STATE (no channel loaded)
   ============================================================ */
.osd-empty {
  position: fixed; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg); cursor: pointer; gap: 8px;
}
.osd-empty-title { font-size: 24px; font-weight: 700; letter-spacing: 1px; margin-bottom: 8px; }
.osd-empty-sub   { font-size: 15px; color: var(--text-2); }

/* ============================================================
   TOP BAR (channel info + navigation)
   Auto-hides. Shows on mouse/touch. Persistent gradient.
   ============================================================ */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; padding: 16px 24px 56px;
  background: linear-gradient(180deg, rgba(10,10,10,.97) 0%, rgba(10,10,10,.7) 55%, transparent 100%);
  opacity: 0; transition: opacity .35s; pointer-events: none;
}
.topbar.show { opacity: 1; pointer-events: auto; }

.topbar-left  { display: flex; align-items: center; gap: 16px; flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

/* brand (idle state) */
.topbar-brand {
  font-size: 13px; font-weight: 700; letter-spacing: 3px;
  text-transform: uppercase; color: var(--text-2);
}

/* channel info (active state) */
.topbar-ch   { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; }
.ch-logo     { width: 52px; height: 36px; flex-shrink: 0; background: #fff; border-radius: 4px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.ch-logo img { max-width: 88%; max-height: 88%; object-fit: contain; }
.ch-logo .ph { font-size: 10px; color: #888; text-align: center; padding: 2px; line-height: 1.1; font-weight: 600; }
.ch-info     { flex-shrink: 0; min-width: 130px; }
.ch-num      { font-size: 11px; color: var(--text-2); font-weight: 700; letter-spacing: 1px; font-variant-numeric: tabular-nums; }
.ch-name     { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-epg      { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; justify-content: center; }
.ch-epg .now  { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-epg .now .live, .ch-epg .none .live { font-size: 10px; font-weight: 700; letter-spacing: .5px; color: var(--text); margin-right: 4px; }
.ch-epg .next { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-epg .none { font-size: 13px; color: var(--text-3); }

/* clock */
.ch-clock {
  font-size: 17px; font-weight: 500; color: var(--text-2);
  font-variant-numeric: tabular-nums; letter-spacing: 1px;
  font-family: "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  padding-right: 12px;
}

/* ============================================================
   BUTTON SYSTEM
   Shared base + variants for consistent sizing/states.
   ============================================================ */

/* nav buttons (Guide, Settings in topbar) */
.btn-nav {
  background: var(--surface-2); color: var(--text);
  border: none; padding: 10px 20px;
  cursor: pointer; font-size: 13px; font-weight: 700;
  letter-spacing: 1.5px; text-transform: uppercase;
  transition: background .15s; min-height: 40px;
}
.btn-nav:hover, .btn-nav:focus { background: var(--surface-3); outline: none; }
.btn-nav:active { background: var(--surface-4); }

/* icon variant — square, centered SVG */
.btn-icon { padding: 0; width: 40px; display: flex; align-items: center; justify-content: center; }

/* close button (overlays) */
.btn-close {
  background: var(--surface-2); color: var(--text-2);
  border: none; width: 40px; height: 40px;
  cursor: pointer; font-size: 20px; font-weight: 400; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s; flex-shrink: 0;
}
.btn-close:hover, .btn-close:focus { background: var(--surface-4); color: var(--text); outline: none; }

/* primary action button (Save, Add) */
.btn-primary {
  background: var(--text); color: #000;
  border: none; padding: 12px 24px;
  cursor: pointer; font-size: 14px; font-weight: 700;
  letter-spacing: .5px; transition: opacity .15s; min-height: 44px;
}
.btn-primary:hover { opacity: .82; }

/* secondary/ghost button (Clear All, Select All) */
.btn-ghost {
  background: none; color: var(--text-2);
  border: 1px solid var(--border-2); padding: 11px 20px;
  cursor: pointer; font-size: 13px; font-weight: 600;
  transition: background .15s, color .15s; min-height: 44px;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

/* mini button (Fav, Hide in channel management) */
.btn-mini {
  background: var(--surface-3); color: var(--text-2);
  border: none; padding: 8px 14px;
  cursor: pointer; font-size: 13px; font-weight: 600;
  transition: background .15s, color .15s; min-height: 36px;
}
.btn-mini:hover { background: var(--surface-4); color: var(--text); }
.btn-mini.active { background: var(--surface-4); color: var(--text); }

/* destructive text link (Remove source) */
.btn-remove {
  background: none; border: none; color: var(--text-2);
  cursor: pointer; font-size: 13px; font-weight: 600;
  padding: 8px 12px; transition: color .15s;
}
.btn-remove:hover { color: var(--text); text-decoration: underline; }

/* ============================================================
   OVERLAY SHELL (shared by guide + settings)
   ============================================================ */
.overlay {
  position: fixed; inset: 0; z-index: 25;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.75);
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.overlay.show { opacity: 1; pointer-events: auto; }

/* overlay header bar (shared layout) */
.overlay-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.overlay-title { font-size: 17px; font-weight: 700; letter-spacing: .5px; }

/* ============================================================
   CHANNEL GUIDE
   ============================================================ */
.guide-panel {
  position: absolute; bottom: 0; left: 0; right: 0; height: 68vh;
  background: var(--surface-1);
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateY(100%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
}
.guide-overlay.show .guide-panel { transform: translateY(0); }

.guide-hint { font-size: 12px; color: var(--text-3); flex: 1; text-align: center; }

/* filter row */
.guide-filters {
  display: flex; gap: 8px; padding: 0 20px 12px;
  align-items: center; flex-wrap: wrap;
}
.input-field {
  padding: 11px 14px; background: var(--surface-2); color: var(--text);
  border: none; font-size: 14px; font-family: inherit; outline: none;
  transition: background .15s;
}
.input-field:focus { background: var(--surface-3); }
.guide-filters .input-field { flex: 1; min-width: 160px; }
.guide-count { font-size: 12px; color: var(--text-3); margin-left: auto; white-space: nowrap; }

/* channel list */
.guide-list-wrap { flex: 1; overflow-y: auto; padding: 0 8px 8px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; }
.guide-list-wrap::-webkit-scrollbar { width: 6px; }
.guide-list-wrap::-webkit-scrollbar-track { background: transparent; }
.guide-list-wrap::-webkit-scrollbar-thumb { background: var(--surface-3); }
.guide-list { display: flex; flex-direction: column; }

.g-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; cursor: pointer;
  transition: background .1s; border-bottom: 1px solid var(--border);
}
.g-row:hover, .g-row.focus { background: var(--surface-2); }
.g-row.active { background: var(--surface-3); }
.g-row .num   { width: 34px; text-align: right; color: var(--text-3); font-size: 13px; font-variant-numeric: tabular-nums; flex-shrink: 0; font-weight: 600; }
.g-row .pin-btn { background: none; border: none; color: var(--text-3); font-size: 18px; cursor: pointer; flex-shrink: 0; padding: 0; width: 24px; line-height: 1; }
.g-row .pin-btn.pinned { color: #e8e8e8; }
.g-row .pin-btn:hover { color: var(--text); }
.g-row .logo  { width: 44px; height: 32px; flex-shrink: 0; background: #fff; border-radius: 4px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.g-row .logo img { max-width: 88%; max-height: 88%; object-fit: contain; }
.g-row .logo .ph { font-size: 9px; color: #888; padding: 2px; text-align: center; line-height: 1.1; font-weight: 600; }
.g-row .info  { width: 150px; flex-shrink: 0; }
.g-row .name  { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-row .tag   { font-size: 11px; color: var(--text-3); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-row .epg   { flex: 1; min-width: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
.g-row .epg .live { font-size: 10px; font-weight: 700; letter-spacing: .5px; color: var(--text); }
.g-row .epg .epg-none { color: var(--text-3); }

/* ============================================================
   SETTINGS
   ============================================================ */
.settings-panel {
  width: 92%; max-width: 660px; max-height: 85vh;
  background: var(--surface-1);
  display: flex; flex-direction: column; overflow: hidden;
  margin: auto;
  transform: scale(.96); opacity: 0; transition: transform .2s, opacity .2s;
}
.settings-overlay.show .settings-panel { transform: scale(1); opacity: 1; }

/* tabs */
.settings-tabs {
  display: flex; gap: 0; padding: 0 16px;
  border-bottom: 1px solid var(--border); overflow-x: auto;
  scrollbar-width: none;
}
.settings-tabs::-webkit-scrollbar { display: none; }
.settings-tabs .tab {
  background: none; border: none; color: var(--text-3);
  padding: 12px 16px; cursor: pointer; font-size: 14px; font-weight: 600;
  border-bottom: 2px solid transparent; transition: color .15s, border-color .15s;
  white-space: nowrap; flex-shrink: 0;
}
.settings-tabs .tab:hover { color: var(--text-2); }
.settings-tabs .tab.active { color: var(--text); border-bottom-color: var(--text); }

/* body */
.settings-body { padding: 20px 24px 24px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.settings-section { margin-bottom: 28px; }
.settings-section:last-child { margin-bottom: 0; }
.settings-section-title { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.settings-section-desc  { font-size: 13px; color: var(--text-2); margin-bottom: 14px; line-height: 1.5; }

/* source list rows */
.src-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.src-group-hdr { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text-3); padding: 8px 0 4px; }
.src-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--surface-2);
}
.src-row .src-en   { width: 18px; height: 18px; accent-color: var(--text); flex-shrink: 0; }
.src-row .src-type { font-size: 10px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 1px; flex-shrink: 0; }
.src-row .src-name { font-size: 14px; font-weight: 600; min-width: 100px; flex-shrink: 0; }
.src-row .src-url  { font-size: 12px; color: var(--text-2); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* source add form */
.src-add-form { display: flex; gap: 8px; flex-wrap: wrap; }
.src-add-form .input-field { font-size: 13px; padding: 11px 14px; }
.src-add-form .input-field:focus { background: var(--surface-3); }
.src-input-type { width: 140px; flex-shrink: 0; }
.src-input-name { width: 130px; flex-shrink: 0; }
.src-input-url  { flex: 1; min-width: 160px; }
.src-input-user, .src-input-pass { width: 120px; flex-shrink: 0; }

/* country grid */
.country-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 2px; margin-bottom: 12px; max-height: 260px; overflow-y: auto;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y;
}
.country-grid::-webkit-scrollbar { width: 6px; }
.country-grid::-webkit-scrollbar-thumb { background: var(--surface-3); }
.country-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; cursor: pointer; font-size: 14px;
  transition: background .1s;
}
.country-item:hover { background: var(--surface-2); }
.country-item input { width: 18px; height: 18px; accent-color: var(--text); }

.country-actions { display: flex; gap: 8px; }

/* channel management */
.ch-mgmt-search {
  width: 100%; margin-bottom: 12px;
}
.ch-mgmt-list { max-height: 340px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; }
.ch-mgmt-list::-webkit-scrollbar { width: 6px; }
.ch-mgmt-list::-webkit-scrollbar-thumb { background: var(--surface-3); }
.ch-mgmt-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; margin-bottom: 4px; background: var(--surface-2);
}
.ch-mgmt-row.hidden { opacity: .4; }
.ch-mgmt-row.fav { border-left: 3px solid var(--on); }
.ch-mgmt-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ch-mgmt-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-mgmt-tag  { font-size: 11px; color: var(--text-3); }
.ch-mgmt-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* key-value settings rows */
.kv-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--border); }
.kv-row label { font-size: 15px; }
.kv-row select { padding: 10px 14px; background: var(--surface-2); color: var(--text); border: none; font-size: 14px; font-family: inherit; outline: none; }
.kv-row select:focus { background: var(--surface-3); }
.kv-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--text); }

/* EPG coverage */
.epg-stat-line   { font-size: 14px; padding: 14px 16px; background: var(--surface-2); }
.epg-covered-list { margin-top: 8px; font-size: 13px; color: var(--text-2); max-height: 140px; overflow-y: auto; }
.epg-id { color: var(--text-3); font-size: 11px; }
.epg-hint { margin-top: 8px; font-size: 13px; color: var(--text-2); line-height: 1.5; padding: 14px 16px; background: var(--surface-2); }

/* save bar */
.settings-actions {
  display: flex; align-items: center; gap: 16px;
  padding-top: 18px; margin-top: 4px; border-top: 1px solid var(--border);
}
.settings-status { font-size: 13px; color: var(--text-2); }

/* ============================================================
   LOADING / SPINNER / EMPTY STATES
   ============================================================ */
.loading { text-align: center; padding: 40px; color: var(--text-3); }
.spinner {
  display: inline-block; width: 28px; height: 28px;
  border: 3px solid var(--surface-3); border-top-color: var(--text);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.no-results { text-align: center; padding: 48px 20px; color: var(--text-2); font-size: 15px; }

/* stream error overlay */
.stream-error {
  position: fixed; inset: 0; z-index: 10;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; background: rgba(0,0,0,.85);
}
.stream-error.show { display: flex; }
.stream-error-title { font-size: 20px; font-weight: 700; }
.stream-error-sub { font-size: 14px; color: var(--text-2); text-align: center; max-width: 400px; line-height: 1.5; }

/* play overlay for shared links */
.play-overlay {
  position: fixed; inset: 0; z-index: 8;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; background: rgba(0,0,0,.6); cursor: pointer;
}
.play-overlay.show { display: flex; }
.play-overlay-btn {
  width: 96px; height: 96px; border-radius: 50%;
  background: rgba(255,255,255,.9); color: #000;
  font-size: 40px; display: flex; align-items: center; justify-content: center;
  padding-left: 8px; transition: transform .15s, background .15s;
}
.play-overlay:hover .play-overlay-btn { transform: scale(1.08); background: #fff; }
.play-overlay-text { font-size: 16px; font-weight: 600; color: var(--text); letter-spacing: 1px; }

/* ============================================================
   MOBILE / TOUCH
   ============================================================ */
@media (max-width: 768px) {
  body { font-size: 16px; }

  /* topbar: compact for narrow landscape screens */
  .topbar { padding: 10px 12px 48px; gap: 6px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .topbar-brand { font-size: 11px; letter-spacing: 2px; }
  .ch-logo { width: 44px; height: 32px; }
  .ch-name { font-size: 15px; }
  .ch-info { min-width: 100px; }
  .ch-num { font-size: 10px; }
  .ch-epg .now { font-size: 12px; }
  .ch-epg .next { font-size: 11px; }
  .ch-clock { font-size: 14px; padding-right: 4px; }
  .btn-nav { padding: 10px 12px; font-size: 12px; min-height: 40px; letter-spacing: 1px; }
  /* hide share button on narrow screens to save space */
  #btn-share { display: none; }

  /* guide: full screen on mobile */
  .guide-panel { height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }
  .overlay-head { padding: 12px 14px 10px; }
  .guide-hint { display: none; }
  .guide-filters { flex-direction: row; flex-wrap: wrap; padding: 0 14px 10px; gap: 6px; }
  .guide-filters .input-field { font-size: 16px; padding: 12px 14px; }
  .guide-filters #q { width: 100%; flex: 1 1 100%; }
  .guide-count { margin-left: auto; }

  .g-row { padding: 12px 10px; gap: 10px; }
  .g-row .num { width: 30px; font-size: 14px; }
  .g-row .logo { width: 40px; height: 30px; }
  .g-row .info { width: auto; flex: 1; }
  .g-row .name { font-size: 16px; }
  .g-row .epg { display: none; }

  /* settings: full screen on mobile */
  .settings-panel { width: 100%; max-width: 100%; max-height: 100dvh; }
  .settings-tabs .tab { padding: 12px 12px; font-size: 14px; }
  .settings-body { padding: 14px; }

  .src-row { flex-wrap: wrap; gap: 8px; padding: 12px; }
  .src-row .src-en { width: 22px; height: 22px; }
  .src-row .src-name { flex: 1; min-width: 0; font-size: 16px; }
  .src-row .src-url { width: 100%; flex: none; }
  .src-row .btn-remove { padding: 12px 16px; font-size: 14px; width: 100%; text-align: center; background: var(--surface-3); }

  .src-add-form { flex-direction: column; }
  .src-add-form .input-field { width: 100%; font-size: 16px; padding: 13px 16px; }
  .btn-primary { width: 100%; padding: 16px; font-size: 16px; }

  .country-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; }
  .country-item { padding: 12px 10px; font-size: 16px; }
  .country-item input { width: 22px; height: 22px; }
  .country-actions { flex-direction: column; gap: 8px; }
  .country-actions .btn-ghost { width: 100%; }

  .ch-mgmt-search.input-field { font-size: 16px; padding: 13px 16px; }
  .ch-mgmt-row { padding: 12px 12px; }
  .ch-mgmt-name { font-size: 15px; }
  .btn-mini { padding: 10px 14px; font-size: 14px; min-height: 40px; }

  .kv-row label { font-size: 16px; }
  .kv-row select { font-size: 16px; padding: 12px 14px; }
  .kv-row input[type="checkbox"] { width: 24px; height: 24px; }

  .btn-close { width: 44px; height: 44px; font-size: 22px; }
}

/* share toast */
.share-toast {
  position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface-3, #262626); color: var(--text, #e8e8e8);
  padding: 12px 24px; font-size: 14px; z-index: 100;
  opacity: 0; transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.share-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }