/* ============ Prisme : jetons de design ============ */
:root {
  --font-display: "Bricolage Grotesque", "Figtree", system-ui, sans-serif;
  --font-body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --radius-s: 8px; --radius-m: 12px; --radius-l: 20px;
  --side-w: 308px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}
[data-theme="dark"] {
  --bg: #13152E; --bg-2: #181B39; --panel: #1C1F41; --raise: #242852;
  --line: #2C305C; --line-2: #3A3F72;
  --text: #ECEAF7; --muted: #A3A5C8; --faint: #6F729C;
  --accent: #ECEAF7; --accent-ink: #13152E;
  --c-audio: #6FD6C3; --c-video: #F4A261; --c-image: #C8A2F7; --c-text: #84A9FF;
  --danger: #FF8A8A; --shadow: 0 18px 50px -20px rgba(4, 5, 20, .7);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #F4F4FA; --bg-2: #EEEEF7; --panel: #FFFFFF; --raise: #F1F1F9;
  --line: #E1E2EE; --line-2: #CFD1E3;
  --text: #1B1D3A; --muted: #5C5F86; --faint: #9092B3;
  --accent: #1B1D3A; --accent-ink: #FFFFFF;
  --c-audio: #10917D; --c-video: #C8661A; --c-image: #8A4FD6; --c-text: #3563E0;
  --danger: #C8323C; --shadow: 0 18px 50px -24px rgba(27, 29, 58, .28);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 400 15.5px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top, 0px);
}
button, select, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--c-text); outline-offset: 2px; border-radius: 6px; }
code { font-family: var(--font-mono); font-size: .88em; background: var(--raise); padding: .1em .35em; border-radius: 5px; }

.shell { display: grid; grid-template-columns: var(--side-w) 1fr; height: 100%; }

/* ============ Panneau latéral ============ */
.side {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--bg-2); border-right: 1px solid var(--line);
  padding: 18px 16px calc(14px + env(safe-area-inset-bottom, 0px)); min-height: 0; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 4px 14px; }
.brand-mark { width: 38px; height: 26px; color: var(--text); }
.brand-name { font: 700 22px/1 var(--font-display); letter-spacing: -.02em; }
.brand .icon-btn { margin-left: auto; }

.side-block { padding: 6px 2px 14px; }
.side-block.grow { flex: 1; }
.side-title { font: 650 15px/1.3 var(--font-display); margin: 6px 4px 10px; display: flex; gap: 8px; align-items: baseline; }
.count { color: var(--faint); font: 500 13px var(--font-body); }

.drop {
  display: grid; justify-items: center; gap: 4px; text-align: center;
  padding: 20px 14px; border: 1.5px dashed var(--line-2); border-radius: var(--radius-m);
  background: var(--panel); cursor: pointer; transition: border-color .2s, background .2s;
}
.drop:hover, .drop.over { border-color: var(--c-text); background: var(--raise); }
.drop-icon { width: 22px; height: 22px; color: var(--muted); margin-bottom: 2px; }
.drop-title { font-weight: 600; }
.drop-hint { color: var(--muted); font-size: 13px; line-height: 1.4; }

.field-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 12px 4px 0; font-size: 13px; color: var(--muted); }
.field-row select, .select-wrap select {
  appearance: none; background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center / 14px;
  border: 1px solid var(--line); border-radius: var(--radius-s); padding: 5px 28px 5px 10px; font-size: 13px;
}

.jobs { display: grid; gap: 8px; margin-top: 12px; }
.job { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px 12px; font-size: 13px; }
.job-head { display: flex; justify-content: space-between; gap: 8px; }
.job-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-pct { color: var(--muted); font-variant-numeric: tabular-nums; }
.job-stage { color: var(--muted); margin: 2px 0 8px; }
.bar { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: inherit; transition: width .5s var(--ease);
  background: linear-gradient(90deg, var(--c-audio), var(--c-video), var(--c-image), var(--c-text)); }
.job.done .bar > i { background: var(--c-audio); }
.job-err { color: var(--danger); margin-top: 6px; }

.modalities { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 2px; }
.modalities li { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--radius-s); color: var(--muted); font-size: 14px; }
.modalities li i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.modalities li b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
[data-type="AUDIO"] { --c: var(--c-audio); } [data-type="VIDEO"] { --c: var(--c-video); }
[data-type="IMAGE"] { --c: var(--c-image); } [data-type="TEXT"] { --c: var(--c-text); }

