:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e8eaed;
  --muted: #9aa2b1;
  --accent: #ff5a5f;
  --accent-2: #ffb400;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#map { position: absolute; inset: 0; }

/* ---------- Top bar ---------- */
#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(15, 17, 21, 0.92), rgba(15, 17, 21, 0));
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

.brand {
  font-weight: 700;
  font-size: 18px;
  white-space: nowrap;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 560px;
}
#search {
  width: 100%;
  padding: 12px 38px 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  box-shadow: var(--shadow);
  outline: none;
}
#search:focus { border-color: var(--accent); }
#search-clear {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  width: 30px; height: 30px;
  cursor: pointer;
  display: none;
}
.search-wrap.has-value #search-clear { display: block; }

#toggle-list {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

/* ---------- Add button ---------- */
#add-spot {
  position: absolute;
  z-index: 5;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 22px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(255, 90, 95, 0.45);
}
#add-spot:active { transform: translateX(-50%) scale(0.97); }
#add-spot .plus { font-size: 20px; line-height: 1; }

/* ---------- Sidebar ---------- */
#sidebar {
  position: absolute;
  z-index: 6;
  top: 0; right: 0;
  height: 100%;
  width: min(380px, 92vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease;
}
#sidebar.hidden { transform: translateX(100%); }

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 8px;
}
.sidebar-head h2 { margin: 0; font-size: 18px; }
.sidebar-head button, .modal-head button {
  border: none; background: transparent; color: var(--muted);
  font-size: 26px; cursor: pointer; line-height: 1;
}
.spot-count { padding: 0 18px 10px; color: var(--muted); font-size: 13px; }

#spot-list { list-style: none; margin: 0; padding: 0 10px 20px; overflow-y: auto; flex: 1; }
.spot-item {
  display: flex;
  gap: 12px;
  padding: 10px;
  border-radius: 12px;
  cursor: pointer;
}
.spot-item:hover { background: var(--panel-2); }
.spot-item img {
  width: 56px; height: 56px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--panel-2);
  flex-shrink: 0;
}
.spot-item .meta { min-width: 0; }
.spot-item .meta h3 { margin: 0 0 3px; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spot-item .meta .tags { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.empty-hint, .geo-status {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}
.empty-hint { padding: 30px 24px; text-align: center; }

/* ---------- Modal ---------- */
#modal-backdrop, #feedback-backdrop {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 640px) {
  #modal-backdrop, #feedback-backdrop { align-items: center; }
}
#modal, #feedback-modal {
  width: min(520px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
}
@media (min-width: 640px) { #modal, #feedback-modal { border-radius: var(--radius); } }

#feedback-form { padding: 16px 18px 20px; display: flex; flex-direction: column; gap: 14px; }
#feedback-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
#feedback-form small { font-weight: 400; }
#feedback-form input, #feedback-form textarea, #feedback-form select {
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
#feedback-form input:focus, #feedback-form textarea:focus, #feedback-form select:focus { border-color: var(--accent); }
.fb-intro { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.5; }

/* Onglets feedback */
.fb-tabs { display: flex; gap: 6px; padding: 12px 18px 0; border-bottom: 1px solid var(--line); }
.fb-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 6px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.fb-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.fb-badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

/* Liste des retours */
#feedback-list-pane { padding: 12px 14px 20px; max-height: 70vh; overflow-y: auto; }
.fb-list-toolbar { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.fb-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  margin-bottom: 10px;
}
.fb-item-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.fb-item-type { font-size: 13px; font-weight: 600; }
.fb-item-date { font-size: 11px; color: var(--muted); white-space: nowrap; }
.fb-item-name { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.fb-item-msg { font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.fb-item-ctx { margin-top: 8px; }
.fb-item-ctx summary { font-size: 11px; color: var(--muted); cursor: pointer; }
.fb-item-ctx pre { font-size: 11px; color: var(--muted); white-space: pre-wrap; margin: 6px 0 0; }

/* Bouton flottant feedback */
#feedback-btn {
  position: absolute;
  z-index: 5;
  bottom: 24px; left: 18px;
  width: 48px; height: 48px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
#feedback-btn:active { transform: scale(0.95); }

/* ---------- Mode placement (pin fixe au centre) ---------- */
#place-mode { position: absolute; inset: 0; z-index: 8; pointer-events: none; }
/* La carte doit rester manipulable : seul le bandeau capte les touches. */
#place-crosshair {
  position: absolute;
  left: 50%; top: 50%;
  width: 44px; height: 44px;
  transform: translate(-50%, -100%); /* la pointe du pin vise le centre exact */
  pointer-events: none;
  filter: drop-shadow(0 4px 5px rgba(0, 0, 0, 0.55));
}
#place-crosshair svg { width: 100%; height: 100%; display: block; }
/* petit point de visée au centre exact */
#place-mode::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
#place-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(15, 17, 21, 0), rgba(15, 17, 21, 0.95) 40%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
}
.place-hint { color: var(--text); font-size: 14px; text-align: center; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6); }
.place-actions { display: flex; gap: 10px; }
.place-actions .btn-primary { flex: 2; }
.btn-ghost {
  flex: 1;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
/* Pendant le placement, on masque les boutons flottants qui gêneraient */
body.placing #add-spot,
body.placing #feedback-btn,
body.placing #topbar { display: none; }

/* Empêche le menu natif / la sélection lors de l'appui long sur la carte */
#map, .maplibregl-canvas {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--panel);
}
.modal-head h2 { margin: 0; font-size: 17px; }

#spot-form { padding: 16px 18px 20px; display: flex; flex-direction: column; gap: 14px; }
#spot-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
#spot-form small { font-weight: 400; }
#spot-form input[type="text"],
#spot-form textarea,
#spot-form select {
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
#spot-form input:focus, #spot-form textarea:focus, #spot-form select:focus { border-color: var(--accent); }
.row { display: flex; gap: 12px; }
.row label { flex: 1; }

.photo-drop {
  display: block;
  cursor: pointer;
  border: 2px dashed var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel-2);
}
#photo-preview-wrap {
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.photo-hint { color: var(--muted); font-size: 14px; padding: 20px; }
#photo-preview { width: 100%; max-height: 260px; object-fit: cover; display: block; }

