/* Palette chaude : l'outil sert à encoder des dizaines de champs numériques d'affilée,
   des neutres froids rendaient l'ensemble clinique. Le teal porte l'action, l'ambre
   signale ce qui demande attention. */
:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f5f1ea;
  --surface-3: #ece5da;
  --text: #241f1b;
  --muted: #6b6259;
  --line: #e4dccf;
  --line-strong: #cfc3b1;
  --accent: #0f6156;
  --accent-hover: #0b4a41;
  --accent-text: #ffffff;
  --accent-soft: #e4efec;
  --amber: #8a5600;
  --amber-soft: #fbf0dc;
  --danger: #a3302a;
  --danger-soft: #f8e9e7;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(60, 45, 25, 0.06), 0 6px 20px rgba(60, 45, 25, 0.05);
  --shadow-sticky: 0 4px 16px rgba(60, 45, 25, 0.1);

  --header-h: 58px;
  --nav-h: 48px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #17140f;
    --surface: #211d18;
    --surface-2: #2a251f;
    --surface-3: #352f27;
    --text: #f1ece4;
    --muted: #a99f92;
    --line: #37312a;
    --line-strong: #4c443a;
    --accent: #5ec4b3;
    --accent-hover: #7bd3c4;
    --accent-text: #10201d;
    --accent-soft: #1d332f;
    --amber: #e3aa55;
    --amber-soft: #33291a;
    --danger: #e89b95;
    --danger-soft: #331f1d;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);
    --shadow-sticky: 0 4px 16px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + var(--nav-h) + 12px); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
}

main { max-width: 1220px; margin: 0 auto; padding: 28px 16px 120px; }

h1 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem); line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 6px; }
h2 { font-size: 1.2rem; letter-spacing: -0.01em; margin: 0; }
h3 {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin: 28px 0 10px; font-weight: 700;
}
sup { font-size: 0.7em; }
a { color: var(--accent); text-underline-offset: 2px; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.875rem; margin: 6px 0 14px; max-width: 78ch; }
.num { text-align: right; }

/* En-tête et navigation ------------------------------------------------ */
.site-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  min-height: var(--header-h);
  padding: 0 18px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; letter-spacing: -0.015em; text-decoration: none; color: var(--text);
}
.brand svg { flex: none; }
.brand span { color: var(--muted); font-weight: 500; }
.site-header nav { display: flex; gap: 6px; align-items: center; }
.site-header nav a, .site-header nav button {
  padding: 6px 12px; border-radius: 999px; text-decoration: none;
  color: var(--muted); font-size: 0.9rem; font-weight: 500;
}
.site-header nav a:hover, .site-header nav button:hover { background: var(--surface-2); color: var(--text); }
.site-header form { margin: 0; }

/* Navigation de section, collante sous l'en-tête. */
.section-nav {
  position: sticky; top: var(--header-h); z-index: 30;
  display: flex; gap: 6px; align-items: center; overflow-x: auto;
  min-height: var(--nav-h);
  margin: 0 -16px 20px; padding: 0 16px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.section-nav::-webkit-scrollbar { display: none; }
.section-nav a {
  display: flex; align-items: center; gap: 7px; flex: none;
  padding: 6px 13px; border-radius: 999px;
  font-size: 0.875rem; font-weight: 500; text-decoration: none;
  color: var(--muted); border: 1px solid transparent; white-space: nowrap;
}
.section-nav a:hover { background: var(--surface); border-color: var(--line); color: var(--text); }
.section-nav a .step {
  display: grid; place-items: center; width: 20px; height: 20px;
  border-radius: 50%; background: var(--surface-3); color: var(--muted);
  font-size: 0.72rem; font-weight: 700;
}
.section-nav a:hover .step { background: var(--accent); color: var(--accent-text); }

.site-footer {
  border-top: 1px solid var(--line);
  padding: 20px 16px; color: var(--muted); font-size: 0.85rem; text-align: center;
}

.page-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; margin-bottom: 18px; }

