:root {
  --bg: #0d1117;
  --panel: #131a24;
  --panel-2: #1a2332;
  --border: #232e3f;
  --text: #e6edf3;
  --muted: #8b96a5;
  --accent: #3fa9f5;
  --accent-2: #1e6fb8;
  --danger: #e5534b;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* Garde-fou global : sans ceci, tout selecteur de classe/id qui fixe
   `display` (flex/grid/block...) bat la regle native `[hidden]{display:none}`
   des qu'il a une specificite egale ou superieure, laissant l'element visible
   malgre `el.hidden = true` en JS. Vecu plusieurs fois sur ce projet. */
[hidden] { display: none !important; }

.icon-sprite { display: none; }
.icon { width: 18px; height: 18px; fill: currentColor; display: block; }

.qr-modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(3, 6, 10, .75);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity .15s;
}
.qr-modal-overlay.open { opacity: 1; pointer-events: auto; }
.qr-modal-box {
  position: relative;
  width: 100%; max-width: 320px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px 24px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.qr-modal-close {
  position: absolute; top: 10px; right: 10px;
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.qr-modal-title { font-weight: 700; font-size: 16px; margin: 0; }
.qr-modal-svg { width: 200px; height: 200px; background: #fff; padding: 10px; border-radius: 8px; }
.qr-modal-svg svg { width: 100%; height: 100%; display: block; }
.qr-modal-phone { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: .03em; }
.qr-modal-hint { font-size: 13px; color: var(--muted); margin: 0; }

.qr-scan-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(3, 6, 10, .9);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity .15s;
}
.qr-scan-overlay.open { opacity: 1; pointer-events: auto; }
.qr-scan-box {
  position: relative;
  width: 100%; max-width: 360px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.qr-scan-video-wrap { position: relative; width: 100%; aspect-ratio: 1; background: #000; border-radius: 8px; overflow: hidden; }
.qr-scan-video-wrap video { width: 100%; height: 100%; object-fit: cover; }
.qr-scan-frame {
  position: absolute; inset: 12%; border: 2px solid var(--accent); border-radius: 8px; pointer-events: none;
}
.qr-scan-status { font-size: 13px; color: var(--muted); margin: 0; min-height: 18px; }
.qr-scan-close {
  position: absolute; top: 10px; right: 10px;
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  z-index: 1;
}

html, body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
}

/* body en colonne flex : le header et les bandeaux (essai/pub) gardent leur
   hauteur naturelle, .layout prend TOUT le reste (flex:1) - ainsi n'importe
   quel bandeau ajoute/retire de hauteur sans jamais faire deborder ou
   ecraser le lecteur video (bug vecu avec un calcul en "calc(100vh - 60px)"
   fixe qui ne connaissait pas l'existence des bandeaux). Ne s'applique
   qu'aux pages qui ont ce header + .layout (index.php). */
body:has(> .layout) {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  min-height: 60px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.brand-logo { height: 34px; width: 34px; object-fit: contain; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: .3px; }
.brand-name .accent { color: var(--accent); }

.search-wrap { flex: 1; max-width: 420px; }
#search {
  width: 100%;
  padding: 9px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  outline: none;
  font-size: 14px;
}
#search:focus { border-color: var(--accent); }

.stats { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }

.account { display: flex; align-items: center; gap: 10px; }
.account-info { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.3; }
.account-info span:first-child { font-size: 13px; font-weight: 600; }
.account-expiry { font-size: 11px; color: var(--muted); }
#logoutBtn, #showQrBtn, .menu-btn {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  cursor: pointer;
}
#logoutBtn:hover, #showQrBtn:hover, .menu-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Panneau lateral client (drawer) : "Mon code QR"/"Mon abonnement"/
   "Parrainage"/"Trouver un revendeur"/"Offrir un abonnement" - meme
   convention que .qr-modal-overlay (overlay + panneau, transition opacity),
   mais un panneau qui glisse depuis la droite plutot qu'une boite centree. */
.drawer-overlay {
  position: fixed; inset: 0; z-index: 600;
  background: rgba(3, 6, 10, .6);
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 100%; max-width: 340px;
  background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .2s;
  overflow-y: auto;
}
.drawer-overlay.open .drawer-panel { transform: translateX(0); }
.drawer-panel { box-shadow: -12px 0 40px rgba(0,0,0,.45); max-width: 360px; }

.drawer-head {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
}
.drawer-head-logo { width: 34px; height: 34px; object-fit: contain; flex-shrink: 0; }
.drawer-head-text { flex: 1; min-width: 0; line-height: 1.25; }
.drawer-title { font-weight: 700; font-size: 15px; display: block; }
.drawer-subtitle { font-size: 12px; color: var(--muted); }
.drawer-close {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.drawer-close:hover { border-color: var(--accent); color: var(--accent); }

.drawer-nav { display: flex; flex-direction: column; padding: 12px; gap: 6px; flex-shrink: 0; }
.drawer-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px; border-radius: 14px;
  border: 1px solid transparent; background: transparent; color: var(--text);
  font-size: 14px; text-align: left; cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, transform .15s;
}
.drawer-item:hover { background: var(--panel-2); border-color: var(--border); transform: translateX(-2px); }
.drawer-item-icon {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(63, 169, 245, .14); color: var(--accent);
}
.drawer-item-icon .icon { width: 20px; height: 20px; }
.drawer-item-text { flex: 1; min-width: 0; line-height: 1.3; }
.drawer-item-title { display: block; font-weight: 600; }
.drawer-item-sub { display: block; font-size: 11.5px; color: var(--muted); }
.drawer-item-chevron { color: var(--muted); flex-shrink: 0; }
.drawer-item-chevron .icon { width: 16px; height: 16px; }

.drawer-footer {
  margin-top: auto; padding: 14px 18px; border-top: 1px solid var(--border);
  text-align: center; font-size: 11px; color: var(--muted); flex-shrink: 0;
}

.drawer-content { padding: 4px 14px 18px; }
.drawer-card h3 { margin: 6px 0 10px; font-size: 15px; }
.drawer-card p { margin: 0 0 10px; font-size: 13.5px; }
.drawer-hint { color: var(--muted); font-size: 12.5px; }
.drawer-loading, .drawer-empty { color: var(--muted); font-size: 13px; padding: 14px; text-align: center; }

.drawer-link-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 14px; border-radius: var(--radius);
  background: var(--accent-2); color: #fff; text-decoration: none;
  font-size: 13px; font-weight: 600; margin-top: 4px;
}
.drawer-link-btn:hover { background: var(--accent); }

.drawer-referral-code {
  font-size: 22px; font-weight: 700; letter-spacing: .08em; text-align: center;
  color: var(--accent); border: 1px dashed var(--accent); border-radius: var(--radius);
  padding: 10px; margin-bottom: 12px;
}
.drawer-copy-row { display: flex; gap: 6px; margin-bottom: 6px; }
.drawer-input {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 12px;
}
.drawer-btn {
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); cursor: pointer; font-size: 13px; white-space: nowrap;
}
.drawer-btn:hover { border-color: var(--accent); color: var(--accent); }
.drawer-copy-status { color: var(--accent); font-size: 12px; margin: 0 0 8px; }