.geo-status { padding: 2px; }
.geo-status.ok { color: #55d187; }
.geo-status.warn { color: var(--accent-2); }
.link-btn {
  margin-top: 6px;
  padding: 8px 12px;
  border: 1px solid var(--accent-2);
  border-radius: 8px;
  background: transparent;
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.coords-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); }
#coords-label { color: var(--text); font-size: 13px; }
.coords-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.chip-btn {
  flex-shrink: 0;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.chip-btn:active { transform: scale(0.96); }

.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.btn-primary {
  flex: 1;
  padding: 13px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger {
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

/* ---------- Popup (map) ---------- */
.maplibregl-popup-content {
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  box-shadow: var(--shadow);
  max-width: 260px;
}
.maplibregl-popup-close-button { color: #fff; font-size: 18px; padding: 2px 8px; }
.popup-img { width: 100%; height: 150px; object-fit: cover; display: block; background: var(--panel-2); }
.popup-body { padding: 10px 12px 12px; }
.popup-body h3 { margin: 0 0 4px; font-size: 15px; }
.popup-body .p-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.popup-body .chip { background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.popup-body p { margin: 6px 0 0; font-size: 13px; color: var(--muted); line-height: 1.4; }
.popup-body .p-meta { font-size: 11px; color: var(--muted); margin-top: 6px; }
.popup-edit { display: inline-block; margin-top: 8px; color: var(--accent); font-size: 13px; cursor: pointer; font-weight: 600; }

/* ---------- Marker ---------- */
.pin {
  width: 30px; height: 30px;
  cursor: pointer;
  transform: translateY(-4px);
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.5));
}

/* ---------- Toast ---------- */
#toast {
  position: absolute;
  z-index: 50;
  bottom: 90px; left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
}

.hidden { display: none !important; }