.files { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.files li { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: var(--radius-s); font-size: 13.5px; }
.files li:hover { background: var(--panel); }
.files .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files .ftypes { display: flex; gap: 3px; }
.files .ftypes i { width: 7px; height: 7px; border-radius: 2px; background: var(--c); }
.files .fcount { color: var(--faint); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.empty-files { color: var(--faint); font-size: 13.5px; margin: 0 8px; }

.side-foot .text-btn { white-space: nowrap; padding-left: 6px; }
.side-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.models { color: var(--faint); font-size: 11.5px; text-align: right; line-height: 1.35; }

/* ============ Boutons ============ */
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--raise); color: var(--text); }
.text-btn { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--muted); padding: 6px 10px; border-radius: var(--radius-s); font-size: 13.5px; }
.text-btn:hover { background: var(--raise); color: var(--text); }
.text-btn.danger:hover { color: var(--danger); }
.only-mobile { display: none; }

/* ============ Zone principale ============ */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.top { display: flex; align-items: center; gap: 8px; padding: 10px 16px; }
.top-right { margin-left: auto; }
[data-theme="dark"] .sun, [data-theme="light"] .moon { display: none; }
.banner { margin: 0 auto 8px; max-width: 760px; width: calc(100% - 32px); padding: 10px 14px; border-radius: var(--radius-s);
  background: color-mix(in srgb, var(--danger) 12%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); font-size: 14px; }

.scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.thread { max-width: 780px; margin: 0 auto; padding: 8px 24px 40px; }

/* Accueil */
.hero { padding: 7vh 0 20px; }
.hero-prism { width: min(100%, 520px); height: auto; color: var(--text); overflow: visible; }
.prism-body { fill: color-mix(in srgb, var(--text) 5%, transparent); stroke: var(--text); stroke-width: 2.2; stroke-linejoin: round; }
.ray { stroke-width: 3; stroke-linecap: round; stroke-dasharray: 320; stroke-dashoffset: 320; animation: ray 1.4s var(--ease) forwards; }
.r-audio { stroke: var(--c-audio); } .r-video { stroke: var(--c-video); animation-delay: .12s; }
.r-image { stroke: var(--c-image); animation-delay: .24s; } .r-text { stroke: var(--c-text); animation-delay: .36s; }
@keyframes ray { to { stroke-dashoffset: 0; } }
.hero h1 { font: 700 clamp(30px, 4.6vw, 46px)/1.08 var(--font-display); letter-spacing: -.03em; margin: 22px 0 12px; max-width: 16ch; }
.hero-sub { color: var(--muted); font-size: 16.5px; max-width: 56ch; margin: 0 0 26px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; }
.suggestions button { border: 1px solid var(--line-2); background: transparent; border-radius: 999px; padding: 8px 14px; font-size: 14px; color: var(--text); transition: background .15s, border-color .15s; }
.suggestions button:hover { background: var(--raise); border-color: var(--faint); }

