/* ========================================================================
 * VARIABLES & THÈME (VARIABLES & THEME)
 * ==================================================================== */
:root {
  --asphalt: #1b1b1f;
  --asphalt-soft: #26262c;
  --asphalt-line: #3a3a42;
  --paint: #f5c518;
  --paint-deep: #e0ac00;
  --paper: #eceae4;
  --card: #ffffff;
  --line: #d8d6cf;
  --ink: #1b1b1f;
  --muted: #74737a;
  --muted-soft: #9b9aa0;
  --danger: #b5462f;
  --ok: #2f7d5b;
  --radius: 12px;
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

/* ========================================================================
 * BASE & RÉINITIALISATION (BASE & RESET)
 * ==================================================================== */
* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background: var(--paper);
}

.shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ========================================================================
 * MISE EN PAGE (LAYOUT)
 * ==================================================================== */
/* Barre du haut */
.topbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 18px;
  height: 62px;
  padding: 0 22px;
  border-bottom: 3px solid var(--paint);
  color: #fff;
  background: var(--asphalt);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 11px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.16em;
}

.wordmark .dash {
  display: inline-flex;
  gap: 4px;
}

.wordmark .dash i {
  display: block;
  width: 13px;
  height: 5px;
  background: var(--paint);
  border-radius: 1px;
  opacity: 0.55;
}

.wordmark .dash i:nth-child(2) {
  opacity: 0.8;
}

.wordmark .dash i:nth-child(3) {
  opacity: 1;
}

.tagline {
  font-size: 12.5px;
  font-weight: 400;
  color: #b7b6bd;
  letter-spacing: 0.01em;
}

.topbar .spacer {
  flex: 1;
}

.key-toggle {
  display: flex;
  align-items: center;
  gap: 7px;

  padding: 7px 13px;
  border: 1px solid var(--asphalt-line);

  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 500;
  color: #cfced4;

  background: transparent;
  border-radius: 8px;

  transition: 0.15s;
  cursor: pointer;
}

.key-toggle:hover {
  border-color: var(--paint);
  color: #fff;
}

.key-dot {
  width: 7px;
  height: 7px;
  background: var(--danger);
  border-radius: 50%;
}

.key-dot.set {
  background: var(--ok);
}

/* Structure de l'app */
.app {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: 392px 1fr;
  min-height: 0;
}

.panel {
  padding: 22px 22px 30px;
  border-right: 1px solid var(--line);
  background: var(--paper);
  overflow-y: auto;
}

.map-wrap {
  position: relative;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: #dedcd6;
}

/* ========================================================================
 * COMPOSANTS (COMPONENTS)
 * ==================================================================== */
/* ---------- Contrôles & formulaire ---------- */
.eyebrow {
  margin: 2px 0 18px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.field {
  margin-bottom: 18px;
}

.field > label {
  display: block;
  margin-bottom: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.02em;
}

.field .hint {
  font-weight: 400;
  font-size: 11.5px;
  color: var(--muted-soft);
}

select,
input[type=text] {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--line);

  font-family: var(--font-body);
  font-size: 14.5px;
  color: var(--ink);

  background: var(--card);
  border-radius: 10px;
  outline: none;

  transition: border-color 0.15s, box-shadow 0.15s;
}

