/* HTag — charte H3Campus : bleu marine #123C5B, orange #FA8334, jaune crème #FCFDAF, bleu ciel #1394DB.
   Titres : Fraunces (substitut libre de Recoleta, utilisée sur h3campus.fr) · Texte : Karla. */

:root {
  --navy: #123C5B;
  --navy-2: #1B527A;
  --navy-3: #0C2A41;
  --orange: #FA8334;
  --orange-2: #E86E1C;
  --orange-soft: #FFE9D9;
  --on-orange: #0C2A41;       /* texte sur orange : 5,9:1 (blanc sur orange n'atteint que 2,5:1) */
  --cream: #FCFDAF;
  --cream-soft: #FEFEE8;
  --sky: #1394DB;
  --sky-soft: #E3F3FC;
  --sky-text: #0E6FA6;        /* bleu ciel lisible sur fond clair (contraste AA) */
  --orange-text: #B4500F;     /* orange lisible sur fond clair (contraste AA) */

  --bg: #F7F5EF;
  --surface: #FFFFFF;
  --surface-2: #FBFAF6;
  --text: #1C2833;
  --muted: #5E6B78;
  --border: #E5E1D6;
  --user-bg: var(--navy);
  --user-text: #FFFFFF;
  --code-bg: #F2F0E8;
  --shadow: 0 1px 2px rgba(18, 60, 91, .06), 0 8px 24px rgba(18, 60, 91, .07);
  --shadow-lg: 0 24px 64px rgba(12, 42, 65, .22);
  --ok: #1E9E6A;
  --danger: #D6453D;

  --font-display: "Fraunces", "Recoleta", Georgia, serif;
  --font-body: "Karla", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "JetBrains Mono", "Cascadia Code", Menlo, monospace;
  --radius: 18px;
  --sidebar: 288px;
  --panel: 400px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1C28; --surface: #142838; --surface-2: #112333; --text: #E7EDF2; --muted: #9AABB9;
    --border: #23394B; --code-bg: #0B1822; --user-bg: #1E5A86; --orange-soft: #3A2616;
    --sky-soft: #10324A; --cream-soft: #1B2A2A; --sky-text: #6FC3F0; --orange-text: #FFB27A; --sky-text: #6FC3F0; --orange-text: #FFB27A; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1C28; --surface: #142838; --surface-2: #112333; --text: #E7EDF2; --muted: #9AABB9;
  --border: #23394B; --code-bg: #0B1822; --user-bg: #1E5A86; --orange-soft: #3A2616;
  --sky-soft: #10324A; --cream-soft: #1B2A2A; --sky-text: #6FC3F0; --orange-text: #FFB27A; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.6 var(--font-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
a { color: var(--sky-text); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--orange) 60%, transparent); outline-offset: 2px; border-radius: 8px; }

/* ---------- mise en page ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr 0; height: 100dvh; overflow: hidden; transition: grid-template-columns .25s ease; }
.app.show-sources { grid-template-columns: var(--sidebar) 1fr var(--panel); }
.scrim { display: none; }

/* ---------- barre latérale ---------- */
.sidebar {
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-3) 100%);
  color: #E9F0F6; display: flex; flex-direction: column; padding: 20px 16px 16px; gap: 18px; min-width: 0;
  position: relative; overflow: hidden;
}
.sidebar::after { /* touche crème discrète, comme les aplats du site */
  content: ""; position: absolute; width: 260px; height: 260px; border-radius: 50%;
  background: radial-gradient(circle, rgba(252,253,175,.10), transparent 70%); right: -120px; top: -110px; pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px; }
