/* ------------------------------------------------------------------ *
 *  Vinyle — feuille de style unique, mobile-first
 * ------------------------------------------------------------------ */
:root {
  --bg: #f4efe7;
  --bg-elev: #fffdf9;
  --card: #ffffff;
  --ink: #241f1c;
  --ink-soft: #6b625b;
  --ink-faint: #9a9089;
  --line: #e5ddd0;
  --accent: #7b2d3b;
  --accent-ink: #ffffff;
  --accent-soft: #f3e3e5;
  --ok: #2f7d51;
  --warn: #b4531a;
  --err: #b23b3b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .08);
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .05);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f;
    --bg-elev: #211d17;
    --card: #262119;
    --ink: #f1e9dd;
    --ink-soft: #b8aca0;
    --ink-faint: #857c70;
    --line: #37312a;
    --accent: #d98695;
    --accent-ink: #24140f;
    --accent-soft: #3a2a2d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .45);
    --shadow-soft: 0 1px 2px rgba(0, 0, 0, .35), 0 2px 10px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(96px + var(--safe-b)); }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* évite le zoom iOS */
  color: var(--ink);
}

a { color: var(--accent); }

img { max-width: 100%; display: block; }

/* ---- En-tête ---------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 14px 16px 10px;
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.app-header h1 .disc {
  width: 22px; height: 22px; flex: none;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, var(--bg-elev) 0 14%, var(--accent) 15% 34%, var(--ink) 35% 100%);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
}

.stats {
  margin-top: 3px;
  font-size: 13px;
  color: var(--ink-soft);
  display: flex;
  gap: 14px;
}
.stats b { color: var(--ink); font-weight: 600; }

.toolbar {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  box-shadow: var(--shadow-soft);
}
.search input {
  flex: 1;
  border: none;
  outline: none;
  background: none;
}
.search svg { flex: none; color: var(--ink-faint); }

.icon-btn {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-soft);
  color: var(--ink-soft);
}
.icon-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.icon-btn .dot {
  position: absolute;
  transform: translate(14px, -14px);
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}
.icon-btn { position: relative; }

/* ---- Contenu -------------------------------------------------------------- */
main { padding: 14px 16px 0; max-width: 1100px; margin: 0 auto; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  font-size: 12.5px;
  padding: 6px 10px 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
.chip button { font-size: 14px; line-height: 1; opacity: .7; }

/* Grille pochettes */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1040px) { .grid { grid-template-columns: repeat(5, 1fr); } }

.card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--line);
  transition: transform .12s ease;
}
.card:active { transform: scale(.975); }

.cover {
  aspect-ratio: 1 / 1;
  width: 100%;
  object-fit: cover;
  background: var(--accent-soft);
}
.cover.placeholder {
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 30px;
}
.card .meta { padding: 9px 11px 12px; }
.card .meta .t { font-weight: 600; font-size: 13.5px; line-height: 1.25; }
.card .meta .a { color: var(--ink-soft); font-size: 12.5px; margin-top: 2px; }
.card .meta .y { color: var(--ink-faint); font-size: 11.5px; margin-top: 3px; }
.line-clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.line-clamp-1 { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }

/* Vue liste */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px;
  box-shadow: var(--shadow-soft);
}
.row:active { background: var(--bg-elev); }
.row img, .row .thumb-ph {
  width: 54px; height: 54px; flex: none;
  border-radius: 8px; object-fit: cover;
  background: var(--accent-soft);
}
.row .thumb-ph { display: grid; place-items: center; color: var(--accent); }
.row .rmeta { flex: 1; min-width: 0; }
.row .rmeta .t { font-weight: 600; font-size: 14px; }
.row .rmeta .a { color: var(--ink-soft); font-size: 12.5px; margin-top: 1px; }
.row .rmeta .x { color: var(--ink-faint); font-size: 11.5px; margin-top: 2px; }
.row .cond { font-size: 11px; padding: 3px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); flex: none; }

/* États vides / chargement */
.empty {
  text-align: center;
  padding: 60px 24px;
  color: var(--ink-soft);
}
.empty .big { font-size: 44px; margin-bottom: 10px; }
.empty h3 { margin: 0 0 6px; color: var(--ink); }

.skeleton .card { pointer-events: none; }
.sk-box { background: linear-gradient(100deg, var(--line) 30%, var(--bg-elev) 50%, var(--line) 70%); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---- Bouton flottant --------------------------------------------------- */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + var(--safe-b));
  width: 60px; height: 60px;
  border-radius: 20px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(123, 45, 59, .45);
  z-index: 30;
}
.fab:active { transform: scale(.94); }
.fab svg { width: 28px; height: 28px; }

