:root {
  --bg: #0b1020;
  --panel: #131a2e;
  --panel-2: #1b2440;
  --text: #e8eefc;
  --muted: #93a0c0;
  --accent: #38bdf8;
  --border: #263252;
  --excellent: #22c55e;
  --good: #84cc16;
  --medium: #f59e0b;
  --bad: #ef4444;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: linear-gradient(180deg, #0b1020, #0b1020ee);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 28px; }
.brand h1 { margin: 0; font-size: 19px; letter-spacing: 0.3px; }
.tagline { margin: 0; font-size: 12px; color: var(--muted); }

.header-btns { display: flex; gap: 8px; }
.icon-btn.active { background: var(--accent); border-color: var(--accent); }
.icon-btn {
  font-size: 22px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 46px; height: 46px;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.95); }

/* Controls */
.controls {
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: relative;
}
.loc-form { display: flex; gap: 8px; }
.loc-form input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
}
.btn {
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #05233a;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.btn:active { transform: scale(0.97); }

.suggestions {
  list-style: none;
  margin: 6px 0 0;
  padding: 6px;
  position: absolute;
  left: 16px; right: 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  z-index: 600;
  max-height: 240px;
  overflow-y: auto;
}
.suggestions li {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
}
.suggestions li:active, .suggestions li:hover { background: var(--panel); }

.sliders {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.sliders label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sliders b { color: var(--text); font-size: 13px; }
.sliders input[type="range"] { width: 100%; accent-color: var(--accent); }

/* Toggle zones interdites */
.zone-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  cursor: pointer;
  user-select: none;
}
.zone-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  flex: 0 0 auto;
  width: 44px; height: 26px;
  border-radius: 13px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.15s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s, background 0.15s;
}
.zone-toggle input:checked + .switch { background: var(--accent); }
.zone-toggle input:checked + .switch::after { transform: translateX(18px); background: #05233a; }
.zone-toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
.zone-toggle-label { font-size: 13px; line-height: 1.3; }
.zone-toggle-label small { color: var(--muted); display: block; font-size: 11px; }

.zone-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12px;
  color: #cdd7f0;
}
.zone-legend span { display: inline-flex; align-items: center; gap: 6px; }
.zone-legend .lg { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.lg-red { background: rgba(230, 60, 60, 0.75); }
.lg-orange { background: rgba(245, 175, 70, 0.85); }
.lg-pink { background: rgba(235, 130, 180, 0.8); }

/* Recherche + menu déroulant "Régions" */
.loc-row { display: flex; gap: 8px; align-items: stretch; }
.loc-row .loc-form { flex: 1; min-width: 0; }

.regions-dropdown { position: relative; flex: 0 0 auto; }
.btn-regions {
  height: 100%;
  white-space: nowrap;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-regions .caret { transition: transform 0.15s; display: inline-block; }
.btn-regions[aria-expanded="true"] .caret { transform: rotate(180deg); }

.region-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 240px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  z-index: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.region-list[hidden] { display: none !important; }
.region-list li {
  padding: 9px 11px;
  border-radius: 10px;
  cursor: pointer;
}
.region-list li:active, .region-list li:hover { background: var(--panel); }
.region-name { font-weight: 700; font-size: 13px; }
.region-note { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.25; }
.region-crowd { font-size: 10px; margin-top: 4px; color: #9fb0d6; }

.spot-kind { font-size: 11px; color: #9fb0d6; }

/* Map */
.map {
  height: 42vh;
  min-height: 260px;
  width: 100%;
  background: #0f1526;
}

/* Results */
.results { padding: 12px 16px 24px; }
.status {
  font-size: 13px;
  color: var(--muted);
  padding: 8px 0;
  min-height: 20px;
}
.status.error { color: var(--bad); }

.spot-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.spot {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
}
.spot:active { background: var(--panel-2); }

.spot-rank { font-weight: 800; color: var(--muted); font-size: 14px; min-width: 26px; }
.spot-name { font-weight: 700; font-size: 16px; }
.spot-meta { font-size: 12px; color: var(--muted); margin: 2px 0 6px; }
.spot-weather { display: flex; flex-wrap: wrap; gap: 10px; font-size: 13px; color: #cdd7f0; }
.spot-weather span { white-space: nowrap; }

.spot-score {
  text-align: center;
  border-radius: 12px;
  padding: 8px 10px;
  min-width: 66px;
  color: #05233a;
}
.spot-score .score-num { display: block; font-size: 22px; font-weight: 800; line-height: 1; }
.spot-score .score-lbl { font-size: 11px; font-weight: 700; }
.spot-score.excellent { background: var(--excellent); }
.spot-score.good { background: var(--good); }
.spot-score.medium { background: var(--medium); }
.spot-score.bad { background: var(--bad); color: #fff; }

.app-footer {
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
  border-top: 1px solid var(--border);
}

/* Corrige le conflit entre l'attribut [hidden] et les règles display ci-dessous :
   sans ça, display:flex garderait ces éléments visibles malgré hidden. */
.overlay[hidden],
.zone-legend[hidden],
.suggestions[hidden] { display: none !important; }

/* Modal détail */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(3, 7, 18, 0.72);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  animation: slideUp 0.22s ease;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-right: 40px;
  margin-bottom: 12px;
}
.modal-name { font-size: 19px; font-weight: 800; }
.modal-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }

.sat-figure { margin: 0 0 12px; }
.sat-img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: 14px;
  background: var(--panel-2);
  display: block;
}
.sat-figure figcaption { font-size: 11px; color: var(--muted); margin-top: 6px; text-align: center; }

.modal-weather {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 14px;
  color: #cdd7f0;
  padding: 12px;
  background: var(--panel-2);
  border-radius: 12px;
  margin-bottom: 14px;
}

.photos-block { margin-bottom: 16px; }
.photos-title { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.photos-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.photos-row a { flex: 0 0 auto; }
.photos-row img {
  height: 96px;
  width: 128px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
}
.photos-empty { font-size: 13px; color: var(--muted); }

.modal-actions { display: flex; gap: 10px; }
.btn-ghost {
  flex: 1;
  text-align: center;
  text-decoration: none;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
}

@media (min-width: 720px) {
  .overlay { align-items: center; }
  .modal { border-radius: 20px; }

  .map { height: 50vh; }
  .results { max-width: 900px; margin: 0 auto; }
  .controls { max-width: 900px; margin: 0 auto; }
}