select {
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2374737a' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

input[type=text]:focus,
select:focus {
  border-color: var(--paint);
  box-shadow: 0 0 0 3px rgba(245,197,24,0.25);
}

::placeholder {
  color: var(--muted-soft);
}

.autocomplete {
  position: relative;
}

.suggest {
  position: absolute;
  top: calc(100% + 5px);
  right: 0;
  left: 0;
  z-index: 30;

  display: none;

  border: 1px solid var(--line);

  background: var(--card);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(27,27,31,0.13);

  overflow: hidden;
}

.suggest.open {
  display: block;
}

.suggest button {
  display: block;

  width: 100%;
  padding: 10px 13px;
  border: 0;
  border-bottom: 1px solid var(--paper);

  font-family: var(--font-body);
  font-size: 13.5px;
  color: var(--ink);
  text-align: left;

  background: none;

  cursor: pointer;
}

.suggest button:last-child {
  border-bottom: 0;
}

.suggest button:hover,
.suggest button.active {
  background: var(--paper);
}

.suggest .suggest-label {
  font-weight: 500;
}

.suggest .suggest-sub {
  display: block;
  margin-top: 1px;
  font-size: 11.5px;
  color: var(--muted);
}

.suggest-empty {
  padding: 11px 13px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
}

.maptip {
  margin-top: 7px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

.maptip b {
  font-weight: 600;
  color: var(--ink);
}

.go {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;

  width: 100%;
  margin-top: 4px;
  padding: 14px;
  border: 0;

  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--asphalt);
  letter-spacing: 0.03em;

  background: var(--paint);
  border-radius: 11px;

  transition: 0.15s;
  cursor: pointer;
}

.go:hover:not(:disabled) {
  background: var(--paint-deep);
}

.go:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.go .spin {
  display: none;
  width: 15px;
  height: 15px;
  border: 2.4px solid rgba(27,27,31,0.3);
  border-top-color: var(--asphalt);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.go.loading .spin {
  display: block;
}

.go.loading .go-label {
  opacity: 0.7;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Actions d'itinéraire (points de passage) ---------- */
.route-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.zbtn.waypoint {
  color: var(--ink);
  background: var(--card);
}

.zbtn.waypoint:hover {
  border-color: var(--paint);
}

.zbtn.waypoint.active {
  border-color: var(--paint-deep);
  color: var(--asphalt);
  background: var(--paint);
}

.zbtn.waypoint-reset {
  flex: 0 0 auto;
  color: var(--ink);
  background: var(--card);
}

.zbtn.waypoint-reset:hover:not(:disabled) {
  border-color: var(--paint);
}

.zbtn.waypoint-reset:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- Zones interdites ---------- */
.zones {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px dashed var(--line);
}

.zones-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 11px;
}

.zones-head .zones-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13.5px;
  letter-spacing: 0.02em;
}

.zones-head .zone-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

.zones-head .zone-count b {
  font-weight: 700;
  color: var(--ink);
}

.zones-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.zbtn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--line);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 12.5px;
  border-radius: 9px;
  transition: 0.15s;
  cursor: pointer;
}

.zbtn.add {
  border-color: var(--asphalt);
  color: #fff;
  background: var(--asphalt);
}

.zbtn.add:hover {
  background: var(--asphalt-soft);
}

.zbtn.add.drawing {
  border-color: var(--paint-deep);
  color: var(--asphalt);
  background: var(--paint);
}

.zbtn.exp {
  flex: 0 0 auto;
  color: var(--ink);
  background: var(--card);
}

.zbtn.exp:hover {
  border-color: var(--paint);
}

.zbtn.edit {
  flex: 0 0 auto;
  color: var(--ink);
  background: var(--card);
}

.zbtn.edit:hover {
  border-color: var(--paint);
}

.zbtn.edit.active {
  border-color: var(--paint-deep);
  color: var(--asphalt);
  background: var(--paint);
}

.zones-buffer {
  margin-bottom: 12px;
}

.zones-buffer label {
  display: block;
  margin-bottom: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

.zones-buffer label b {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--ink);
}

.zones-buffer input[type=range] {
  width: 100%;
  accent-color: var(--danger);
  cursor: pointer;
}

.zones-buffer-warn {
  display: none;
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid #ecdd9c;
  font-size: 11px;
  line-height: 1.45;
  color: #7a5c00;
  background: #fbf2cf;
  border-radius: 8px;
}

.zones-hist {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.zbtn.hist {
  font-size: 12px;
  color: var(--ink);
  background: var(--card);
}

.zbtn.hist:hover:not(:disabled) {
  border-color: var(--paint);
}

.zbtn.hist:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.zone-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.zone-empty {
  padding: 4px 0;
  font-size: 12px;
  color: var(--muted-soft);
}

.zone-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 9px;
}

.zone-item.selected {
  border-color: var(--paint);
  box-shadow: 0 0 0 2px rgba(245,197,24,0.25);
}

.zone-item .zone-type {
  flex: 0 0 auto;

  padding: 2px 6px;
  border: 1px solid var(--line);

  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;

  background: var(--paper);
  border-radius: 5px;
}

.zone-item .zone-name {
  flex: 1;

  min-width: 0;
  padding: 0;
  border: 0;

  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;

  background: none;

  cursor: pointer;
  overflow: hidden;
}

.zone-item .zone-name:hover {
  color: var(--paint-deep);
  text-decoration: underline;
}

.zone-item .zone-name:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.zone-item .zone-name:disabled:hover {
  color: var(--ink);
  text-decoration: none;
}

.zone-ren,
.zone-del {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;

  width: 24px;
  height: 24px;
  border: 0;

  font-size: 13px;
  line-height: 1;
  color: var(--muted);

  background: transparent;
  border-radius: 6px;

  transition: 0.15s;
  cursor: pointer;
}

