/* ---------- Tokens ---------- */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --border: #e2e6ee;
  --text: #101828;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-contrast: #ffffff;
  --primary-tint: #eaf0fe;
  --accent: #ea580c;
  --accent-tint: #fff1e8;
  --danger: #dc2626;
  --danger-tint: #fdecec;
  --success: #16a34a;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.16);
  --sidebar-width: 400px;

  --fuel-gazole: #a1590a;
  --fuel-sp95: #15803d;
  --fuel-sp98: #2563eb;
  --fuel-e10: #0d9488;
  --fuel-e85: #7c3aed;
  --fuel-gplc: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #131b2c;
    --surface-2: #1a2438;
    --border: #263248;
    --text: #eef2f8;
    --text-muted: #96a2b8;
    --text-faint: #6b7994;
    --primary: #4c8dff;
    --primary-dark: #2f6fe0;
    --primary-contrast: #ffffff;
    --primary-tint: #17223b;
    --accent: #fb923c;
    --accent-tint: #2a1c10;
    --danger: #f16565;
    --danger-tint: #2a1616;
    --success: #4ade80;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.55);
  }
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; }
html, body {
  height: 100%;
  overflow: hidden; /* the map and the panel manage their own scrolling */
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font: inherit; }
input, select, button { color: inherit; }
a { color: inherit; }
ul { list-style: none; margin: 0; padding: 0; }

/* ---------- Map (full-bleed canvas) ---------- */
#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--surface-2);
}
.leaflet-control-zoom, .leaflet-control-attribution {
  margin-top: 12px !important;
  margin-right: 12px !important;
}

/* ---------- "Search this area" floating button ---------- */
.search-area-btn {
  position: fixed;
  top: max(16px, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: transform .15s, box-shadow .15s;
}
.search-area-btn[hidden] { display: none; }
.search-area-btn svg { width: 15px; height: 15px; }
.search-area-btn:hover { box-shadow: var(--shadow-md), 0 0 0 1px var(--primary); }
.search-area-btn:active { transform: translateX(-50%) scale(0.97); }
@media (min-width: 900px) {
  .search-area-btn {
    left: calc(var(--sidebar-width) + (100% - var(--sidebar-width)) / 2);
  }
}

/* ---------- Panel (sidebar on desktop, bottom sheet on mobile) ---------- */
.panel {
  position: fixed;
  z-index: 10;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.drag-handle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  border: none;
  background: transparent;
  padding: 10px 0 6px;
  cursor: grab;
  flex-shrink: 0;
  touch-action: none;
}
.drag-handle-bar {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
}
.panel.dragging .drag-handle { cursor: grabbing; }

.panel-header {
  flex-shrink: 0;
  padding: 4px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.panel-header-top {
  display: flex;
  align-items: center;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}
.brand-icon { font-size: 1.35rem; }

.panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 24px;
  overscroll-behavior: contain;
}

/* ---------- Search ---------- */
.search-form {
  display: flex;
  align-items: center;
  gap: 8px;
}
.search-input-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-faint);
  pointer-events: none;
}
#search-input {
  width: 100%;
  height: 44px;
  padding: 0 36px 0 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
#search-input::placeholder { color: var(--text-faint); }
#search-input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-tint);
}
.clear-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}
.clear-btn[hidden] { display: none; }
.clear-btn:hover { background: var(--border); }

.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 30;
  max-height: 320px;
  overflow-y: auto;
}
.suggestion-item {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-bottom: 1px solid var(--border);
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover, .suggestion-item.active { background: var(--surface-2); }
.suggestion-main { font-size: 0.92rem; font-weight: 600; }
.suggestion-sub { font-size: 0.78rem; color: var(--text-muted); }

.geoloc-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.geoloc-btn svg { width: 19px; height: 19px; }
.geoloc-btn:hover { background: var(--primary-tint); border-color: var(--primary); color: var(--primary); }
.geoloc-btn.loading { opacity: 0.7; pointer-events: none; }
.geoloc-btn.loading svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Filters ---------- */
.filters-row {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 1px;
}
.filters-row::-webkit-scrollbar { display: none; }

.fuel-chips {
  display: flex;
  gap: 8px;
}
.fuel-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  flex-shrink: 0;
}
.fuel-chip:hover { border-color: var(--primary); color: var(--text); }
.fuel-chip .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.fuel-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-contrast);
}
.fuel-chip.active .dot { background: var(--primary-contrast) !important; }

.filters-right {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.select-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 4px 0 10px;
  height: 34px;
  flex-shrink: 0;
}
.select-label { font-size: 0.76rem; color: var(--text-muted); white-space: nowrap; }
#radius-select, #sort-select {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.83rem;
  font-weight: 600;
  height: 32px;
  outline: none;
  cursor: pointer;
}

.status-line {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  min-height: 1.2em;
}
.status-line strong { color: var(--text); }
.status-line.error { color: var(--danger); }

