/* ===== Variables ===== */
:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --text: #e6edf3;
  --text-muted: #8b9eb5;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
  --radius: 8px;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  --font-sans: "DM Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
}

/* ===== Reset & base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Typography ===== */
h1, h2 { font-weight: 600; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--font-mono); font-size: 0.85em; background: var(--surface2); padding: 0.1em 0.4em; border-radius: 4px; }

/* ===== Header ===== */
.header {
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
  flex-shrink: 0;
}
.subtitle { color: var(--text-muted); font-size: 0.9rem; margin: 0.25rem 0 1rem; }
.controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; }
.search-box { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.search-box label { flex: 0 0 auto; }
.search-box input {
  width: 220px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.search-box input::placeholder { color: var(--text-muted); }
.search-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.25);
}
.search-box button, .btn-load {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
  font-weight: 500;
}
.search-box button:hover, .btn-load:hover { background: var(--accent-hover); }
.btn-load { background: var(--success); }
.btn-load:hover { filter: brightness(1.1); }
.btn-load:disabled { opacity: 0.6; cursor: not-allowed; }

.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem;
  font-size: 0.875rem; color: var(--text-muted);
}
.filters span { margin-right: 0.25rem; }
.filters label { display: inline-flex; align-items: center; gap: 0.35rem; cursor: pointer; }
.filters input { accent-color: var(--accent); }

/* ===== Main & Map ===== */
main { flex: 1; position: relative; min-height: 0; }
#map {
  width: 100%;
  height: calc(100vh - 180px);
  min-height: 400px;
  background: #1a2634;
}

/* MapLibre – thème sombre */
.maplibregl-ctrl-group button { background: var(--surface) !important; color: var(--text); }
.maplibregl-ctrl-group button:hover { background: var(--surface2) !important; }
.maplibregl-ctrl-attrib { background: rgba(26, 35, 50, 0.9) !important; color: var(--text-muted); font-size: 10px; }
.maplibregl-ctrl-attrib a { color: var(--accent); }
.maplibregl-ctrl-attrib .maplibregl-ctrl-attrib-button { background: transparent; }

/* ===== Panel (Légende) ===== */
.panel {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 260px;
  max-height: calc(100% - 2rem);
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.panel.collapsed {
  transform: translateY(calc(-100% + 48px));
  opacity: 0.9;
  pointer-events: none;
}
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--surface2);
}
.panel-header h2 { font-size: 0.95rem; }
#btn-close-panel {
  background: none; border: none; color: var(--text-muted);
  font-size: 1.25rem; cursor: pointer; padding: 0 0.25rem; line-height: 1;
}
#btn-close-panel:hover { color: var(--text); }
.legend {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.legend-item {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 0.5rem; font-size: 0.8rem;
}
.legend-swatch {
  width: 24px; height: 4px; border-radius: 2px; flex-shrink: 0;
}
.legend-label { color: var(--text-muted); }
.info {
  padding: 1rem;
  border-top: 1px solid var(--surface2);
  font-size: 0.75rem; color: var(--text-muted);
}
.info p { margin: 0 0 0.5rem; }
.info p:last-child { margin-bottom: 0; }

.btn-toggle-panel {
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  z-index: 999;
  box-shadow: var(--shadow);
  display: none;
}
.btn-toggle-panel:hover { background: var(--surface2); }
@media (max-width: 720px) {
  .panel { width: calc(100% - 2rem); right: 1rem; left: 1rem; }
  .btn-toggle-panel { display: block; }
  .panel:not(.collapsed) ~ .btn-toggle-panel { display: none; }
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 0.75rem 1.25rem;
  background: var(--surface2);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 2000;
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  max-width: 90vw;
}
.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }
