/* ==========================================================================
   Valmorin — socle commun (portail public + espace agents)
   Palette calme : papier chaud, vert « service public », touche soleil.
   ========================================================================== */
:root {
  color-scheme: light;
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --surface-2: #FBFAF7;
  --ink: #17201F;
  --ink-2: #3D4947;
  --muted: #5B6664;
  --line: #E3DFD5;
  --line-2: #EFECE4;

  --primary: #1D6B58;
  --primary-hover: #165544;
  --primary-soft: #E2EFEA;

  --sun: #F2B544;
  --sun-soft: #FDF3DC;
  --info: #24507A;
  --info-soft: #E4EDF6;
  --warn: #7F4C00;
  --warn-soft: #FCEFD6;
  --ok: #1F6641;
  --ok-soft: #E1F1E7;
  --danger: #B42318;
  --danger-soft: #FCE8E6;
  --violet: #5A4A94;
  --violet-soft: #ECE9F6;

  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(23, 32, 31, .06);
  --shadow: 0 1px 2px rgba(23, 32, 31, .05), 0 12px 32px -16px rgba(23, 32, 31, .22);
  --ease: cubic-bezier(.2, .7, .2, 1);

  --font-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-head: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { font-family: var(--font-head); line-height: 1.2; margin: 0; letter-spacing: -.01em; color: var(--ink); }
p { margin: 0; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.ic { flex-shrink: 0; display: inline-block; vertical-align: middle; }
.container { width: min(1160px, 100% - 40px); margin-inline: auto; }
@media (max-width: 480px) { .container { width: calc(100% - 32px); } }
.muted { color: var(--muted); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.min0 { min-width: 0; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: .625rem 1.1rem; border-radius: 12px;
  border: 1.5px solid transparent; font-weight: 700; font-size: 1rem; line-height: 1.2;
  text-decoration: none; white-space: nowrap;
  transition: background-color .18s var(--ease), border-color .18s, color .18s, transform .12s, box-shadow .18s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.06), 0 8px 18px -10px rgba(29,107,88,.7); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: #cbc5b7; background: var(--surface-2); }
.btn-soft { background: var(--primary-soft); color: var(--primary-hover); }
.btn-soft:hover { background: #d2e6de; }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #f9d6d2; }
.btn-lg { min-height: 54px; padding: .85rem 1.4rem; font-size: 1.0625rem; border-radius: 14px; }
.btn-sm { min-height: 36px; padding: .35rem .75rem; font-size: .9rem; border-radius: 10px; }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-busy="true"] { opacity: .75; cursor: progress; }

.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border-radius: 12px; border: 0; background: transparent; color: var(--ink-2);
  transition: background-color .15s, color .15s;
}
.icon-btn:hover { background: var(--line-2); color: var(--ink); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .2rem .65rem; border-radius: 999px;
  font-size: .8125rem; font-weight: 700; line-height: 1.4; white-space: nowrap;
}
.badge::before { content: ""; width: .45rem; height: .45rem; border-radius: 50%; background: currentColor; }
.badge.no-dot::before { display: none; }
.tone-info { background: var(--info-soft); color: var(--info); }
.tone-warn { background: var(--warn-soft); color: var(--warn); }
.tone-ok { background: var(--ok-soft); color: var(--ok); }
.tone-danger { background: var(--danger-soft); color: var(--danger); }
.tone-violet { background: var(--violet-soft); color: var(--violet); }
.tone-muted { background: #ECEAE4; color: #4F5957; }

/* ---------- Formulaires ---------- */
.field { display: grid; gap: .4rem; align-content: start; }
.field > label, .label { font-weight: 700; font-size: .9375rem; }
.opt { font-weight: 400; color: var(--muted); font-size: .875rem; }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: .7rem .9rem;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder, .textarea::placeholder { color: #8A928F; }
.input:hover, .select:hover, .textarea:hover { border-color: #cdc7b9; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(29,107,88,.16); }
.textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
.select {
  appearance: none; padding-right: 2.4rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%235B6664' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .75rem center;
}
.hint { color: var(--muted); font-size: .875rem; }
.error-msg { color: var(--danger); font-size: .925rem; font-weight: 700; display: flex; gap: .45rem; align-items: center; margin-top: .75rem; }
.check { display: flex; align-items: center; gap: .6rem; font-weight: 700; cursor: pointer; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

/* ---------- Dialogues ---------- */
dialog {
  border: 0; padding: 0; color: var(--ink); background: var(--surface);
  border-radius: 20px; box-shadow: 0 30px 80px -20px rgba(15,25,23,.45);
  max-width: calc(100vw - 32px); max-height: calc(100dvh - 32px); overflow: auto;
  overscroll-behavior: contain;
}
dialog::backdrop { background: rgba(20, 30, 28, .48); }
dialog[open] { animation: dlg-in .24s var(--ease); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(14px) scale(.985); } }
.dlg-pad { padding: 1.25rem clamp(1.1rem, 4vw, 1.75rem) 1.5rem; }
.dlg-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.dlg-top h2 { font-size: 1.35rem; font-weight: 800; }
.dlg-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; flex-wrap: wrap; }
.dlg-actions .spacer { margin-right: auto; }

/* ---------- Toast ---------- */
.toast-host {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 9999; display: grid; gap: 8px; pointer-events: none; width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  background: var(--ink); color: #fff; padding: .75rem 1.05rem; border-radius: 12px;
  display: flex; gap: .55rem; align-items: center; box-shadow: var(--shadow); font-weight: 700;
  animation: toast-in .28s var(--ease);
}
.toast .ic { color: #8FD6B8; }
.toast.out { opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

.spinner { width: 20px; height: 20px; border: 3px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.dark { border-color: rgba(29,107,88,.2); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Barre de démonstration (retour présentation / bascule portail ↔ admin) ---------- */
.demo-bar {
  position: relative; z-index: 70; display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  min-height: 44px; padding: 0 max(12px, env(safe-area-inset-left)); background: #17201F; color: #E9EEEC; font-size: .875rem;
}
.demo-label { color: #A9B6B2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.demo-link { display: inline-flex; align-items: center; gap: .35rem; min-height: 36px; padding: .3rem .7rem; border-radius: 8px; color: #fff; text-decoration: none; font-weight: 700; white-space: nowrap; }
.demo-link:hover { background: rgba(255,255,255,.1); }
.demo-link-strong { background: var(--sun); color: #17201F; }
.demo-link-strong:hover { background: #F5C66A; }
.demo-link:focus-visible { outline-color: var(--sun); }
@media (max-width: 520px) { .demo-label { display: none; } }
.is-embed .demo-bar { display: none; }

/* Leaflet */
.vm-pin { background: none; border: 0; }
.leaflet-container { font-family: var(--font-body); }
.leaflet-popup-content-wrapper { border-radius: 12px; }
.map-off { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 1.5rem; color: var(--muted); background: repeating-linear-gradient(45deg, #EEF2EF 0 12px, #E7ECE8 12px 24px); }