/* ---------- Results list ---------- */
.results-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 4px;
}

/* ---------- Station card ---------- */
.station-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  scroll-margin: 12px;
}
.station-card.highlighted {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-tint), var(--shadow-md);
}

.station-card.best::before {
  content: "Moins cher";
  position: absolute;
  top: -9px;
  left: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  padding: 3px 9px;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.card-head h3 {
  margin: 0 0 2px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.card-addr {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.35;
}
.distance-badge {
  flex-shrink: 0;
  background: var(--primary-tint);
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.prices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}
.price-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.price-chip .fuel-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.price-chip .fuel-label .dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.price-chip .fuel-value {
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}
.price-chip.highlight {
  background: var(--primary-tint);
  border-color: var(--primary);
}
.price-chip.highlight .fuel-value { color: var(--primary-dark); }
.price-chip.cheapest {
  background: var(--accent-tint);
  border-color: var(--accent);
}
.price-chip.cheapest .fuel-value { color: var(--accent); }

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.updated {
  font-size: 0.73rem;
  color: var(--text-faint);
}
.card-actions { display: flex; gap: 8px; }
.route-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--primary-tint);
  transition: background .15s;
}
.route-link:hover { background: var(--primary); color: #fff; }
.route-link svg { width: 13px; height: 13px; }
.map-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: transparent;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.map-link:hover { border-color: var(--primary); color: var(--primary); }
.map-link svg { width: 13px; height: 13px; }

/* ---------- Skeleton ---------- */
.skeleton { gap: 10px; }
.sk-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
.sk-title { width: 55%; height: 17px; }
.sk-sub { width: 75%; }
.sk-chips { display: flex; gap: 8px; margin-top: 4px; }
.sk-chip {
  flex: 1;
  height: 42px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ---------- Empty / error states ---------- */
.state-panel {
  text-align: center;
  padding: 32px 12px;
  color: var(--text-muted);
}
.state-panel .state-icon { font-size: 2.2rem; margin-bottom: 10px; }
.state-panel h3 { margin: 0 0 6px; color: var(--text); font-size: 1.02rem; }
.state-panel p { margin: 0 auto; max-width: 340px; font-size: 0.86rem; line-height: 1.5; }
.state-panel button {
  margin-top: 14px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}
.state-panel button:hover { background: var(--primary-dark); }

/* ---------- Leaflet marker skins ---------- */
.fm-div-icon { background: transparent; border: none; }
.fm-marker {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid var(--surface);
  box-shadow: var(--shadow-md);
}
.fm-marker.fm-marker-best {
  width: 34px;
  height: 34px;
  background: var(--accent);
}
.fm-origin-marker {
  width: 18px;
  height: 18px;
  position: relative;
}
.fm-origin-marker .fm-origin-dot {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid var(--surface);
  box-shadow: var(--shadow-md);
}
.fm-origin-marker .fm-origin-pulse {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0.45;
  animation: fm-pulse 2s ease-out infinite;
}
@keyframes fm-pulse {
  0% { transform: scale(1); opacity: 0.45; }
  100% { transform: scale(3.2); opacity: 0; }
}

.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { margin: 12px 14px; min-width: 190px; }
.fm-popup h4 { margin: 0 0 3px; font-size: 0.92rem; }
.fm-popup .fm-popup-addr { margin: 0 0 8px; font-size: 0.78rem; color: var(--text-muted); }
.fm-popup .fm-popup-prices { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.fm-popup .fm-popup-price {
  font-size: 0.76rem;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
}
.fm-popup a.route-link { display: inline-flex; }

/* ================= Layout: mobile bottom sheet ================= */
@media (max-width: 899px) {
  .panel {
    left: 0;
    right: 0;
    bottom: 0;
    height: min(92dvh, 760px);
    border-radius: 20px 20px 0 0;
    transition: transform 0.32s cubic-bezier(0.22, 0.9, 0.32, 1);
    transform: translateY(0);
  }
  .panel.dragging { transition: none; }
  .panel--peek { transform: translateY(calc(100% - var(--peek-px, 190px))); }
  .panel--half { transform: translateY(calc(100% - var(--half-px, 420px))); }
  .panel--full { transform: translateY(0); }

  .drag-handle { display: flex; }
  .panel-header-top { display: none; }
}

/* ================= Layout: desktop sidebar ================= */
@media (min-width: 900px) {
  .panel {
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    height: 100dvh;
    border-radius: 0;
    transform: none !important;
  }
  .panel-header { padding: 16px 18px 14px; }
  .panel-body { padding: 0 18px 24px; }
  .drag-handle { display: none; }
  .panel-header-top { display: flex; }
}

/* ---------- Small screens ---------- */
@media (max-width: 380px) {
  .filters-right .select-label { display: none; }
  .select-wrap { padding: 0 4px 0 8px; }
}
