@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --c-bg: #080f14;
  --c-panel: #0d1a22;
  --c-panel-2: #12262f;
  --c-panel-glass: rgba(13, 26, 34, 0.92);
  --c-text: #edf5f4;
  --c-muted: #7a959a;
  --c-accent: #2fb6a3;
  --c-accent-dim: rgba(47, 182, 163, 0.12);
  --c-accent-2: #f0a83a;
  --c-border: #18303a;
  --c-edit: #f0a030;
  --c-education: #3a9fff;
  --c-communautaire: #2fb6a3;
  --c-subsistance: #f0a83a;
  --c-piste: #c0524a;
  --font: 'Inter', -apple-system, 'Segoe UI', Arial, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,.18);
  --shadow-md: 0 4px 16px rgba(0,0,0,.28);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.45);
  --shadow-xl: 0 16px 48px rgba(0,0,0,.55);
  --transition: .18s ease;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  height: 100%; margin: 0;
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
#app { height: 100vh; display: flex; flex-direction: column; }

/* ─── ICON UTILITY ──────────────────────────────────────────────────── */
.icon {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ─── TOPBAR ────────────────────────────────────────────────────────── */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: linear-gradient(180deg, var(--c-panel) 0%, rgba(13,26,34,.95) 100%);
  border-bottom: 1px solid var(--c-border);
  flex-wrap: wrap; gap: 10px;
  position: relative; z-index: 100;
}
#topbar::after {
  content: '';
  position: absolute; bottom: -12px; left: 0; right: 0;
  height: 12px;
  background: linear-gradient(180deg, rgba(0,0,0,.15) 0%, transparent 100%);
  pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  background: linear-gradient(135deg, var(--c-accent) 0%, #25a08f 100%);
  color: #04201a; font-weight: 800;
  border-radius: var(--radius-md); padding: 9px 14px;
  font-size: 14px; letter-spacing: 1.5px;
  box-shadow: 0 2px 12px rgba(47,182,163,.25);
}
.titles h1 { font-size: 15px; font-weight: 700; margin: 0; letter-spacing: -.2px; }
.titles p { font-size: 11px; color: var(--c-muted); margin: 3px 0 0; font-weight: 400; }
.topbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }

.stat-pill {
  background: var(--c-panel-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 6px 14px; text-align: center;
  min-width: 72px;
  transition: border-color var(--transition);
}
.stat-pill:hover { border-color: rgba(47,182,163,.3); }
.stat-pill b {
  display: block; font-size: 16px; font-weight: 700;
  color: var(--c-accent-2);
  letter-spacing: -.3px;
}
.stat-pill span { font-size: 10px; color: var(--c-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .3px; }

.topbar-btns { display: flex; gap: 8px; }
.topbtn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius-md);
  border: 1px solid var(--c-border);
  background: var(--c-panel-2); color: var(--c-text);
  font-size: 12px; font-weight: 500; font-family: var(--font);
  cursor: pointer; transition: all var(--transition);
  white-space: nowrap;
}
.topbtn:hover {
  border-color: var(--c-accent); color: var(--c-accent);
  background: var(--c-accent-dim);
}
.topbtn.active {
  background: var(--c-edit); border-color: var(--c-edit);
  color: #1a0a00; font-weight: 700;
}
.topbtn.active .icon { stroke: #1a0a00; }
.topbtn.dia-active {
  background: var(--c-accent); border-color: var(--c-accent);
  color: #04201a; font-weight: 700;
}
.topbtn.dia-active .icon { stroke: #04201a; }

/* ─── MAIN LAYOUT ───────────────────────────────────────────────────── */
#main { flex: 1; display: flex; min-height: 0; }

/* ─── SIDEBAR ───────────────────────────────────────────────────────── */
#sidebar {
  width: 310px; flex: 0 0 310px;
  background: var(--c-panel);
  border-right: 1px solid var(--c-border);
  overflow-y: auto; padding: 16px;
}
.sidebar-section { margin-bottom: 24px; }
.sidebar-section h2 {
  display: flex; align-items: center; gap: 7px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--c-accent); margin: 0 0 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--c-border);
}
.sidebar-section h2 .icon { opacity: .7; }
.field-label {
  display: block; font-size: 11px; font-weight: 500;
  color: var(--c-muted); margin: 10px 0 4px;
  letter-spacing: .2px;
}

