/* ---- Design tokens ------------------------------------------------- */
:root {
  --bg: #14110F;
  --surface: #1E1A16;
  --surface-hi: #292420;
  --line: #35302A;
  --text: #EDE7DD;
  --text-muted: #93897B;
  --accent: #C9A227;      /* laiton / platine */
  --accent-soft: #E4C766;
  --accent2: #3EC9A7;     /* état "en lecture" */
  --danger: #D9634C;

  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

* { box-sizing: border-box; }

/* Garantit que l'attribut HTML "hidden" masque bien l'élément même quand
   sa classe impose un "display" (grid/flex) — sans cette règle, une classe
   comme .modal, .now-playing ou .playlist-bar l'emporte sur le comportement
   par défaut du navigateur pour [hidden], et l'élément reste visible malgré
   l'attribut (c'est ce qui rendait les fenêtres modales impossibles à
   fermer et affichait la barre "en cours de lecture" avant toute lecture). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0,0,0,0);
}

button { font-family: inherit; cursor: pointer; }

/* ---- Logo vinyle (signature) ---------------------------------------- */
.vinyl {
  width: 96px; height: 96px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #0B0908 0 18%, #1a1613 19% 100%);
  position: relative;
  margin: 0 auto 18px;
  animation: spin 12s linear infinite;
  box-shadow: 0 0 0 2px var(--line), 0 12px 30px rgba(0,0,0,.5);
}
.vinyl-small { width: 34px; height: 34px; margin: 0; animation-duration: 8s; }
.custom-logo {
  max-width: 140px; max-height: 96px;
  margin: 0 auto 18px; display: block;
  object-fit: contain;
}
.vinyl-grooves {
  position: absolute; inset: 6%;
  border-radius: 50%;
  background: repeating-radial-gradient(circle, #262019 0 2px, transparent 3px 6px);
  opacity: .55;
}
.vinyl-label {
  position: absolute; inset: 36%;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1400;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 11px;
  letter-spacing: .04em;
}
.vinyl-small .vinyl-label { font-size: 8px; }

@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .vinyl { animation: none; }
}

/* ---- Ecran de connexion --------------------------------------------- */
.login-screen {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px;
  gap: 16px;
  background:
    radial-gradient(1200px 600px at 50% -10%, #221c15 0%, transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 36px 28px 28px;
  text-align: center;
  box-shadow: 0 30px 60px rgba(0,0,0,.4);
}
.logo h1 {
  font-family: var(--font-display);
  font-size: 26px;
  margin: 0 0 4px;
  letter-spacing: .01em;
}
.logo h1 span { color: var(--accent); }
.tagline { color: var(--text-muted); margin: 0 0 26px; font-size: 14px; }

.pin-boxes {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}
.pin-box {
  width: 100%;
  min-width: 0;
  aspect-ratio: 1 / 1.2;
  text-align: center;
  font-family: var(--font-mono);
  font-size: clamp(14px, 4.2vw, 20px);
  color: var(--accent-soft);
  background: var(--surface-hi);
  border: 1px solid var(--line);
  border-radius: 8px;
  -webkit-text-security: disc;
}
.pin-box:focus { outline: none; }

.pin-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
  margin: 4px 0 14px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.key {
  padding: 16px 0;
  font-family: var(--font-mono);
  font-size: 18px;
  color: var(--text);
  background: var(--surface-hi);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: background .12s ease, transform .05s ease;
}
.key:active { transform: scale(.96); background: #33291a; }
.key-clear, .key-back { font-family: var(--font-body); font-size: 13px; color: var(--text-muted); }

/* ---- Tableau de bord --------------------------------------------------- */
/* Toutes les cibles tactiles de cette page visent au moins 44x44px
   (recommandation Apple/Google), y compris sur mobile/tablette. */

.app-shell { max-width: 1100px; margin: 0 auto; padding: 16px 16px 140px; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 8px 2px 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 700; font-size: 17px;
  white-space: nowrap;
}
.brand .accent { color: var(--accent); }

.header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.user-badge {
  font-size: 12px; color: var(--text-muted);
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px;
  display: none; /* réapparaît à partir de la tablette, voir media query */
}
.btn-icon {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 17px; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn-icon:active { background: var(--surface-hi); color: var(--accent); }

.btn-ghost {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 14px; font-size: 13px; text-decoration: none;
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
}
.btn-ghost:active { color: var(--text); border-color: var(--accent); }

.device-bar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px;
}
.device-bar-label { font-size: 13px; color: var(--text-muted); flex-shrink: 0; }
.device-toggle {
  display: flex; flex: 1; gap: 8px;
}
.device-btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  gap: 10px;
  background: var(--surface-hi); color: var(--text-muted);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 10px; font-family: var(--font-body); font-size: 14px;
  min-height: 52px;
  text-align: center;
  transition: background .15s, color .15s, border-color .15s;
}
.device-btn.active {
  background: var(--accent); color: #1a1400;
  border-color: var(--accent); font-weight: 600;
}

.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab {
  background: transparent; border: 1px solid var(--line); color: var(--text-muted);
  padding: 11px 18px; border-radius: 999px; font-size: 14px;
  min-height: 44px; flex: 1;
}
.tab.active { background: var(--accent); color: #1a1400; border-color: var(--accent); font-weight: 600; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.group-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  margin: 28px 0 12px;
}
.group-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: #ffffff;
  text-transform: none;
  letter-spacing: .02em;
  margin: 0;
}
.group-header:first-child, .tab-panel > .group-header:first-of-type { margin-top: 0; }

.btn-play-all {
  background: var(--surface-hi); color: var(--accent-soft);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; font-size: 12px; white-space: nowrap;
  min-height: 36px;
}
.btn-play-all:active { border-color: var(--accent); }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}
.tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  padding: 0;
  text-align: left;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.tile:active { border-color: var(--accent); }
