/* Portail client ADNT — « l'instrument calme » (PDL §6.8).
   Jetons et contrastes : PDL UX-04 / UX-05. Aucun style en ligne (CSP). */

@font-face {
  font-family: "Sora";
  src: url("fonts/sora-latin-var.0d0e5e4d2f9f.woff2") format("woff2");
  font-weight: 100 800;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/jetbrains-mono-latin-400.caf0dfde4e44.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --bg: #f4f8fc;
  --surface: #ffffff;
  --fg: #0f172a;
  --muted: #475569;
  --accent: #0e7490;
  --accent-hover: #155e75;
  --on-accent: #ffffff;
  --focus: #0e7490;
  --border-input: #64748b;
  --line: #cbd5e1;
  --signal: #06b6d4;
  --danger: #b91c1c;
  --on-danger: #ffffff;

  --b-grey-fg: #334155; --b-grey-bg: #e2e8f0;
  --b-cyan-fg: #155e75; --b-cyan-bg: #cffafe;
  --b-amber-fg: #92400e; --b-amber-bg: #fef3c7;
  --b-green-fg: #065f46; --b-green-bg: #d1fae5;
  --b-red-fg: #991b1b; --b-red-bg: #fee2e2;

  --font: "Sora", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", monospace;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r-control: 6px; --r-card: 10px;
  --shadow: 0 8px 24px rgb(15 23 42 / 0.16);
  --sidebar: 15rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #050b1a;
    --surface: #0b1528;
    --fg: #e2e8f0;
    --muted: #94a3b8;
    --accent: #22d3ee;
    --accent-hover: #67e8f9;
    --on-accent: #050b1a;
    --focus: #67e8f9;
    --border-input: #7c8aa0;
    --line: #1e2a44;
    --danger: #f87171;
    --on-danger: #050b1a;

    --b-grey-fg: #e2e8f0; --b-grey-bg: #334155;
    --b-cyan-fg: #cffafe; --b-cyan-bg: #164e63;
    --b-amber-fg: #fef3c7; --b-amber-bg: #78350f;
    --b-green-fg: #d1fae5; --b-green-bg: #064e3b;
    --b-red-fg: #fee2e2; --b-red-bg: #7f1d1d;
    --shadow: 0 8px 24px rgb(0 0 0 / 0.5);
  }
}

