/* ═══════════════════════════════════════════════════════════════
   common.css — Shared design tokens, resets, and base components
   used across all three platforms (desktop / mobile / tv)
════════════════════════════════════════════════════════════════ */

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

:root {
  /* ── Core Palette ─────────────────────── */
  --bg-primary:    #080c10;
  --bg-secondary:  #0d1117;
  --bg-tertiary:   #131920;
  --bg-card:       #111820;
  --bg-hover:      #1a2333;
  --border:        #1e2d3d;
  --border-subtle: #131e2b;

  --accent:        #00c4ff;
  --accent-dim:    rgba(0,196,255,.15);
  --accent-glow:   rgba(0,196,255,.35);
  --accent2:       #ff5e3a;
  --accent-grad:   linear-gradient(135deg,#00c4ff,#0077ff);
  --accent-purple: #8B5CF6;
  --accent-pink:   #ec4899;

  --text-primary:   #e8f0fe;
  --text-secondary: #7a90a8;
  --text-muted:     #3d5269;
  --live-red:       #ff3b3b;

  /* ── Fonts ────────────────────────────── */
  --font-display: 'Barlow Condensed', sans-serif;
  --font-body:    'DM Sans', sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  overflow: hidden;
}

/* Scanline texture */
body::after {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,.04) 2px, rgba(0,0,0,.04) 4px);
  pointer-events: none;
  z-index: 99999;
}

/* ── ANIMATIONS ───────────────────────────────────────────── */
@keyframes pulse  { 0%,100%{ opacity:1; transform:scale(1);  } 50%{ opacity:.7; transform:scale(1.15); } }
@keyframes spin   { to{ transform:rotate(360deg); } }
@keyframes shimmer{ 0%{ background-position:200% 0; } 100%{ background-position:-200% 0; } }

