/* Mobile d'abord. Les couleurs suivent le système, ou le choix fait avec le bouton de thème. */
:root {
  color-scheme: light dark;
  --page: light-dark(#f5f6f9, #0d1016);
  --surface: light-dark(#ffffff, #161a22);
  --sunken: light-dark(#eef1f6, #1f2530);
  --ink: light-dark(#141a26, #eef1f6);
  --muted: light-dark(#566074, #a3adbf);
  --line: light-dark(#dfe3eb, #2b3240);
  --field: light-dark(#858fa3, #69748a);
  --accent: light-dark(#2350d8, #8badff);
  --accent-hover: light-dark(#1a3fb0, #a9c2ff);
  --on-accent: light-dark(#ffffff, #0c1630);
  --accent-soft: light-dark(#e8eeff, #1d2a4c);
  --good: light-dark(#0b6b2a, #6fd58c);
  --good-soft: light-dark(#e0f5e6, #153322);
  --warn: light-dark(#855000, #f7c35c);
  --warn-soft: light-dark(#fff1d3, #3a2c10);
  --bad: light-dark(#b02025, #ff9393);
  --bad-soft: light-dark(#fde7e7, #421c20);
  --shadow: 0 1px 2px light-dark(rgb(20 26 38 / .06), rgb(0 0 0 / .4));
  --r: 14px;
  --r-s: 10px;
  --nav-h: 64px;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; }
body { margin: 0; background: var(--page); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3, p, ul, dl, dd, figure { margin: 0; }
h1 { font-size: clamp(1.45rem, 1.2rem + 1.2vw, 1.9rem); line-height: 1.2; letter-spacing: -.02em; overflow-wrap: anywhere; text-wrap: balance; }
h2 { font-size: 1.12rem; line-height: 1.3; letter-spacing: -.01em; }
h3 { font-size: 1rem; line-height: 1.35; }
a { color: var(--accent); text-underline-offset: 3px; }
svg.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: fixed; top: 8px; left: 8px; z-index: 50; padding: 10px 16px; background: var(--surface); border-radius: var(--r-s); transform: translateY(-200%); }
.skip:focus { transform: none; }
.muted { color: var(--muted); font-size: .9rem; }
.break { overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }

/* ---------- Structure ---------- */
.side { display: none; }
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--surface); border-bottom: 1px solid var(--line); }
.top .brand { margin-right: auto; }
.brand { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); font-size: 1.1rem; font-weight: 700; letter-spacing: -.02em; text-decoration: none; }
.logo { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; background: var(--accent); color: var(--on-accent); }
main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; max-width: 1200px; margin: 0 auto; padding: 20px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
.strip { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 16px; background: var(--warn-soft); color: var(--warn); font-size: .88rem; font-weight: 600; }
.strip svg { width: 16px; height: 16px; }
.bottom { position: fixed; inset: auto 0 0; z-index: 10; display: grid; grid-template-columns: repeat(3, 1fr); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); }
.bottom a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--nav-h); color: var(--muted); font-size: .78rem; font-weight: 600; text-decoration: none; }
.bottom a[aria-current] { color: var(--accent); }

.head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; }
.head > div:first-child { min-width: 0; flex: 1 1 240px; }
.title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.crumb { display: inline-flex; align-items: center; gap: 4px; min-height: 36px; color: var(--muted); font-size: .9rem; text-decoration: none; }
.crumb:hover { color: var(--accent); }
.crumb svg { width: 16px; height: 16px; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-content: start; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row.end { align-items: flex-end; }
.between { justify-content: space-between; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 16px; align-items: start; }
.grid > .wide { grid-column: 1 / -1; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); gap: 16px; }

.card { min-width: 0; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card.link { position: relative; transition: border-color .15s; }
.card.link:hover { border-color: var(--accent); }
.card.link h3 a { color: inherit; text-decoration: none; }
.card.link h3 a::after { content: ""; position: absolute; inset: 0; border-radius: var(--r); }
.card.link h3 a:focus-visible { outline: none; }
.card.link:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Onglets et filtres ---------- */
.tabs, .chips { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin-inline: -16px; padding: 4px 16px; scroll-padding-inline: 16px; }
.tabs::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.tabs { box-shadow: inset 0 -1px var(--line); padding-bottom: 0; }
.tabs a { display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 14px; color: var(--muted); font-weight: 600; white-space: nowrap; text-decoration: none; border-bottom: 3px solid transparent; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current] { color: var(--accent); border-color: var(--accent); }
.tabs a:focus-visible, .chips a:focus-visible { outline-offset: -3px; }
.chips { gap: 8px; }
.chips a { display: flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); color: var(--ink); font-size: .9rem; white-space: nowrap; text-decoration: none; }
.chips a[aria-current] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ---------- Badges, chiffres, jauges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 99px; background: var(--sunken); color: var(--ink); font-size: .82rem; font-weight: 600; line-height: 1.4; white-space: nowrap; }
.badge svg { width: 14px; height: 14px; stroke-width: 2.4; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 148px), 1fr)); gap: 12px; }
.kpi { display: flex; flex-direction: column; gap: 4px; padding: 16px; }
.kpi dt { color: var(--muted); font-size: .88rem; }
.kpi dd { font-size: 1.7rem; font-weight: 650; line-height: 1.15; letter-spacing: -.02em; }
.kpi dd small { color: var(--muted); font-size: .95rem; font-weight: 500; letter-spacing: 0; }
.kpi .muted { font-size: .84rem; letter-spacing: 0; font-weight: 400; line-height: 1.4; }
.mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini dt { color: var(--muted); font-size: .8rem; }
.mini dd { font-weight: 650; font-size: 1.1rem; }
.meter { height: 8px; margin-top: 10px; overflow: hidden; border-radius: 99px; background: var(--accent-soft); }
.meter i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }

.facts { display: grid; gap: 12px; }
.facts dt { color: var(--muted); font-size: .85rem; }
.facts dd { overflow-wrap: anywhere; }

/* ---------- Messages ---------- */
.note { display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--r); background: var(--accent-soft); }
.note > svg { margin-top: 2px; color: var(--accent); }
.note > div { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.note.warn { background: var(--warn-soft); } .note.warn > svg { color: var(--warn); }
.note.bad { background: var(--bad-soft); } .note.bad > svg { color: var(--bad); }
.note.good { background: var(--good-soft); } .note.good > svg { color: var(--good); }
.todo { display: grid; gap: 4px; margin-top: 8px; padding: 0; list-style: none; }
.todo a { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; color: inherit; text-decoration: none; border-top: 1px solid var(--line); }
.todo a:hover span { text-decoration: underline; }
.empty { display: grid; justify-items: center; gap: 8px; padding: 36px 18px; text-align: center; border: 1px dashed var(--field); border-radius: var(--r); }
.empty > svg { width: 32px; height: 32px; color: var(--accent); }
.empty p { max-width: 46ch; color: var(--muted); }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 30; display: flex; align-items: center; gap: 12px; margin: auto; max-width: 460px; padding: 8px 8px 8px 16px; border-radius: var(--r); background: light-dark(#141a26, #eef1f6); color: light-dark(#fff, #141a26); box-shadow: 0 10px 30px rgb(0 0 0 / .25); }
.toast span { flex: 1; }
.toast button { background: none; color: inherit; border: 0; }

/* ---------- Boutons et champs ---------- */
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 9px 16px; border: 1px solid transparent; border-radius: var(--r-s); background: var(--accent); color: var(--on-accent); font: inherit; font-weight: 600; line-height: 1.25; text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s; }
button:hover, .btn:hover { background: var(--accent-hover); }
button svg.i, .btn svg.i { width: 18px; height: 18px; }
.light { background: var(--surface); color: var(--ink); border-color: var(--field); }
.light:hover { background: var(--sunken); }
.danger { background: var(--surface); color: var(--bad); border-color: currentColor; }
.danger:hover { background: var(--bad-soft); }
[data-yes].danger { background: light-dark(#b02025, #ff9393); color: light-dark(#fff, #2b0808); border-color: transparent; }
.ghost { background: transparent; color: var(--muted); }
.ghost:hover { background: var(--sunken); color: var(--ink); }
.icon { width: 44px; padding: 0; }
button:disabled { opacity: .5; cursor: not-allowed; }
button[aria-busy="true"] { cursor: progress; opacity: .75; }
button[aria-busy="true"]::before { content: ""; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
button[aria-busy="true"] svg { display: none; }
@keyframes spin { to { transform: rotate(1turn); } }

form.stack { gap: 16px; }
label { display: block; min-width: 0; font-size: .92rem; font-weight: 600; }
label small { display: block; color: var(--muted); font-size: .84rem; font-weight: 400; }
input, textarea, select { display: block; width: 100%; min-height: 44px; margin-top: 6px; padding: 9px 12px; border: 1px solid var(--field); border-radius: var(--r-s); background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; font-weight: 400; }
textarea { resize: vertical; line-height: 1.55; field-sizing: content; min-height: 5.5em; }
textarea.mail { min-height: 15em; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline-offset: -1px; border-color: var(--accent); border-radius: var(--r-s); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input[readonly] { background: var(--sunken); }
input[type="file"] { padding: 14px; border-style: dashed; background: var(--sunken); }
input[type="file"]::file-selector-button { margin-right: 12px; padding: 6px 12px; border: 1px solid var(--field); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; cursor: pointer; }
.num { flex: 0 1 120px; }
.grow { flex: 1 1 200px; }
.check { display: flex; align-items: flex-start; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: var(--r-s); font-weight: 500; cursor: pointer; }
.check input { flex: none; width: 20px; min-height: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--accent); }
.actions { display: grid; gap: 10px; }

details > summary { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; list-style: none; font-weight: 600; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: ""; flex: none; width: 8px; height: 8px; margin: 0 6px 4px auto; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform .15s; }
details[open] > summary::after { transform: translateY(4px) rotate(225deg); }
details[open] > summary { margin-bottom: 14px; }
summary > span:first-of-type { min-width: 0; overflow-wrap: anywhere; }
.sub { padding: 8px 14px; border: 1px solid var(--line); border-radius: var(--r-s); }
.sub[open] { padding-bottom: 14px; }
.sub-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }

/* ---------- Éditeur d'email ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.vars { display: flex; flex-wrap: wrap; gap: 6px; }
.vars button { min-height: 36px; padding: 4px 12px; background: var(--accent-soft); color: var(--accent); font-size: .85rem; }
.vars button:hover { border-color: var(--accent); }
.preview { padding: 16px; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--sunken); }
.preview .subject { margin: 4px 0 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); font-weight: 650; overflow-wrap: anywhere; }
.preview .body, pre { margin: 0; font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- Étapes et historique ---------- */
.step-n { display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.timeline { display: grid; gap: 18px; margin: 0; padding: 0 0 0 22px; list-style: none; border-left: 2px solid var(--line); }
.timeline li { position: relative; min-width: 0; overflow-wrap: anywhere; }
.timeline li::before { content: ""; position: absolute; left: -29px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }

/* ---------- Tableaux : une carte par ligne sur petit écran ---------- */
.table { display: block; width: 100%; border-collapse: collapse; }
.table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.table tbody { display: grid; gap: 12px; }
.table tr { display: grid; gap: 8px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.table td { display: grid; grid-template-columns: minmax(96px, 38%) minmax(0, 1fr); gap: 12px; overflow-wrap: anywhere; font-size: .95rem; }
.table td::before { content: attr(data-label); color: var(--muted); font-size: .86rem; }
.table td > div { min-width: 0; }
.table td:first-child { display: block; font-weight: 600; font-size: 1rem; }
.table td:first-child::before { content: none; }
.table td:first-child a { display: inline-flex; align-items: center; min-height: 32px; overflow-wrap: anywhere; }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }

/* ---------- Fenêtres ---------- */
dialog { width: min(460px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgb(0 0 0 / .3); }
dialog::backdrop { background: rgb(8 12 20 / .55); }
dialog .row { justify-content: flex-end; }

/* ---------- Connexion et pages des destinataires ---------- */
.solo { display: grid; align-content: center; gap: 20px; min-height: 100svh; max-width: 520px; padding-block: 32px; }
.solo.login { max-width: 420px; }
.solo .card { display: grid; gap: 14px; padding: clamp(20px, 5vw, 32px); }
.solo h2 { margin-top: 4px; }
.solo button { width: 100%; }

@media (max-width: 599px) {
  .tabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0; padding-inline: 4px; }
  .tabs a { flex-direction: column; justify-content: center; gap: 4px; min-height: 60px; padding: 4px 0; font-size: .75rem; }
}
@media (min-width: 560px) {
  .actions { display: flex; flex-wrap: wrap; }
}
@media (min-width: 760px) {
  main { padding-inline: 28px; gap: 24px; }
  .tabs, .chips { margin-inline: 0; padding-inline: 2px; }
  .card { padding: 22px; }
  .kpi { padding: 18px 20px; }
  .table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
  .table { display: table; }
  .table thead { position: static; display: table-header-group; width: auto; height: auto; clip-path: none; }
  .table tbody { display: table-row-group; }
  .table tr { display: table-row; padding: 0; border: 0; }
  .table th, .table td, .table td:first-child { display: table-cell; padding: 12px 16px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); font-size: .93rem; font-variant-numeric: tabular-nums; }
  .table th { color: var(--muted); font-size: .82rem; font-weight: 600; background: var(--sunken); white-space: nowrap; }
  .table td::before { content: none; }
  .table tbody tr:last-child td { border-bottom: 0; }
  .table tbody tr:hover { background: var(--sunken); }
}
@media (min-width: 1000px) {
  body.app { display: grid; grid-template-columns: 284px minmax(0, 1fr); }
  .top, .bottom, .strip { display: none; }
  .side { position: sticky; top: 0; display: flex; flex-direction: column; gap: 4px; height: 100dvh; padding: 18px 14px; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line); }
  .side .brand { margin: 0 8px 16px; }
  .side nav { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .side nav a { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: var(--r-s); color: var(--muted); font-weight: 600; text-decoration: none; }
  .side nav a span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .side nav a:hover { background: var(--sunken); color: var(--ink); }
  .side nav a[aria-current] { background: var(--accent-soft); color: var(--accent); }
  .side nav a .state { flex: none; margin-left: auto; font-size: .75rem; }
  .side h2 { margin: 18px 12px 6px; color: var(--muted); font-size: .8rem; font-weight: 600; letter-spacing: 0; }
  .side footer { display: grid; justify-items: start; gap: 8px; margin-top: auto; padding: 16px 8px 0; }
  main { width: 100%; padding: 32px 36px 56px; }
  body:not(.app) main { padding: 32px; }
  .toast { left: auto; right: 28px; bottom: 28px; width: 420px; }
  .editor, .split { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
  .split { display: grid; gap: 20px; align-items: start; }
  .preview { position: sticky; top: 20px; align-self: start; }
  html { scroll-padding-top: 20px; }
}
.split { display: grid; gap: 20px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: 2s !important; }
}
@media (forced-colors: active) {
  .meter { border: 1px solid CanvasText; }
  .meter i { background: Highlight; forced-color-adjust: none; }
}