.zone-ren:hover {
  color: var(--ink);
  background: var(--paper);
}

.zone-del:hover {
  color: var(--danger);
  background: #f7e6e1;
}

.zone-icon {
  display: block;
  width: 15px;
  height: 15px;
}

.zones-tip {
  margin: 11px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}

.zones-tip p {
  margin: 0 0 7px;
}

.zones-tip p:last-child {
  margin: 0;
}

.zones-tip b {
  font-weight: 600;
  color: var(--ink);
}

.zones-tip code {
  padding: 1px 4px;
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 10.5px;
  background: var(--card);
  border-radius: 4px;
}

/* ---------- Note (avertissement OpenStreetMap) ---------- */
.note {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}

/* ---------- Panneau clé API ---------- */
.keybox {
  position: relative;
  display: none;
  margin-bottom: 20px;
  padding: 16px 16px 18px;
  background: var(--asphalt-soft);
  border-radius: var(--radius);
}

.keybox.open {
  display: block;
  animation: drop 0.18s ease;
}

@keyframes drop {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.keybox-close {
  position: absolute;
  top: 12px;
  right: 12px;

  padding: 2px 4px;
  border: 0;

  font-size: 18px;
  line-height: 1;
  color: #8a8990;

  background: transparent;

  transition: 0.15s;
  cursor: pointer;
}

.keybox-close:hover {
  color: var(--paint);
}

.keybox h3 {
  margin: 0 0 4px;
  padding-right: 22px;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.keybox p {
  margin: 0 0 12px;
  font-size: 12px;
  line-height: 1.5;
  color: #aaa9b0;
}

.keybox p a {
  border-bottom: 1px solid rgba(245,197,24,0.4);
  color: var(--paint);
  text-decoration: none;
}

.keybox input {
  border-color: #3a3a42;
  font-family: var(--font-mono);
  font-size: 13px;
  color: #fff;
  background: #15151a;
}

.keybox input:focus {
  border-color: var(--paint);
}

.keybox-actions {
  display: flex;
  gap: 8px;
  margin-top: 11px;
}

.keybox .save {
  flex: 1;

  padding: 10px;
  border: 0;

  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  color: #fff;

  background: #3a3a42;
  border-radius: 9px;

  transition: 0.15s;
  cursor: pointer;
}

.keybox .save:hover {
  background: #46464f;
}

.keybox .clear {
  flex: 0 0 auto;

  padding: 10px 12px;
  border: 1px solid #3a3a42;

  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  color: #cfced4;

  background: transparent;
  border-radius: 9px;

  transition: 0.15s;
  cursor: pointer;
}

.keybox .clear:hover {
  border-color: var(--danger);
  color: #fff;
}

.keynote {
  font-size: 11px;
  line-height: 1.5;
  color: #8a8990;
}

/*
 * Écart AU-DESSUS du paragraphe du bas, symétrique à celui du haut (.keybox p
 * margin-bottom:12px). Sélecteur porté à .keybox .keynote (2 classes) pour
 * l'emporter sur .keybox p (1 classe + 1 type), qui sinon imposerait son
 * margin:0 0 12px et créerait l'écart parasite SOUS le texte. margin-bottom
 * laissé à 0 : aucune marge ajoutée vers le bas du panneau.
 */
.keybox .keynote {
  margin: 12px 0 0;
}

.keynote b {
  font-weight: 600;
  color: #cfced4;
}

/* ---------- Modale réutilisable (confirmation / saisie) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15,15,18,0.55);
  backdrop-filter: blur(2px);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 340px;
  padding: 20px 20px 18px;
  border: 1px solid var(--asphalt-line);
  border-top: 3px solid var(--paint);

  color: #fff;

  background: var(--asphalt);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0,0,0,0.45);

  animation: rise 0.2s ease;
}

.modal-card [hidden] {
  display: none;
} /* prime sur les display des éléments internes */

.modal-card h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
}

.modal-card p {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.5;
  color: #b7b6bd;
}

.modal-input {
  width: 100%;
  margin: 0 0 18px;
  padding: 11px 12px;
  border: 1px solid #3a3a42;

  font-family: var(--font-body);
  font-size: 14px;
  color: #fff;

  background: #15151a;
  border-radius: 9px;
  outline: none;
}

.modal-input:focus {
  border-color: var(--paint);
  box-shadow: 0 0 0 3px rgba(245,197,24,0.25);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-btn {
  padding: 10px 16px;
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  border-radius: 9px;
  transition: 0.15s;
  cursor: pointer;
}

.modal-btn.cancel {
  border-color: var(--asphalt-line);
  color: #cfced4;
  background: transparent;
}

.modal-btn.cancel:hover {
  border-color: #fff;
  color: #fff;
}

.modal-btn.primary {
  border-color: var(--paint-deep);
  color: var(--asphalt);
  background: var(--paint);
}

.modal-btn.primary:hover {
  background: var(--paint-deep);
}

/* ---------- Résultat & tarifs ---------- */
.result {
  display: none;
  margin-top: 24px;
}

.result.show {
  display: block;
  animation: rise 0.25s ease;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.routes {
  margin-top: 20px;
}

.routes-trip {
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.routes-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.route-entry {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
}

.route-entry-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  color: #fff;
  background: var(--asphalt);
}

.route-entry-dot {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.route-entry-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 12.5px;
}

.route-entry-dist {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #cfced4;
}

.route-entry-interval {
  padding: 6px 12px;
  border-bottom: 1px solid var(--paper);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

/* Tarifs mis en évidence : c'est sur eux que se fait le choix. */
.route-entry-rates {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1px;
  background: var(--paper);
}

.route-entry-rate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 6px;
  text-align: center;
  background: var(--card);
}

.route-entry-rate .rate-label {
  font-size: 10px;
  color: var(--muted-soft);
  letter-spacing: 0.02em;
}

.route-entry-rate .rate-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
}

.route-entry-rate .rate-value small {
  margin-left: 2px;
  font-weight: 400;
  font-size: 9.5px;
  color: var(--muted);
}

/* ---------- Messages ---------- */
.msg {
  display: none;
  margin-top: 18px;
  padding: 13px 15px;
  font-size: 13px;
  line-height: 1.5;
  border-radius: 10px;
}

.msg.show {
  display: block;
}

.msg.err {
  border: 1px solid #e6c3b8;
  color: #7d2c19;
  background: #f7e6e1;
}

.msg.warn {
  border: 1px solid #ecdd9c;
  color: #7a5c00;
  background: #fbf2cf;
}

/* ========================================================================
 * CARTE (MAP)
 * ==================================================================== */
/* Note superposée sur la carte */
.mapnote {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 500;

  max-width: 260px;
  padding: 8px 11px;

  font-size: 11px;
  line-height: 1.45;
  color: #e9e8ee;

  background: rgba(27,27,31,0.86);
  border-radius: 8px;
  backdrop-filter: blur(4px);
}

.mapnote b {
  font-weight: 600;
  color: var(--paint);
}

.leaflet-container {
  font-family: var(--font-body);
}

.pin {
  display: flex;
  align-items: center;
  justify-content: center;

  width: 30px;
  height: 30px;

  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;

  border-radius: 50% 50% 50% 2px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.35);

  transform: rotate(45deg);
}

.pin span {
  transform: rotate(-45deg);
}

.pin.plant {
  border: 2px solid var(--paint);
  color: var(--paint);
  background: var(--asphalt);
}

.pin.dest {
  border: 2px solid var(--asphalt);
  color: var(--asphalt);
  background: var(--paint);
}

.pin.waypoint {
  border: 2px dashed var(--paint-deep);
  color: var(--asphalt);
  background: var(--card);
}

/* Marqueur de point de passage : épingle + poubelle toujours visible */
.waypoint-marker {
  position: relative;
  width: 30px;
  height: 30px;
}

.waypoint-delete {
  position: absolute;
  top: -6px;
  left: 20px;

  display: flex;
  align-items: center;
  justify-content: center;

  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;

  color: #fff;

  background: var(--danger);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);

  transition: 0.15s;
  cursor: pointer;
}

.waypoint-delete:hover {
  background: #8f3826;
}

.waypoint-delete .zone-icon {
  width: 12px;
  height: 12px;
}

/* ========================================================================
 * UTILITAIRES & ÉTATS (UTILITIES & STATES)
 * ==================================================================== */
:focus-visible {
  outline: 2px solid var(--paint);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* ========================================================================
 * ADAPTATIF (RESPONSIVE)
 * ==================================================================== */
@media (max-width: 880px) {
  .app {
    grid-template-columns: 1fr;
    grid-auto-rows: min-content;
  }

  .panel {
    order: 1;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .map-wrap {
    order: 2;
    height: 50vh;
    min-height: 320px;
  }

  .tagline {
    display: none;
  }
}