/* --- Base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--fg);
  font: 16px/1.5 var(--font);
}
h1, h2, h3 { line-height: 1.25; font-weight: 600; margin: 0 0 var(--s4); }
h1 { font-size: 1.5625rem; }            /* 25 px */
h2 { font-size: 1.25rem; margin-top: var(--s6); }
h3 { font-size: 1rem; }
p { margin: 0 0 var(--s4); max-width: 70ch; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mono, code { font-family: var(--mono); font-size: .9em; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.icon { width: 1.125em; height: 1.125em; flex: none; vertical-align: -0.2em; }

.skip-link { position: absolute; left: var(--s4); top: -3rem; z-index: 10; padding: var(--s2) var(--s4);
  background: var(--surface); border-radius: var(--r-control); box-shadow: var(--shadow); }
.skip-link:focus { top: var(--s2); }

/* --- Layout ---------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: var(--s4);
  min-height: 56px; padding: 0 var(--s4); background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: var(--s2); color: var(--fg); text-decoration: none; font-weight: 600; }
.brand img { height: 28px; width: auto; }
.brand .product { color: var(--muted); font-weight: 400; }
.topbar .spacer { flex: 1; }
.instance-badge { padding: 2px var(--s2); border: 1px solid var(--accent); border-radius: 999px;
  color: var(--accent); font-size: .75rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }

.shell { display: flex; min-height: calc(100vh - 57px); }
.sidebar { width: var(--sidebar); flex: none; padding: var(--s4) var(--s3); border-right: 1px solid var(--line);
  background: var(--surface); }
.content { flex: 1; min-width: 0; padding: var(--s5) var(--s5) var(--s7); }
.content-inner { max-width: 72rem; }
.footer { padding: var(--s4) var(--s5); color: var(--muted); font-size: .8125rem; }

.nav-section { margin: var(--s5) 0 var(--s2); padding: 0 var(--s3); color: var(--muted);
  font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.nav { list-style: none; margin: 0; padding: 0; }
.nav a { display: flex; align-items: center; gap: var(--s3); min-height: 40px; padding: 0 var(--s3);
  border-radius: var(--r-control); color: var(--fg); text-decoration: none; }
.nav a:hover { background: var(--bg); color: var(--fg); }
.nav a[aria-current="page"] { background: var(--b-cyan-bg); color: var(--b-cyan-fg); font-weight: 600; }
.nav .count { margin-left: auto; min-width: 1.5rem; padding: 0 var(--s2); border-radius: 999px; text-align: center;
  background: var(--b-amber-bg); color: var(--b-amber-fg); font-size: .75rem; font-weight: 600; }

.org-switch { display: block; margin-bottom: var(--s2); padding: var(--s2) var(--s3); border: 1px solid var(--line);
  border-radius: var(--r-control); color: var(--fg); text-decoration: none; }
.org-switch small { display: block; color: var(--muted); font-size: .75rem; }
.org-switch strong { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }

/* Mobile : barre latérale dans un <details> (sans JavaScript). */
.mobile-menu { display: none; }
@media (max-width: 64rem) {
  .shell { display: block; }
  .sidebar { display: none; }
  .mobile-menu { display: block; border-bottom: 1px solid var(--line); background: var(--surface); }
  .mobile-menu > summary { display: flex; align-items: center; gap: var(--s2); min-height: 48px; padding: 0 var(--s4);
    cursor: pointer; list-style: none; font-weight: 600; }
  .mobile-menu > summary::-webkit-details-marker { display: none; }
  .mobile-menu .sidebar { display: block; width: auto; border: 0; }
  .content { padding: var(--s4) var(--s4) var(--s6); }
  .topbar .user-email { display: none; }
}

.user-menu { position: relative; }
.user-menu > summary { display: flex; align-items: center; gap: var(--s2); min-height: 40px; padding: 0 var(--s2);
  border-radius: var(--r-control); cursor: pointer; list-style: none; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu .menu { position: absolute; right: 0; top: calc(100% + 4px); min-width: 16rem; padding: var(--s2);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow); }
.menu a, .menu button { display: flex; align-items: center; gap: var(--s2); width: 100%; min-height: 40px;
  padding: 0 var(--s3); border: 0; border-radius: var(--r-control); background: none; color: var(--fg);
  font: inherit; text-align: left; text-decoration: none; cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--bg); }
.menu .who { padding: var(--s2) var(--s3); color: var(--muted); font-size: .875rem; border-bottom: 1px solid var(--line);
  margin-bottom: var(--s2); }

/* Bandeau « vous consultez ce client en tant qu'ADNT » (ADM-04). */
.staff-banner { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s5);
  background: var(--b-cyan-bg); color: var(--b-cyan-fg); font-size: .875rem; }

/* --- Composants ------------------------------------------------------------ */
.button, button.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 40px;
  padding: 0 var(--s4); border: 1px solid transparent; border-radius: var(--r-control);
  background: var(--accent); color: var(--on-accent); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.button:hover { background: var(--accent-hover); color: var(--on-accent); }
.button.secondary { background: transparent; color: var(--accent); border-color: var(--accent); }
.button.secondary:hover { background: var(--b-cyan-bg); color: var(--b-cyan-fg); }
.button.quiet { background: transparent; color: var(--accent); }
.button.quiet:hover { background: var(--bg); }
.button.danger { background: var(--danger); color: var(--on-danger); }
.button.small { min-height: 32px; padding: 0 var(--s3); font-size: .875rem; }
.button.block { width: 100%; }
@media (pointer: coarse) { .button, .nav a, .menu a, .menu button { min-height: 44px; } }
.actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
form.inline { display: inline; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: var(--s5); }
.card + .card { margin-top: var(--s4); }
.card > :last-child { margin-bottom: 0; }
.card.narrow { max-width: 30rem; }
.grid { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
  margin-bottom: var(--s4); }

/* Équerres cyan : réservées à ce qui attend une action (UX-03). */
.brackets { position: relative; }
.brackets::before, .brackets::after { content: ""; position: absolute; width: 14px; height: 14px; border: 2px solid var(--signal); }
.brackets::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; border-top-left-radius: var(--r-card); }
.brackets::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; border-bottom-right-radius: var(--r-card); }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s4);
  margin-bottom: var(--s5); }
.page-head h1 { margin: 0; }
.page-head .subtitle { margin: var(--s1) 0 0; color: var(--muted); }
.breadcrumb { margin-bottom: var(--s2); font-size: .875rem; }