.tile img {
  width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block;
  background: var(--surface-hi);
}
/* Bouton lecture (haut droite) — même style pour MP3 et MP4 ;
   la distinction MP3/MP4 se fait via la pastille centrale de la pochette. */
.tile-play {
  position: absolute; top: 8px; right: 8px;
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(20,17,15,.8);
  color: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.tile-play-audio,
.tile-play-video {
  color: var(--accent-soft);
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.tile-caption {
  display: block; padding: 8px 10px 10px;
  font-size: 15px; line-height: 1.35;
  color: #3ecf6e;
  font-weight: 600;
}
.tile-caption small { color: var(--text-muted); font-size: 12px; font-weight: 400; }
.tile.playing { outline: 2px solid var(--accent2); }
.tile.playing .tile-play { color: var(--accent2); }

/* ---- Barre "en cours de lecture" (fixe en bas, pensée mobile d'abord) --- */
.now-playing {
  position: fixed; left: 0; right: 0; bottom: 0;
  /* Doit rester utilisable même quand la popup vidéo (.modal, z-index 10)
     est ouverte en même temps (lecture MP4) — d'où un z-index supérieur. */
  z-index: 30;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "cover info"
    "controls controls"
    "volume stop";
  align-items: center;
  gap: 8px 12px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface-hi);
  border-top: 1px solid var(--line);
  font-size: 14px;
  box-shadow: 0 -8px 24px rgba(0,0,0,.35);
}
.now-playing-cover {
  grid-area: cover;
  width: 44px; height: 44px; border-radius: 8px; object-fit: cover;
  background: var(--surface);
}
.now-playing-info { grid-area: info; display: flex; flex-direction: column; min-width: 0; }
.now-playing-info strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now-playing-info span { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.now-playing-controls {
  grid-area: controls;
  display: flex; align-items: center; justify-content: center; gap: 18px;
  padding: 4px 0;
}
.btn-round {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}
.btn-round:disabled { opacity: .35; }
.btn-round-lg {
  width: 54px; height: 54px; font-size: 20px;
  background: var(--accent); color: #1a1400; border-color: var(--accent);
}
.btn-round:active:not(:disabled) { border-color: var(--accent); }

.volume-control {
  grid-area: volume;
  display: flex; align-items: center; gap: 8px;
  font-size: 14px;
}
.volume-control input[type="range"] {
  flex: 1;
  height: 44px; /* zone tactile confortable, même si le rail visuel est fin */
  accent-color: var(--accent);
}

.btn-stop {
  grid-area: stop;
  justify-self: end;
  background: var(--danger); color: #1a0a06; border: none;
  padding: 0 18px; height: 40px; border-radius: 8px; font-weight: 600;
}

/* Tablette / desktop : barre de lecture sur une seule ligne */
@media (min-width: 720px) {
  .user-badge { display: inline-flex; }
  .device-bar { max-width: 640px; }
  .device-btn { min-height: 56px; white-space: nowrap; font-size: 14px; }
  .device-dot { width: 36px; height: 36px; }
  /* Sur téléphone (hors media query), le libellé peut revenir sur deux
     lignes si la place manque — comportement volontairement différent,
     l'écran étant plus étroit. */

  .now-playing {
    grid-template-columns: auto 1fr auto auto auto;
    grid-template-areas: "cover info controls volume stop";
    padding: 12px 24px;
  }
  .now-playing-controls { padding: 0; }
}

/* ---- Administrateur --------------------------------------------------- */
.admin-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  max-width: 640px;
}
.admin-hint { color: var(--text-muted); font-size: 14px; line-height: 1.5; margin-bottom: 20px; }

.dirs-list { list-style: none; padding: 0; margin: 0 0 18px; display: flex; flex-direction: column; gap: 8px; }
.dirs-list li {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-hi); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px;
}
.dir-path { font-family: var(--font-mono); font-size: 13px; word-break: break-all; }
.user-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.user-actions .btn-ghost { padding: 4px 10px; font-size: 12px; min-height: 32px; }
.btn-remove {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 18px; line-height: 1; padding: 0 4px;
}
.btn-remove:hover { color: var(--danger); }

