/* Retrouv'IA — styles (mobile d'abord, thème clair/sombre automatique) */
:root {
  color-scheme: dark;
  --bg: #0d0d11;
  --bg-2: #13131a;
  --surface: #18181f;
  --surface-2: #22222b;
  --border: #2c2c37;
  --text: #f5f2ed;
  --muted: #a6a2ae;
  --faint: #72707c;
  --accent: #ff6b4a;
  --accent-2: #ffb547;
  --on-accent: #1a0d08;
  --grad: linear-gradient(135deg, #ff6b4a 0%, #ff8d3f 55%, #ffb547 100%);
  --ok: #3ddc97;
  --warn: #ffc94d;
  --err: #ff5c6c;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  --glow: rgba(255, 107, 74, 0.14);
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f7f4ef;
    --bg-2: #fbf9f6;
    --surface: #ffffff;
    --surface-2: #f2eee8;
    --border: #e6e0d7;
    --text: #1b1a1f;
    --muted: #67636e;
    --faint: #98949f;
    --accent: #e9532f;
    --accent-2: #f39c12;
    --shadow: 0 18px 50px rgba(60, 40, 20, 0.16);
    --glow: rgba(233, 83, 47, 0.1);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background: radial-gradient(1100px 520px at 50% -260px, var(--glow), transparent 70%), var(--bg);
  background-attachment: fixed;
  font: 16px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { letter-spacing: -0.02em; line-height: 1.15; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i.xs { width: 12px; height: 12px; }

/* ---------- Structure ---------- */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 860px; margin: 0 auto; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; min-width: 0; }
.brand img { border-radius: 10px; }
.brand span { display: grid; min-width: 0; }
.brand strong { font-size: 17px; letter-spacing: -0.01em; }
.brand small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.status-chip {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 14px; font-weight: 600;
}
.status-chip:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.busy { background: var(--accent-2); animation: pulse 1.2s ease-in-out infinite; }

/* ---------- Progression ---------- */
.progress {
  margin: 10px 16px 0; padding: 12px 14px; display: grid; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
}
.progress-head { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.progress-head strong { flex: 1; min-width: 0; }
.progress-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.progress.alert { border-color: color-mix(in srgb, var(--warn) 55%, var(--border)); }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--grad); border-radius: inherit; transition: width 0.4s ease; }
.link { background: none; border: 0; padding: 4px 2px; color: var(--accent); font-weight: 600; font-size: 14px; }

/* ---------- Chat ---------- */
.chat { position: relative; flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 8px 16px 24px; }

.welcome { display: grid; gap: 18px; padding: 28px 0 8px; animation: rise 0.4s ease-out; }
.hero-badge {
  justify-self: start; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
}
.hero-badge .i { width: 16px; height: 16px; }
.welcome h1 { font-size: clamp(30px, 7.4vw, 46px); font-weight: 800; }
.lead { margin: 0; color: var(--muted); font-size: 17px; max-width: 560px; }
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.feature {
  display: grid; gap: 2px; padding: 12px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--border);
}
.feature .i { color: var(--accent); margin-bottom: 4px; }
.feature b { font-size: 14px; }
.feature small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.examples { display: grid; gap: 8px; margin-top: 4px; }
.examples-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); }
.example {
  text-align: left; padding: 11px 14px; border-radius: 14px;
  background: transparent; border: 1px dashed var(--border); color: var(--muted); font-size: 15px;
}
.example:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }

.msg { display: flex; gap: 10px; margin: 16px 0; animation: rise 0.25s ease-out; }
.msg.user { justify-content: flex-end; }
.bubble { padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user .bubble {
  max-width: 82%; background: var(--grad); color: var(--on-accent); font-weight: 500;
  border-radius: 18px 18px 4px 18px;
}
.msg.bot .bubble {
  justify-self: start; max-width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px 18px 18px 4px;
}
.avatar { width: 32px; height: 32px; flex: none; border-radius: 10px; overflow: hidden; }
.avatar img { width: 100%; height: 100%; display: block; }
.msg-body { flex: 1; min-width: 0; display: grid; gap: 10px; justify-items: start; }
.msg-body > .results { justify-self: stretch; }

.typing { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: blink 1.2s infinite both; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }

/* ---------- Résultats ---------- */
.results { display: grid; gap: 12px; }
@media (min-width: 640px) {
  .results.multi { grid-template-columns: 1fr 1fr; }
  .results.multi .card.primary { grid-column: 1 / -1; }
}
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card.primary { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent); }
.card .media { display: block; width: 100%; max-height: 440px; object-fit: contain; background: #000; }
.card img.media { cursor: zoom-in; }
.card .media.missing { position: relative; display: grid; place-items: center; min-height: 160px; }
.card .media.missing img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0.55; }
.card .media.missing .btn { position: relative; }
.card-body { padding: 12px 14px 14px; display: grid; gap: 8px; }
.card-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.card-title .name { font-weight: 700; overflow-wrap: anywhere; }
.card-title .meta, .meta { color: var(--muted); font-size: 13px; }
.best { justify-self: start; font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.reason { margin: 0; color: var(--muted); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); font-size: 13px; font-weight: 600;
}
.chip .i { width: 14px; height: 14px; }
.chip.accent { background: var(--grad); color: var(--on-accent); border-color: transparent; }

