/* Charte Stanley Outsourcing déclinée en interface utilitaire : le violet porte l'identité,
   les couleurs ne portent du sens que pour un statut ou une alerte. */
:root {
  --bg: #f6f5fa;
  --surface: #ffffff;
  --surface-2: #efedf6;
  --text: #1c1929;
  --muted: #55516b;
  --border: #cfcbdd;
  --primary: #392869;
  --on-primary: #ffffff;
  --link: #392869;
  --focus: #b00f55;
  --ok-bg: #dcf1e4; --ok-text: #14562f;
  --prov-bg: #e6defa; --prov-text: #392869;
  --warn-bg: #fbe9c4; --warn-text: #6b4200;
  --off-bg: #e4e2ea; --off-text: #4b475e;
  --alert-bg: #fde0ec; --alert-text: #a30e4c;
  --radius: 4px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14121c; --surface: #1d1a2b; --surface-2: #272339; --text: #ecebf4; --muted: #b3afc9;
    --border: #413c5a; --primary: #c3b4ff; --on-primary: #14121c; --link: #c3b4ff; --focus: #ff7fb0;
    --ok-bg: #173a27; --ok-text: #9fe0b8; --prov-bg: #34295c; --prov-text: #d7ccff;
    --warn-bg: #45330c; --warn-text: #f3d28a; --off-bg: #2e2b3d; --off-text: #bdb9d0;
    --alert-bg: #4a1630; --alert-text: #ffb3d1;
  }
}
:root[data-theme="dark"] {
  --bg: #14121c; --surface: #1d1a2b; --surface-2: #272339; --text: #ecebf4; --muted: #b3afc9;
  --border: #413c5a; --primary: #c3b4ff; --on-primary: #14121c; --link: #c3b4ff; --focus: #ff7fb0;
  --ok-bg: #173a27; --ok-text: #9fe0b8; --prov-bg: #34295c; --prov-text: #d7ccff;
  --warn-bg: #45330c; --warn-text: #f3d28a; --off-bg: #2e2b3d; --off-text: #bdb9d0;
  --alert-bg: #4a1630; --alert-text: #ffb3d1;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 1rem/1.5 var(--font); }
h1 { font-size: 1.375rem; line-height: 1.25; margin: 0 0 .75rem; }
h2 { font-size: 1.0625rem; line-height: 1.3; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: .75rem 0 .25rem; }
p { margin: 0 0 .75rem; max-width: 72ch; }
a { color: var(--link); }
code, .mono { font-family: var(--mono); font-size: .875rem; overflow-wrap: anywhere; }
.muted, .meta { color: var(--muted); }
.meta { font-size: .875rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 80ch; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.spacer { flex: 1; }
.skip { position: absolute; left: -999px; top: 0; background: var(--primary); color: var(--on-primary); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: 0; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.topbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: .5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; color: var(--primary); }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a { padding: .5rem .75rem; text-decoration: none; border-radius: var(--radius); color: var(--text); }
.topbar nav a[aria-current="page"] { background: var(--surface-2); font-weight: 600; box-shadow: inset 0 -3px 0 var(--primary); }
.inline { display: inline-flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: 0; }
.subnav { display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }

main { padding: 1rem; }
.narrow { max-width: 28rem; margin: 3rem auto; }
.page { max-width: 56rem; margin: 0 auto; }
.page.wide { max-width: 80rem; }

.stack { display: flex; flex-direction: column; gap: .5rem; max-width: 40rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: .75rem 0; }
label { font-weight: 600; font-size: .9375rem; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .625rem; min-height: 2.5rem; width: 100%; }
input[type="checkbox"] { width: auto; min-height: 0; }
textarea { resize: vertical; }

button, .button { font: inherit; display: inline-block; min-height: 2.5rem; padding: .4rem .9rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; }
button.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); font-weight: 600; }
button.secondary, .button { background: var(--surface-2); }
button.ghost { background: transparent; border-color: transparent; text-decoration: underline; }
button.danger { color: var(--alert-text); }
button:hover, .button:hover { border-color: var(--primary); }

.alert { background: var(--alert-bg); color: var(--alert-text); border-left: 4px solid var(--alert-text); padding: .5rem .75rem; max-width: 40rem; }
.notice { background: var(--ok-bg); color: var(--ok-text); border-left: 4px solid var(--ok-text); padding: .5rem .75rem; max-width: 40rem; }
.note-provisoire { background: var(--prov-bg); color: var(--prov-text); border-left: 4px solid var(--prov-text); padding: .5rem .75rem; }
.key { display: inline-block; background: var(--surface-2); padding: .5rem .75rem; border-radius: var(--radius); letter-spacing: .1em; }

