/* ============================================
   Family TV — Dashboard Styles
   ============================================ */

:root {
  --bg-dark: #0f0f13;
  --bg-card: #1a1a24;
  --bg-sidebar: #15151e;
  --bg-hover: #252535;
  --bg-active: #2a2a40;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --text-primary: #f0f0f5;
  --text-secondary: #8888a0;
  --text-muted: #55556a;
  --border: #2a2a3a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --topbar-h: 64px;
  --sidebar-w: 260px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

.hidden { display: none !important; }

/* ---- Loading Screen ---- */
#loading-screen {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-dark);
}
.loader-content { text-align: center; }
.tv-icon { font-size: 64px; margin-bottom: 16px; animation: pulse 1.5s ease-in-out infinite; }
.loader-content h1 { font-size: 32px; margin-bottom: 8px; font-weight: 700; }
.loader-content p { color: var(--text-secondary); margin-bottom: 24px; }
.loader-bar { width: 200px; height: 4px; background: var(--bg-card); border-radius: 2px; overflow: hidden; margin: 0 auto; }
.loader-fill { height: 100%; width: 30%; background: var(--accent); border-radius: 2px; animation: load 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1); } }
@keyframes load { 0% { transform: translateX(-100%); } 100% { transform: translateX(400%); } }

/* ---- Top Bar ---- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.topbar-center { flex: 1; max-width: 500px; }
.topbar-right { min-width: 200px; text-align: right; color: var(--text-secondary); font-size: 14px; }
.logo { font-size: 22px; font-weight: 700; background: linear-gradient(135deg, var(--accent), var(--accent-light)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

.icon-btn {
  background: none; border: none; color: var(--text-primary); cursor: pointer;
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.icon-btn:hover { background: var(--bg-hover); }

.search-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-dark); border: 1px solid var(--border);
  border-radius: 50px; padding: 8px 16px;
  transition: border-color 0.2s;
}
.search-box:focus-within { border-color: var(--accent); }
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.search-box input {
  background: none; border: none; outline: none; color: var(--text-primary);
  font-size: 15px; width: 100%; font-family: inherit;
}
.search-box input::placeholder { color: var(--text-muted); }
#search-clear {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 16px; padding: 0 4px;
}

/* ---- Layout ---- */
#main-layout {
  display: flex;
  margin-top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
}

/* ---- Sidebar ---- */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: margin-left 0.3s ease;
}
#sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }
.sidebar-header { padding: 16px 20px 8px; }
.sidebar-header h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text-muted); font-weight: 600; }

#category-list {
  list-style: none; overflow-y: auto; flex: 1;
  padding: 4px 8px 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-hover) transparent;
}
#category-list li {
  padding: 10px 14px; margin: 2px 0;
  border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14px;
  display: flex; justify-content: space-between; align-items: center;
  color: var(--text-secondary);
  transition: all 0.15s;
}
#category-list li:hover,
#category-list li:focus { background: var(--bg-hover); color: var(--text-primary); outline: none; }
#category-list li:focus { outline: 2px solid var(--accent-light); outline-offset: -2px; }
#category-list li.active { background: var(--accent); color: #fff; font-weight: 500; }
#category-list li .cat-count {
  font-size: 12px; background: rgba(255,255,255,0.1);
  padding: 2px 8px; border-radius: 50px; min-width: 28px; text-align: center;
}
#category-list li.active .cat-count { background: rgba(255,255,255,0.2); }

/* ---- Content / Grid ---- */
#content {
  flex: 1; overflow-y: auto; padding: 20px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-hover) transparent;
}
#current-category-label {
  font-size: 24px; font-weight: 700; margin-bottom: 20px;
}

#channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.channel-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  min-height: 160px;
  justify-content: center;
}
.channel-card:hover,
.channel-card.focused {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(108,92,231,0.15);
}
.channel-card:focus {
  outline: 3px solid var(--accent-light);
  outline-offset: 2px;
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(108,92,231,0.3);
}
.channel-card:active { transform: scale(0.98); }

.channel-logo-wrap {
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--bg-dark);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px; overflow: hidden;
  flex-shrink: 0;
}
.channel-logo-wrap img {
  width: 60px; height: 60px; object-fit: contain;
}
.channel-logo-placeholder {
  font-size: 32px; color: var(--accent);
  font-weight: 700;
}
.channel-name {
  font-size: 13px; font-weight: 500;
  line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 100%;
}
.channel-quality {
  font-size: 11px; color: var(--accent-light);
  margin-top: 4px;
}

#no-results {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted); font-size: 18px;
}

/* ---- Player Overlay ---- */
#player-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: #000;
  display: flex; flex-direction: column;
}
#player-container {
  width: 100%; height: 100%;
  position: relative;
}
#player-topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: rgba(0,0,0,0.8);
  z-index: 10;
}
#player-channel-name {
  font-size: 18px; font-weight: 600;
}
.player-topbar-spacer { flex: 1; }