.admin-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-primary {
  background: var(--accent); color: #1a1400; border: none;
  padding: 10px 18px; border-radius: 8px; font-weight: 600; font-size: 14px;
}
.admin-message { min-height: 18px; color: var(--accent2); font-size: 13px; margin-top: 12px; }

/* ---- Modale explorateur de dossiers ------------------------------------ */
.modal {
  position: fixed; inset: 0; background: rgba(10,8,6,.65);
  display: flex; align-items: center; justify-content: center; z-index: 10;
  /* Laisse la barre "en cours de lecture" (z-index supérieur, voir plus bas)
     accessible en bas d'écran quand une vidéo est ouverte en même temps. */
  padding-bottom: 110px;
}
.modal-card {
  width: 100%; max-width: 480px; max-height: 70vh;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  font-family: var(--font-mono); font-size: 12px; color: var(--text-muted);
}
.folder-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.folder-list li {
  padding: 10px 12px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.folder-list li:hover { background: var(--surface-hi); }
.folder-list li.empty { color: var(--text-muted); cursor: default; }
.folder-list li.empty:hover { background: none; }
.modal-footer {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-top: 1px solid var(--line);
}

/* ---- Logo (page Administrateur) ---------------------------------------- */
.logo-preview-row {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  margin-bottom: 10px;
}
.logo-preview {
  width: 120px; height: 90px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-hi); border: 1px dashed var(--line); border-radius: 12px;
  overflow: hidden; flex-shrink: 0;
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-preview-empty { font-size: 11px; color: var(--text-muted); text-align: center; padding: 0 8px; }
.logo-preview-actions { display: flex; flex-direction: column; gap: 8px; }
.file-btn { cursor: pointer; text-align: center; }

/* ---- Champs texte des formulaires admin -------------------------------- */
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.modal-card-video { width: min(720px, 96vw); }
.modal-body-video { padding: 0; background: #000; }
#video-player { width: 100%; max-height: 75vh; display: block; }
.field-label { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.field-label:first-child { margin-top: 0; }
.text-input {
  background: var(--surface-hi); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 10px; font-size: 15px; min-height: 44px;
  font-family: var(--font-body);
}
.pin-input { font-family: var(--font-mono); letter-spacing: .3em; }
.version-row { display: flex; gap: 8px; margin-top: 4px; }
.version-row .text-input { flex: 1; }

/* ---- Statistiques (tableau de bord) ------------------------------------ */
.stats-bar {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-muted);
  margin: -8px 0 14px;
}
.stats-bar strong { color: var(--accent-soft); font-family: var(--font-mono); }
.stats-sep { opacity: .5; }

/* ---- Barre d'outils : recherche + dossier + playlist -------------------- */
.toolbar-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.search-wrap { position: relative; flex: 1; min-width: 180px; }
.search-wrap .text-input { width: 100%; }
.search-dropdown {
  list-style: none; margin: 4px 0 0; padding: 6px;
  position: absolute; left: 0; right: 0; z-index: 20;
  background: var(--surface-hi); border: 1px solid var(--line);
  border-radius: 10px; max-height: 320px; overflow-y: auto;
  box-shadow: 0 12px 24px rgba(0,0,0,.35);
}
.search-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.search-item:hover { background: var(--surface); }
.search-item img { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
.search-item small { color: var(--text-muted); }

/* ---- Voyant de connexion des enceintes (points x4 pour lisibilité) ------- */
.device-btn-lg { min-height: 60px; font-size: 15px; font-weight: 600; }
.device-dot {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--line); flex-shrink: 0;
  transition: background .2s, box-shadow .2s;
}
.device-dot.dot-online { background: #3ecf6e; box-shadow: 0 0 12px #3ecf6eaa; }
.device-dot.dot-offline { background: var(--danger); box-shadow: 0 0 12px #d9634caa; }

/* ---- Sélection multiple pour la création de playlist --------------------- */
.tile-select {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-hi); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: transparent;
}
.tile.select-mode .tile-play { display: none; }
.tile.selected .tile-select { background: var(--accent); color: #1a1400; border-color: var(--accent); }
.tile.selected img { outline: 2px solid var(--accent); }

.playlist-bar {
  position: sticky; bottom: 0; z-index: 15;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px; margin-top: 12px;
  background: var(--surface-hi); border: 1px solid var(--line);
  border-radius: 12px; font-size: 14px;
}
.playlist-bar-actions { display: flex; gap: 8px; }
.playlist-actions { display: flex; gap: 4px; align-items: center; }
.empty-hint { color: var(--text-muted); font-size: 14px; padding: 8px 0; }

/* ---- Dossier musique : liste avec fichiers -------------------------------- */
.folder-item-file { color: var(--text-muted); cursor: default; }
.folder-item-file:hover { background: none; }
.folder-item-file small { margin-left: 6px; }

/* ---- Version affichée sous le clavier virtuel (centré) ------------------- */
.app-version {
  margin: 0; text-align: center;
  font-size: 13px; color: var(--text-muted);
  width: 100%; max-width: 420px;
}
