/* À voir — styles */

:root {
  --bg: #0D0F12;
  --surface: #16191E;
  --surface-2: #1F242A;
  --line: rgba(255, 255, 255, .08);
  --text: #F2F4F5;
  --muted: #98A2AA;
  --accent: #2FB39A;
  --accent-ink: #04201B;
  --danger: #FF6B6B;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #F4F6F5;
    --surface: #FFFFFF;
    --surface-2: #EBEFED;
    --line: rgba(0, 0, 0, .08);
    --text: #111416;
    --muted: #5D686E;
    --accent: #0A574B;
    --accent-ink: #FFFFFF;
    --danger: #D64545;
    --shadow: 0 10px 30px rgba(0, 0, 0, .12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 Poppins, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
body.modal-open { overflow: hidden; }

h1, h2, h3 { font-weight: 600; margin: 0; line-height: 1.2; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.err { color: var(--danger); font-size: 14px; min-height: 1.5em; margin: 0; }

/* ---------- Boutons & champs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600;
  background: var(--surface-2);
  transition: transform .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }

.link { background: none; border: 0; padding: 8px 0; color: var(--accent); font-size: 15px; }
.link.strong { font-weight: 600; }
.link.center { display: block; margin: 16px auto 0; }

.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.input {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 16px; /* évite le zoom automatique sur iPhone */
  padding: 11px 14px; outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; line-height: 1.55; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }

.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border-radius: 12px; padding: 0 12px;
  color: var(--muted);
}
.search svg { width: 18px; height: 18px; flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; background: none; outline: none;
  color: var(--text); font: inherit; font-size: 16px; padding: 11px 0;
}

/* Contrôles segmentés */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: none; border-radius: 9px; padding: 7px 14px;
  font-size: 14px; color: var(--muted); white-space: nowrap;
}
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.seg button span { font-weight: 400; opacity: .6; margin-left: 2px; }
.seg.small button { padding: 6px 11px; font-size: 13px; }
.seg.full { display: flex; }
.seg.full button { flex: 1; }

/* Puces plateformes */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrapable { flex-wrap: wrap; overflow: visible; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  border: 1px solid var(--line); background: transparent; border-radius: 99px;
  padding: 6px 12px; font-size: 13px; color: var(--muted); white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--muted)); }
.chip.on .dot { box-shadow: 0 0 0 1.5px var(--accent-ink); }
.chip small { opacity: .7; font-size: 12px; }

/* ---------- Connexion ---------- */

.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 360px; display: grid; gap: 14px; text-align: center;
}
.auth-logo { margin: 0 auto 4px; border-radius: 16px; }
.auth-card h1 { font-size: 28px; }
.auth-card p { margin: 0; }

/* ---------- En-tête ---------- */

.top {
  position: sticky; top: 0; z-index: 10;
  padding: calc(var(--safe-t) + 10px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-bottom: 1px solid var(--line);
  display: grid; gap: 10px;
}
.top > * { width: 100%; max-width: 1200px; margin-inline: auto; }
.top-row { display: flex; align-items: center; justify-content: space-between; }
.brand { font-size: 26px; letter-spacing: -.02em; }
.top-actions { display: flex; gap: 2px; margin-right: -8px; }
.filters { display: flex; gap: 10px; align-items: center; min-width: 0; }
.filters .seg { flex: none; }
.filters .chips { flex: 1; min-width: 0; padding-left: 10px; border-left: 1px solid var(--line); }
.controls { display: grid; gap: 10px; min-width: 0; }
@media (min-width: 760px) {
  .controls { display: flex; align-items: center; gap: 14px; }
  #statusSeg { flex: none; width: 260px; }
  .filters { flex: 1; }
}

/* ---------- Grille ---------- */

.wrap { max-width: 1200px; margin: 0 auto; padding: 16px 16px calc(var(--safe-b) + 100px); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 20px 14px; }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 28px 20px; } }

.card {
  display: block; align-self: start; border: 0; padding: 0; background: none; text-align: left;
  transition: transform .2s;
}
.card:active { transform: scale(.97); }
@media (hover: hover) { .card:hover .poster img { transform: scale(1.04); } }

.poster {
  position: relative; aspect-ratio: 2 / 3; border-radius: 12px; overflow: hidden;
  background: var(--surface-2); box-shadow: var(--shadow);
}
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s; }
.poster .ph {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 14px;
  text-align: center; font-weight: 600; font-size: 15px; color: var(--muted);
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
}
.badge-seen {
  position: absolute; top: 8px; left: 8px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 99px;
}
.badge-type {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,.6); color: #fff; backdrop-filter: blur(6px);
  font-size: 11px; padding: 3px 8px; border-radius: 99px;
}