/* Search */
.search-wrap {
  position: relative;
}
.search-wrap .search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--c-muted); pointer-events: none;
}
#search {
  width: 100%; padding: 8px 10px 8px 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--c-border);
  background: var(--c-bg); color: var(--c-text);
  font-size: 12px; font-family: var(--font);
  transition: border-color var(--transition);
}
#search:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-dim);
}
#search::placeholder { color: var(--c-muted); opacity: .6; }

/* Chips */
.chip-group { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  cursor: pointer; user-select: none;
  font-size: 11px; font-weight: 500; font-family: var(--font);
  padding: 4px 10px; border-radius: 20px;
  border: 1px solid var(--c-border);
  background: var(--c-panel-2); color: var(--c-muted);
  transition: all var(--transition);
}
.chip:hover {
  border-color: rgba(47,182,163,.4);
  color: var(--c-text);
}
.chip.active {
  background: var(--c-accent); color: #04201a;
  border-color: var(--c-accent); font-weight: 600;
}

#resetFilters {
  margin-top: 14px; width: 100%; padding: 8px;
  background: transparent; border: 1px solid var(--c-border);
  color: var(--c-muted); border-radius: var(--radius-sm);
  cursor: pointer; font-size: 11px; font-weight: 500; font-family: var(--font);
  transition: all var(--transition);
}
#resetFilters:hover {
  border-color: var(--c-accent); color: var(--c-accent);
  background: var(--c-accent-dim);
}

/* Story */
#story p { font-size: 12px; line-height: 1.6; color: var(--c-text); margin: 0 0 8px; }
#story p.muted { color: var(--c-muted); font-size: 11px; }
.story-stat { color: var(--c-accent-2); font-weight: 700; }

/* Legend */
#legend { display: flex; flex-direction: column; gap: 6px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 500; }
.legend-dot { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 11px; }
.note { font-size: 10px; color: var(--c-muted); margin-top: 8px; line-height: 1.7; }
.precision-indicator {
  display: inline-flex; align-items: center; justify-content: center;
  width: 12px; height: 12px; border-radius: 50%;
  margin-right: 5px; vertical-align: middle;
}
.precision-indicator.exact { background: var(--c-accent); }
.precision-indicator.centroid { background: var(--c-accent); opacity: .55; }
.precision-indicator.dept {
  background: transparent;
  border: 2px solid var(--c-accent);
  opacity: .35;
  width: 11px; height: 11px;
}

/* ─── MAP ───────────────────────────────────────────────────────────── */
#mapwrap { flex: 1; position: relative; }
#map { height: 100%; width: 100%; background: #060e13; }

/* ─── EDIT BANNER ───────────────────────────────────────────────────── */
#editBanner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 900;
  display: flex; align-items: center; gap: 8px;
  background: var(--c-edit); color: #1a0900;
  padding: 9px 20px; border-radius: var(--radius-md);
  font-size: 12px; font-weight: 500; white-space: nowrap;
  box-shadow: 0 4px 20px rgba(240,160,48,.3);
}
#editBanner.hidden { display: none; }

/* ─── DETAIL PANEL ──────────────────────────────────────────────────── */
#detailPanel {
  position: absolute; top: 12px; right: 12px;
  width: 320px; max-height: calc(100% - 24px);
  background: var(--c-panel-glass);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  z-index: 800; padding: 16px;
}
#detailPanel.hidden { display: none; }

#closeDetail {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; color: var(--c-muted);
  cursor: pointer; padding: 4px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  display: flex; align-items: center; justify-content: center;
}
#closeDetail:hover { color: var(--c-text); background: rgba(255,255,255,.06); }