/* ---------- Saisie ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 92%, transparent);
}
.composer textarea {
  flex: 1; min-width: 0; resize: none; max-height: 140px; min-height: 46px;
  padding: 11px 14px; border-radius: 16px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; line-height: 1.45; outline: none;
}
.composer textarea:focus { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }
.icon-btn {
  width: 46px; height: 46px; flex: none; display: grid; place-items: center; padding: 0;
  border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.icon-btn:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.icon-btn.send { background: var(--grad); color: var(--on-accent); border: 0; }
.icon-btn.send:disabled { opacity: 0.5; cursor: default; }
.icon-btn.rec { background: var(--err); color: #fff; border-color: transparent; animation: pulse 1.2s infinite; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 12px 18px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 650; font-size: 15px; text-align: center;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.btn.primary { background: var(--grad); color: var(--on-accent); border: 0; box-shadow: 0 10px 28px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.danger { color: var(--err); }
.btn.lg { min-height: 56px; font-size: 17px; border-radius: 16px; }
.btn.sm { min-height: 38px; padding: 8px 14px; font-size: 14px; border-radius: 12px; }
.btn .i { width: 18px; height: 18px; }

/* ---------- Feuilles (modales) ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(5, 5, 8, 0.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade 0.2s ease-out;
}
.backdrop.top { z-index: 60; }
.sheet {
  width: 100%; max-width: 520px; max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--border); border-bottom: 0; border-radius: 26px 26px 0 0;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom)); box-shadow: var(--shadow);
  animation: up 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.wide { max-width: 860px; }
@media (min-width: 720px) {
  .backdrop { align-items: center; padding: 24px; }
  .sheet { border-radius: 26px; border-bottom: 1px solid var(--border); padding-bottom: 22px; }
}
.sheet h2 { font-size: 24px; margin-bottom: 8px; }
.sheet > p { margin: 0 0 14px; }
.sheet-art { position: relative; height: 110px; display: grid; place-items: center; margin-bottom: 14px; }
.sheet-art img { position: relative; border-radius: 18px; box-shadow: 0 12px 30px color-mix(in srgb, var(--accent) 35%, transparent); }
.tile-art { position: absolute; width: 64px; height: 76px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); }
.tile-art.a { transform: translateX(-64px) rotate(-12deg); background: linear-gradient(160deg, #3a7bd5, #2c3e70); }
.tile-art.b { transform: translateX(64px) rotate(12deg); background: linear-gradient(160deg, #f6b26b, #c8553d); }
.tile-art.c { transform: translateY(-6px) scale(0.92); background: linear-gradient(160deg, #57c785, #2a7b5f); opacity: 0.8; }
.facts { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 10px; }
.facts li { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); font-size: 14px; color: var(--muted); }
.facts li b { color: var(--text); }
.facts .i { color: var(--accent); margin-top: 1px; }
.sheet-actions { display: grid; gap: 8px; }
.fineprint { margin: 14px 0 0; font-size: 12px; color: var(--faint); text-align: center; }
.pick-tip { margin: 0; font-size: 13px; line-height: 1.45; color: var(--muted); max-width: 46ch; }
.welcome > .pick-tip { margin: -8px auto 0; text-align: center; }
.sheet-toolbar + .pick-tip { margin: -4px 0 14px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-head h2 { margin-bottom: 2px; }
.sheet-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

/* ---------- Grille de la galerie ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.tile { position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); }
.tile-badge {
  position: absolute; left: 6px; bottom: 6px; display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 6px; border-radius: 6px; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 11px; font-weight: 700;
}
.tile-badge .i { fill: currentColor; stroke: none; }
.tile-state {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 800; color: #fff; background: rgba(0, 0, 0, 0.55);
}
.tile-state.err { background: var(--err); }
.tile-state.spin { border: 3px solid rgba(255, 255, 255, 0.35); border-top-color: #fff; background: transparent; animation: spin 0.8s linear infinite; }
.tile.pending img, .tile.analyzing img { filter: saturate(0.4) brightness(0.75); }
.empty { text-align: center; padding: 24px 0; }

/* ---------- Détails ---------- */
.details { display: grid; gap: 14px; }
.details-media { width: 100%; max-height: 60vh; object-fit: contain; background: #000; border-radius: 14px; display: block; }
.details h3 { font-size: 20px; overflow-wrap: anywhere; }
.details section { display: grid; gap: 6px; }
.details section h4 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); }
.details section p { margin: 0; white-space: pre-wrap; }
.passage { display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.passage .ts { flex: none; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); }
.notice { padding: 10px 12px; border-radius: 12px; font-size: 14px; background: color-mix(in srgb, var(--warn) 14%, transparent); }
.notice.err { background: color-mix(in srgb, var(--err) 15%, transparent); }

/* ---------- Divers ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 80; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
  animation: rise 0.2s ease-out;
}
.dropzone {
  position: fixed; inset: 12px; z-index: 90; display: grid; place-items: center; pointer-events: none;
  border: 2px dashed var(--accent); border-radius: 24px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  font-size: 20px; font-weight: 700;
}
.dropzone div { display: flex; align-items: center; gap: 10px; }
.offscreen { position: fixed; left: 0; top: 0; width: 2px; height: 2px; opacity: 0; pointer-events: none; z-index: -1; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.45; } }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

@media (max-width: 420px) {
  .features { grid-template-columns: 1fr; }
  .feature { grid-template-columns: auto 1fr; column-gap: 10px; align-items: center; }
  .feature .i { grid-row: span 2; margin: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
