/* ============================================================
   DKmytube — téléchargeur MP3. Design repris du design system DKup.
   ============================================================ */
:root {
  --primary: #4a6cf7;
  --primary-light: #6b8cff;
  --primary-lighter: #8da8ff;
  --success: #50c878;
  --warning: #f5a623;
  --danger: #e74c3c;

  --text-white: #ffffff;
  --text-light: #ccc;
  --text-normal: #999;
  --text-muted: #666;
  --text-subtle: #555;

  --bg-dark: #0a0a0c;
  --bg-darker: #111115;
  --bg-card: rgba(18, 18, 22, 0.5);
  --bg-panel: rgba(14, 14, 18, 0.95);

  --border-subtle: rgba(255, 255, 255, 0.03);
  --border-light: rgba(255, 255, 255, 0.06);
  --border-normal: rgba(255, 255, 255, 0.08);
  --border-active: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; }

/* Anti double-tap zoom (mobile) ; on garde la sélection de texte ailleurs */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-dark);
  color: #e0e0e0;
  background-image:
    radial-gradient(ellipse 600px 400px at 10% 20%, rgba(74, 108, 247, 0.12), transparent),
    radial-gradient(ellipse 500px 500px at 85% 15%, rgba(168, 85, 247, 0.08), transparent),
    radial-gradient(ellipse 400px 300px at 50% 80%, rgba(59, 130, 246, 0.08), transparent);
  background-attachment: fixed;
  min-height: 100vh;
  padding-bottom: 120px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Barre de défilement (large, facile à attraper) ---------- */
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.22) transparent; }
::-webkit-scrollbar { width: 16px; height: 16px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  border: 4px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.32); background-clip: padding-box; }

/* ---------- Header ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.8rem 2rem;
  padding-top: calc(0.8rem + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border-light);
  backdrop-filter: blur(20px);
  background: rgba(10, 10, 12, 0.55);
}
/* Header équilibré : logo à gauche, recherche centrée, espace symétrique à droite */
.header-left { display: flex; align-items: center; flex: 1 0 auto; }
.header-spacer { flex: 1 0 auto; }
.header-logo-link { cursor: pointer; display: flex; align-items: center; }
.header-logo-link:hover { opacity: 0.85; }
.header-logo { height: 30px; }

/* Loader du scroll infini */
.scroll-loader {
  display: flex; align-items: center; justify-content: center; gap: 0.6rem;
  padding: 1.2rem 0; color: var(--text-muted); font-size: 0.82rem;
}
.scroll-loader.hidden { display: none; }
#scroll-sentinel { height: 1px; }

/* ---------- Recherche + autocomplete ---------- */
.search { flex: 0 1 600px; margin: 0 auto; }
.search-wrap { display: flex; align-items: center; gap: 0.5rem; }
.search-field { position: relative; flex: 1; }
.search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
#search-input {
  width: 100%;
  padding: 0.6rem 2.6rem 0.6rem 2.5rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-normal);
  border-radius: 10px;
  color: #fff; font-size: 16px; /* 16px = pas de zoom auto iOS */
  font-family: inherit; transition: border-color 0.15s;
}
#search-input::placeholder { color: var(--text-subtle); }
#search-input:focus { outline: none; border-color: rgba(74, 108, 247, 0.5); }

.search-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light); border-radius: 8px;
  color: var(--text-normal); cursor: pointer; transition: all 0.15s;
}
.search-clear:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.search-clear.hidden { display: none; }