/* Messages (4 variantes, UX-07). */
.messages { list-style: none; margin: 0 0 var(--s5); padding: 0; display: grid; gap: var(--s2); }
.message { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--r-control);
  border: 1px solid; max-width: 70ch; }
.message.success { background: var(--b-green-bg); color: var(--b-green-fg); border-color: var(--b-green-fg); }
.message.info { background: var(--b-cyan-bg); color: var(--b-cyan-fg); border-color: var(--b-cyan-fg); }
.message.warning { background: var(--b-amber-bg); color: var(--b-amber-fg); border-color: var(--b-amber-fg); }
.message.error { background: var(--b-red-bg); color: var(--b-red-fg); border-color: var(--b-red-fg); }

/* Badges de statut (UX-05). */
.badge { display: inline-flex; align-items: center; gap: var(--s1); padding: 1px var(--s2); border-radius: 999px;
  font-size: .8125rem; font-weight: 600; white-space: nowrap; }
.badge.grey { background: var(--b-grey-bg); color: var(--b-grey-fg); }
.badge.cyan { background: var(--b-cyan-bg); color: var(--b-cyan-fg); }
.badge.amber { background: var(--b-amber-bg); color: var(--b-amber-fg); }
.badge.green { background: var(--b-green-bg); color: var(--b-green-fg); }
.badge.red { background: var(--b-red-bg); color: var(--b-red-fg); }

/* Tableaux : cadre à défilement horizontal. */
.table-wrap { overflow-x: auto; margin-bottom: var(--s5); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: var(--s3) var(--s4); text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: .8125rem; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.actions-cell { text-align: right; white-space: nowrap; }

/* Formulaires (UX-07). */
.field { margin-bottom: var(--s4); max-width: 34rem; }
.field label, .field legend { display: block; margin-bottom: var(--s1); font-weight: 600; font-size: .9375rem; }
.field .help { margin-top: var(--s1); color: var(--muted); font-size: .875rem; }
.field .errors { margin: var(--s1) 0 0; padding: 0; list-style: none; color: var(--b-red-fg); font-size: .875rem; }
input[type="text"], input[type="email"], input[type="search"], input[type="number"], input[type="date"],
select, textarea {
  width: 100%; min-height: 40px; padding: var(--s2) var(--s3); border: 1px solid var(--border-input);
  border-radius: var(--r-control); background: var(--surface); color: var(--fg); font: inherit;
}
textarea { min-height: 6rem; }
.field-check { display: flex; gap: var(--s2); align-items: center; font-weight: 400; }
.field-check input { width: 1.125rem; height: 1.125rem; accent-color: var(--accent); }
.form-errors { margin: 0 0 var(--s4); }
.inline-fields { display: flex; flex-wrap: wrap; gap: var(--s4); align-items: flex-end; }
.inline-fields .field { margin: 0; flex: 1 1 14rem; }

/* États vides. */
.empty { padding: var(--s5); border: 1px dashed var(--line); border-radius: var(--r-card); color: var(--muted); }
.empty p { margin-bottom: var(--s3); }

/* Listes d'objets (organisations, demandes). */
.rows { list-style: none; margin: 0 0 var(--s5); padding: 0; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); }
.rows > li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3) var(--s4); padding: var(--s4);
  border-bottom: 1px solid var(--line); }
.rows > li:last-child { border-bottom: 0; }
.rows .grow { flex: 1 1 16rem; min-width: 0; }
.rows .title { font-weight: 600; }

/* Onglets (fiche client). */
.tabs { display: flex; gap: var(--s1); margin: 0 0 var(--s5); padding: 0; list-style: none; border-bottom: 1px solid var(--line);
  overflow-x: auto; }
.tabs a { display: block; padding: var(--s2) var(--s4); border-bottom: 2px solid transparent; color: var(--muted);
  text-decoration: none; white-space: nowrap; }
.tabs a[aria-current="page"] { border-color: var(--accent); color: var(--fg); font-weight: 600; }

