:root {
  --bg: #f4f4f6;
  --panel: #ffffff;
  --text: #1b1b1f;
  --muted: #6b6b75;
  --line: #e3e3e8;
  --field: #f6f6f8;
  --primary: #E4572E;
  --accent: #1B1B1F;
  --on-primary: #ffffff;
  --danger: #d92d20;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f12;
    --panel: #18181c;
    --text: #f2f2f5;
    --muted: #9a9aa5;
    --line: #2b2b33;
    --field: #222228;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.app { display: grid; grid-template-columns: 400px 1fr; height: 100vh; }
.panel { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.scroll { overflow-y: auto; padding: 4px 18px 24px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brandmark { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; white-space: nowrap; color: inherit; text-decoration: none; }
.brandmark .mark { width: 22px; height: 22px; }
.brandmark strong { font-weight: 700; letter-spacing: .24em; }
.brandmark b { color: #E10600; }
.brandmark span { color: var(--muted); margin-left: 4px; }
.topbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 20px 0 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--field); color: var(--text);
  padding: 7px 12px; border-radius: 10px; font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(0.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: transparent; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.on { background: var(--accent); color: #fff; border-color: transparent; }

.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=search], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--field);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; resize: vertical;
}
input:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

.brand-header {
  border-radius: 18px; padding: 16px; color: var(--on-primary);
  background: var(--primary);
}
.brand-row { display: flex; gap: 12px; align-items: center; }
.brand-org { font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; opacity: .85; }
.brand-name { font-size: 21px; font-weight: 900; line-height: 1.15; }
.brand-welcome { margin-top: 10px; font-size: 14px; opacity: .92; }
.brand-welcome:empty { display: none; }
.logo {
  width: 56px; height: 56px; border-radius: 13px; flex: none; overflow: hidden;
  display: grid; place-items: center; background: var(--primary); color: var(--on-primary);
  font-weight: 900; font-size: 22px; border: 1px solid rgba(0,0,0,.08);
}
.logo.small { width: 40px; height: 40px; font-size: 15px; border-radius: 10px; }
.logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; padding: 4px; }

.colors { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.color-field { display: flex; gap: 10px; align-items: center; font-size: 13px; cursor: pointer; }
.color-field input { width: 42px; height: 42px; border: none; padding: 0; background: none; cursor: pointer; }
.color-field code { color: var(--muted); }
.logo-row { display: flex; gap: 10px; align-items: center; margin-top: 12px; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--field); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.segmented button { border: none; background: transparent; color: var(--text); font: inherit; padding: 7px; border-radius: 8px; cursor: pointer; }
.segmented button.on { background: var(--accent); color: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); font-weight: 600; }
.segmented button.on .ico-stop { box-shadow: 0 0 0 2px #fff; }
.summary { font-weight: 600; margin: 12px 0 8px; }
.context { background: var(--field); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.context:empty { display: none; }
.context h3 { margin: 0 0 8px; font-size: 15px; display: flex; justify-content: space-between; gap: 8px; }
.context h3 small { color: var(--muted); font-weight: 500; }
.context .label { font-size: 13px; font-weight: 600; margin: 10px 0 6px; }
.context .error { color: var(--danger); font-size: 13px; margin: 6px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: transparent; color: var(--text); border-radius: 999px; padding: 6px 11px; font: inherit; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--accent); color: #fff; border-color: transparent; }
.chip.on::before { content: "⦸ "; }
.option { display: flex; justify-content: space-between; width: 100%; border: none; background: none; color: var(--text); font: inherit; padding: 6px 2px; cursor: pointer; text-align: left; }
.option .muted { color: var(--muted); }
.option.on { font-weight: 700; }
.row-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.hint, .help { color: var(--muted); font-size: 13px; }
.help ul { padding-left: 18px; margin: 0; }
.help li { margin-bottom: 6px; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; font-size: 11px; }

.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }
.search { position: absolute; top: 12px; left: 12px; width: min(360px, calc(100% - 70px)); z-index: 2; }
.search input { background: var(--panel); box-shadow: 0 2px 10px rgba(0,0,0,.18); }
.search-results { background: var(--panel); border-radius: 10px; margin-top: 4px; box-shadow: 0 4px 16px rgba(0,0,0,.18); overflow: hidden; }
.search-results:empty { display: none; }
.search-results button { display: block; width: 100%; text-align: left; border: none; background: none; color: var(--text); font: inherit; padding: 9px 12px; cursor: pointer; }
.search-results button:hover { background: var(--field); }
.search-results small { color: var(--muted); }
.style-switch { position: absolute; bottom: 30px; left: 12px; z-index: 2; display: flex; background: var(--panel); border-radius: 10px; padding: 3px; box-shadow: 0 2px 10px rgba(0,0,0,.18); }
.style-switch button { border: none; background: none; color: var(--text); font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 7px; cursor: pointer; }
.style-switch button.on { background: var(--accent); color: #fff; }
.toast { position: absolute; left: 50%; bottom: 30px; transform: translateX(-50%); background: rgba(20,20,24,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 3; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; }

/* Marqueurs */
.stop-marker {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary); color: var(--on-primary); font-weight: 900; font-size: 13px;
  border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); cursor: grab;
}
.stop-marker.selected { border-color: var(--accent); transform: scale(1.18); }
.via-marker {
  width: 14px; height: 14px; background: #fff; border: 3px solid var(--accent);
  border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.35); cursor: grab;
}
.via-marker.selected { border-width: 4px; transform: scale(1.35); }

/* Feuille de route : étapes (pastilles pleines) et passages forcés (ronds blancs, en retrait) */
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .l-stop { width: 14px; height: 14px; border-radius: 50%; background: var(--primary); }
.legend .l-via { width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2.5px solid var(--accent); }
.stops-list { list-style: none; margin: 0 0 10px; padding: 0 0 0 0; position: relative; }
.stops-list li { position: relative; display: flex; align-items: center; gap: 10px; padding: 5px 4px; border-radius: 8px; cursor: pointer; }
.stops-list li:hover { background: var(--field); }
.stops-list li.selected { background: var(--field); outline: 1.5px solid var(--accent); }
.stops-list .badge { width: 28px; height: 28px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); font-weight: 900; font-size: 12px; position: relative; z-index: 1; }
.stops-list .row-stop .name { font-weight: 700; }
.stops-list .row-via { padding-left: 34px; font-size: 13px; color: var(--muted); }
.stops-list .row-via .dot { width: 11px; height: 11px; border-radius: 50%; background: #fff; border: 2.5px solid var(--accent); flex: none; }
.stops-list .row-segment { padding: 2px 4px 2px 44px; font-size: 12px; color: var(--muted); cursor: pointer; }
.stops-list .row-segment .segment-label::before { content: "↓ "; }
/* Fil vertical qui relie les étapes, comme une feuille de route */
.stops-list::before { content: ""; position: absolute; left: 17px; top: 16px; bottom: 16px; border-left: 2px dotted var(--muted); opacity: .6; }
.stops-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stops-list .km { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.stops-list .remove { border: none; background: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.stops-list .remove:hover { color: var(--danger); background: var(--panel); }
.kind { display: inline-block; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; padding: 2px 7px; border-radius: 999px; margin-right: 4px; vertical-align: middle; }
.kind-stop { background: var(--primary); color: var(--on-primary); }
.kind-via { background: #fff; color: #222; border: 2px solid var(--accent); }
.kind-segment { background: var(--line); color: var(--text); }
.segmented .ico-stop, .segmented .ico-via { display: inline-block; vertical-align: -1px; margin-right: 6px; border-radius: 50%; }
.segmented .ico-stop { width: 12px; height: 12px; background: var(--primary); }
.segmented .ico-via { width: 9px; height: 9px; background: #fff; border: 2.5px solid var(--accent); }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 10; padding: 16px; }
.overlay[hidden] { display: none; }
.dialog { background: var(--panel); border-radius: 18px; padding: 22px; width: min(420px, 100%); display: grid; gap: 12px; }
.dialog h2 { margin: 0; font-size: 18px; text-transform: none; letter-spacing: 0; color: var(--text); }
.dialog p { margin: 0; color: var(--muted); }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 55vh auto; height: auto; min-height: 100vh; }
  .map-wrap { grid-row: 1; height: 55vh; }
  .panel { grid-row: 2; border-right: none; border-top: 1px solid var(--line); }
  .scroll { padding: 4px 16px 24px; }
  .topbar { position: sticky; top: 0; background: var(--panel); z-index: 1; }
  .legend { flex-direction: column; gap: 4px; }
}

[hidden] { display: none !important; }

.demo-banner { background: color-mix(in srgb, var(--primary) 14%, var(--panel)); border-bottom: 1px solid var(--line); padding: 10px 14px; font-size: 13px; line-height: 1.45; }
.demo-banner a { color: #E10600; font-weight: 700; margin-left: 4px; white-space: nowrap; }

/* Roadbook papier */
.rb-open { width: 100%; justify-content: center; gap: 8px; margin-top: 10px; display: inline-flex; align-items: center; }
.rb-open svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rb-dialog { width: min(780px, 100%); max-height: calc(100vh - 32px); grid-template-rows: auto 1fr; padding: 0; overflow: hidden; }
.rb-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 20px; border-bottom: 1px solid rgba(0,0,0,.08); flex-wrap: wrap; }
.rb-head p { margin: 2px 0 0; }
.rb-list { list-style: none; margin: 0; padding: 12px 20px 20px; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.rb-list > li { flex: none; }
.rb-loading { color: var(--muted); padding: 30px 0; text-align: center; }
.rb-case { display: grid; grid-template-columns: 96px 84px 1fr; border: 1px solid rgba(0,0,0,.12); border-radius: 12px; overflow: hidden; background: #fff; color: #111; }
.rb-case > div { padding: 8px 10px; }
.rb-dist { border-right: 1px solid rgba(0,0,0,.1); text-align: right; display: grid; align-content: center; position: relative; }
.rb-num { position: absolute; top: 6px; left: 8px; font-size: 11px; font-weight: 700; color: #8e8e93; }
.rb-dist b { font-size: 20px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.rb-dist small { color: #6e6e73; font-variant-numeric: tabular-nums; }
.rb-tulip { border-right: 1px solid rgba(0,0,0,.1); display: grid; place-items: center; padding: 4px !important; }
.rb-tulip svg { width: 72px; height: 72px; }
.rb-info { display: grid; gap: 2px; align-content: center; }
.rb-info strong { font-size: 15px; }
.rb-info span { font-size: 13px; color: #3a3a3c; }
.rb-note { margin-top: 4px; font: inherit; font-size: 12.5px; font-style: italic; border: 1px dashed rgba(0,0,0,.18); border-radius: 8px; padding: 5px 8px; background: #fafafa; }
.rb-note:focus { outline: 2px solid var(--blue, #E10600); border-color: transparent; background: #fff; }
.rb-stage, .rb-finish, .rb-start { background: #f5f8ff; }
@media (max-width: 560px) { .rb-case { grid-template-columns: 78px 70px 1fr; } .rb-tulip svg { width: 60px; height: 60px; } .rb-dist b { font-size: 16px; } }

/* Rallye d'un compte : enregistrement automatique */
.save-state { align-self: center; font-size: 12px; color: var(--muted); padding: 0 4px; white-space: nowrap; }
.save-state.error { color: var(--danger); font-weight: 600; }
.account-info .btn { margin-top: 10px; display: inline-flex; text-decoration: none; color: inherit; }

/* Zone de prise élargie : les étapes et passages s'attrapent facilement même dézoomé */
.stop-marker::after, .via-marker::after { content: ""; position: absolute; border-radius: 50%; }
.stop-marker::after { inset: -10px; }
.via-marker::after { inset: -11px; }
.via-marker { z-index: 1; }
.stop-marker { z-index: 2; }

/* Logo THE ROADBOOK */
.wordmark-img { display: inline-block; aspect-ratio: 1794 / 548; height: 28px; background: currentColor; -webkit-mask: url("img/wordmark.png") center / contain no-repeat; mask: url("img/wordmark.png") center / contain no-repeat; vertical-align: middle; }
.brandmark .wordmark-img { height: 26px; color: inherit; margin-left: 0; }

/* Roadbook : cartouches de route et panneaux */
.rb-roads { display: flex; gap: 5px; flex-wrap: wrap; margin: 2px 0; }
.rb-roads:empty { display: none; }
.rb-road { font-size: 12px; font-weight: 800; padding: 1px 6px; border-radius: 4px; border: 1.5px solid #111; letter-spacing: .02em; }
.rb-signs { display: flex; gap: 4px; margin-top: 4px; }
.rb-sign { width: 30px; height: 30px; padding: 3px; border-radius: 8px; border: 1px solid rgba(0,0,0,.12); background: #fff; cursor: pointer; opacity: .28; filter: grayscale(1); }
.rb-sign svg { width: 100%; height: 100%; display: block; }
.rb-sign.on { opacity: 1; filter: none; border-color: #111; }
.rb-sign:hover { opacity: .7; }
.rb-sign.on:hover { opacity: 1; }
/* Panneau d'entrée d'agglomération (fond blanc, bordure rouge, capitales) */
.rb-town { justify-self: start; display: inline-block; padding: 3px 10px; border: 3px solid #D7001D; border-radius: 4px; background: #fff; color: #111 !important; font-size: 13px !important; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
