/* =========================================================
   Thème
   ========================================================= */
:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-2: #f3f3f0;
  --surface-3: #ebebe7;
  --text: #1c1c1a;
  --muted: #6f6f6a;
  --faint: #a3a39d;
  --line: #e7e6e2;
  --accent: #1f5fd6;
  --accent-soft: #e9f0fd;
  --accent-text: #ffffff;
  --mark: #fff1b8;
  --mark-text: #1c1c1a;
  --quote-bar: #1f5fd6;
  --danger: #c0392b;
  --ok: #1e8e5a;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(20,20,10,.05);
  --shadow: 0 1px 2px rgba(20,20,10,.04), 0 8px 24px rgba(20,20,10,.06);
  --shadow-lg: 0 2px 6px rgba(20,20,10,.06), 0 24px 60px rgba(20,20,10,.14);
  --ease: cubic-bezier(.2,.8,.2,1);
  --spring: cubic-bezier(.34,1.56,.64,1);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111110; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2b2b28; --text: #ecece9;
    --muted: #9b9b95; --faint: #6c6c66; --line: #2d2d2a; --accent: #8ab0ff; --accent-soft: #1b2741;
    --accent-text: #0d1424; --mark: #4b3f10; --mark-text: #fbf1c9; --quote-bar: #8ab0ff;
    --danger: #ff8170; --ok: #5fd39a; --shadow-sm: none; --shadow: 0 0 0 1px rgba(255,255,255,.02);
    --shadow-lg: 0 24px 60px rgba(0,0,0,.5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111110; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2b2b28; --text: #ecece9;
  --muted: #9b9b95; --faint: #6c6c66; --line: #2d2d2a; --accent: #8ab0ff; --accent-soft: #1b2741;
  --accent-text: #0d1424; --mark: #4b3f10; --mark-text: #fbf1c9; --quote-bar: #8ab0ff;
  --danger: #ff8170; --ok: #5fd39a; --shadow-sm: none; --shadow: 0 0 0 1px rgba(255,255,255,.02);
  --shadow-lg: 0 24px 60px rgba(0,0,0,.5); color-scheme: dark;
}

/* Transition de thème : cercle qui s'étend depuis le bouton (View Transitions) */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
/* Repli sans View Transitions : fondu des couleurs */
.theme-fade, .theme-fade * {
  transition: background-color .45s var(--ease), color .45s var(--ease), border-color .45s var(--ease), fill .45s, stroke .45s !important;
}

/* =========================================================
   Base
   ========================================================= */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: clip; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
h1, h2, h3, h4 { margin: 0; font-weight: 620; letter-spacing: -.015em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

input, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
textarea { resize: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius);
  padding: 9px 16px; cursor: pointer; white-space: nowrap;
  transition: transform .18s var(--ease), background .2s, box-shadow .2s, opacity .2s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover { box-shadow: 0 6px 18px -6px rgba(0,0,0,.35); transform: translateY(-1px); }
.btn.primary:active { transform: scale(.96); }
.btn:disabled { opacity: .55; cursor: default; transform: none; box-shadow: none; }
.btn.danger { color: var(--danger); }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--muted); flex-shrink: 0;
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  transition: background .2s, color .2s, transform .2s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.9); }
.link {
  border: 0; background: none; padding: 0; color: var(--muted); cursor: pointer; font-size: 13px;
  transition: color .2s;
}
.link:hover { color: var(--text); }

/* Bouton thème : soleil / lune qui tournent */
.theme-btn { position: relative; overflow: hidden; }
.theme-btn svg { position: absolute; transition: transform .5s var(--spring), opacity .3s; }
:root[data-theme="dark"] .theme-btn .ic-moon,
:root:not([data-theme="dark"]) .theme-btn .ic-sun { transform: rotate(-90deg) scale(.4); opacity: 0; }