.card-meta { padding: 10px 2px 0; }
.card-meta h3 { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.plats { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.plat { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.plat::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c, var(--muted)); }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

.credits { margin: 48px 0 0; text-align: center; font-size: 11px; color: var(--muted); opacity: .7; }

/* ---------- Bouton flottant ---------- */

.fab {
  position: fixed; z-index: 20;
  right: max(20px, calc((100vw - 1200px) / 2 + 20px));
  bottom: calc(var(--safe-b) + 20px);
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: 0 8px 24px rgba(0,0,0,.35);
  transition: transform .15s;
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.2; }
.fab:active { transform: scale(.92); }

/* ---------- Feuilles (dialog) ---------- */

.sheet {
  width: 100%; max-width: 640px; max-height: 92dvh;
  margin: auto auto 0; padding: 0; border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--surface); color: var(--text);
  overflow: hidden;
}
.sheet::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px); }
.sheet[open] { animation: up .28s cubic-bezier(.2, .9, .3, 1); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
#editSheet .sheet-inner { min-height: 75dvh; }
@media (min-width: 700px) {
  .sheet { margin: auto; border-radius: 22px; max-height: 88dvh; }
  #editSheet .sheet-inner { min-height: 0; }
  #editSheet #searchStep { min-height: 420px; }
}

.sheet-inner { max-height: inherit; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet-head {
  position: sticky; top: 0; z-index: 2;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-size: 16px; outline: none; }
.sheet-head .link:last-child { justify-self: end; }
.sheet-head .link:first-child { justify-self: start; color: var(--muted); }
.sheet-body { padding: 16px 18px calc(var(--safe-b) + 24px); }

/* Résultats de recherche TMDB */
.results { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 4px; }
.results button {
  width: 100%; display: flex; gap: 12px; align-items: center; text-align: left;
  border: 0; background: none; padding: 8px; border-radius: 12px;
}
.results button:active, .results button:hover { background: var(--surface-2); }
.results img, .results .thumb-ph {
  width: 46px; height: 69px; border-radius: 6px; object-fit: cover; flex: none; background: var(--surface-2);
}
.results strong { display: block; font-weight: 600; font-size: 15px; }
.results small { color: var(--muted); font-size: 13px; }
.results .loading { opacity: .5; pointer-events: none; }
.results-msg { color: var(--muted); text-align: center; padding: 20px 0; font-size: 14px; }

/* Formulaire */
.form { display: grid; gap: 16px; }
.form .back { justify-self: start; padding: 0; }
.form-top { display: grid; grid-template-columns: 110px 1fr; gap: 14px; align-items: start; }
.form-top-fields { display: grid; gap: 10px; }
.poster-preview {
  aspect-ratio: 2 / 3; border-radius: 10px; overflow: hidden; background: var(--surface-2);
  display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center;
}
.poster-preview img { width: 100%; height: 100%; object-fit: cover; }
.add-plat { display: flex; gap: 8px; margin-top: 4px; }
.add-plat .btn { flex: none; padding: 10px 14px; }

.toggle { display: flex; align-items: center; gap: 12px; font-weight: 600; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-ui { width: 46px; height: 28px; border-radius: 99px; background: var(--surface-2); position: relative; transition: background .2s; border: 1px solid var(--line); }
.toggle-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.toggle input:checked + .toggle-ui { background: var(--accent); }
.toggle input:checked + .toggle-ui::after { transform: translateX(18px); }

/* Fiche détaillée */
.detail-hero { position: relative; padding: 22px 18px 18px; display: grid; grid-template-columns: 120px 1fr; gap: 16px; align-items: end; overflow: hidden; }
.detail-hero::before {
  content: ""; position: absolute; inset: -40px; z-index: 0;
  background: var(--img) center / cover; filter: blur(40px) saturate(1.3); opacity: .45;
}
.detail-hero::after { content: ""; position: absolute; inset: 0; z-index: 0; background: linear-gradient(to bottom, transparent, var(--surface)); }
.detail-hero > * { position: relative; z-index: 1; }
.detail-hero .poster { box-shadow: 0 12px 30px rgba(0,0,0,.45); }
.detail-hero h2 { font-size: 22px; letter-spacing: -.01em; }
.detail-hero p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.detail-close {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.45); color: #fff; display: grid; place-items: center;
}
.detail-close svg { width: 18px; height: 18px; }
.detail-body { padding: 4px 18px calc(var(--safe-b) + 24px); display: grid; gap: 18px; }
.detail-body h4 { margin: 0 0 8px; font-size: 13px; font-weight: 400; color: var(--muted); }
.detail-body .synopsis { margin: 0; white-space: pre-line; line-height: 1.65; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detail-actions .btn.primary { grid-column: 1 / -1; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 92px); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 600;
  padding: 10px 18px; border-radius: 99px; box-shadow: var(--shadow);
  transition: opacity .25s, transform .25s; max-width: calc(100vw - 40px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