.badge { display: inline-block; font-size: .8125rem; font-weight: 600; padding: .05rem .5rem; border-radius: 999px; border: 1px solid currentColor; }
.badge-actif { background: var(--ok-bg); color: var(--ok-text); }
.badge-provisoire { background: var(--prov-bg); color: var(--prov-text); }
.badge-a_valider { background: var(--warn-bg); color: var(--warn-text); }
.badge-caduc { background: var(--off-bg); color: var(--off-text); text-decoration: line-through; }
.badge-alerte { background: var(--alert-bg); color: var(--alert-text); }

/* Assistant : conversation à gauche, sources à droite */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 22rem; gap: 1rem; align-items: start; max-width: 96rem; margin: 0 auto; }
.conversation { display: flex; flex-direction: column; min-width: 0; }
.messages { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }
.message { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; }
.message.user { background: var(--surface-2); }
.message .who { font-weight: 700; color: var(--muted); font-size: .875rem; margin-bottom: .25rem; }
.message.error { border-color: var(--alert-text); }
.answer-text { max-width: 72ch; }
.answer-text p:first-child { font-size: 1.0625rem; font-weight: 600; }
.status { color: var(--muted); font-style: normal; }
.live .answer-text { white-space: pre-wrap; }
.steps { margin: .5rem 0; padding-left: 1.75rem; }
.steps li { font-size: 1.0625rem; margin: .35rem 0; padding-left: .25rem; }
.steps li::marker { font-weight: 700; color: var(--primary); }
.cite { font-size: .75rem; vertical-align: super; padding: 0 .2rem; text-decoration: none; font-weight: 700; }
.empty { padding: 2rem 1rem; color: var(--muted); }
.empty h1 { color: var(--text); }

.choices { margin: .75rem 0 0; }
.choice-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .35rem; }
.choice-list button { width: 100%; text-align: left; min-height: 2.75rem; display: flex; gap: .75rem; align-items: center; }
.num { display: inline-block; min-width: 1.5rem; font-weight: 700; color: var(--primary); }
.other { display: flex; gap: .5rem; align-items: end; flex-wrap: wrap; margin-top: .5rem; }
.other input { flex: 1; min-width: 12rem; }
.feedback { display: flex; gap: .5rem; align-items: center; margin-top: .5rem; flex-wrap: wrap; }
.feedback input { max-width: 18rem; }

.composer { position: sticky; bottom: 0; background: var(--bg); padding: .5rem 0 1rem; }
.composer textarea { min-height: 5rem; }
.composer-row { display: flex; gap: .5rem; align-items: center; margin-top: .5rem; flex-wrap: wrap; }
.composer-row input { width: 12rem; }

.sources { position: sticky; top: .5rem; }
.sources summary { cursor: pointer; }
.sources summary h2 { display: inline; margin: 0; }
.source-list { list-style: none; padding: 0; margin: .5rem 0 0; display: flex; flex-direction: column; gap: .5rem; }
.source { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .75rem; }
.source.status-provisoire { border-left: 4px solid var(--prov-text); }
.source:target { outline: 3px solid var(--focus); }
.source p { margin: 0 0 .25rem; }

.rows { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.rows li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .75rem; display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.card-plain { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card-plain.late { border-left: 4px solid var(--alert-text); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; }
.facts dt { font-weight: 600; } .facts dd { margin: 0; }
.passage { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .75rem; margin-bottom: .5rem; }
.passage.current { border-color: var(--primary); border-width: 2px; }
.passage h2, .passage h3 { margin-top: 0; font-size: .9375rem; }
.side-by-side { display: grid; grid-template-columns: 1fr 2fr; gap: 1rem; }
.alerts li { color: var(--warn-text); background: var(--warn-bg); padding: .25rem .5rem; margin-bottom: .25rem; list-style: none; }
.comment { flex-basis: 100%; margin: 0; }

table { border-collapse: collapse; width: 100%; background: var(--surface); }
th, td { border: 1px solid var(--border); padding: .4rem .6rem; text-align: left; vertical-align: top; }
th { background: var(--surface-2); }

.toast { position: fixed; right: 1rem; bottom: 1rem; background: var(--primary); color: var(--on-primary); padding: .5rem 1rem; border-radius: var(--radius); }
.toast:empty { display: none; }

@media (max-width: 64rem) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .sources { position: static; }
  .side-by-side { grid-template-columns: 1fr; }
  .topbar { gap: .5rem; }
}
@media (max-width: 40rem) {
  main { padding: .75rem; }
  button, .button, input, select { min-height: 2.75rem; }
  .facts { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