/* =========================================================
   Animations
   ========================================================= */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop-out { to { opacity: 0; transform: scale(.96) translateY(6px); } }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheet-out { to { transform: translateY(100%); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes dot { 0%, 80%, 100% { transform: scale(.5); opacity: .35; } 40% { transform: scale(1); opacity: 1; } }
@keyframes flash { 0% { box-shadow: 0 0 0 0 var(--accent); } 100% { box-shadow: 0 0 0 10px transparent; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes chip-in { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: none; } }
@keyframes collapse { to { opacity: 0; transform: translateX(16px); height: 0; padding-block: 0; margin: 0; border-width: 0; } }
@keyframes word { from { opacity: 0; filter: blur(4px); transform: translateY(3px); } to { opacity: 1; filter: none; transform: none; } }

.reveal { animation: rise .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 55ms); }
.panel-enter { animation: rise .4s var(--ease) both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}

/* =========================================================
   Connexion
   ========================================================= */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 360px; display: grid; gap: 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: var(--shadow-lg);
  animation: pop .6s var(--spring) both;
}
.auth-logo {
  width: 44px; height: 44px; border-radius: 12px; background: var(--text); color: var(--bg);
  display: grid; place-items: center; animation: float 3s ease-in-out infinite;
}
.auth-card p { margin: 0; }

/* =========================================================
   Structure
   ========================================================= */
.app { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.topbar { display: none; }
.scrim { display: none; }

.side {
  border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column;
  gap: 10px; position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; background: var(--bg);
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 6px; }
.logo { font-weight: 680; letter-spacing: -.02em; font-size: 16px; }
.side-label { margin: 6px 8px 0; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); }
.subjects { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.subject {
  position: relative; display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%;
  text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 10px; cursor: pointer;
  transition: background .2s, transform .2s var(--ease), color .2s;
}
.subject span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subject:hover { background: var(--surface-2); transform: translateX(2px); }
.subject.active { background: var(--surface); box-shadow: var(--shadow); font-weight: 560; }
.subject.active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px;
  background: var(--accent); animation: fade .3s both;
}
.subject .count {
  color: var(--muted); font-size: 11.5px; background: var(--surface-2); border-radius: 99px;
  padding: 1px 8px; min-width: 24px; text-align: center; transition: background .2s;
}
.subject.active .count { background: var(--accent-soft); color: var(--accent); }
.new-subject input { border-style: dashed; background: transparent; padding: 8px 10px; font-size: 14px; }
.side-foot { display: flex; justify-content: space-between; padding: 12px 8px 0; border-top: 1px solid var(--line); }

.main {
  padding: 32px clamp(16px, 4vw, 48px) 80px; width: 100%; max-width: 980px; margin: 0 auto;
}
.main-head {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap;
  margin-bottom: 24px;
}
.title-wrap { min-width: 0; }
.title-wrap h2 { font-size: clamp(20px, 3vw, 26px); overflow-wrap: anywhere; }
.title-wrap.swap { animation: rise .35s var(--ease) both; }
.main-head p { margin: 2px 0 0; }

/* Onglets avec indicateur glissant */
.tabs, .seg {
  position: relative; display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 12px;
}
.tab, .seg-btn {
  position: relative; z-index: 1; border: 0; background: none; padding: 7px 14px; border-radius: 9px;
  cursor: pointer; color: var(--muted); transition: color .25s; font-size: 14px; white-space: nowrap;
}
.tab.active, .seg-btn.active { color: var(--text); }
.tab-ind, .seg-ind {
  position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 0; width: 0; border-radius: 9px;
  background: var(--surface); box-shadow: var(--shadow);
  transition: transform .4s var(--spring), width .4s var(--spring);
}

/* =========================================================
   Question
   ========================================================= */
.ask {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 6px;
  box-shadow: var(--shadow); transition: border-color .25s, box-shadow .25s;
}
.ask:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); }
.ask textarea { border: 0; background: transparent; min-height: 58px; max-height: 40vh; box-shadow: none; font-size: 15.5px; }
.ask-bar { display: flex; align-items: center; gap: 12px; padding: 4px 6px 4px 10px; }
.ask-bar .hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.send { margin-left: auto; border-radius: 12px; }
.send svg { transition: transform .25s var(--ease); }
.send:hover svg { transform: translateX(3px); }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 14px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; margin: 0; }
.track {
  width: 36px; height: 21px; border-radius: 99px; background: var(--surface-3); position: relative;
  transition: background .25s;
}
.thumb {
  position: absolute; top: 2.5px; left: 2.5px; width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .35s var(--spring);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .thumb { transform: translateX(15px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.answer { margin-top: 26px; display: grid; gap: 14px; }

/* Chargement */
.thinking { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; animation: fade .3s both; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: dot 1.2s infinite ease-in-out both; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
.step { transition: opacity .3s; }
.skel {
  height: 110px; border-radius: 16px; border: 1px solid var(--line);
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 40%, var(--surface) 80%) 0 0 / 200% 100%;
  animation: shimmer 1.4s linear infinite, fade .4s both;
}
.skel.short { height: 64px; }

/* Carte réponse */
.reply-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 18px 20px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.reply-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), transparent);
}
.reply-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; letter-spacing: .02em;
  color: var(--accent); background: var(--accent-soft); padding: 3px 10px; border-radius: 99px;
}
.reply { font-size: 16.5px; line-height: 1.7; margin: 0; overflow-wrap: anywhere; }
.reply .nb { white-space: nowrap; }
.reply .w { animation: word .5s var(--ease) both; animation-delay: calc(var(--d) * 18ms); }
.meta-line { display: flex; gap: 6px 12px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.meta-line .saved { color: var(--ok); }

/* Référence cliquable dans la réponse : [1] */
.ref {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; margin: 0 1px;
  border-radius: 6px; font-size: 11.5px; font-weight: 650; vertical-align: 2px;
  background: var(--accent-soft); color: var(--accent); cursor: pointer; border: 0; font-family: inherit;
  animation: chip-in .45s var(--spring) both; animation-delay: calc(var(--d, 0) * 18ms + 120ms);
  transition: transform .2s var(--spring), background .2s, color .2s;
}
.ref:hover { transform: translateY(-2px) scale(1.08); background: var(--accent); color: var(--accent-text); }

.warn {
  margin: 0; padding: 12px 14px; border-radius: var(--radius); font-size: 14px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
}

.section-label {
  display: flex; align-items: center; gap: 10px; margin: 10px 2px 0; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em; color: var(--faint);
}
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Carte de citation */
.cite {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden;
  box-shadow: var(--shadow-sm); transition: box-shadow .25s, border-color .25s;
  scroll-margin: 90px;
}
.cite:hover { box-shadow: var(--shadow); }
.cite.flash { animation: flash .9s var(--ease); border-color: var(--accent); }
.cite-head { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px 0; }
.cite-num {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; background: var(--accent); color: var(--accent-text);
}
.cite.plain .cite-num { background: var(--surface-2); color: var(--muted); }
.cite-meta { min-width: 0; flex: 1; }
.cite-doc { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; min-width: 0; }
.cite-doc svg { flex-shrink: 0; color: var(--muted); }
.cite-doc .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  flex-shrink: 0; font-size: 11px; font-weight: 500; padding: 1px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted);
}
.crumbs { display: flex; flex-wrap: wrap; gap: 2px 4px; margin-top: 3px; font-size: 12.5px; color: var(--muted); }
.crumbs span:not(:last-child)::after { content: "›"; margin-left: 4px; color: var(--faint); }
.crumbs span:last-child { color: var(--text); }
.page-badge {
  flex-shrink: 0; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 8px;
  border: 1px solid var(--line); color: var(--muted); font-variant-numeric: tabular-nums;
}