.detail-type {
  display: inline-flex; align-items: center;
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  padding: 3px 10px; border-radius: 20px;
  margin-bottom: 8px; font-weight: 600;
}
#detailContent h3 { font-size: 14px; font-weight: 700; margin: 0 0 10px; line-height: 1.4; }
#detailContent .kv { font-size: 11.5px; margin: 4px 0; color: var(--c-muted); }
#detailContent .kv b { color: var(--c-text); font-weight: 600; }
#detailContent .desc {
  font-size: 11.5px; line-height: 1.6; margin-top: 10px;
  border-top: 1px solid var(--c-border); padding-top: 10px;
}
.precision-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; padding: 3px 9px;
  border-radius: var(--radius-sm);
  background: var(--c-panel-2); color: var(--c-muted);
  margin-top: 8px;
}
.edited-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10px; padding: 3px 9px;
  border-radius: var(--radius-sm);
  background: rgba(240,160,48,.1); color: var(--c-edit);
  border: 1px solid rgba(240,160,48,.25);
  margin-top: 4px; margin-left: 4px;
}

/* ─── EDIT FORM ─────────────────────────────────────────────────────── */
#editLatLon { margin-top: 12px; border-top: 1px solid var(--c-border); padding-top: 12px; }
.edit-form label {
  display: block; font-size: 11px; font-weight: 500;
  color: var(--c-muted); margin-bottom: 8px;
}
.edit-form input {
  width: 100%; padding: 7px 10px;
  background: var(--c-bg); border: 1px solid var(--c-border);
  border-radius: var(--radius-sm); color: var(--c-text);
  font-size: 12px; font-family: var(--font);
  margin-top: 3px; transition: border-color var(--transition);
}
.edit-form input:focus {
  outline: none; border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-dim);
}
.edit-actions { display: flex; gap: 8px; margin-top: 10px; }
.edit-actions button {
  flex: 1; padding: 7px;
  border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 500; font-family: var(--font);
  cursor: pointer; border: 1px solid;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  transition: all var(--transition);
}
#applyLatLon { background: var(--c-edit); color: #1a0900; border-color: var(--c-edit); font-weight: 700; }
#applyLatLon:hover { box-shadow: 0 2px 12px rgba(240,160,48,.3); }
#resetLatLon { background: transparent; color: var(--c-muted); border-color: var(--c-border); }
#resetLatLon:hover { border-color: var(--c-accent); color: var(--c-accent); }

/* ─── POPUP ─────────────────────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: var(--c-panel-glass);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  color: var(--c-text); border-radius: var(--radius-md);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-md);
}
.leaflet-popup-tip { background: var(--c-panel); }
.popup-title { font-weight: 700; font-size: 12px; margin-bottom: 4px; }
.popup-meta { font-size: 11px; color: var(--c-muted); }
.popup-link {
  color: var(--c-accent); font-size: 11px; font-weight: 500;
  cursor: pointer; display: inline-block; margin-top: 5px;
}

/* ─── DIAPORAMA OVERLAY ─────────────────────────────────────────────── */
#diaporamaOverlay {
  position: fixed; top: 65px; right: 16px; z-index: 2000;
  display: flex; align-items: flex-start; justify-content: flex-end;
  pointer-events: none;
}
#diaporamaOverlay.hidden { display: none; }

#diaporamaPanel {
  width: 350px;
  background: var(--c-panel-glass);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden; pointer-events: all;
}
.dia-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: rgba(18,38,47,.5);
  border-bottom: 1px solid var(--c-border);
}
.dia-header h2 {
  margin: 0; font-size: 14px; font-weight: 700; color: var(--c-accent);
  display: flex; align-items: center; gap: 8px;
}
#closeDia {
  background: none; border: none; color: var(--c-muted);
  cursor: pointer; padding: 4px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  display: flex; align-items: center; justify-content: center;
}
#closeDia:hover { color: var(--c-text); background: rgba(255,255,255,.06); }