.drawer-progress { height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; margin: 6px 0 12px; }
.drawer-progress-fill { height: 100%; background: var(--accent); }

.drawer-reseller-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.drawer-reseller-row:last-child { border-bottom: none; }
.drawer-reseller-distance { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.drawer-reseller-call { margin-top: 0; padding: 7px 12px; font-size: 12.5px; }

.device-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.device-row:last-child { border-bottom: none; }
.device-info { min-width: 0; }
.device-label { font-weight: 600; font-size: 14px; }
.device-seen { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.device-remove-btn {
  flex-shrink: 0; padding: 7px 12px; border-radius: var(--radius);
  background: transparent; border: 1px solid var(--danger); color: var(--danger);
  font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.device-remove-btn:hover { background: var(--danger); color: #fff; }
.device-remove-btn:disabled { opacity: .5; cursor: default; }

.device-limit-hint {
  color: var(--muted); font-size: 12px; margin: -4px 0 14px;
}

.trial-banner {
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  color: #051018; font-weight: 700; font-size: 13px;
  text-align: center; padding: 8px 12px;
  flex-shrink: 0;
}

.ads-banner {
  background: var(--bg); border-bottom: 1px solid var(--border); flex-shrink: 0;
  padding: 10px 16px; display: flex; justify-content: center;
}
.ads-link {
  display: flex; align-items: center; justify-content: center; position: relative;
  max-height: 90px; max-width: 640px; width: 100%; overflow: hidden;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  transition: border-color .15s, transform .15s;
}
.ads-link:hover { border-color: var(--accent); transform: translateY(-1px); }
.ads-link img { max-width: 100%; max-height: 90px; object-fit: contain; display: block; }
.ads-tag {
  position: absolute; top: 8px; left: 8px; font-size: 10px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: #fff; background: rgba(0,0,0,.55);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  padding: 3px 8px; border-radius: 20px;
}

/* Bandeau d'installation PWA (assets/pwa-register.js), meme convention que
   .trial-banner/.ads-banner : bande fine sous le header, jamais superposee
   au contenu (sinon elle cacherait le lecteur video sur index.php). */
.install-banner {
  display: none; align-items: center; gap: 12px;
  background: var(--panel-2); border-bottom: 1px solid var(--accent);
  padding: 10px 16px; flex-shrink: 0;
}
.install-banner.open { display: flex; }
.install-banner-text { flex: 1; font-size: 13px; color: var(--text); min-width: 0; }
.install-banner-btn {
  flex-shrink: 0; padding: 7px 16px; border-radius: 20px; border: none;
  background: var(--accent); color: #06131f; font-weight: 700; font-size: 13px; cursor: pointer;
}
.install-banner-btn:hover { background: var(--accent-2); color: #fff; }
.install-banner-close {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%; border: none;
  background: transparent; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer;
}
.install-banner-close:hover { color: var(--text); }

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 340px;
  min-width: 260px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.groups {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  overflow-y: auto;
  max-height: 120px;
}

.language-filter {
  display: block;
  width: calc(100% - 20px);
  margin: 10px;
  padding: 8px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.language-filter:focus { border-color: var(--accent); }

.group-chip {
  padding: 4px 10px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.group-chip.active { background: var(--accent-2); color: #fff; border-color: var(--accent-2); }

.channel-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.channel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
}
.channel-item:hover { background: var(--panel-2); }
.channel-item.active { background: var(--accent-2); }

.channel-item img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 4px;
  background: #fff1;
  flex-shrink: 0;
}

.channel-item .meta { min-width: 0; }
.channel-item .name {
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.channel-item .group { font-size: 11px; color: var(--muted); }
.channel-item.active .group { color: #dbeafe; }

.lang-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .03em;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 1px 4px;
  margin-right: 6px;
  vertical-align: middle;
}
.channel-item.active .lang-badge { color: #fff; border-color: #fff; }

.channel-item .fav-btn {
  background: none; border: none; cursor: pointer;
  color: var(--muted); flex-shrink: 0; padding: 6px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.channel-item .fav-btn:hover { color: var(--accent); background: rgba(255,255,255,.06); }
.channel-item .fav-btn.active { color: #f5c518; }
.channel-item .fav-btn .icon { width: 18px; height: 18px; }
.channel-item.active .fav-btn:not(.active) { color: #dbeafe; }

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

.player-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  padding: 20px;
}

.video-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#video { width: 100%; height: 100%; background: #000; }

.overlay-buffering, .overlay-error, .overlay-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 20px;
}

.overlay-buffering { background: transparent; pointer-events: none; }
.overlay-error { background: rgba(10, 14, 20, .88); }
.overlay-empty { color: var(--muted); background: #05070a; }
.empty-logo { width: 84px; height: 84px; object-fit: contain; opacity: .5; }

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

.overlay-actions { display: flex; gap: 10px; }
.overlay-actions button, .controls button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
}
.overlay-actions button:hover, .controls button:hover { border-color: var(--accent); }

.now-playing {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(10, 14, 20, .6);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
}
.now-playing img { width: 22px; height: 22px; object-fit: contain; border-radius: 4px; }

.controls {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(to top, rgba(0,0,0,.75), transparent);
}
.controls button { padding: 6px 10px; font-size: 15px; }
.controls .spacer { flex: 1; }
#volume { width: 100px; }

/* Credit discret "realise par Netcrafter" (agence ayant developpe la
   plateforme) - ne doit jamais rivaliser visuellement avec le logo
   principal de la plateforme (.brand-logo / .auth-logo / .staff-logo). */
.site-credit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 6px;
  font-size: 11px;
  line-height: 1;
  color: var(--muted);
  text-decoration: none;
  border-top: 1px solid var(--border);
}
.site-credit:hover { color: var(--accent); }
.site-credit img { width: 14px; height: 14px; object-fit: contain; opacity: .85; border-radius: 3px; }

@media (max-width: 820px) {
  .topbar { padding: 8px 12px; gap: 8px 12px; }
  .brand { min-width: 0; gap: 8px; }
  .brand-logo { height: 28px; width: 28px; }
  .brand-name { font-size: 15px; }

  /* La recherche passe sur sa propre ligne pleine largeur quand ca manque
     de place, plutot que d'ecraser le reste du header. */
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }

  .stats { display: none; }

  .account-info { display: none; }
  .account { gap: 0; }

  /* Le lecteur passe AVANT la liste de chaines a l'ecran (ordre visuel),
     sans toucher au DOM/HTML - c'est ce qu'on est venu regarder en premier. */
  .layout { flex-direction: column; }
  .player-area { order: -1; flex: 0 0 auto; height: 38vh; min-height: 200px; padding: 8px; }
  .sidebar {
    width: 100%;
    flex: 1;
    min-height: 0;
    border-right: none;
    border-top: 1px solid var(--border);
  }

  /* Categories en une seule ligne qui defile horizontalement, pour ne pas
     manger toute la hauteur restreinte avec plusieurs lignes de chips. */
  .groups { max-height: none; flex-wrap: nowrap; overflow-x: auto; }
  .group-chip { flex-shrink: 0; }

  /* Cibles tactiles plus genereuses (recommandation ~44px). */
  .channel-item { padding: 10px; }
  .channel-item img { width: 38px; height: 38px; }
  .controls button { padding: 10px; }
  .controls .icon { width: 20px; height: 20px; }
  #volume { width: 70px; }
}

@media (max-width: 480px) {
  .brand-name .accent { display: none; }
  #volume { display: none; }
}
