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

:root {
  --bg:           #12121f;
  --sidebar-bg:   #0e0e1a;
  --sidebar-w:    240px;
  --accent:       #e94560;
  --accent-dim:   rgba(233, 69, 96, 0.15);
  --surface:      #1c1c30;
  --border:       #2a2a42;
  --text:         #d0d0e8;
  --text-muted:   #666688;
  --radius:       8px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

#sidebar-header {
  padding: 14px 12px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#app-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: #fff;
}

#search {
  width: 100%;
  padding: 7px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
#search:focus { border-color: var(--accent); }
#search::placeholder { color: var(--text-muted); }

#channel-list {
  overflow-y: auto;
  flex: 1;
  padding: 6px 0 12px;
}
#channel-list::-webkit-scrollbar { width: 3px; }
#channel-list::-webkit-scrollbar-track { background: transparent; }
#channel-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.category { margin-bottom: 4px; }

.category-header {
  padding: 10px 14px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  user-select: none;
}

.channel-item {
  padding: 8px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.channel-item:hover { background: var(--accent-dim); color: #fff; }
.channel-item.active {
  background: var(--accent-dim);
  border-left-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

/* ── Main ─────────────────────────────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Player wrapper ───────────────────────────────────────────────────────── */
#player-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* Status badge */
.badge-idle    { background: rgba(255,255,255,0.06); color: var(--text-muted); }
.badge-loading { background: rgba(255,165,0,0.15);   color: #ffaa00; animation: blink 1s step-start infinite; }
.badge-live    { background: rgba(0,200,100,0.15);   color: #00cc66; }
.badge-error   { background: rgba(233,69,96,0.15);   color: var(--accent); }

#status-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
@keyframes blink { 50% { opacity: 0.35; } }

/* Video container */
#video-container {
  flex: 1;
  position: relative;
  background: #000;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

/* Fullscreen */
#video-container:fullscreen,
#video-container:-webkit-full-screen {
  background: #000;
}
#video-container:fullscreen #video,
#video-container:-webkit-full-screen #video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#video-container:fullscreen #player-controls,
#video-container:-webkit-full-screen #player-controls {
  display: none;
}

/* Loading overlay */
#loading-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-muted);
  font-size: 13px;
  z-index: 10;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Controls bar */
#player-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

#quality-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

#quality {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
#quality:focus { border-color: var(--accent); }

#player-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}

#player-btns button {
  padding: 5px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
#player-btns button:hover { background: var(--accent-dim); border-color: var(--accent); color: #fff; }

#btn-stop:hover { background: var(--accent) !important; border-color: var(--accent) !important; }

#volume {
  width: 80px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Sidebar title row (desktop + mobile) ────────────────────────────────── */
#sidebar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#btn-sidebar-close { display: none; }
#btn-menu          { display: none; }
#sidebar-backdrop  { display: none; }

/* ── Mobile : tout en overlay, tap-to-reveal ─────────────────────────────── */
@media (max-width: 640px) {

  /* Sidebar : overlay fixe, masquée à gauche par défaut */
  #sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    width: var(--sidebar-w);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  /* Barre de contrôles : overlay fixe, masquée en bas par défaut */
  #player-controls {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 100;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px;
    transform: translateY(100%);
    transition: transform 0.25s ease;
  }

  /* État UI visible : les deux apparaissent */
  #app.ui-open #sidebar         { transform: translateX(0); }
  #app.ui-open #player-controls { transform: translateY(0); }

  /* Main occupe toute la largeur */
  #main { width: 100%; }

  /* Vidéo occupe tout l'écran */
  #video-container { height: 100vh; }

  /* Contrôles touch-friendly */
  #quality-wrapper             { flex: 1 1 auto; }
  #player-btns                 { flex: 1 1 auto; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
  #player-btns button          { padding: 8px 16px; font-size: 15px; }
  #volume                      { width: 70px; }

  /* Message d'erreur au-dessus de la barre de contrôles */
  #error-text {
    position: fixed;
    bottom: 70px;
    left: 14px; right: 14px;
    margin: 0;
    z-index: 95;
  }
}

/* Error */
#error-text {
  margin: 8px 14px;
  padding: 8px 14px;
  background: rgba(233,69,96,0.08);
  border: 1px solid rgba(233,69,96,0.25);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 12px;
  line-height: 1.6;
  flex-shrink: 0;
}
