:root {
  --paper: #f7f5f0;
  --surface: #ffffff;
  --ink: #16181d;
  --ink-2: #4a4f5a;
  --muted: #7a7f89;
  --line: #e3dfd6;
  --accent: #b3122b;       /* rouge suisse, utilisé avec parcimonie */
  --accent-ink: #ffffff;
  --cite-bg: #f3ecdf;
  --cite-ink: #6b4a12;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121317; --surface: #1a1c21; --ink: #ecebe7; --ink-2: #b8b9bd; --muted: #8b8e96;
    --line: #2b2e35; --accent: #e0455c; --cite-bg: #2a2418; --cite-ink: #e6c88f;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 16px/1.6 var(--sans); min-height: 100vh; display: flex; flex-direction: column; }
a { color: inherit; text-underline-offset: 3px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; letter-spacing: -0.01em; }
.muted { color: var(--muted); }

/* ---------- En-tête ---------- */
.top { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--paper); position: sticky; top: 0; z-index: 5; }
.brand { font: 600 22px/1 var(--serif); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand .mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); font-size: 17px; }
.brand .dot { color: var(--muted); font-weight: 400; }
.beta { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 2px 8px; }
.top nav { margin-left: auto; display: flex; align-items: center; gap: 18px; font-size: 15px; }
.top nav a { text-decoration: none; color: var(--ink-2); }
.top nav form { margin: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--ink); color: var(--paper); border: 0; border-radius: var(--radius); padding: 12px 20px; font: 500 15px/1 var(--sans); text-decoration: none; cursor: pointer; }
.top nav a.btn { color: var(--paper); }
.btn:hover { opacity: .9; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { padding: 8px 14px; font-size: 14px; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--ink-2); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Accueil ---------- */
.home { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 32px 48px; font-size: 15px; }
.hero { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.25fr); gap: 48px; align-items: center; padding: 56px 0 40px; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: 11px; color: var(--accent); font-weight: 600; margin: 0 0 14px; }
.hero h1 { font-size: clamp(28px, 3.1vw, 40px); margin: 0 0 16px; letter-spacing: -0.015em; }
.lead { font-size: 16px; line-height: 1.65; color: var(--ink-2); margin: 0 0 24px; }
.cta { display: flex; flex-wrap: wrap; gap: 10px; }
.home .btn { padding: 11px 18px; font-size: 14px; }
.fine { font-size: 12px; color: var(--muted); margin-top: 12px; }
.hero-photo { margin: 0; position: relative; }
.hero-photo img { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9.05; object-fit: cover; border-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 24px 48px -28px rgba(20,24,32,.45); }
.hero-photo::after { content: ""; position: absolute; inset: 0; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.06); pointer-events: none; }

.figures { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 8px 0 44px; }
.figures div { padding: 18px 20px; display: flex; flex-direction: column; gap: 2px; }
.figures div + div { border-left: 1px solid var(--line); }
.figures strong { font: 600 26px/1.1 var(--serif); letter-spacing: -0.01em; }
.figures span { font-size: 12.5px; color: var(--muted); }

.duo { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 48px; align-items: start; }
.example { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 22px 24px; box-shadow: 0 18px 40px -32px rgba(0,0,0,.3); }
.example .label { margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.example .q { font-weight: 600; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px dashed var(--line); }
.example .a p { margin: 0 0 8px; color: var(--ink-2); }
.cite { display: inline-block; background: var(--cite-bg); color: var(--cite-ink); font-size: 12px; padding: 1px 7px; border-radius: 5px; white-space: nowrap; }

.pillars { display: flex; flex-direction: column; gap: 20px; }
.pillars article { padding-left: 16px; border-left: 2px solid var(--line); }
.pillars h2 { font-size: 17px; margin: 0 0 4px; }
.pillars p { margin: 0; color: var(--ink-2); font-size: 14px; }
.scope { margin-top: 44px; padding: 18px 22px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; }
.scope h2 { font-size: 16px; margin: 0 0 4px; }
.scope p { margin: 0; color: var(--ink-2); font-size: 14px; }

/* ---------- Formulaires ---------- */
.auth { width: 100%; max-width: 520px; margin: 48px auto; padding: 0 24px; }
.auth h1 { font-size: 34px; margin-bottom: 8px; }
.stack { display: flex; flex-direction: column; gap: 16px; margin: 24px 0; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; }
input, select, textarea { font: 16px/1.4 var(--sans); color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ink); outline-offset: 1px; border-color: transparent; }
label.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; color: var(--ink-2); }
label.check input { width: auto; margin-top: 4px; }
.alert { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); border-radius: 8px; padding: 10px 14px; font-size: 14px; }