.stat { font-size: 1.5625rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: minmax(7rem, max-content) minmax(0, 1fr); gap: var(--s2) var(--s4); margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* Page de connexion. */
.auth { display: grid; place-items: start center; padding-top: 8vh; }
.auth .card { width: min(100%, 28rem); }
.auth .logo { height: 48px; margin-bottom: var(--s4); }
.h3 { font-size: 1rem; margin-top: 0; }
.card > h2:first-child, .card > h1:first-child { margin-top: 0; }
/* Pages without navigation (sign-in, refusal): centred column. */
.shell:not(:has(.sidebar)) .content-inner { margin: 0 auto; }
.lines-editor td { padding: var(--s2); }
.lines-editor input, .lines-editor select { min-width: 5rem; }
.lines-editor td:first-child input { min-width: 16rem; }
.lines-editor select { min-width: 12rem; }
.lines-editor input.num { width: 7rem; min-width: 0; }
input.num { text-align: right; }
tfoot td, tfoot th { font-weight: 400; font-size: 1rem; color: var(--fg); }
tfoot tr:first-child td, tfoot tr:first-child th { border-top: 1px solid var(--line); }
tfoot tr:last-child th, tfoot tr:last-child td { border-top: 2px solid var(--fg); font-weight: 600; }

/* Filter bar below a page title. */
.filters { display: flex; flex-wrap: wrap; gap: var(--s3) var(--s4); align-items: flex-end; margin-bottom: var(--s5); }
.filters .field { margin: 0; flex: 0 1 14rem; }
/* Form sections in columns (billing profile). */
.form-grid { display: grid; gap: 0 var(--s5); grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
.form-grid .field { max-width: none; }
fieldset { border: 0; margin: 0 0 var(--s4); padding: 0; }
legend { font-weight: 600; margin-bottom: var(--s3); }
.address { font-style: normal; line-height: 1.6; }
.week-grid th[scope="row"] { font-size: 1rem; color: var(--fg); font-weight: 600; }
.week-grid td.num { min-width: 4.5rem; }

/* Markdown written in the portal (mission books, HRS-17). */
.prose { overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3 { margin: var(--s5) 0 var(--s2); }
.prose h1 { font-size: 1.4rem; }
.prose h2 { font-size: 1.2rem; }
.prose h3 { font-size: 1.05rem; }
.prose ul, .prose ol { padding-left: 1.4rem; }
.prose table { border-collapse: collapse; width: 100%; margin: var(--s3) 0; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: var(--s2); text-align: left; vertical-align: top; }
.prose pre { background: var(--bg); padding: var(--s3); border-radius: 6px; overflow-x: auto; }
.prose blockquote { border-left: 3px solid var(--line); margin-left: 0; padding-left: var(--s4); color: var(--muted); }

/* Clock (PDL MOB-03): large targets, readable at arm's length on a phone. */
.clock .chrono { font-size: clamp(2.5rem, 12vw, 4rem); font-weight: 600; margin: var(--s2) 0; letter-spacing: .02em; }
.clock.running { border-color: var(--accent); }
.button.big { min-height: 56px; min-width: 10rem; font-size: 1.15rem; }

/* Mission book WYSIWYG editor (Milkdown, HRS-17): the portal's tokens instead of the theme's. */
.markdown-editor { border: 1px solid var(--border-input); border-radius: 8px; overflow: hidden; margin-bottom: var(--s4); }
.markdown-editor .milkdown {
  --crepe-color-background: var(--surface);
  --crepe-color-on-background: var(--fg);
  --crepe-color-surface: var(--bg);
  --crepe-color-surface-low: var(--bg);
  --crepe-color-on-surface: var(--fg);
  --crepe-color-on-surface-variant: var(--muted);
  --crepe-color-outline: var(--line);
  --crepe-color-primary: var(--accent);
  --crepe-color-hover: var(--bg);
  --crepe-color-selected: var(--line);
  --crepe-font-title: inherit;
  --crepe-font-default: inherit;
  --crepe-font-code: var(--mono);
  --crepe-base-font-size: 1rem;
}
.markdown-editor .milkdown .ProseMirror { min-height: 16rem; padding: var(--s4) var(--s5); }
.field:has(> .markdown-editor) { max-width: none; }
.markdown-editor .milkdown .ProseMirror h1 { font-size: 1.4rem; margin: var(--s5) 0 var(--s2); }
.markdown-editor .milkdown .ProseMirror h2 { font-size: 1.2rem; margin: var(--s5) 0 var(--s2); }
.markdown-editor .milkdown .ProseMirror h3 { font-size: 1.05rem; margin: var(--s4) 0 var(--s2); }