.cite-body { position: relative; padding: 16px 18px 6px; }
.quote {
  position: relative; margin: 0; padding: 4px 0 4px 18px; border-left: 3px solid var(--quote-bar);
  font-family: var(--serif); font-size: 16.5px; line-height: 1.75; overflow-wrap: anywhere;
}
.quote::before {
  content: "“"; position: absolute; left: 6px; top: -22px; font-size: 60px; line-height: 1;
  color: var(--accent); opacity: .16; font-family: var(--serif); pointer-events: none;
}
.quote p { margin: 0 0 .45em; }
.quote p:last-child { margin-bottom: 0; }
.quote ul { margin: .2em 0 .5em; padding-left: 1.2em; }
.quote li { margin: .15em 0; }
.quote li::marker { color: var(--accent); }
.quote .ctx { color: var(--faint); }
.quote .gap { display: block; color: var(--faint); font-family: system-ui, sans-serif; font-size: 13px; margin: .2em 0; letter-spacing: .2em; }
.term {
  text-decoration: underline; text-decoration-color: var(--accent);
  text-decoration-thickness: 1.5px; text-underline-offset: 3px;
}

.cite-actions { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 10px 10px; }
.act {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; cursor: pointer;
  color: var(--muted); font-size: 13px; padding: 6px 10px; border-radius: 9px;
  transition: background .2s, color .2s, transform .15s;
}
.act:hover { background: var(--surface-2); color: var(--text); }
.act:active { transform: scale(.95); }
.act svg { transition: transform .35s var(--spring); }
.act.on svg.chev { transform: rotate(180deg); }
.act.done { color: var(--ok); }

