:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #1565c0;
  --accent-dark: #0b3d91;
  --ok: #1b7f3b;
  --warn: #b45309;
  --err: #c62828;
  --radius: 10px;
  --sidebar-w: 372px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--panel);
}

#topbar {
  height: 50px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--bg);
  color: #fff;
  z-index: 1200;
  position: relative;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.2px;
  font-size: 1.05rem;
}
.brand__logo {
  width: 32px;
  height: 32px;
  flex: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
}
.brand__name em { font-style: normal; color: #7cc4ff; }

#toggle-sidebar {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  border-radius: 8px;
  padding: 4px 9px;
  cursor: pointer;
  font-size: 1rem;
}

.status {
  margin-left: auto;
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.status--pending { background: rgba(255,255,255,.12); }
.status--ok { background: rgba(34,197,94,.22); border-color: rgba(34,197,94,.5); }
.status--warn { background: rgba(245,158,11,.22); border-color: rgba(245,158,11,.5); }
.status--err { background: rgba(239,68,68,.22); border-color: rgba(239,68,68,.5); }

#layout { display: flex; height: calc(100% - 50px); }

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  overflow-y: auto;
  background: #f8fafc;
  border-right: 1px solid var(--line);
  padding: 12px;
  transition: margin-left 0.2s ease;
}
#sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w) - 2px); }

#map-wrap { position: relative; flex: 1; }
#map { position: absolute; inset: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
}

.panel__title {
  margin: 0 0 10px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: default;
}
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; }
details[open] > summary::before { content: "▾ "; }

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  align-items: center;
  margin-bottom: 8px;
}
.field-grid label { font-size: 0.8rem; color: var(--muted); }
.field-label { display: block; font-size: 0.8rem; color: var(--muted); margin: 8px 0 4px; }

input, select {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.86rem;
  color: var(--ink);
  background: #fff;
}
input:focus, select:focus { outline: 2px solid rgba(21,101,192,.35); border-color: var(--accent); }

.combo { position: relative; }
.combo__list {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 1500;
  max-height: 240px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.combo__item {
  padding: 7px 10px;
  font-size: 0.86rem;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.combo__item:hover, .combo__item--active { background: #eef4fb; }
.combo__item + .combo__item { border-top: 1px solid var(--line); }
.combo__meta { margin-left: auto; color: var(--muted); font-size: 0.74rem; white-space: nowrap; }

.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.row input, .row select { flex: 1; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.84rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #f1f5f9; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; flex: 1; }
.btn--primary:hover { background: var(--accent-dark); }
.btn--ghost { background: #f8fafc; }
.btn--tiny { padding: 2px 7px; font-size: 0.8rem; margin-left: auto; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.check { display: flex; align-items: center; gap: 8px; font-size: 0.86rem; margin: 6px 0; }
.check input { width: auto; }

.hint { font-size: 0.76rem; color: var(--muted); margin: 8px 0 0; line-height: 1.35; }
.muted { color: var(--muted); font-size: 0.82rem; }
.small { font-size: 0.76rem; }
.hidden { display: none !important; }

.banner {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.79rem;
  line-height: 1.4;
  border: 1px solid;
}
.banner--ok { background: #ecfdf3; border-color: #b7e4c7; color: #14532d; }
.banner--warn { background: #fffbeb; border-color: #fde68a; color: #78350f; }
.banner--err { background: #fef2f2; border-color: #fecaca; color: #7f1d1d; }

.progress { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 0.82rem; color: var(--muted); }
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid #cbd5e1; border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.summary-grid .k { font-size: 0.76rem; color: var(--muted); }
.summary-grid .v { font-size: 0.92rem; font-weight: 600; }
.summary-et a { color: var(--accent); }

.breakdown { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.76rem; padding: 3px 8px; border-radius: 999px;
  background: #f1f5f9; border: 1px solid var(--line);
}
.chip__dot { width: 9px; height: 9px; border-radius: 50%; }

.warn-item { font-size: 0.78rem; padding: 6px 8px; border-radius: 6px; margin-top: 6px; }
.warn-item--warn { background: #fffbeb; color: #78350f; border: 1px solid #fde68a; }
.warn-item--err { background: #fef2f2; color: #7f1d1d; border: 1px solid #fecaca; }

#routes-list { display: flex; flex-direction: column; gap: 6px; }
.route-card {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px;
  font-size: 0.78rem; background: #fff; cursor: pointer;
}
.route-card:hover { border-color: var(--accent); }
.route-card__head { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.route-card__meta { color: var(--muted); margin-top: 2px; }
.route-card__del { border: none; background: none; color: var(--err); cursor: pointer; font-size: 0.8rem; }

.legend {
  position: absolute; right: 12px; bottom: 24px; z-index: 1000;
  background: rgba(255,255,255,.94); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; box-shadow: var(--shadow);
  font-size: 0.72rem; display: flex; flex-direction: column; gap: 3px;
}
.legend__row { display: flex; align-items: center; gap: 6px; }
.legend__dot { width: 12px; height: 4px; border-radius: 2px; }

.toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  z-index: 2000; max-width: 620px; padding: 10px 14px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 0.84rem; line-height: 1.4;
}
.toast--ok { background: #ecfdf3; border: 1px solid #b7e4c7; color: #14532d; }
.toast--warn { background: #fffbeb; border: 1px solid #fde68a; color: #78350f; }
.toast--err { background: #fef2f2; border: 1px solid #fecaca; color: #7f1d1d; }
.toast strong { display: block; margin-bottom: 2px; }

/* Marqueurs Leaflet personnalisés */
.route-marker__dot {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  color: #fff; font-weight: 700; font-size: 0.78rem;
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
}

.point-tooltip .tt { font-size: 0.76rem; }
.tt__head { font-weight: 700; margin-bottom: 4px; }
.point-tooltip table { border-collapse: collapse; }
.point-tooltip td { padding: 1px 6px 1px 0; }
.point-tooltip td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.leaflet-tooltip.point-tooltip { background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); }

/* Menu contextuel */
.ctx-menu {
  position: fixed; z-index: 3000; min-width: 230px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 5px; overflow: hidden;
}
.ctx-menu__title {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); padding: 5px 8px 6px;
}
.ctx-menu__item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: none; background: none; text-align: left;
  padding: 7px 9px; border-radius: 7px; font-size: 0.84rem; cursor: pointer;
  color: var(--ink);
}
.ctx-menu__item:hover:not(:disabled) { background: #eff6ff; }
.ctx-menu__item:disabled { opacity: 0.45; cursor: not-allowed; }
.ctx-menu__item.is-danger { color: var(--err); }
.ctx-menu__icon { width: 18px; text-align: center; }
.ctx-menu__hint { margin-left: auto; font-size: 0.72rem; color: var(--muted); }

@media (max-width: 720px) {
  :root { --sidebar-w: 300px; }
  #sidebar { position: absolute; z-index: 1100; box-shadow: var(--shadow); }
  #layout { position: relative; }
}