.suggest {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border-normal); border-radius: 10px;
  overflow: hidden; z-index: 60;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4); backdrop-filter: blur(10px);
}
.suggest-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.9rem; font-size: 0.9rem; color: var(--text-light); cursor: pointer;
}
.suggest-item:hover, .suggest-item.active { background: rgba(74, 108, 247, 0.1); color: #fff; }
.suggest-item svg { color: var(--text-muted); flex-shrink: 0; }

/* ---------- Contenu ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 1.8rem 2rem; }
.hidden { display: none !important; }

.view-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; }
h2 { font-size: 1.3rem; font-weight: 700; margin: 0; color: #fff; }
.count { color: var(--text-muted); font-size: 0.9rem; font-weight: 400; }
.empty { color: var(--text-muted); font-size: 0.95rem; line-height: 1.6; text-align: center; max-width: 460px; margin: 3.5rem auto; }

/* ---------- Liste / lignes ---------- */
.list { display: flex; flex-direction: column; gap: 2px; }
.row {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.5rem 0.7rem; border-radius: 8px;
  border: 1px solid transparent; transition: all 0.15s; cursor: pointer;
}
.row:hover { background: rgba(255, 255, 255, 0.03); }
.row.playing { background: rgba(74, 108, 247, 0.08); border-color: rgba(74, 108, 247, 0.25); }
.row img {
  width: 46px; height: 46px; border-radius: 5px; object-fit: cover;
  background: rgba(255, 255, 255, 0.04); flex-shrink: 0;
}
.row-meta { flex: 1; min-width: 0; }
.row-title { font-size: 0.92rem; color: #eee; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.playing .row-title { color: var(--primary-light); font-weight: 600; }
.row-sub { font-size: 0.76rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.row-dur { color: var(--text-muted); font-size: 0.76rem; font-variant-numeric: tabular-nums; min-width: 38px; text-align: right; }

.row-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.row-actions button {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border-light);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-light); cursor: pointer;
  display: grid; place-items: center; transition: all 0.15s;
}
.row-actions button:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.row-actions button.dl:hover { background: rgba(74, 108, 247, 0.22); border-color: rgba(74, 108, 247, 0.4); color: var(--primary-lighter); }
.row-actions button.dl.done { background: rgba(80, 200, 120, 0.18); border-color: rgba(80, 200, 120, 0.4); color: var(--success); }
.row-actions button:disabled { cursor: progress; }

/* ---------- Mini-lecteur d'aperçu ---------- */
.player {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: grid; grid-template-columns: 1fr 1.6fr auto;
  align-items: center; gap: 1.5rem;
  min-height: 92px; padding: 0 1.8rem;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-panel);
  border-top: 1px solid var(--border-normal);
  backdrop-filter: blur(20px); z-index: 40;
}
.player.hidden { display: none; }

.player-now { display: flex; align-items: center; gap: 0.9rem; min-width: 0; }
.player-thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.player-meta { min-width: 0; }
.player-title { font-weight: 600; font-size: 0.88rem; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-artist { color: var(--text-muted); font-size: 0.76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.player-center { display: flex; align-items: center; gap: 1rem; }
.player-controls { display: flex; align-items: center; justify-content: center; }
#btn-play {
  width: 50px; height: 50px; border-radius: 50%;
  background: #fff; color: #000; border: none; cursor: pointer;
  display: grid; place-items: center; transition: transform 0.15s; flex-shrink: 0;
}
#btn-play:hover { transform: scale(1.06); }
#btn-play:active { transform: scale(0.94); }

.player-progress { display: flex; align-items: center; gap: 0.7rem; flex: 1; }
.player-progress span { font-size: 0.7rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
#seek {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 6px; border-radius: 4px;
  background: linear-gradient(90deg, var(--primary) var(--seek, 0%), rgba(255, 255, 255, 0.14) var(--seek, 0%));
  outline: none; cursor: pointer;
}
#seek::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: none; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4); transition: transform 0.12s;
}
#seek::-webkit-slider-thumb:active { transform: scale(1.45); background: var(--primary-light); }
#seek::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #fff; border: none; cursor: pointer; }
/* Barre verrouillée tant que l'aperçu n'est pas prêt (anti-erreur de seek) */
#seek:disabled { opacity: 0.45; cursor: progress; }

.player-right { display: flex; align-items: center; justify-content: flex-end; gap: 0.8rem; }
.badge { font-size: 0.65rem; padding: 0.2rem 0.55rem; border-radius: 10px; color: var(--text-muted); border: 1px solid var(--border-light); white-space: nowrap; }