/* Dépliage animé du passage complet */
.fold { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .45s var(--ease); }
.fold.open { grid-template-rows: 1fr; }
.fold > div { overflow: hidden; min-height: 0; }
.full {
  margin: 0 16px 16px; padding: 14px 16px; border-radius: 12px; background: var(--surface-2);
  font-size: 14.5px; line-height: 1.7; overflow-wrap: anywhere;
}
.full p { margin: 0 0 .5em; } .full p:last-child { margin: 0; }
.full ul { margin: .2em 0 .5em; padding-left: 1.2em; }
.full mark, .md mark {
  background: var(--mark); color: var(--mark-text); border-radius: 4px; padding: 1px 2px;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}

details.more > summary {
  list-style: none; cursor: pointer; color: var(--muted); font-size: 14px; padding: 10px 4px;
  display: flex; align-items: center; gap: 8px; transition: color .2s;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary:hover { color: var(--text); }
details.more > summary svg { transition: transform .35s var(--spring); }
details.more[open] > summary svg { transform: rotate(180deg); }
details.more .cite { margin-bottom: 12px; }
details.more[open] .cite { animation: rise .4s var(--ease) both; animation-delay: calc(var(--i, 0) * 50ms); }

.empty {
  text-align: center; color: var(--muted); padding: 48px 16px; display: grid; justify-items: center; gap: 10px;
  animation: rise .5s var(--ease) both;
}
.empty-ic {
  width: 52px; height: 52px; border-radius: 16px; background: var(--surface-2); display: grid; place-items: center;
  color: var(--muted); animation: float 3s ease-in-out infinite;
}

/* =========================================================
   Documents
   ========================================================= */
.drop {
  display: grid; place-items: center; gap: 6px; text-align: center; padding: 34px 16px; cursor: pointer;
  border: 1.5px dashed var(--line); border-radius: 18px; background: var(--surface);
  transition: border-color .25s, background .25s, transform .3s var(--spring);
}
.drop-ic {
  width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); transition: transform .4s var(--spring);
}
.drop:hover { border-color: var(--accent); }
.drop:hover .drop-ic { transform: translateY(-4px); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.015); }
.drop.over .drop-ic { animation: float .8s ease-in-out infinite; }
.queue, .list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.queue:empty { margin: 0; }
.queue li, .list li {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; transition: box-shadow .25s, transform .25s var(--ease);
}
.list li:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.list li.removing, .queue li.removing { animation: collapse .35s var(--ease) forwards; overflow: hidden; }
.list li.empty-row { display: block; border-style: dashed; }
.file-ic {
  flex-shrink: 0; width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted);
}
.list li .grow, .queue li .grow { flex: 1; min-width: 0; }
.list li .name, .queue li .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 520; }
.row-actions { display: flex; gap: 12px; flex-shrink: 0; }
.bar { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar > i {
  display: block; height: 100%; width: 0; border-radius: 4px; transition: width .35s var(--ease);
  background: linear-gradient(90deg, var(--accent), var(--accent-soft), var(--accent)) 0 0 / 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
.queue li.done .bar > i { background: var(--ok); animation: none; }
.danger-zone { margin-top: 28px; display: flex; gap: 8px; flex-wrap: wrap; }

/* =========================================================
   Parties
   ========================================================= */
.plan-tools { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.search-field { position: relative; flex: 1; min-width: 200px; }
.search-field svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-field input { padding-left: 36px; }
.group { margin-bottom: 20px; }
.group h3 { font-size: 14.5px; margin-bottom: 6px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.group h3 .muted { font-weight: 400; font-size: 12px; }
.group h3 .multi { color: var(--accent); background: var(--accent-soft); padding: 0 8px; border-radius: 99px; font-size: 11.5px; font-weight: 550; }
.part {
  display: flex; justify-content: space-between; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  border: 0; border-bottom: 1px solid var(--line); background: none; padding: 9px 8px; font-size: 14px; border-radius: 8px;
  transition: background .2s, padding .25s var(--ease);
}
.part span:first-child { min-width: 0; overflow-wrap: anywhere; }
.part:hover { background: var(--surface-2); padding-left: 14px; }
.part .muted { flex-shrink: 0; font-size: 12px; }

/* =========================================================
   Lecteur (dialog)
   ========================================================= */
.reader {
  width: min(780px, calc(100vw - 32px)); max-height: 86vh; padding: 0; border: 1px solid var(--line);
  border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  overflow: auto; overscroll-behavior: contain;
}
.reader[open] { animation: pop .35s var(--spring) both; }
.reader.closing { animation: pop-out .2s var(--ease) forwards; }
.reader::backdrop { background: rgba(10,10,8,.4); backdrop-filter: blur(3px); animation: fade .3s both; }
.reader.closing::backdrop { opacity: 0; transition: opacity .2s; }
.reader-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.reader-titles { min-width: 0; overflow-wrap: anywhere; }
.reader-body { padding: 8px 22px 28px; }
.md { font-size: 15px; line-height: 1.7; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.3em 0 .4em; line-height: 1.3; }
.md h1 { font-size: 21px; } .md h2 { font-size: 18px; } .md h3, .md h4 { font-size: 15.5px; }
.md p { margin: .55em 0; }
.md ul { padding-left: 20px; margin: .4em 0; }
.md .page {
  color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  border-top: 1px solid var(--line); padding-top: 6px; margin-top: 20px; scroll-margin: 80px;
}
.md .page.target { color: var(--accent); border-color: var(--accent); }
.hist-item .q { font-weight: 520; }

.toast {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; z-index: 50;
  transform: translateX(-50%) translateY(20px) scale(.96); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-size: 14px;
  transition: transform .35s var(--spring), opacity .25s; pointer-events: none; max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1024px) {
  .app { grid-template-columns: 220px minmax(0, 1fr); }
  .main { padding-top: 24px; }
}

/* Tablette portrait & mobile : tiroir latéral */
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .topbar {
    display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 20;
    padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top));
    background: var(--bg); border-bottom: 1px solid var(--line);
  }
  @supports (backdrop-filter: blur(1px)) {
    .topbar { background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: saturate(1.4) blur(12px); }
  }
  .topbar .logo { flex: 1; text-align: center; }
  .side {
    position: fixed; z-index: 40; left: 0; top: 0; bottom: 0; width: min(300px, 84vw); height: auto;
    padding-top: calc(18px + env(safe-area-inset-top)); padding-bottom: calc(14px + env(safe-area-inset-bottom));
    background: var(--surface); box-shadow: var(--shadow-lg);
    transform: translateX(-105%); transition: transform .45s var(--ease), visibility 0s .45s; visibility: hidden;
  }
  .side .theme-btn { display: none; }
  .app.drawer-open .side { transform: none; visibility: visible; transition: transform .45s var(--ease), visibility 0s; }
  .app.drawer-open .side .subject { animation: rise .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 35ms + 80ms); }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: 30; background: rgba(10,10,8,.38);
    opacity: 0; pointer-events: none; transition: opacity .35s;
  }
  .app.drawer-open .scrim { opacity: 1; pointer-events: auto; }
  .main { padding: 20px 16px calc(60px + env(safe-area-inset-bottom)); }
}