.brand-logo { filter: drop-shadow(0 4px 10px rgba(0,0,0,.25)); background: #fff; border-radius: 14px; padding: 3px; }
.brand-name { font: 700 26px/1 var(--font-display); letter-spacing: -.01em; color: #fff; }
.brand-sub { font-size: 12.5px; color: #B7C8D6; margin-top: 3px; }
.brand-sub strong { color: var(--cream); font-weight: 600; }

.btn-new {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--orange); color: var(--on-orange); border: 0; border-radius: 999px; padding: 11px 16px; font-weight: 700;
  box-shadow: 0 6px 18px rgba(250,131,52,.35); transition: transform .15s, background .15s;
}
.btn-new:hover { background: var(--orange-2); color: var(--on-orange); transform: translateY(-1px); }

.history { flex: 1; overflow-y: auto; margin: 0 -6px; padding: 0 6px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent; }
.history h3 { font: 600 11px/1 var(--font-body); text-transform: uppercase; letter-spacing: .09em; color: #8FA7BA; margin: 16px 10px 8px; }
.conv { display: flex; align-items: center; gap: 6px; border-radius: 12px; padding: 0 4px 0 12px; color: #D9E4EC; }
.conv button.open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 9px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14.5px; }
.conv .del { opacity: 0; background: none; border: 0; color: #9FB3C3; padding: 6px; border-radius: 8px; }
.conv .del svg { width: 16px; height: 16px; }
.conv:hover { background: rgba(255,255,255,.07); }
.conv:hover .del, .conv:focus-within .del { opacity: 1; }
@media (hover: none) { .conv .del { opacity: .7; } }
.conv .del:hover { color: #fff; background: rgba(255,255,255,.1); }
.conv.active { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 var(--orange); }
.history .none { font-size: 13.5px; color: #8FA7BA; padding: 8px 10px; }

.side-footer { display: grid; gap: 12px; }
.index-card { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08); border-radius: 14px; padding: 12px 14px; font-size: 13px; }
.index-row { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(30,158,106,.25); }
.dot.busy { background: var(--orange); box-shadow: 0 0 0 3px rgba(250,131,52,.3); animation: pulse 1.2s infinite; }
.dot.off { background: #8FA7BA; box-shadow: none; }
.index-figures { color: #A9BCCB; margin-top: 4px; }
.side-actions { display: flex; gap: 8px; }
.icon-btn { display: inline-flex; align-items: center; gap: 8px; background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: 12px; padding: 8px 10px; transition: background .15s, border-color .15s; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.light { border-color: rgba(255,255,255,.14); color: #E9F0F6; }
.icon-btn.light:hover { background: rgba(255,255,255,.08); }
.side-actions .icon-btn:first-child { flex: 1; justify-content: center; }
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; } :root[data-theme="dark"] .i-moon { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .i-sun { display: block; } :root:not([data-theme="light"]) .i-moon { display: none; } }

/* ---------- zone principale ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); position: relative; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px); }
.topbar .menu { display: none; }
.conv-title { flex: 1; min-width: 0; margin: 0; font: 600 19px/1.2 var(--font-display); color: var(--navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
:root[data-theme="dark"] .conv-title { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .conv-title { color: #fff; } }

.mode-switch { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px; gap: 2px; box-shadow: var(--shadow); }
.mode-switch button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 7px 14px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--muted); transition: all .2s; }
.mode-switch button svg { width: 16px; height: 16px; }
.mode-switch button[aria-checked="true"] { background: var(--navy); color: #fff; }
.mode-switch button[data-mode="cloud"][aria-checked="true"] { background: var(--orange); color: var(--on-orange); }
.mode-switch button:disabled { opacity: .45; cursor: not-allowed; }

.thread { flex: 1; overflow-y: auto; padding: 32px 24px 12px; scroll-behavior: smooth; }
.messages { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }

/* écran d'accueil */
.welcome { max-width: 760px; margin: 6vh auto 0; text-align: center; animation: rise .5s ease both; }
.welcome[hidden] { display: none; }
.welcome-logo { filter: drop-shadow(0 12px 24px rgba(18,60,91,.18)); animation: float 5s ease-in-out infinite; }
.welcome h2 { font: 600 clamp(30px, 4.4vw, 44px)/1.15 var(--font-display); color: var(--navy); margin: 18px 0 10px; letter-spacing: -.015em; }
:root[data-theme="dark"] .welcome h2 { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .welcome h2 { color: #fff; } }
.accent { background: linear-gradient(transparent 62%, var(--cream) 62%, var(--cream) 92%, transparent 92%); padding: 0 4px; color: var(--navy); }
:root[data-theme="dark"] .accent { background: var(--cream); border-radius: 6px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .accent { background: var(--cream); border-radius: 6px; } }
.lead { font-size: 17.5px; color: var(--muted); max-width: 600px; margin: 0 auto 30px; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; text-align: left; }
.suggestion { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); transition: transform .15s, border-color .15s; text-align: left; }
.suggestion:hover { transform: translateY(-2px); border-color: var(--orange); }
.suggestion .ico { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--orange-soft); color: var(--orange-text); flex: none; }
.suggestion .ico.pdf { background: var(--sky-soft); color: var(--sky-text); }
.suggestion .ico svg { width: 18px; height: 18px; }
.suggestion b { display: block; font-weight: 600; font-size: 14.5px; line-height: 1.35; }
.suggestion small { color: var(--muted); font-size: 12.5px; }

/* messages */
.msg { display: flex; gap: 12px; animation: rise .3s ease both; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--user-bg); color: var(--user-text); border-radius: 20px 20px 6px 20px; padding: 12px 18px; max-width: 78%; white-space: pre-wrap; box-shadow: var(--shadow); }
.msg.assistant .avatar { flex: none; margin-top: 2px; }
.msg.assistant .bubble { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 6px 20px 20px 20px; padding: 16px 20px 10px; box-shadow: var(--shadow); }
.msg.error .bubble { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.content { overflow-wrap: anywhere; }
.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 4px; }
.content h1, .content h2, .content h3, .content h4 { font-family: var(--font-display); color: var(--navy); line-height: 1.25; margin: 1.1em 0 .4em; }
:root[data-theme="dark"] .content :is(h1,h2,h3,h4) { color: var(--cream); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .content :is(h1,h2,h3,h4) { color: var(--cream); } }
.content h1 { font-size: 1.35em; } .content h2 { font-size: 1.2em; } .content h3, .content h4 { font-size: 1.05em; }
.content p { margin: .55em 0; }
.content ul, .content ol { padding-left: 1.35em; margin: .5em 0; }
.content li { margin: .2em 0; }
.content li::marker { color: var(--orange); }
.content code { font: .88em var(--font-mono); background: var(--code-bg); border-radius: 6px; padding: .12em .4em; }
.content pre { border: 1px solid color-mix(in srgb, var(--border) 60%, transparent); background: var(--navy-3); color: #E6EEF5; border-radius: 12px; padding: 14px 16px; overflow-x: auto; position: relative; margin: .8em 0; }
.content pre code { background: none; padding: 0; color: inherit; font-size: .86em; line-height: 1.55; }
.content pre .copy-code { position: absolute; top: 8px; right: 8px; font-size: 12px; background: rgba(255,255,255,.1); color: #fff; border: 0; border-radius: 8px; padding: 3px 9px; opacity: 0; transition: opacity .15s; }
.content pre:hover .copy-code { opacity: 1; }
.content blockquote { border-left: 3px solid var(--orange); margin: .7em 0; padding: .2em 0 .2em 1em; color: var(--muted); }
.content table { border-collapse: collapse; width: 100%; font-size: .93em; margin: .8em 0; display: block; overflow-x: auto; }
.content th, .content td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.content th { background: var(--surface-2); }
.content strong { color: var(--navy); }
:root[data-theme="dark"] .content strong { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .content strong { color: #fff; } }

.cite {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; margin: 0 1px;
  border: 0; border-radius: 999px; background: var(--orange-soft); color: var(--orange-text);
  font: 700 11.5px/1 var(--font-body); vertical-align: 2px; transition: background .15s, color .15s;
}
.cite:hover, .cite.on { background: var(--orange); color: var(--on-orange); }

.cites { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.cites:empty { display: none; }
.cite-chip { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 4px 12px 4px 4px; font-size: 13px; color: var(--text); transition: border-color .15s; }
.cite-chip:hover { border-color: var(--orange); }
.cite-chip .n { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--navy); color: #fff; font-weight: 700; font-size: 11.5px; flex: none; }
.cite-chip .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }

.msg-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border); color: var(--muted); font-size: 12.5px; }
.msg-foot .actions { display: flex; gap: 2px; }
.mini { background: none; border: 0; color: var(--muted); padding: 5px; border-radius: 8px; }
.mini svg { width: 16px; height: 16px; }
.mini:hover { background: var(--surface-2); color: var(--text); }
.msg.streaming .msg-foot { visibility: hidden; }
.meta .badge { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--sky-soft); color: var(--sky-text); font-weight: 600; margin-right: 6px; }
.meta .badge.cloud { background: var(--orange-soft); color: var(--orange-text); }

.typing { display: inline-flex; gap: 5px; padding: 6px 0; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--orange); animation: blink 1.2s infinite ease-in-out both; }
.typing i:nth-child(2) { animation-delay: .15s; background: var(--navy-2); }
.typing i:nth-child(3) { animation-delay: .3s; background: var(--sky); }
.caret::after { content: ""; display: inline-block; width: 8px; height: 1em; background: var(--orange); margin-left: 2px; vertical-align: -2px; animation: blink 1s steps(2) infinite; border-radius: 2px; }

/* composer */
.composer { padding: 10px 24px 14px; }
.composer-box { max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px; background: var(--surface); border: 1.5px solid var(--border); border-radius: 24px; padding: 8px 8px 8px 20px; box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; }
.composer-box:focus-within { border-color: var(--navy-2); box-shadow: 0 0 0 4px color-mix(in srgb, var(--sky) 15%, transparent), var(--shadow); }
.composer textarea { flex: 1; border: 0; outline: 0; resize: none; background: transparent; padding: 9px 0; max-height: 220px; line-height: 1.5; }
.composer textarea::placeholder { color: var(--muted); }
.send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--orange); color: var(--on-orange); display: grid; place-items: center; transition: background .15s, transform .15s; flex: none; }
.send:hover { background: var(--orange-2); transform: scale(1.04); }
.send:disabled { background: color-mix(in srgb, var(--muted) 40%, var(--surface)); cursor: default; transform: none; }
.send .i-stop { display: none; }
.busy .send { background: var(--navy); color: #fff; }
.busy .send .i-stop { display: block; } .busy .send .i-send { display: none; }
.disclaimer { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 0; }

/* ---------- panneau des sources ---------- */
.app:not(.show-sources) .sources { visibility: hidden; }
.sources { background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.sources-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.sources-head h2 { margin: 0; font: 600 19px var(--font-display); }
.sources-list { overflow-y: auto; padding: 14px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-content: start; }
.sources-list .empty { color: var(--muted); font-size: 14px; padding: 8px; }
.source { min-width: 0; overflow-wrap: anywhere; border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; background: var(--surface-2); transition: border-color .2s, box-shadow .2s; scroll-margin: 14px; }
.source.on { border-color: var(--orange); box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 20%, transparent); }
.source-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.source .n { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--navy); color: #fff; font-weight: 700; font-size: 12px; flex: none; }
.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 2px 8px; border-radius: 999px; background: var(--orange-soft); color: var(--orange-text); }
.tag.pdf { background: var(--sky-soft); color: var(--sky-text); }
.source h3 { margin: 0; font: 600 15px/1.3 var(--font-body); }
.source .path { font-size: 12.5px; color: var(--muted); margin: 2px 0 8px; }
.source .excerpt { font-size: 13.5px; line-height: 1.55; color: var(--text); white-space: pre-line; max-height: 9.3em; overflow: hidden; position: relative; }
.source .excerpt.open { max-height: none; }
.source mark { background: var(--cream); color: var(--navy); border-radius: 3px; padding: 0 2px; }
.source-actions { display: flex; gap: 12px; margin-top: 8px; font-size: 13px; }
.source-actions a, .source-actions button { color: var(--sky-text); background: none; border: 0; padding: 0; font-weight: 600; text-decoration: none; }
.source-actions a:hover, .source-actions button:hover { text-decoration: underline; }

/* ---------- réglages ---------- */
.modal { border: 0; border-radius: 22px; padding: 0; width: min(860px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.modal::backdrop { background: rgba(12, 42, 65, .5); backdrop-filter: blur(3px); }
.modal[open] { display: flex; flex-direction: column; animation: rise .25s ease both; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 1px solid var(--border); background: linear-gradient(90deg, var(--navy), var(--navy-2)); color: #fff; }
.modal-head h2 { margin: 0; font: 600 22px var(--font-display); }
.modal-head .icon-btn { color: #fff; border-color: rgba(255,255,255,.25); }
.modal-head .icon-btn:hover { background: rgba(255,255,255,.1); }
#settingsBody { display: flex; flex-direction: column; min-height: 0; flex: 1; }
#settingsBody[hidden], .login[hidden] { display: none; }
#settingsForm { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.tabs { display: flex; gap: 4px; padding: 10px 20px 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { border: 0; background: none; padding: 10px 14px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--orange); }
.tab-panel { display: none; padding: 20px 24px; overflow-y: auto; }
.tab-panel.active { display: block; }
fieldset { border: 1px solid var(--border); border-radius: 16px; padding: 14px 18px 16px; margin: 0 0 16px; }
legend { display: flex; align-items: center; gap: 10px; padding: 0 6px; font: 600 16px var(--font-display); }
legend small { font: 400 13px var(--font-body); color: var(--muted); }
.field { display: grid; gap: 5px; margin: 10px 0; }
.field > span { font-size: 13.5px; font-weight: 600; color: var(--muted); }
.field input, .field select { width: 100%; border: 1.5px solid var(--border); background: var(--surface-2); border-radius: 11px; padding: 9px 12px; outline: 0; transition: border-color .15s; }
.field input:focus, .field select:focus { border-color: var(--navy-2); }
.field.inline { display: flex; align-items: center; gap: 8px; align-self: end; padding-bottom: 8px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > .field { min-width: 150px; }
.grow { flex: 1; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.hint code { background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: color-mix(in srgb, var(--muted) 45%, transparent); border-radius: 999px; transition: background .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--orange); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--orange) 50%, transparent); }

.chips-select { display: flex; flex-wrap: wrap; gap: 6px; max-height: 190px; overflow-y: auto; padding: 2px; }
.chips-select label { display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--border); border-radius: 999px; padding: 4px 12px; font-size: 13.5px; cursor: pointer; user-select: none; transition: all .15s; }
.chips-select label { position: relative; }
.chips-select input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.chips-select label:has(input:focus-visible) { outline: 3px solid color-mix(in srgb, var(--orange) 60%, transparent); outline-offset: 2px; }
.chips-select label:has(input:checked) { background: var(--navy); border-color: var(--navy); color: #fff; }
.chips-select em { color: var(--muted); font-size: 13.5px; }

.btn { border: 0; border-radius: 999px; padding: 10px 20px; font-weight: 700; transition: background .15s, transform .1s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--orange); color: var(--on-orange); }
.btn.primary:hover { background: var(--orange-2); }
.btn.ghost { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn.ghost:hover { border-color: var(--navy-2); }
.btn.small { padding: 6px 14px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.test-result { font-size: 13.5px; margin-left: 8px; }
.test-result.ok { color: var(--ok); } .test-result.ko { color: var(--danger); }
.modal-foot { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-top: 1px solid var(--border); background: var(--surface-2); }
.save-state { flex: 1; font-size: 13.5px; color: var(--muted); text-align: right; }
.login { padding: 28px; display: grid; gap: 10px; max-width: 420px; }
.form-error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; }
.stat b { display: block; font: 600 26px/1.1 var(--font-display); color: var(--navy); }
:root[data-theme="dark"] .stat b { color: var(--cream); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .stat b { color: var(--cream); } }
.stat span { font-size: 13px; color: var(--muted); }
.index-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 14px; }
.progress .bar { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress .bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--orange), var(--cream)); transition: width .3s; }
.progress-label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.log { background: var(--navy-3); color: #CFE0EC; border-radius: 12px; padding: 12px 14px; font: 12.5px/1.6 var(--font-mono); max-height: 220px; overflow: auto; white-space: pre-wrap; margin: 12px 0 0; }
.log:empty { display: none; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 2px solid var(--border); white-space: nowrap; }
.table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table td.q { max-width: 380px; }
.table .warn { color: var(--orange-2); font-weight: 600; }
.table .err { color: var(--danger); font-weight: 600; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: all .25s; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- animations ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: scale(.85); } 40% { opacity: 1; transform: scale(1); } }
@keyframes pulse { 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .app, .app.show-sources { grid-template-columns: var(--sidebar) 1fr; }
  .sources { position: fixed; right: 0; top: 0; bottom: 0; width: min(var(--panel), 100vw); z-index: 30; transform: translateX(100%); transition: transform .25s ease, visibility .25s; visibility: hidden; }
  .app.show-sources .sources { transform: none; visibility: visible; box-shadow: var(--shadow-lg); }
}
@media (max-width: 820px) {
  .app, .app.show-sources { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); z-index: 40; transform: translateX(-100%); transition: transform .25s ease, visibility .25s; visibility: hidden; }
  .app.show-menu .sidebar { transform: none; visibility: visible; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(12,42,65,.45); z-index: 35; opacity: 0; pointer-events: none; transition: opacity .25s; }
  .app.show-menu .scrim { opacity: 1; pointer-events: auto; }
  .topbar { padding: 10px 16px; gap: 8px; }
  .topbar .menu { display: inline-flex; }
  .mode-switch button span { display: none; }
  .mode-switch button { padding: 7px 10px; }
  .thread { padding: 20px 16px 8px; }
  .composer { padding: 8px 16px 12px; }
  .suggestions { grid-template-columns: 1fr; }
  .msg.user .bubble { max-width: 90%; }
  .msg.assistant .avatar { display: none; }
  .msg.assistant .bubble { padding: 14px 16px 8px; }
  .cite-chip .t { max-width: 180px; }
}

/* ---------- connexion / 2FA ---------- */
[hidden] { display: none !important; }
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 85% -10%, rgba(252,253,175,.16), transparent 60%),
              linear-gradient(160deg, var(--navy) 0%, var(--navy-3) 70%); }
.auth-card { width: min(440px, 100%); background: var(--surface); color: var(--text); border-radius: 24px; padding: 28px 28px 22px; box-shadow: var(--shadow-lg); animation: rise .35s ease both; }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.auth-name { font: 700 30px/1 var(--font-display); color: var(--navy); }
.auth-sub { font-size: 13.5px; color: var(--muted); margin-top: 4px; }
.auth-sub strong { color: var(--orange-2); }
.auth-step h1 { font: 600 22px/1.25 var(--font-display); margin: 6px 0 8px; }
.auth-help { font-size: 14px; color: var(--muted); margin: 0 0 10px; }
.auth-help.small { font-size: 12.5px; margin-top: 12px; }
.auth-steps { font-size: 14px; padding-left: 1.2em; margin: 0 0 8px; color: var(--text); }
.auth-steps li { margin: 4px 0; }
.code-input { font: 600 24px/1.2 var(--font-mono) !important; letter-spacing: .3em; text-align: center; }
.btn.wide { width: 100%; margin-top: 8px; padding: 12px 20px; }
.link { background: none; border: 0; color: var(--sky-text); font-weight: 600; padding: 8px 0 0; }
.link:hover { text-decoration: underline; }
.qr { display: grid; place-items: center; margin: 4px auto 10px; width: 220px; padding: 10px; background: #fff; border-radius: 16px; border: 1px solid var(--border); }
.qr img { display: block; width: 200px; height: 200px; image-rendering: pixelated; }
.manual { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.manual code { display: block; margin-top: 6px; word-break: break-all; font: 600 14px var(--font-mono); color: var(--text); background: var(--code-bg); padding: 8px 10px; border-radius: 8px; letter-spacing: .05em; }
.recovery { list-style: none; padding: 0; margin: 0 0 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.recovery li { font: 600 15px var(--font-mono); text-align: center; background: var(--cream-soft); border: 1px dashed var(--orange); border-radius: 10px; padding: 8px; color: var(--text); }
:root[data-theme="dark"] .auth-name { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .auth-name { color: #fff; } }

/* bloc utilisateur (barre latérale) */
.user-card { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 10px; border-radius: 14px; background: rgba(255,255,255,.06); }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--orange); color: var(--on-orange); font-weight: 700; flex: none; }
.user-info { flex: 1; min-width: 0; line-height: 1.2; }
.user-info b { display: block; color: #fff; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info small { color: #A9BCCB; font-size: 12px; }
.user-card .icon-btn { padding: 6px; border-color: transparent; }
.user-card .icon-btn svg { width: 18px; height: 18px; }

.modal.small { width: min(460px, calc(100vw - 32px)); }
.account-body { padding: 18px 24px 22px; display: grid; gap: 4px; }
.btn.gen { align-self: end; margin-bottom: 10px; }
.table .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.table .acts button { font-size: 12.5px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.table .acts button:hover { border-color: var(--navy-2); }
.table .acts button.danger:hover { border-color: var(--danger); color: var(--danger); }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 9px; border-radius: 999px; background: var(--sky-soft); color: var(--sky-text); }
.pill.admin { background: var(--orange-soft); color: var(--orange-text); }
.pill.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill.no { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }

/* ---- À propos ---- */
.side-actions #btnAbout { flex: 1; justify-content: center; }
.modal.about { width: min(960px, calc(100vw - 32px)); height: min(760px, calc(100dvh - 48px)); }
.about-head { align-items: flex-start; gap: 16px; padding: 20px 24px; }
.about-id { display: flex; gap: 18px; align-items: flex-start; min-width: 0; }
.about-id > div { min-width: 0; }
.about-id img { flex: none; background: rgba(255,255,255,.08); border-radius: 18px; padding: 6px; }
.about-id h2 { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.about-version { font: 600 13px var(--font-body); background: var(--orange); color: var(--on-orange); border-radius: 999px; padding: 2px 10px; }
.about-desc { margin: 6px 0 10px; color: #DCE6EE; font-size: 14.5px; line-height: 1.45; max-width: 62ch; }
.about-tags { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.about .tabs { padding: 10px 14px 0; }
.about .tab { padding: 10px 11px; }
.about-tags li { white-space: nowrap; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); color: #F2F6F9; }
.about-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.about-body .tab-panel.active { flex: 1; min-height: 0; }
.about-body h3 { font: 600 17px var(--font-display); color: var(--navy); margin: 18px 0 8px; }
.about-body h3:first-child { margin-top: 0; }
.about-list { margin: 0 0 6px; padding-left: 1.3em; line-height: 1.55; }
.about-list li { margin: 4px 0; }
.about-list li::marker { color: var(--orange); }
.about-list.plain { list-style: none; padding: 0; }
.about-steps { margin: 0 0 6px; padding-left: 1.5em; line-height: 1.55; }
.about-steps li { margin: 6px 0; }
.about-steps li::marker { color: var(--orange-text); font-weight: 700; }
.about-body code, .about-body kbd { font: .88em var(--font-mono); background: var(--code-bg); border-radius: 6px; padding: .1em .4em; }
.about-body kbd { border: 1px solid var(--border); border-bottom-width: 2px; }
.about-table { margin: 4px 0 12px; font-size: 14px; }
.about-table td:first-child { font-weight: 600; white-space: nowrap; }
.about-table td { line-height: 1.45; }
.about-changelog h1 { display: none; }
.about-changelog h2 { border-top: 1px solid var(--border); padding-top: 14px; }
.about-changelog h2:first-of-type { border-top: 0; padding-top: 0; }
.about-ai { margin-top: 18px; padding: 14px 18px; border-radius: 14px; background: var(--cream-soft); border-left: 4px solid var(--orange); font-size: 15px; font-weight: 600; color: var(--text); }
@media (max-width: 640px) {
  .about-head { padding: 16px; }
  .about-id { gap: 12px; }
  .about-id img { width: 44px; height: 44px; padding: 4px; border-radius: 12px; }
  .about-desc { font-size: 13.5px; margin-bottom: 8px; }
  .about-tags { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-right: -16px; }
  .about-table td:first-child { white-space: normal; }
}
:root[data-theme="dark"] .about-body h3 { color: var(--cream); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .about-body h3 { color: var(--cream); } }

/* ---- Avis et activité ---- */
.mini.fb.on { color: var(--orange-text); background: var(--orange-soft); }
.sub-title { font: 600 16px var(--font-display); margin: 18px 0 8px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.sub-title small { font: 400 13px var(--font-body); color: var(--muted); }