/* Blocs ---------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin: 0 0 22px;
  box-shadow: var(--shadow);
}
.card > h2:first-child, .card-head { margin-bottom: 4px; }

/* Titre de section : pastille numérotée + icône. */
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.card-head .step {
  display: grid; place-items: center; flex: none; width: 34px; height: 34px;
  border-radius: 11px; background: var(--accent-soft); color: var(--accent);
}
.card-head .step svg { width: 18px; height: 18px; }

fieldset {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px 18px; margin: 0 0 16px; background: var(--surface-2);
}
legend { color: var(--muted); font-size: 0.8rem; font-weight: 600; padding: 0 7px; }

/* Formulaires ---------------------------------------------------------- */
label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 5px; color: var(--muted); }

input[type='text'], input[type='email'], input[type='number'], input[type='password'], textarea {
  width: 100%;
  padding: 9px 11px;
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
}
input:hover:not([readonly]), textarea:hover:not([readonly]) { border-color: var(--accent); }
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[readonly] { background: var(--surface-2); color: var(--muted); border-style: dashed; }
textarea { resize: vertical; }

.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 18px; align-items: end; }
.grid-form.narrow { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.checks { display: flex; flex-wrap: wrap; gap: 18px; margin: 12px 0; }
.checks label, label.check {
  display: flex; align-items: center; gap: 9px; margin: 8px 0;
  color: var(--text); font-weight: 400; cursor: pointer;
}
.checks input, label.check input { width: auto; accent-color: var(--accent); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin: 22px 0; align-items: center; }
.toolbar form { margin: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  font: inherit; font-weight: 500; text-decoration: none;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  cursor: pointer; transition: background 0.12s, border-color 0.12s, transform 0.06s;
}
.btn:hover { border-color: var(--accent); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
button.link { background: none; border: none; font: inherit; cursor: pointer; }

/* Tableaux de saisie --------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface);
}

.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.925rem; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.table tbody tr:last-child th, .table tbody tr:last-child td { border-bottom: none; }
.table th.num, .table td.num { text-align: right; }
.table thead th {
  position: relative;
  background: var(--surface-2);
  font-size: 0.76rem; font-weight: 700; color: var(--muted);
  letter-spacing: 0.02em; vertical-align: bottom;
  border-bottom: 1px solid var(--line-strong);
}
.table tbody th[scope='row'] { font-weight: 500; }
.table tbody tr:nth-child(even) > * { background: var(--surface-2); }
.table tbody tr:hover > * { background: var(--accent-soft); }

/* Le nom de la fonction reste visible quand on fait défiler les colonnes :
   sans cela, sur un écran étroit, on saisit à l'aveugle. */
.table.grid tbody th[scope='row'] {
  position: sticky; left: 0; z-index: 2;
  background: var(--surface);
  border-right: 1px solid var(--line);
  min-width: 210px; max-width: 320px;
}
.table.grid thead th:first-child {
  position: sticky; left: 0; z-index: 3;
  background: var(--surface-2);
  border-right: 1px solid var(--line-strong);
}
.table.grid tbody th[scope='row'] .muted { display: block; font-size: 0.78rem; }

.table.grid td.num input { width: 88px; text-align: right; padding: 6px 9px; }
/* Un champ vide s'efface visuellement pour que les valeurs saisies ressortent
   du quadrillage — il y a plus de trente lignes et la plupart restent à zéro. */
.table.grid td.num input:placeholder-shown { color: var(--muted); border-color: var(--line); background: transparent; }
.table.grid thead th.num { max-width: 148px; white-space: normal; }
.table .total { font-variant-numeric: tabular-nums; font-weight: 700; }
.table td.total { color: var(--accent); }
.table td.total.is-zero { color: var(--muted); font-weight: 500; }

.table.recap tbody tr.has-vacant > * { background: var(--amber-soft); }
.table.recap tbody tr.has-vacant td.total { color: var(--amber); }
.table.recap tbody tr:not(.has-vacant) { color: var(--muted); }
.table tfoot th {
  background: var(--surface-2); font-weight: 700;
  border-top: 1px solid var(--line-strong); border-bottom: none;
}

.row-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.row-actions form { margin: 0; }
.btn.icon-only { padding: 8px; color: var(--muted); }
.btn.icon-only:hover { color: var(--danger); background: var(--danger-soft); border-color: var(--danger); }

.col-num {
  display: inline-grid; place-items: center; width: 18px; height: 18px; margin-right: 5px;
  background: var(--surface-3); color: var(--accent);
  border-radius: 5px; font-size: 0.7rem; font-weight: 800;
}

.identity { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin: 18px 0 0; }
.identity div { margin: 0; }
.identity dt { font-size: 0.78rem; color: var(--muted); font-weight: 500; }
.identity dd { margin: 3px 0 0; font-weight: 500; }

/* Barre de total, toujours visible pendant la saisie. */
.summary-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 11px 20px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
  border-top: 1px solid var(--line-strong);
  box-shadow: var(--shadow-sticky);
}
.summary-bar .label { display: block; color: var(--muted); font-size: 0.8rem; font-weight: 500; }
.summary-bar .value { font-size: 1.35rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.summary-bar .value.is-zero { color: var(--muted); }
.summary-bar .btn { padding: 8px 15px; }
.summary-total { min-width: 0; }
/* Toutes les actions restent visibles : l'application est utilisée au bureau,
   pas sur téléphone. Sur un écran étroit elles passent simplement à la ligne. */
.summary-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.summary-actions form { margin: 0; }

/* Statuts -------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 11px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600; border: 1px solid var(--line-strong); color: var(--muted);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.final { color: var(--accent); border-color: currentColor; background: var(--accent-soft); }
.badge.draft { color: var(--amber); border-color: currentColor; background: var(--amber-soft); }

.notice {
  padding: 11px 16px; margin: 14px 0;
  border-left: 3px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--accent-soft);
}
.notice.warn { border-left-color: var(--amber); background: var(--amber-soft); }
.error { color: var(--danger); background: var(--danger-soft); padding: 10px 14px; border-radius: var(--radius-sm); }

/* Connexion ------------------------------------------------------------ */
.login-body {
  display: grid; place-items: center; min-height: 100vh; padding: 16px;
  background: radial-gradient(120% 90% at 50% 0%, var(--accent-soft) 0%, var(--bg) 58%);
}
.login { width: min(400px, 100%); }
.login h1 { font-size: 1.4rem; }
.login h1 span { color: var(--muted); font-weight: 500; }
.login .btn { width: 100%; justify-content: center; margin-top: 18px; }

/* Impression ----------------------------------------------------------- */
.print-body { background: var(--surface); }
.sheet { max-width: 820px; margin: 0 auto; padding: 36px 20px; }
.sheet h1 { font-size: 1.4rem; }
.sheet h2 { margin-top: 30px; font-size: 1.05rem; }
.sheet .table { border: 1px solid var(--line); border-radius: var(--radius-sm); }
.footnote { margin-top: 34px; font-size: 0.85rem; }

@media print {
  :root {
    --bg: #fff; --surface: #fff; --surface-2: #fff; --surface-3: #fff;
    --text: #000; --muted: #444; --line: #999; --line-strong: #666;
    --accent: #000; --accent-soft: #fff; --amber: #000; --amber-soft: #fff;
    --shadow: none;
  }
  .site-header, .site-footer, .toolbar, .section-nav, .summary-bar { display: none; }
  .sheet { padding: 0; max-width: none; }
  .card { box-shadow: none; border: none; padding: 0; }
  .table { font-size: 0.8rem; }
}

@media (max-width: 640px) {
  main { padding: 20px 14px 110px; }
  .card { padding: 18px 14px; border-radius: var(--radius-sm); }
  .table.grid tbody th[scope='row'] { min-width: 160px; font-size: 0.85rem; }
  .summary-bar { padding: 9px 12px; gap: 10px; }
  .summary-bar .value { font-size: 1.15rem; }
  .summary-bar .label { font-size: 0.72rem; }
  .summary-bar .btn { padding: 7px 11px; font-size: 0.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