#diaConfig { padding: 16px; }
#diaCount {
  margin-top: 14px; font-size: 12px; font-weight: 500;
  color: var(--c-accent-2); text-align: center;
}
.dia-start-btn {
  width: 100%; margin-top: 14px; padding: 11px;
  background: linear-gradient(135deg, var(--c-accent) 0%, #25a08f 100%);
  border: none; border-radius: var(--radius-md);
  color: #04201a; font-size: 13px; font-weight: 700; font-family: var(--font);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: all var(--transition);
  box-shadow: 0 2px 12px rgba(47,182,163,.2);
}
.dia-start-btn:hover { box-shadow: 0 4px 20px rgba(47,182,163,.35); }
.dia-start-btn:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; }

/* ─── DIAPORAMA PLAYER ──────────────────────────────────────────────── */
#diaPlayer { padding: 16px; }
.dia-progress-wrap { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.dia-progress-bar {
  flex: 1; height: 4px;
  background: var(--c-border); border-radius: 2px; overflow: hidden;
}
#diaProgressFill {
  height: 100%;
  background: linear-gradient(90deg, var(--c-accent) 0%, #25a08f 100%);
  width: 0%; transition: width linear;
  border-radius: 2px;
}
#diaCounter { font-size: 11px; font-weight: 500; color: var(--c-muted); white-space: nowrap; }

#diaSlideContent { min-height: 160px; max-height: 340px; overflow-y: auto; }
.dia-slide-type {
  display: inline-flex; align-items: center;
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  padding: 3px 10px; border-radius: 20px;
  margin-bottom: 6px; font-weight: 600;
}
#diaSlideContent h3 { font-size: 14px; font-weight: 700; margin: 0 0 6px; line-height: 1.4; }
#diaSlideContent .kv { font-size: 11px; margin: 3px 0; color: var(--c-muted); }
#diaSlideContent .kv b { color: var(--c-text); font-weight: 600; }
#diaSlideContent .desc {
  font-size: 11px; line-height: 1.55; margin-top: 10px;
  border-top: 1px solid var(--c-border); padding-top: 10px; color: var(--c-muted);
}

.dia-controls { display: flex; gap: 6px; margin-top: 14px; align-items: center; }
.dia-controls button {
  padding: 8px 10px; border-radius: var(--radius-md);
  border: 1px solid var(--c-border);
  background: var(--c-panel-2); color: var(--c-text);
  cursor: pointer; font-size: 13px; font-family: var(--font);
  flex: 1; transition: all var(--transition);
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
}
.dia-controls button:hover { border-color: var(--c-accent); }
#diaPlayPause {
  background: var(--c-accent) !important;
  color: #04201a !important;
  border-color: var(--c-accent) !important;
  font-weight: 700;
}
.dia-stop {
  background: transparent !important;
  color: var(--c-muted) !important;
  font-size: 11px !important; font-weight: 500 !important;
}

/* Drag cursor */
.edit-mode .leaflet-marker-pane circle { cursor: move !important; }

/* ─── SCROLLBAR ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(47,182,163,.3); }

/* ─── UTILITY ───────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── RESPONSIVE ────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  #sidebar { width: 260px; flex: 0 0 260px; padding: 12px; }
  #detailPanel { width: 280px; }
  #diaporamaPanel { width: 300px; }
}
@media (max-width: 700px) {
  #main { flex-direction: column; }
  #sidebar {
    width: 100%; flex: 0 0 auto;
    max-height: 35vh; border-right: none;
    border-bottom: 1px solid var(--c-border);
  }
  #detailPanel { width: calc(100% - 24px); right: 12px; left: 12px; }
  #diaporamaPanel { width: calc(100vw - 32px); }
  .topbar-btns { gap: 4px; }
  .topbtn { padding: 6px 10px; font-size: 11px; }
  .stat-pill { min-width: 60px; padding: 5px 10px; }
}