/* ── CHANNEL LIST SHARED ELEMENTS ─────────────────────────── */
.skeleton-card { display:flex; align-items:center; gap:9px; padding:6px 10px; margin:1px 6px; }
.skeleton-logo { width:34px; height:34px; border-radius:7px; background:linear-gradient(90deg,#1a1a1a 25%,#222 50%,#1a1a1a 75%); background-size:200% 100%; animation:shimmer 1.4s infinite; }
.skeleton-text { flex:1; display:flex; flex-direction:column; gap:5px; }
.skeleton-line { height:9px; border-radius:4px; background:linear-gradient(90deg,#1a1a1a 25%,#222 50%,#1a1a1a 75%); background-size:200% 100%; animation:shimmer 1.4s infinite; }
.skeleton-line.short { width:55%; }

.channel-card    { display:flex; align-items:center; gap:9px; padding:6px 10px; cursor:pointer; border-radius:8px; margin:1px 6px; transition:background .12s; position:relative; user-select:none; }
.channel-card:hover { background:var(--bg-hover); }
.channel-card.active{ background:rgba(139,92,246,.15); }
.channel-card.active::before { content:''; position:absolute; left:0; top:50%; transform:translateY(-50%); width:3px; height:60%; background:var(--accent-grad); border-radius:0 3px 3px 0; }
.channel-card.kb-focus { outline:2px solid var(--accent); outline-offset:-2px; }

.channel-number   { font-size:10px; color:var(--text-muted); width:18px; text-align:right; flex-shrink:0; }
.channel-logo     { width:34px; height:34px; border-radius:7px; flex-shrink:0; background:var(--bg-tertiary); border:1px solid var(--border-subtle); display:flex; align-items:center; justify-content:center; overflow:hidden; position:relative; }
.channel-logo img { width:100%; height:100%; object-fit:contain; }
.channel-initials { font-size:10px; font-weight:700; color:var(--text-secondary); }
.live-indicator   { position:absolute; bottom:2px; right:2px; width:6px; height:6px; background:var(--live-red); border-radius:50%; border:1.5px solid var(--bg-secondary); animation:pulse 2s infinite; }
.channel-info     { flex:1; overflow:hidden; }
.channel-name     { font-size:13px; font-weight:500; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.channel-badges   { display:flex; gap:3px; margin-top:2px; }
.ch-badge         { font-size:9px; font-weight:600; padding:1px 5px; border-radius:4px; background:rgba(255,255,255,.07); color:var(--text-muted); }
.recent-badge     { font-size:9px; font-weight:700; padding:1px 5px; border-radius:4px; background:rgba(139,92,246,.25); color:var(--accent-purple); }
.watched-badge    { font-size:9px; font-weight:700; padding:1px 5px; border-radius:4px; background:rgba(250,204,21,.15); color:#facc15; }

.fav-btn { width:22px; height:22px; background:none; border:none; cursor:pointer; color:var(--text-muted); display:flex; align-items:center; justify-content:center; border-radius:6px; flex-shrink:0; transition:all .15s; opacity:0; }
.channel-card:hover .fav-btn { opacity:1; }
.fav-btn svg { width:12px; height:12px; }
.fav-btn.active { color:#facc15; opacity:1; }
.fav-btn.active svg { fill:#facc15; }
.fav-btn:hover { color:#facc15; }

.category-header { display:flex; align-items:center; justify-content:space-between; padding:8px 14px 4px; position:sticky; top:0; background:var(--bg-secondary); z-index:2; }
.category-name   { font-size:10px; font-weight:700; letter-spacing:.8px; text-transform:uppercase; color:var(--text-muted); }
.category-count  { font-size:10px; font-weight:600; color:var(--text-muted); background:var(--bg-tertiary); border-radius:99px; padding:1px 6px; }

.empty-state { padding:24px; text-align:center; color:var(--text-muted); font-size:13px; }

/* ── CCTV GRID ────────────────────────────────────────────── */
.cctv-grid  { flex:1; display:grid; background:#000; overflow:hidden; gap:2px; padding:2px; }
.cctv-pane  { position:relative; background:#0d0d0d; overflow:hidden; cursor:pointer; border:2px solid transparent; transition:border-color .15s; }
.cctv-pane:hover    { border-color:rgba(139,92,246,.5); }
.cctv-pane.selected { border-color:var(--accent-purple); }
.cctv-pane.playing  { border-color:transparent; }
.cctv-pane.playing:hover { border-color:rgba(139,92,246,.4); }
.cctv-pane.focus-main { border-color:#facc15 !important; z-index:10; }
.cctv-pane video { width:100%; height:100%; object-fit:contain; display:block; }

.pane-overlay { position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:6px; background:rgba(0,0,0,.7); pointer-events:none; }
.pane-overlay.hidden { display:none; }
.pane-num  { width:28px; height:28px; border-radius:50%; background:rgba(255,255,255,.1); border:1px solid rgba(255,255,255,.2); display:flex; align-items:center; justify-content:center; font-size:12px; font-weight:700; color:rgba(255,255,255,.6); }
.pane-hint { font-size:10px; color:rgba(255,255,255,.3); }

.pane-skeleton { position:absolute; inset:0; background:linear-gradient(90deg,#0d0d0d 25%,#161616 50%,#0d0d0d 75%); background-size:400% 100%; animation:shimmer 1.6s infinite; z-index:4; display:none; }
.pane-skeleton.show { display:block; }

.pane-loading { position:absolute; inset:0; display:flex; align-items:center; justify-content:center; background:rgba(0,0,0,.8); z-index:5; }
.pane-loading.hidden { display:none; }
.pane-loader { width:28px; height:28px; position:relative; }
.pane-loader-ring { position:absolute; inset:0; border-radius:50%; border:2px solid transparent; animation:spin 1.1s linear infinite; }
.pane-loader-ring:nth-child(1) { border-top-color:var(--accent-purple); }
.pane-loader-ring:nth-child(2) { border-right-color:var(--accent-pink); animation-duration:1.5s; inset:5px; }

.pane-error { position:absolute; inset:0; display:none; flex-direction:column; align-items:center; justify-content:center; gap:6px; z-index:6; }
.pane-error.show { display:flex; }
.pane-error svg  { width:20px; height:20px; color:#ef4444; opacity:.7; }
.pane-error span { font-size:10px; color:var(--text-muted); }

.pane-label { position:absolute; bottom:0; left:0; right:0; z-index:4; background:linear-gradient(transparent,rgba(0,0,0,.75)); padding:12px 8px 5px; opacity:0; transition:opacity .2s; display:flex; align-items:center; gap:5px; }
.cctv-pane:hover .pane-label  { opacity:1; }
.cctv-pane.selected .pane-label { opacity:1; }
.pane-live-dot { width:6px; height:6px; background:var(--live-red); border-radius:50%; flex-shrink:0; animation:pulse 1.5s infinite; }
.pane-ch-name  { font-size:11px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

.cctv-pane.drag-over   { border-color:var(--accent-pink) !important; background:rgba(236,72,153,.08); }
.cctv-pane.drag-source { opacity:.4; }
.cctv-pane.audio-follow { box-shadow:0 0 0 2px #facc15 inset; }

.pane-vol { position:absolute; bottom:28px; left:6px; z-index:8; display:flex; align-items:center; gap:5px; opacity:0; transition:opacity .2s; pointer-events:none; }
.cctv-pane:hover .pane-vol { opacity:1; pointer-events:all; }
.pane-vol-btn { width:22px; height:22px; border-radius:5px; border:none; cursor:pointer; background:rgba(0,0,0,.6); color:#fff; display:flex; align-items:center; justify-content:center; flex-shrink:0; transition:background .12s; }
.pane-vol-btn:hover { background:rgba(139,92,246,.7); }
.pane-vol-btn svg { width:12px; height:12px; }
.pane-vol-slider { -webkit-appearance:none; width:60px; height:3px; border-radius:99px; background:rgba(255,255,255,.3); cursor:pointer; outline:none; touch-action:none; }
.pane-vol-slider::-webkit-slider-thumb { -webkit-appearance:none; width:12px; height:12px; border-radius:50%; background:#fff; cursor:pointer; }

.pane-reconnect { position:absolute; top:6px; right:6px; z-index:8; font-size:10px; color:#facc15; background:rgba(0,0,0,.6); padding:2px 7px; border-radius:99px; display:none; }
.pane-reconnect.show { display:block; }

/* ── TOOLBARS ────────────────────────────────────────────── */
.cctv-toolbar { height:42px; background:var(--bg-secondary); border-bottom:1px solid var(--border-subtle); display:flex; align-items:center; padding:0 10px; gap:5px; flex-shrink:0; overflow-x:auto; overflow-y:hidden; }
.cctv-toolbar::-webkit-scrollbar { height:0; }
.cctv-label { font-size:10px; font-weight:700; color:var(--text-muted); text-transform:uppercase; letter-spacing:.6px; white-space:nowrap; padding-right:6px; border-right:1px solid var(--border); margin-right:2px; flex-shrink:0; }
.preset-btn { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px; padding:4px 6px; border-radius:6px; cursor:pointer; border:1px solid var(--border); background:var(--bg-tertiary); color:var(--text-secondary); transition:all .15s; flex-shrink:0; min-width:40px; }
.preset-btn:hover  { border-color:var(--accent-purple); color:var(--text-primary); }
.preset-btn.active { border-color:var(--accent-purple); background:rgba(139,92,246,.18); color:var(--accent-purple); }
.preset-num { font-size:9px; font-weight:700; line-height:1; }

.saved-presets-bar { height:36px; background:var(--bg-primary); border-bottom:1px solid var(--border-subtle); display:flex; align-items:center; padding:0 10px; gap:5px; flex-shrink:0; overflow-x:auto; overflow-y:hidden; }
.saved-presets-bar::-webkit-scrollbar { height:0; }
.saved-label { font-size:10px; font-weight:700; color:var(--text-muted); text-transform:uppercase; letter-spacing:.6px; white-space:nowrap; padding-right:6px; border-right:1px solid var(--border); margin-right:2px; flex-shrink:0; }
.sp-btn { display:flex; align-items:center; gap:5px; padding:3px 10px; border-radius:6px; border:1px solid var(--border); background:var(--bg-tertiary); color:var(--text-secondary); font-size:11px; font-weight:500; font-family:inherit; cursor:pointer; white-space:nowrap; transition:all .14s; flex-shrink:0; position:relative; }
.sp-btn:hover  { border-color:var(--accent-purple); color:var(--text-primary); }
.sp-btn.active { background:rgba(139,92,246,.2); border-color:var(--accent-purple); color:var(--text-primary); }
.sp-btn.autostart-mark::after { content:'★'; font-size:9px; color:#facc15; margin-left:2px; }
.sp-add-btn { width:26px; height:26px; border-radius:6px; border:1px dashed var(--border); background:none; color:var(--text-muted); cursor:pointer; display:flex; align-items:center; justify-content:center; flex-shrink:0; font-size:16px; line-height:1; transition:all .14s; }
.sp-add-btn:hover { border-color:var(--accent-purple); color:var(--accent-purple); }

/* ── CONTEXT MENUS ───────────────────────────────────────── */
#ctxMenu, #presetCtxMenu, #channelCtxMenu {
  position:fixed; z-index:9999; min-width:190px; background:#1a1a1a; border:1px solid #333; border-radius:10px; box-shadow:0 8px 32px rgba(0,0,0,.7); overflow:hidden; display:none; flex-direction:column; padding:4px;
}
#ctxMenu.open, #presetCtxMenu.open, #channelCtxMenu.open { display:flex; }
#ctxMenu { min-width:210px; }
#channelCtxMenu { min-width:200px; }
.ctx-item { display:flex; align-items:center; gap:9px; padding:8px 12px; border-radius:6px; cursor:pointer; font-size:13px; color:var(--text-primary); transition:background .1s; }
.ctx-item:hover { background:rgba(139,92,246,.18); }
.ctx-item svg { width:14px; height:14px; flex-shrink:0; color:var(--text-secondary); }
.ctx-item.danger { color:#ef4444; }
.ctx-item.danger svg { color:#ef4444; }
.ctx-divider { height:1px; background:#2a2a2a; margin:3px 0; }
.ctx-section { font-size:10px; font-weight:700; letter-spacing:.6px; text-transform:uppercase; color:var(--text-muted); padding:6px 12px 2px; }

/* ── CHANNEL PREVIEW POPUP ───────────────────────────────── */
#chPreview { position:fixed; z-index:9990; pointer-events:none; width:200px; border-radius:10px; overflow:hidden; box-shadow:0 8px 24px rgba(0,0,0,.8); border:1px solid #333; display:none; flex-direction:column; background:#0a0a0a; }
#chPreview.show { display:flex; }
#chPreview video { width:100%; height:112px; object-fit:contain; background:#000; display:block; }
.preview-label  { padding:6px 10px; font-size:11px; font-weight:600; display:flex; align-items:center; gap:6px; border-top:1px solid #222; }
.preview-dot    { width:6px; height:6px; background:var(--live-red); border-radius:50%; animation:pulse 1.5s infinite; flex-shrink:0; }
.preview-loading { width:100%; height:112px; display:flex; align-items:center; justify-content:center; background:#000; position:absolute; top:0; left:0; }
.preview-loader  { width:22px; height:22px; position:relative; }
.preview-loader-ring { position:absolute; inset:0; border-radius:50%; border:2px solid transparent; animation:spin 1.1s linear infinite; }
.preview-loader-ring:nth-child(1) { border-top-color:var(--accent-purple); }
.preview-loader-ring:nth-child(2) { border-right-color:var(--accent-pink); animation-duration:1.5s; inset:4px; }

/* ── MODALS ──────────────────────────────────────────────── */
.modal-backdrop  { position:fixed; inset:0; z-index:10000; display:none; align-items:center; justify-content:center; background:rgba(0,0,0,.7); backdrop-filter:blur(4px); }
.modal-backdrop.open { display:flex; }
.modal-box       { background:#1a1a1a; border:1px solid #333; border-radius:14px; padding:22px; width:340px; display:flex; flex-direction:column; gap:13px; box-shadow:0 16px 48px rgba(0,0,0,.8); }
.modal-box.wide  { width:520px; max-width:95vw; max-height:85vh; overflow-y:auto; }
.modal-title     { font-size:15px; font-weight:700; display:flex; align-items:center; gap:8px; }
.modal-title svg { width:16px; height:16px; color:var(--accent-purple); }
.modal-input     { padding:8px 11px; background:var(--bg-tertiary); border:1px solid var(--border); border-radius:8px; color:var(--text-primary); font-size:13px; font-family:inherit; outline:none; transition:border-color .15s; width:100%; }
.modal-input:focus { border-color:var(--accent-purple); }
.modal-btns      { display:flex; gap:8px; justify-content:flex-end; }
.modal-btn       { padding:7px 18px; border-radius:8px; border:none; cursor:pointer; font-size:13px; font-weight:600; font-family:inherit; transition:opacity .15s; }
.modal-btn.cancel  { background:var(--bg-hover); color:var(--text-secondary); }
.modal-btn.confirm { background:var(--accent-grad); color:#fff; }
.modal-btn:hover { opacity:.85; }
.modal-label     { font-size:12px; color:var(--text-secondary); margin-bottom:4px; display:block; }
.modal-section   { border-top:1px solid var(--border-subtle); padding-top:13px; margin-top:4px; }
.modal-section-title { font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.6px; color:var(--text-muted); margin-bottom:10px; }
.modal-row       { display:flex; align-items:center; gap:8px; }
.modal-select    { flex:1; padding:7px 10px; background:var(--bg-tertiary); border:1px solid var(--border); border-radius:8px; color:var(--text-primary); font-size:13px; font-family:inherit; outline:none; }
.modal-select:focus { border-color:var(--accent-purple); }

.toggle-row     { display:flex; align-items:center; justify-content:space-between; padding:4px 0; }
.toggle-label   { font-size:13px; color:var(--text-primary); }
.toggle-sub     { font-size:11px; color:var(--text-muted); margin-top:1px; }
.toggle-switch  { width:38px; height:22px; background:var(--bg-tertiary); border:1px solid var(--border); border-radius:99px; cursor:pointer; position:relative; flex-shrink:0; transition:background .2s; }
.toggle-switch.on { background:var(--accent-purple); border-color:var(--accent-purple); }
.toggle-thumb   { position:absolute; left:3px; top:50%; transform:translateY(-50%); width:16px; height:16px; border-radius:50%; background:#fff; transition:left .2s; }
.toggle-switch.on .toggle-thumb { left:19px; }

.config-tab-bar { display:flex; gap:4px; border-bottom:1px solid var(--border-subtle); margin:-4px -4px 10px; padding:0 4px; }
.config-tab     { padding:8px 14px; font-size:12px; font-weight:600; color:var(--text-muted); cursor:pointer; border-bottom:2px solid transparent; transition:all .15s; background:none; border-top:none; border-left:none; border-right:none; font-family:inherit; }
.config-tab.active { color:var(--accent-purple); border-bottom-color:var(--accent-purple); }
.config-pane    { display:none; }
.config-pane.active { display:block; }
.config-btn     { width:100%; padding:8px 12px; background:var(--bg-tertiary); border:1px solid var(--border); border-radius:8px; color:var(--text-primary); font-size:13px; font-family:inherit; cursor:pointer; display:flex; align-items:center; justify-content:center; gap:6px; transition:all .15s; margin-top:6px; }
.config-btn:hover { border-color:var(--accent-purple); }
.config-btn svg { width:14px; height:14px; }
.config-btn.danger-btn { color:#ef4444; border-color:#ef444430; }
.config-btn.danger-btn:hover { border-color:#ef4444; background:rgba(239,68,68,.07); }
textarea.modal-input { resize:vertical; min-height:70px; line-height:1.5; }
.blacklist-list { max-height:120px; overflow-y:auto; background:var(--bg-tertiary); border:1px solid var(--border); border-radius:8px; padding:6px; }
.bl-item  { display:flex; align-items:center; justify-content:space-between; padding:3px 4px; border-radius:4px; font-size:12px; }
.bl-item:hover { background:rgba(255,255,255,.04); }
.bl-del   { background:none; border:none; color:var(--text-muted); cursor:pointer; font-size:14px; line-height:1; padding:0 3px; }
.bl-del:hover { color:#ef4444; }

.status-dot       { display:inline-block; width:7px; height:7px; border-radius:50%; margin-right:5px; }
.status-dot.green  { background:#22c55e; }
.status-dot.red    { background:#ef4444; }
.status-dot.yellow { background:#facc15; }

/* ── TOAST ────────────────────────────────────────────────── */
.toast-container { position:fixed; bottom:20px; right:20px; z-index:20000; display:flex; flex-direction:column; gap:8px; pointer-events:none; }
.toast { background:#1a1a1a; border:1px solid #333; border-radius:8px; padding:10px 16px; font-size:13px; color:var(--text-primary); box-shadow:0 4px 16px rgba(0,0,0,.5); opacity:0; transform:translateY(10px); transition:all .3s; pointer-events:none; }
.toast.show    { opacity:1; transform:translateY(0); }
.toast.success { border-left:3px solid #22c55e; }
.toast.error   { border-left:3px solid #ef4444; }
.toast.info    { border-left:3px solid var(--accent-purple); }

/* ── PASSWORD OVERLAY ────────────────────────────────────── */
.pw-overlay { position:fixed; inset:0; z-index:50000; background:rgba(0,0,0,.95); backdrop-filter:blur(16px); display:none; flex-direction:column; align-items:center; justify-content:center; gap:20px; }
.pw-overlay.show { display:flex; }
.pw-box    { background:#1a1a1a; border:1px solid #333; border-radius:16px; padding:32px; width:340px; display:flex; flex-direction:column; gap:16px; align-items:center; }
.pw-logo   { width:56px; height:56px; border-radius:14px; background:var(--accent-grad); display:flex; align-items:center; justify-content:center; }
.pw-logo svg { width:28px; height:28px; color:#fff; }
.pw-title  { font-size:18px; font-weight:700; text-align:center; }
.pw-sub    { font-size:13px; color:var(--text-muted); text-align:center; }
.pw-input  { width:100%; padding:10px 14px; background:var(--bg-tertiary); border:1px solid var(--border); border-radius:10px; color:var(--text-primary); font-size:15px; font-family:inherit; outline:none; text-align:center; letter-spacing:3px; transition:border-color .15s; }
.pw-input:focus { border-color:var(--accent-purple); }
.pw-btn    { width:100%; padding:10px; border-radius:10px; background:var(--accent-grad); color:#fff; font-size:14px; font-weight:700; border:none; cursor:pointer; font-family:inherit; transition:opacity .15s; }
.pw-btn:hover { opacity:.85; }
.pw-err    { font-size:12px; color:#ef4444; display:none; }