@media (max-width: 600px) {
  .main-head { flex-direction: column; align-items: stretch; gap: 14px; margin-bottom: 18px; }
  .tabs { width: 100%; }
  .tab { flex: 1; padding: 8px 6px; }
  .ask { border-radius: 16px; }
  .ask-bar { flex-wrap: wrap; gap: 8px 10px; padding-left: 8px; }
  .ask-bar .hint { order: 3; flex-basis: 100%; padding-bottom: 2px; }
  .reply-card { padding: 16px; border-radius: 16px; }
  .reply { font-size: 16px; }
  .cite-head { padding: 12px 12px 0; gap: 10px; }
  .cite-body { padding: 14px 12px 4px 14px; }
  .quote { font-size: 16px; padding-left: 14px; }
  .full { margin: 0 12px 12px; padding: 12px; }
  .cite-actions { padding: 6px 6px 8px; }
  .act .lbl { display: none; }
  .act { padding: 8px 10px; }
  .list li, .queue li { padding: 10px 12px; gap: 10px; }
  .file-ic { width: 34px; height: 34px; }
  .drop { padding: 26px 14px; }
  .plan-tools { flex-direction: column; flex-wrap: nowrap; }
  .seg-btn { flex: 1; }
  /* Lecteur en feuille plein écran depuis le bas */
  .reader {
    width: 100vw; max-width: 100vw; max-height: 92vh; max-height: 92dvh; margin: auto 0 0;
    border-radius: 20px 20px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom);
  }
  .reader[open] { animation: sheet-in .45s var(--ease) both; }
  .reader.closing { animation: sheet-out .25s var(--ease) forwards; }
  .reader-head { padding: 18px 16px 14px; }
  .reader-head::before {
    content: ""; position: absolute; top: 6px; left: 50%; transform: translateX(-50%); width: 38px; height: 4px;
    border-radius: 4px; background: var(--line);
  }
  .reader-body { padding: 4px 16px 24px; }
}