#video-wrapper {
  position: absolute; inset: 0; background: #000;
  display: flex; align-items: center; justify-content: center;
}
#video-player {
  width: 100%; height: 100%;
  background: #000;
}
#video-error {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,0.85);
  gap: 16px;
}
#video-error p { font-size: 18px; color: var(--text-secondary); }
.btn {
  background: var(--accent); color: #fff; border: none;
  padding: 12px 28px; border-radius: 50px;
  font-size: 15px; font-weight: 500; cursor: pointer;
  transition: background 0.2s;
}
.btn:hover { background: var(--accent-light); }

#player-bottombar {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: rgba(0,0,0,0.8);
  z-index: 10;
}
.nav-btn {
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-primary); cursor: pointer;
  padding: 10px 20px; border-radius: 50px;
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 500;
  transition: all 0.2s;
}
.nav-btn:hover,
.nav-btn:focus { background: var(--bg-hover); border-color: var(--accent); outline: 2px solid var(--accent-light); outline-offset: 2px; }
.btn:focus { outline: 2px solid var(--accent-light); outline-offset: 2px; }

#player-channel-info {
  display: flex; align-items: center; gap: 12px;
}
#player-channel-logo {
  width: 40px; height: 40px; object-fit: contain;
  border-radius: 8px; background: var(--bg-card);
}
#player-channel-title { font-size: 14px; font-weight: 500; }
#player-channel-group { font-size: 12px; color: var(--text-muted); }

/* ---- Watermark ---- */
#watermark {
  position: fixed;
  bottom: 12px; right: 16px;
  font-size: 13px; font-weight: 700;
  letter-spacing: 2px;
  color: rgba(162, 155, 254, 0.35);
  z-index: 150;
  pointer-events: none;
  text-shadow: 0 0 8px rgba(108, 92, 231, 0.2);
}

/* ---- Favorites Button (topbar) ---- */
.topbar-btn {
  background: none; border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer;
  padding: 6px 14px; border-radius: 50px;
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-family: inherit;
  transition: all 0.2s;
  margin-right: 12px;
}
.topbar-btn:hover,
.topbar-btn:focus { border-color: var(--accent); color: var(--text-primary); outline: none; }
.topbar-btn.active {
  background: var(--accent); border-color: var(--accent);
  color: #fff;
}
.topbar-btn svg { width: 16px; height: 16px; }

/* ---- Language Toggle (topbar) ---- */
.lang-toggle {
  display: inline-flex; vertical-align: middle;
  border: 1px solid var(--border); border-radius: 50px;
  overflow: hidden; margin-right: 12px;
}
.lang-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px; font-weight: 600;
  padding: 7px 16px;
  transition: all 0.15s;
}
.lang-btn:hover { color: var(--text-primary); }
.lang-btn:focus { outline: none; color: var(--text-primary); }
.lang-btn.active { background: var(--accent); color: #fff; }

/* ---- Favorite star on cards ---- */
.channel-fav-btn {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.5); border: none;
  color: var(--text-muted); cursor: pointer;
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.2s, color 0.2s;
  z-index: 5;
}
.channel-card { position: relative; }
.channel-card:hover .channel-fav-btn,
.channel-card:focus .channel-fav-btn,
.channel-fav-btn.is-fav { opacity: 1; }
.channel-fav-btn.is-fav { color: #ffd32a; }
.channel-fav-btn:hover { color: #ffd32a; }

/* ---- Player favorite button ---- */
#player-fav-btn svg.is-fav { fill: #ffd32a; stroke: #ffd32a; }

/* ---- TV Mode: auto-hide player chrome ---- */
#player-overlay.chrome-hidden #player-topbar,
#player-overlay.chrome-hidden #player-bottombar {
  opacity: 0; pointer-events: none;
  transition: opacity 0.4s ease;
}
#player-topbar, #player-bottombar {
  transition: opacity 0.4s ease;
}

/* ---- TV Mode: channel number OSD ---- */
#channel-osd {
  position: fixed; top: 40px; right: 40px;
  background: rgba(0,0,0,0.75);
  padding: 12px 24px; border-radius: var(--radius);
  font-size: 36px; font-weight: 700;
  z-index: 300; pointer-events: none;
  opacity: 0; transition: opacity 0.3s;
}
#channel-osd.visible { opacity: 1; }

/* ---- TV Mode: focus hint ---- */
.tv-hint {
  position: fixed; bottom: 16px; right: 16px;
  background: rgba(0,0,0,0.7);
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text-muted);
  z-index: 50;
}

/* ---- Scrollbar (Webkit) ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  :root { --sidebar-w: 100vw; }
  #sidebar {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
    z-index: 50;
    margin-left: calc(-1 * var(--sidebar-w));
  }
  #sidebar.mobile-open { margin-left: 0; }
  #channel-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .channel-card { min-height: 130px; padding: 12px; }
  .channel-logo-wrap { width: 60px; height: 60px; }
  .channel-logo-wrap img { width: 44px; height: 44px; }
}