/* ---------- Pages de texte ---------- */
.prose { width: 100%; max-width: 720px; margin: 40px auto; padding: 0 24px; }
.prose h1 { font-size: 36px; }
.prose h2 { font-size: 20px; margin-top: 28px; }
.prose p { color: var(--ink-2); }
.draft { font-size: 13px; background: var(--cite-bg); color: var(--cite-ink); padding: 8px 12px; border-radius: 8px; }

.foot { margin-top: auto; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 20px; padding: 20px 32px 24px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-2); }
.foot .legal { flex-basis: 100%; color: var(--muted); font-size: 11.5px; letter-spacing: .01em; }
@media (max-width: 720px) { .foot { padding: 18px 16px 22px; } }

/* ---------- Espace de travail ---------- */
body.workspace { height: 100vh; height: 100dvh; overflow: hidden; }
.ws { flex: 1; display: flex; flex-direction: column; min-height: 0; width: 100%; max-width: 860px; margin: 0 auto; }
.thread { flex: 1; overflow-y: auto; padding: 28px 24px 12px; }
.empty { margin-top: 10vh; }
.empty h1 { font-size: 34px; margin: 0 0 6px; }
.empty p { color: var(--ink-2); margin: 0 0 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 8px 14px; font: 14px var(--sans); color: var(--ink-2); cursor: pointer; }
.chip:hover { border-color: var(--ink-2); color: var(--ink); }

.msg { margin: 0 0 26px; }
.msg.user { margin-left: auto; max-width: 85%; width: fit-content; background: var(--ink); color: var(--paper); padding: 12px 16px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
.msg.bot { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.msg.bot .status { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 10px; }
.msg.bot .status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer h1, .answer h2, .answer h3 { font-size: 18px; margin: 18px 0 8px; }
.answer p, .answer ul, .answer ol { margin: 0 0 10px; }
.answer table { border-collapse: collapse; margin: 8px 0 12px; font-size: 14px; }
.answer th, .answer td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.answer code { font-size: 14px; }
.answer .cite { cursor: default; }
.sources { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 13px; color: var(--muted); }
.sources summary { cursor: pointer; }
.sources ul { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.sources a { display: inline-block; text-decoration: none; background: var(--cite-bg); color: var(--cite-ink); border-radius: 6px; padding: 2px 8px; }
.sources a:hover { text-decoration: underline; }
.disclaimer { font-size: 12px; color: var(--muted); margin-top: 10px; }
.msg.error { border-color: var(--accent); color: var(--accent); }

.composer { padding: 12px 24px 18px; background: linear-gradient(to bottom, transparent, var(--paper) 18px); display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.composer textarea { resize: none; max-height: 220px; border-radius: 12px; padding: 13px 14px; }
.composer .btn { align-self: end; height: 48px; }
.composer .meta { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }

@media (max-width: 960px) {
  .hero { grid-template-columns: 1fr; gap: 28px; padding: 36px 0 28px; }
  .hero-photo { order: -1; }
  .duo { grid-template-columns: 1fr; gap: 32px; }
  .figures { grid-template-columns: repeat(2, 1fr); }
  .figures div:nth-child(3) { border-left: 0; }
  .figures div:nth-child(n+3) { border-top: 1px solid var(--line); }
}

@media (max-width: 720px) {
  .top { padding: 12px 16px; }
  .top nav { gap: 12px; }
  .top nav a:not(.btn) { display: none; }
  body.workspace .top nav a { display: inline; }
  .home, .auth, .prose { padding: 0 16px; }
  .home { padding-bottom: 32px; }
  .row { grid-template-columns: 1fr; }
  .thread { padding: 20px 16px 8px; }
  .composer { padding: 10px 16px 14px; }
  .msg.user { max-width: 92%; }
}

/* Sources groupées (lois / jurisprudence / doctrine) */
.sources .src-group { margin: 10px 0 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.sources ul.doctrine { flex-direction: column; gap: 4px; }
.sources ul.doctrine .by { color: var(--muted); }