@media (max-width: 380px) {
  .tab { font-size: 13px; }
  .send-label { display: none; }
  .send { padding: 9px 12px; }
  .row-actions .lbl { display: none; }
}

@media (hover: none) {
  .list li:hover, .subject:hover { transform: none; }
}

/* =========================================================
   Question envoyée (le champ se vide)
   ========================================================= */
.asked {
  display: flex; align-items: center; gap: 8px; justify-self: end; max-width: min(85%, 640px);
  background: var(--text); color: var(--bg); padding: 4px 4px 4px 16px; border-radius: 18px 18px 6px 18px;
  box-shadow: var(--shadow);
}
.asked-q { overflow-wrap: anywhere; padding: 6px 0; font-size: 15px; }
.asked .icon-btn { color: inherit; opacity: .6; width: 32px; height: 32px; }
.asked .icon-btn:hover { opacity: 1; background: rgba(127,127,127,.2); color: inherit; }

/* =========================================================
   Suggestions pendant la saisie
   ========================================================= */
.ask { position: relative; }
.suggest {
  position: absolute; z-index: 15; left: 6px; right: 6px; top: calc(100% - 4px); margin: 0; padding: 6px;
  list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-lg); max-height: 300px; overflow-y: auto; animation: pop .22s var(--ease) both;
  transform-origin: top center;
}
.sug {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; cursor: pointer;
  color: var(--muted); animation: rise .3s var(--ease) both; animation-delay: calc(var(--i, 0) * 25ms);
  transition: background .15s, color .15s;
}
.sug svg { flex-shrink: 0; opacity: .7; }
.sug-l { flex: 1; min-width: 0; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sug-l b { color: var(--accent); font-weight: 650; }
.sug-n { font-size: 11.5px; color: var(--faint); flex-shrink: 0; }
.sug.head .sug-n { color: var(--accent); background: var(--accent-soft); padding: 1px 7px; border-radius: 99px; }
.sug:hover, .sug.active { background: var(--surface-2); }
.sug.active { box-shadow: inset 3px 0 0 var(--accent); }

.dym { text-align: center; color: var(--muted); font-size: 14px; display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; }

/* Pastilles de filtre */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer;
  padding: 6px 12px; border-radius: 99px; font-size: 13.5px; display: inline-flex; align-items: center; gap: 6px;
  transition: background .2s, color .2s, border-color .2s, transform .2s var(--spring);
}
.chip span { font-size: 11.5px; opacity: .7; font-variant-numeric: tabular-nums; }
.chip:hover { color: var(--text); transform: translateY(-1px); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip:active { transform: scale(.95); }

/* =========================================================
   Fiches de révision
   ========================================================= */
.sheet-tools { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.sheet-actions { display: flex; gap: 8px; }
.sheet-title { margin-bottom: 14px; }
.sheet-title h3 { font-size: 20px; }
.sheet-title p { margin: 2px 0 0; }
.sheet-doc { display: flex; align-items: center; gap: 8px; font-size: 16px; margin: 26px 0 10px; }
.sheet-doc svg { color: var(--accent); }
.sheet-sec {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; margin-bottom: 12px;
  break-inside: avoid;
}
.sheet-sec h4 {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13.5px;
  color: var(--muted); font-weight: 560; margin-bottom: 8px;
}
.sheet-sec h4 .page-badge { cursor: pointer; background: none; font-family: inherit; transition: background .2s, color .2s; }
.sheet-sec h4 .page-badge:hover { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.fi {
  display: grid; grid-template-columns: 92px 1fr; gap: 12px; padding: 10px 8px; border-radius: 10px; cursor: pointer;
  border-top: 1px solid var(--line); transition: background .2s;
}
.fi:first-of-type { border-top: 0; }
.fi:hover { background: var(--surface-2); }
.fi-type {
  align-self: start; justify-self: start; font-size: 11px; font-weight: 650; letter-spacing: .03em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.fi-def .fi-type { background: var(--accent-soft); color: var(--accent); }
.fi-key .fi-type { background: var(--mark); color: var(--mark-text); }
.fi-formula .fi-type { background: var(--surface-3); color: var(--ok); }
.fi-text { font-family: var(--serif); font-size: 15.5px; line-height: 1.65; overflow-wrap: anywhere; }
.fi-text strong { font-family: system-ui, sans-serif; font-weight: 650; }
.fi-text ul { margin: .3em 0 0; padding-left: 1.2em; }
.fi-text li::marker { color: var(--accent); }
.fi-formula .fi-text { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 14.5px; }

/* =========================================================
   Lecteur PDF
   ========================================================= */
.reader.wide { width: min(1000px, calc(100vw - 32px)); }
.reader-mode { flex-shrink: 0; margin-left: auto; }
.reader-mode .seg-btn { padding: 5px 12px; font-size: 13px; }
.reader-pdf { padding: 16px; background: var(--surface-2); display: grid; gap: 14px; }
.pdf-page {
  position: relative; width: 100%; border-radius: 6px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 8px 24px rgba(0,0,0,.06);
  background: linear-gradient(90deg, #fff 0%, #eeeeea 40%, #fff 80%) 0 0 / 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.pdf-page.ready { animation: none; background: #fff; }
.pdf-page canvas { display: block; width: 100%; height: auto; animation: fade .35s both; }
.pdf-num {
  position: absolute; right: 8px; bottom: 8px; z-index: 2; font-size: 11px; padding: 2px 8px; border-radius: 99px;
  background: rgba(0,0,0,.55); color: #fff;
}
.pdf-hl {
  position: absolute; z-index: 1; background: rgba(255, 205, 30, .45); mix-blend-mode: multiply; border-radius: 2px;
  animation: hl-in .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 30ms + 150ms); transform-origin: left center;
}
@keyframes hl-in { from { transform: scaleX(0); opacity: 0; } to { transform: none; opacity: 1; } }
.pdf-pill { background: var(--accent-soft); color: var(--accent); font-weight: 600; align-self: center; }

@media (max-width: 600px) {
  .tab { padding: 8px 2px; font-size: 13.5px; }
  .asked { max-width: 92%; }
  .sheet-tools { flex-direction: column; flex-wrap: nowrap; }
  .sheet-tools > * { min-width: 0; }
  .sheet-actions .btn { flex: 1; }
  .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; }
  .fi { grid-template-columns: 1fr; gap: 6px; }
  .reader.wide { width: 100vw; }
  .reader-pdf { padding: 8px; gap: 8px; }
  .reader-head { flex-wrap: wrap; }
  .reader-titles { flex: 1 1 60%; }
}
@media (max-width: 380px) {
  .tab { font-size: 12.5px; }
  .sheet-actions .lbl { display: none; }
}

/* =========================================================
   Impression de la fiche
   ========================================================= */
@media print {
  :root, :root[data-theme="dark"] {
    --bg: #fff; --surface: #fff; --surface-2: #f3f3f0; --text: #111; --muted: #555; --faint: #888; --line: #ddd;
    --accent: #1f5fd6; --accent-soft: #e9f0fd; --mark: #fff1b8; --mark-text: #111; color-scheme: light;
  }
  body.print-sheet .topbar, body.print-sheet .side, body.print-sheet .main-head, body.print-sheet .sheet-tools,
  body.print-sheet .panel:not(#tab-sheet), body.print-sheet .toast, body.print-sheet .scrim { display: none !important; }
  body.print-sheet .app { display: block; }
  body.print-sheet .main { padding: 0; max-width: none; }
  body.print-sheet .reveal, body.print-sheet .panel-enter { animation: none !important; opacity: 1 !important; transform: none !important; }
  body.print-sheet .sheet-sec { box-shadow: none; border-color: #ccc; }
  body.print-sheet .page-badge { border: 0; }
  @page { margin: 14mm; }
}