/* Messages */
.msg { margin: 26px 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { max-width: 85%; background: var(--raise); border: 1px solid var(--line); padding: 10px 16px; border-radius: 18px 18px 6px 18px; white-space: pre-wrap; overflow-wrap: anywhere; }

.status { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.spectrum { width: 22px; height: 3px; border-radius: 3px; flex: none;
  background: linear-gradient(90deg, var(--c-audio), var(--c-video), var(--c-image), var(--c-text), var(--c-audio));
  background-size: 200% 100%; animation: sweep 1.6s linear infinite; }
@keyframes sweep { to { background-position: -200% 0; } }

/* Raisonnement */
.thinking { margin: 4px 0 14px; }
.thinking-head { display: inline-flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 4px 8px 4px 0; color: var(--muted); font-size: 14px; border-radius: var(--radius-s); }
.thinking-head:hover { color: var(--text); }
.thinking-time { font-variant-numeric: tabular-nums; color: var(--faint); }
.thinking-head .chev { width: 15px; height: 15px; transition: transform .2s var(--ease); }
.thinking-head[aria-expanded="false"] .chev { transform: rotate(-90deg); }
.thinking.done .spectrum { animation: none; background: var(--line-2); }
.thinking-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .3s var(--ease); }
.thinking-head[aria-expanded="false"] + .thinking-body { grid-template-rows: 0fr; }
.thinking-head[aria-expanded="false"] + .thinking-body .thinking-text { padding-block: 0; border-color: transparent; }
.thinking-text {
  overflow: hidden; min-height: 0; margin-left: 10px; padding: 2px 0 2px 20px; border-left: 2px solid var(--line-2);
  font: 400 13px/1.65 var(--font-mono); color: var(--muted); opacity: .92; white-space: pre-wrap; overflow-wrap: anywhere;
}
.thinking.live .thinking-text { max-height: 200px; overflow-y: auto; scrollbar-width: none; }
.thinking.live .thinking-text.clip {
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 36px); mask-image: linear-gradient(to bottom, transparent, #000 36px); }
.thinking.done .thinking-text { max-height: 420px; overflow-y: auto; }

/* Réponse (Markdown) */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md p, .md ul, .md ol { margin: 0 0 .85em; }
.md h1, .md h2, .md h3 { font-family: var(--font-display); letter-spacing: -.015em; line-height: 1.25; margin: 1.3em 0 .5em; }
.md h1 { font-size: 1.4em; } .md h2 { font-size: 1.22em; } .md h3 { font-size: 1.06em; }
.md li { margin: .2em 0; }
.md strong { font-weight: 600; }
.md a { color: var(--c-text); }
.md pre { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 12px 14px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0 0 .85em; padding-left: 14px; border-left: 3px solid var(--line-2); color: var(--muted); }
.md .table-wrap { overflow-x: auto; margin: 0 0 1em; }
.md table { border-collapse: collapse; font-size: 14px; min-width: 60%; }
.md th, .md td { text-align: left; padding: 7px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.md th { font-weight: 600; color: var(--muted); }
.answer.streaming > :last-child::after { content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 3px; vertical-align: -2px; background: var(--text); border-radius: 1px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.error { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); border-radius: var(--radius-s); padding: 10px 14px; }

/* Citations */
.cite { display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; margin: 0 1px; vertical-align: 2px;
  border: 0; border-radius: 6px; font: 600 11px/1 var(--font-body); color: var(--accent-ink); background: var(--c, var(--muted)); }
.cite:hover { filter: brightness(1.1); }

/* Sources */
.sources { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.sources summary { list-style: none; display: flex; align-items: center; gap: 10px; cursor: pointer; color: var(--muted); font-size: 14px; padding: 4px 0; width: fit-content; }
.sources summary::-webkit-details-marker { display: none; }
.sources summary:hover { color: var(--text); }
.sources-dots { display: flex; gap: 3px; }
.sources-dots i { width: 8px; height: 8px; border-radius: 2px; background: var(--c); }
.source-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.source { border-radius: var(--radius-s); transition: background .3s; }
.source.flash { background: color-mix(in srgb, var(--c) 16%, transparent); }
.source button { all: unset; box-sizing: border-box; cursor: pointer; display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; width: 100%; padding: 8px 10px; border-radius: var(--radius-s); }
.source button:hover { background: var(--raise); }
.source button:focus-visible { outline: 2px solid var(--c-text); }
.source .num { display: grid; place-items: center; height: 20px; border-radius: 6px; font: 600 11px/1 var(--font-body); color: var(--accent-ink); background: var(--c); }
.source .ref { min-width: 0; font-size: 14px; }
.source .ref small { display: block; color: var(--faint); font-size: 12.5px; }
.source .ref span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source .score { width: 52px; height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.source .score i { display: block; height: 100%; background: var(--c); }
.source .excerpt { display: none; margin: 0 10px 10px 42px; font-size: 13.5px; color: var(--muted); white-space: pre-wrap; line-height: 1.55; }
.source.open .excerpt { display: block; }

.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; margin-top: 12px; color: var(--faint); font-size: 12.5px; }
.meta .copy { margin-left: auto; font-size: 12.5px; padding: 4px 8px; }

/* ============ Zone de saisie ============ */
.composer { padding: 6px 24px calc(10px + env(safe-area-inset-bottom, 0px)); }
.composer-box { max-width: 732px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius-l); box-shadow: var(--shadow); transition: border-color .2s; }
.composer-box:focus-within { border-color: var(--faint); }
.composer textarea { display: block; width: 100%; resize: none; border: 0; background: transparent; padding: 16px 18px 6px; max-height: 220px; font-size: 15.5px; line-height: 1.5; }
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--faint); }
.composer-bar { display: flex; align-items: center; gap: 8px; padding: 6px 8px 8px 12px; }
.controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; flex: 1; min-width: 0; }
.select-wrap select { background-color: transparent; border-color: var(--line); color: var(--muted); }
.select-wrap select:hover { color: var(--text); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); padding: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); font-size: 12.5px; padding: 3px 9px; border-radius: 6px; }
.seg button[aria-checked="true"] { background: var(--raise); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.send { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-ink); flex: none; transition: opacity .15s; }
.send:disabled { opacity: .35; cursor: default; }
.send svg { width: 19px; height: 19px; stroke-width: 2.2; }
.send .i-stop { display: none; fill: currentColor; stroke: none; }
.busy .send .i-send { display: none; } .busy .send .i-stop { display: block; }
.composer-note { text-align: center; color: var(--faint); font-size: 12px; margin: 8px 0 0; }

/* ============ Mobile ============ */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(86vw, 340px); z-index: 20; transform: translateX(-102%); transition: transform .28s var(--ease); box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(8, 9, 25, .5); z-index: 15; }
  .only-mobile { display: grid; }
  .text-btn.only-mobile { display: inline-flex; }
  .thread { padding: 4px 16px 32px; }
  .composer { padding-left: 12px; padding-right: 12px; }
  .hero { padding-top: 3vh; }
  .composer-note { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .ray { stroke-dashoffset: 0; }
}