/* ---- Feuilles / modales ---------------------------------------------- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 12, .5);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  background: var(--bg);
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  border-radius: 22px 22px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideup .22s cubic-bezier(.2, .8, .2, 1);
  box-shadow: 0 -8px 40px rgba(0,0,0,.3);
}
@keyframes slideup { from { transform: translateY(100%); } }

.sheet.full { max-height: 100vh; height: 100vh; border-radius: 0; }
@media (min-width: 680px) {
  .scrim { align-items: center; }
  .sheet { border-radius: 22px; }
  .sheet.full { height: 92vh; border-radius: 22px; }
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.sheet-head h2 { margin: 0; font-size: 17px; flex: 1; }
.sheet-head .close, .sheet-head .back {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--bg-elev); border: 1px solid var(--line);
  color: var(--ink-soft);
}
.sheet-body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.sheet-foot {
  padding: 12px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line);
  flex: none;
  display: flex;
  gap: 10px;
}

/* ---- Boutons ------------------------------------------------------------- */
.btn {
  appearance: none;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, transparent); }
.btn.ghost { background: transparent; }
.btn.block { display: flex; width: 100%; }
.btn.lg { padding: 18px; font-size: 16px; }
.btn[disabled] { opacity: .55; pointer-events: none; }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---- Formulaires ------------------------------------------------------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 13px;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { min-height: 74px; resize: vertical; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

/* ---- Flux ajout par photo ------------------------------------------- */
.photo-drop {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  color: var(--ink-soft);
  background: var(--bg-elev);
}
.photo-drop .big { font-size: 40px; }
.preview-img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: var(--radius);
  background: #000;
  margin-bottom: 12px;
}
.ocr-box {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--ink-soft);
  white-space: pre-wrap;
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.candidate {
  display: flex;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  align-items: center;
  margin-bottom: 8px;
  width: 100%;
  text-align: left;
}
.candidate:active { background: var(--bg-elev); }
.candidate img, .candidate .cph {
  width: 60px; height: 60px; flex: none;
  border-radius: 8px; object-fit: cover;
  background: var(--accent-soft);
}
.candidate .cph { display: grid; place-items: center; color: var(--accent); }
.candidate .cinfo { flex: 1; min-width: 0; }
.candidate .cinfo .t { font-weight: 600; font-size: 14px; }
.candidate .cinfo .a { color: var(--ink-soft); font-size: 12.5px; }
.candidate .cinfo .x { color: var(--ink-faint); font-size: 11.5px; margin-top: 2px; }
.candidate .go { color: var(--ink-faint); flex: none; }

/* ---- Fiche détail ---------------------------------------------------- */
.detail-cover {
  width: 100%;
  max-width: 320px;
  margin: 0 auto 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  aspect-ratio: 1/1;
  object-fit: cover;
  background: var(--accent-soft);
}
.detail-cover.placeholder { display: grid; place-items: center; color: var(--accent); font-size: 60px; }
.detail h2 { margin: 0 0 2px; font-size: 20px; }
.detail .artist { color: var(--ink-soft); font-size: 15px; margin-bottom: 14px; }

.kv { display: grid; grid-template-columns: 96px 1fr; gap: 6px 12px; font-size: 13.5px; margin-bottom: 16px; }
.kv dt { color: var(--ink-faint); }
.kv dd { margin: 0; }

.section-title { font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-faint); margin: 18px 0 8px; font-weight: 700; }

.tracklist { font-size: 13.5px; }
.tracklist div { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.tracklist div .pos { color: var(--ink-faint); flex: none; min-width: 34px; }
.tracklist div .dur { color: var(--ink-faint); margin-left: auto; }

.perso-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.tag-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tag { font-size: 11.5px; padding: 4px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }

/* ---- Toasts --------------------------------------------------------------- */
#toasts {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 0; right: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  padding: 0 12px;
}
.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 11px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: toastin .2s ease;
  max-width: 90vw;
}
.toast.ok { background: var(--ok); color: #fff; }
.toast.err { background: var(--err); color: #fff; }
@keyframes toastin { from { transform: translateY(-12px); opacity: 0; } }

/* ---- Divers ------------------------------------------------------------ */
.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
.spinner.lg { width: 34px; height: 34px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.center-load { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px; color: var(--ink-soft); }

.inline-note { font-size: 12.5px; color: var(--ink-soft); margin-top: 6px; }
.err-note { color: var(--err); font-size: 13px; margin: 8px 0; }
.hidden { display: none !important; }

.seg {
  display: inline-flex;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}
.seg button.active { background: var(--accent); color: var(--accent-ink); }

/* Pastille de repli quand une image distante échoue */
.img-fallback { display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.cover.img-fallback { aspect-ratio: 1/1; width: 100%; font-size: 30px; }
.rthumb.img-fallback { width: 54px; height: 54px; flex: none; border-radius: 8px; }
.cthumb.img-fallback { width: 60px; height: 60px; flex: none; border-radius: 8px; }
.detail-cover.img-fallback { font-size: 60px; }
.preview-img.img-fallback { min-height: 160px; }
