:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1f2a2e;
  --muted: #56636a;
  --line: #e3dfd6;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --accent-soft: #fff1e6;
  --left: #1864ab;
  --right: #c2410c;
  --both: #6741d9;
  --route: #237032;
  --field: #858d92; /* bordure des champs : contraste ≥ 3:1 (WCAG 1.4.11) */
  --focus: #1864ab;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

/* Accessibilité */
.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;
}
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 3000;
  background: var(--ink); color: #fff; padding: 8px 12px; border-radius: 8px;
}
.skip-link:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.seg button:focus-visible { outline-offset: -3px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition: none !important; scroll-behavior: auto !important; }
}
html, body { margin: 0; height: 100%; }
body { display: flex; background: var(--bg); }

#panel {
  width: 400px;
  max-width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-right: 1px solid var(--line);
}
#map { flex: 1; height: 100%; }

.brand { display: flex; gap: 12px; align-items: center; padding: 4px 4px 8px; }
.brand .logo { font-size: 38px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card h2 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.step {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 12px;
}

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
input[type=text], input[type=number], input[type=time], input[type=search], select {
  font: inherit; font-size: 14px; color: var(--ink);
  padding: 7px 9px; border: 1px solid var(--field); border-radius: 8px; background: #fff;
}
.row { display: flex; gap: 8px; }
.row > label { flex: 1; min-width: 0; }
/* Les champs ne débordent jamais de leur carte (largeur intrinsèque des <input> en flex/grid). */
label > input[type=text], label > input[type=number], label > input[type=time], label > select { width: 100%; min-width: 0; }
.grid2 > label { min-width: 0; }
.row > label.narrow { flex: 0 0 90px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  border: 1px solid var(--field); background: #fff; border-radius: 999px;
  padding: 4px 10px; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink);
}
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
input[aria-invalid="true"] { border-color: #c92a2a; outline: 2px solid #c92a2a; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.field-label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.hidden { display: none !important; }

.drop {
  border: 2px dashed var(--field); border-radius: var(--radius);
  padding: 18px; text-align: center; cursor: pointer; color: var(--ink);
  transition: background .15s, border-color .15s;
}
.drop:hover, .drop.over { background: var(--accent-soft); border-color: var(--accent); }
.drop:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.drop small { color: var(--muted); }

button { font: inherit; cursor: pointer; }
button.link {
  background: none; border: none; color: var(--accent); padding: 0;
  text-align: left; font-size: 13px; text-decoration: underline;
}
.seg { display: flex; border: 1px solid var(--field); border-radius: 10px; overflow: hidden; }
.seg button {
  flex: 1; border: none; background: #fff; padding: 8px 4px; font-size: 13px;
  border-left: 1px solid var(--field); display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.seg button:first-child { border-left: none; }
.seg button small { font-size: 11px; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg button.on small { color: #fff; }

details summary { cursor: pointer; font-size: 13px; color: var(--muted); margin-top: 6px; }

.inline { display: flex; gap: 6px; }
.inline input { flex: 1; }
.inline button { border: 1px solid var(--field); background: #fff; border-radius: 8px; padding: 0 10px; }
#geocode-results button {
  display: block; width: 100%; text-align: left; border: none; background: none;
  padding: 6px 4px; font-size: 12px; border-bottom: 1px solid var(--line);
}
#geocode-results button:hover { background: var(--accent-soft); }

.info { font-size: 13px; background: var(--accent-soft); border-radius: 8px; padding: 8px 10px; }
.info b { color: var(--ink); }

.primary {
  background: var(--accent); color: var(--accent-ink); border: none;
  border-radius: var(--radius); padding: 14px; font-size: 16px; font-weight: 700;
  box-shadow: 0 4px 14px rgba(194, 65, 12, .3);
}
.primary:disabled { opacity: .45; box-shadow: none; cursor: not-allowed; }

#results { display: flex; flex-direction: column; gap: 10px; }
#summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 11px; color: var(--muted); }
.warn { background: #fff4e6; border: 1px solid #ffd8a8; color: #8a4b08; border-radius: 8px; padding: 8px 10px; font-size: 13px; }

#timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
#timeline li {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 10px 10px 48px; position: relative; cursor: pointer; font-size: 13px;
}
#timeline li[data-i]:hover, #timeline li[data-i]:focus-within { border-color: var(--accent); }
#timeline li .spot-open {
  all: unset; display: block; width: 100%; cursor: pointer;
}
#timeline li .spot-open:focus-visible { outline: 3px solid var(--focus); outline-offset: 6px; border-radius: 4px; }
#timeline li .num {
  position: absolute; left: 10px; top: 10px;
  width: 28px; height: 28px; border-radius: 50%; color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
#timeline li .title { display: block; font-weight: 600; font-size: 14px; }
#timeline li .meta { display: block; color: var(--muted); margin-top: 2px; }
#timeline li .big { font-variant-numeric: tabular-nums; }
#timeline li.leg { background: none; border: none; padding: 0 0 0 48px; cursor: default; color: var(--muted); font-size: 12px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .main-action { grid-column: 1 / -1; background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 600; }
.actions .main-action:hover { background: #000; }
.coords {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); font-size: 13px;
}
.coords code, .leaflet-popup-content code { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink); }
.copy-coords {
  border: 1px solid var(--field); background: #fff; border-radius: 6px; padding: 2px 8px;
  font-size: 12px; color: var(--ink);
}
.copy-coords:hover { border-color: var(--accent); }
.copy-coords.done { background: var(--route); border-color: var(--route); color: #fff; }
.actions button { flex: 1; border: 1px solid var(--field); background: #fff; border-radius: 10px; padding: 10px; font-size: 13px; }
.actions button:hover { border-color: var(--accent); }

footer { font-size: 12px; color: var(--muted); padding: 8px 4px 0; line-height: 1.5; }
footer nav { margin-bottom: 4px; }
footer nav a { color: var(--ink); }
.safety { margin-top: 2px; }
footer a { color: inherit; }

#busy { position: fixed; inset: 0; background: rgba(31, 42, 46, .35); display: grid; place-items: center; z-index: 2000; }
.busy-box {
  background: #fff; border-radius: var(--radius); padding: 18px 22px; display: flex; gap: 14px;
  align-items: center; max-width: 420px; box-shadow: 0 10px 40px rgba(0,0,0,.2); font-size: 14px;
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Marqueurs Leaflet */
.pin {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
.pin span { transform: rotate(45deg); color: #fff; font-weight: 700; font-size: 13px; }
.emoji-pin { font-size: 24px; line-height: 1; filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }
.km-label {
  background: #fff; border: 1px solid var(--ink); border-radius: 8px; font-size: 10px;
  padding: 0 4px; font-weight: 600; white-space: nowrap; text-align: center;
}
.legend { background: #fff; padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.7; box-shadow: 0 1px 5px rgba(0,0,0,.3); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.legend i.line { border-radius: 0; height: 4px; width: 18px; vertical-align: 3px; }

@media (max-width: 800px) {
  body { flex-direction: column-reverse; height: auto; }
  #panel { width: 100%; height: auto; overflow: visible; border-right: none; }
  #map { height: 55vh; flex: none; position: sticky; top: 0; z-index: 1; }
}

/* Feuille de route (impression / PDF) */
.print-only { display: none; }
/* Avant d'imprimer, la carte prend la taille exacte qu'elle aura sur la page A4 (186 × 105 mm). */
body.print-prep #map { position: fixed; left: 0; top: 0; width: 703px; height: 397px; flex: none; z-index: 1; }

@media print {
  @page { size: A4 portrait; margin: 12mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html, body { height: auto; background: #fff; }
  body { display: block; font-size: 11px; color: #000; }
  #panel, #busy, .skip-link, .leaflet-control-zoom, #sr-status { display: none !important; }
  .print-only { display: block !important; }
  #map {
    position: relative !important; display: block; width: 186mm !important; height: 105mm !important;
    border: 1px solid #999; border-radius: 6px; break-inside: avoid; margin: 0 0 4mm;
  }
  .legend { font-size: 9px; line-height: 1.5; padding: 4px 6px; box-shadow: none; border: 1px solid #999; }
  .leaflet-control-attribution { font-size: 8px; }

  .ps-brand { font-size: 10px; color: #444; text-transform: uppercase; letter-spacing: .06em; }
  #print-head h1 { font-size: 20px; margin: 1mm 0 1mm; }
  .ps-sub { margin: 0 0 1mm; color: #333; }
  .ps-stats { display: flex; gap: 4mm; margin: 2mm 0 3mm; }
  .ps-stats div { flex: 1; border: 1px solid #bbb; border-radius: 6px; padding: 2mm 3mm; }
  .ps-stats b { font-size: 15px; display: block; }

  .ps-table { width: 100%; border-collapse: collapse; }
  .ps-table th { background: #f1f3f5; text-align: left; font-size: 10px; padding: 2mm; border-bottom: 1.5px solid #333; }
  .ps-table td { padding: 1.8mm 2mm; border-bottom: 1px solid #ccc; vertical-align: top; }
  .ps-table tr { break-inside: avoid; }
  .ps-table thead { display: table-header-group; }
  .ps-table small { color: #444; }
  .ps-num span {
    display: inline-grid; place-items: center; width: 7mm; height: 7mm; border-radius: 50%;
    color: #fff; font-weight: 700; font-size: 11px;
  }
  .ps-time b { font-size: 13px; }
  .ps-gps code { font-size: 11.5px; font-weight: 600; }
  .ps-start td { background: #f8f9fa; }
  .ps-warn { margin: 3mm 0 0; padding-left: 5mm; color: #8a4b08; }
  .ps-foot { margin-top: 4mm; font-size: 9px; color: #444; line-height: 1.4; }
}

/* Pages d'information légale */
body.legal { display: block; height: auto; background: var(--bg); }
.legal-wrap { max-width: 760px; margin: 0 auto; padding: 24px 20px 48px; line-height: 1.6; font-size: 16px; }
.legal-wrap > header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.legal-wrap > header a { color: var(--ink); text-decoration: none; font-weight: 700; font-size: 18px; }
.legal-wrap h1 { font-size: 28px; margin: 16px 0 4px; letter-spacing: -0.02em; }
.legal-wrap h2 { font-size: 20px; margin: 28px 0 8px; }
.legal-wrap h3 { font-size: 17px; margin: 20px 0 6px; }
.legal-wrap .updated { color: var(--muted); font-size: 14px; margin: 0 0 16px; }
.legal-wrap a { color: var(--left); }
.legal-wrap table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0; background: #fff; }
.legal-wrap th, .legal-wrap td { border: 1px solid var(--line); padding: 8px; text-align: left; vertical-align: top; }
.legal-wrap th { background: var(--accent-soft); }
.legal-wrap .todo { background: #fff3bf; border: 1px dashed #8a6d00; padding: 0 4px; border-radius: 4px; }
.legal-wrap .box { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.legal-wrap footer { margin-top: 40px; border-top: 1px solid var(--line); padding-top: 12px; font-size: 14px; }
@media (max-width: 600px) { .legal-wrap table { font-size: 13px; } }