/* ---------- Bouton télécharger principal (pill) ---------- */
.dl-main {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.6rem 1.1rem; border-radius: 12px;
  background: var(--primary); color: #fff; border: none;
  font-family: inherit; font-size: 0.85rem; font-weight: 700;
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.dl-main:hover { background: var(--primary-light); }
.dl-main:active { transform: scale(0.97); }
.dl-main:disabled { cursor: progress; opacity: 0.85; }
.dl-main.done { background: rgba(80, 200, 120, 0.2); color: var(--success); }
.dl-ico { display: grid; place-items: center; width: 18px; height: 18px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 108px; left: 50%; transform: translateX(-50%);
  background: var(--bg-darker); border: 1px solid var(--border-normal);
  padding: 0.7rem 1.2rem; border-radius: 8px; z-index: 100;
  font-size: 0.85rem; color: var(--text-light); max-width: 92vw; text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4); animation: fadeSlideIn 0.2s ease;
}
.toast.hidden { display: none; }

/* ---------- Verrou mot de passe ---------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-dark);
  background-image:
    radial-gradient(ellipse 600px 400px at 30% 30%, rgba(74, 108, 247, 0.15), transparent),
    radial-gradient(ellipse 500px 500px at 70% 70%, rgba(168, 85, 247, 0.1), transparent);
  padding: 1.5rem;
}
.login-overlay.hidden { display: none; }
.login-box {
  display: flex; flex-direction: column; align-items: center; gap: 0.9rem;
  width: 100%; max-width: 340px; padding: 2.2rem 1.8rem;
  background: var(--bg-card); backdrop-filter: blur(10px);
  border: 1px solid var(--border-normal); border-radius: 16px;
}
.login-logo { height: 34px; margin-bottom: 0.3rem; }
.login-sub { color: var(--text-muted); font-size: 0.85rem; margin: 0; }
#login-password {
  width: 100%; padding: 0.7rem 1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-normal); border-radius: 10px;
  color: #fff; font-size: 16px; font-family: inherit; text-align: center;
}
#login-password:focus { outline: none; border-color: rgba(74, 108, 247, 0.5); }
.login-box button {
  width: 100%; padding: 0.7rem; border: none; border-radius: 10px;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 0.95rem;
  font-family: inherit; cursor: pointer; transition: background 0.15s;
}
.login-box button:hover { background: var(--primary-light); }
.login-error { color: var(--danger); font-size: 0.82rem; margin: 0; text-align: center; }
.login-error.hidden { display: none; }

/* ---------- Animations ---------- */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes fadeSlideIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 0.8s linear infinite; display: inline-block; }

/* ---------- Responsive (mobile portrait) ---------- */
@media (max-width: 760px) {
  body { padding-bottom: 178px; }

  header { flex-wrap: wrap; gap: 0.6rem; padding: 0.6rem 0.9rem; padding-top: calc(0.6rem + env(safe-area-inset-top, 0px)); }
  .header-left { order: 1; flex: 0 0 auto; }
  .header-spacer { display: none; }
  .search { order: 3; flex: 1 1 100%; max-width: none; margin: 0; }

  main { padding: 1rem 0.9rem; }

  /* Dock empilé verticalement */
  .player {
    grid-template-columns: 1fr; height: auto; gap: 0.7rem;
    padding: 0.8rem 1rem calc(0.8rem + env(safe-area-inset-bottom, 0px));
    align-items: stretch;
  }
  .player-now { order: 1; }
  .player-center { order: 2; gap: 0.8rem; }
  .player-right { order: 3; justify-content: space-between; }
  #btn-play { width: 56px; height: 56px; }
  .dl-main { flex: 1; justify-content: center; padding: 0.75rem 1.1rem; }
  .badge { display: none; }

  /* Lignes plus aérées au doigt + titre lisible sur 2 lignes (plus de boutons
     qui rognent la largeur : on tape la ligne pour écouter). */
  .row { padding: 0.7rem 0.5rem; }
  .row-actions { display: none; }
  .row-title {
    white-space: normal;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; line-height: 1.25;
  }
  .row-dur { align-self: flex-start; margin-top: 2px; }
  .toast { bottom: 168px; }
}
