:root {
  --accent: #e4572e;
  --accent-strong: #c8441d;
  --ink: #1d2433;
  --ink-soft: #5b6475;
  --ink-faint: #8c94a3;
  --line: rgba(29, 36, 51, 0.1);
  --surface: #ffffff;
  --surface-2: #f5f6f8;
  --glass: rgba(255, 255, 255, 0.86);
  --danger: #d64045;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --shadow: 0 4px 12px rgba(16, 24, 40, 0.08), 0 12px 32px rgba(16, 24, 40, 0.12);
  --shadow-lg: 0 24px 64px rgba(16, 24, 40, 0.22);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --panel-w: 400px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #e8eaed;
  color: var(--ink);
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; z-index: 0; background: #e8eaed; }
/* Soften the base map a little so the coloured pins stand out. */
.leaflet-tile-pane { filter: saturate(0.75) brightness(1.03) contrast(0.95); }

.glass {
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
}

/* ---------- Top bar ---------- */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 500;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px 9px 11px;
  border-radius: 14px;
  flex-shrink: 0;
}
.brand-logo { width: 30px; height: 30px; color: var(--accent); filter: drop-shadow(0 2px 3px rgba(228, 87, 46, 0.35)); }
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: -0.02em; line-height: 1.1; }
.brand-sub { font-size: 12px; color: var(--ink-soft); font-weight: 500; }

.filters {
  display: flex;
  gap: 6px;
  padding: 7px;
  border-radius: 14px;
  overflow-x: auto;
  scrollbar-width: none;
  min-width: 0;
  max-width: 100%;
}
.filters::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.15s var(--ease);
}
.chip:hover { border-color: rgba(29, 36, 51, 0.22); }
.chip:active { transform: scale(0.96); }
.chip .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent);
}
.chip .count {
  font-size: 11.5px;
  color: var(--ink-faint);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.chip.off { opacity: 0.45; background: transparent; }
.chip.off .dot { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }

/* ---------- Floating buttons ---------- */

.fab-stack {
  position: fixed;
  right: 20px;
  bottom: calc(28px + env(safe-area-inset-bottom));
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  transition: transform 0.35s var(--ease), opacity 0.25s;
}
body.panel-open .fab-stack,
body.placing .fab-stack { opacity: 0; transform: scale(0.8); pointer-events: none; }

.fab {
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  transition: transform 0.2s var(--ease), box-shadow 0.2s, background 0.2s;
}
.fab svg { width: 22px; height: 22px; }
.fab-small { width: 44px; height: 44px; color: var(--ink); }
.fab-small:hover { transform: translateY(-1px); }
.fab-add {
  width: 60px; height: 60px;
  color: #fff;
  background: linear-gradient(145deg, #f06a3f, var(--accent-strong));
  box-shadow: 0 6px 18px rgba(228, 87, 46, 0.45), 0 2px 4px rgba(0, 0, 0, 0.12);
}
.fab-add svg { width: 28px; height: 28px; transition: transform 0.3s var(--ease); }
.fab-add:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(228, 87, 46, 0.5), 0 2px 4px rgba(0, 0, 0, 0.12); }
.fab-add:hover svg { transform: rotate(90deg); }
.fab-add:active { transform: scale(0.94); }

/* ---------- Placement mode ---------- */

.place-pin {
  position: fixed;
  left: 50%; top: 50%;
  z-index: 450;
  width: 40px; height: 52px;
  margin: -52px 0 0 -20px;
  pointer-events: none;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.25));
  animation: pin-drop 0.45s var(--ease);
}
.place-pin svg { width: 100%; height: 100%; transition: transform 0.2s var(--ease); }
.place-shadow {
  position: absolute;
  left: 50%; bottom: -4px;
  width: 14px; height: 5px;
  margin-left: -7px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.3);
  transition: transform 0.2s var(--ease), opacity 0.2s;
}
body.map-moving .place-pin svg { transform: translateY(-10px); }
body.map-moving .place-shadow { transform: scale(1.6); opacity: 0.5; }

@keyframes pin-drop {
  from { transform: translateY(-40px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.place-bar {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 500;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 12px 12px 20px;
  border-radius: 18px;
  width: max-content;
  max-width: calc(100vw - 32px);
  animation: slide-up 0.35s var(--ease);
}
.place-text { display: flex; flex-direction: column; font-size: 13.5px; color: var(--ink-soft); }
.place-text strong { color: var(--ink); font-size: 15px; }
.place-actions { display: flex; gap: 8px; flex-shrink: 0; }

@keyframes slide-up {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 650;
  font-size: 14.5px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.15s var(--ease), box-shadow 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-sm { height: 34px; padding: 0 13px; font-size: 13.5px; border-radius: 10px; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(228, 87, 46, 0.35); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger-ghost { background: transparent; color: var(--danger); padding: 0 12px; }
.btn-danger-ghost:hover { background: color-mix(in srgb, var(--danger) 9%, transparent); }
.btn-danger-ghost.armed { background: var(--danger); color: #fff; box-shadow: 0 2px 8px rgba(214, 64, 69, 0.35); }

.icon-btn {
  display: grid; place-items: center;
  width: 36px; height: 36px;
  border: 0; border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-soft);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: #eaecf0; color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Panel (form) ---------- */

.panel {
  position: fixed;
  top: 12px; right: 12px; bottom: 12px;
  z-index: 600;
  width: var(--panel-w);
  max-width: calc(100vw - 24px);
  background: var(--surface);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  transform: translateX(calc(100% + 24px));
  transition: transform 0.42s var(--ease);
  display: flex;
  flex-direction: column;
}
body.panel-open .panel { transform: none; }
.panel-grip { display: none; }

#site-form { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 22px 22px 6px 24px;
}
.panel-eyebrow {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.panel-head h2 { margin: 3px 0 0; font-size: 23px; font-weight: 800; letter-spacing: -0.025em; }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 24px 8px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px 18px 18px;
  border-top: 1px solid var(--line);
}
.spacer { flex: 1; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 13px; font-weight: 700; color: var(--ink); }
.field-label em { font-style: normal; font-weight: 500; color: var(--ink-faint); margin-left: 4px; }

.field input[type="text"],
.field textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  outline: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.field textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
.field input[type="text"]:focus,
.field textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 15%, transparent);
}
.field input::placeholder, .field textarea::placeholder { color: var(--ink-faint); }

/* Category picker */
.cat-picker { display: flex; flex-wrap: wrap; gap: 7px; }
.cat-opt {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 13px 0 9px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  font-size: 13.5px;
  font-weight: 600;
  transition: all 0.15s var(--ease);
}
.cat-opt:hover { border-color: color-mix(in srgb, var(--c) 60%, transparent); }
.cat-opt .swatch {
  display: grid; place-items: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c) 18%, white);
  font-size: 12px;
}
.cat-opt .swatch:empty::after {
  content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c);
}
.cat-opt[aria-checked="true"] {
  background: var(--c);
  border-color: var(--c);
  color: #fff;
  box-shadow: 0 3px 10px color-mix(in srgb, var(--c) 40%, transparent);
}
.cat-opt[aria-checked="true"] .swatch { background: rgba(255, 255, 255, 0.25); }
.cat-opt[aria-checked="true"] .swatch:empty::after { background: #fff; }
.cat-opt.add {
  border-style: dashed;
  color: var(--ink-soft);
  padding: 0 13px;
}
.cat-opt.add:hover { color: var(--accent); border-color: var(--accent); }

.new-cat {
  margin-top: 4px;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: fade-in 0.25s var(--ease);
}
.new-cat-row { display: flex; gap: 8px; }
.new-cat input[type="text"] { background: var(--surface); }
.field .new-cat-row input[type="text"] { flex: 1; min-width: 0; }
.field .new-cat-row input.nc-icon { flex: none; width: 52px; text-align: center; padding-left: 6px; padding-right: 6px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch-btn {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 0;
  background: var(--c);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
  transition: transform 0.15s var(--ease), box-shadow 0.15s;
}
.swatch-btn:hover { transform: scale(1.12); }
.swatch-btn[aria-checked="true"] { box-shadow: 0 0 0 2px var(--surface-2), 0 0 0 4px var(--c); }
.swatch-custom {
  position: relative;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
  overflow: hidden;
}
.swatch-custom input { position: absolute; inset: -8px; width: 44px; height: 44px; opacity: 0; cursor: pointer; }
.swatch-custom[aria-checked="true"] { box-shadow: 0 0 0 2px var(--surface-2), 0 0 0 4px var(--ink); }
.new-cat-actions { display: flex; justify-content: flex-end; gap: 8px; }

@keyframes fade-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.loc-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--ink-soft);
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
}
.loc-hint svg { width: 16px; height: 16px; color: var(--accent); flex-shrink: 0; }
#loc-coords { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }

.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--danger) 9%, white);
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 600;
}

/* ---------- Map pins ---------- */

.pin { background: none; border: 0; }
.pin-inner {
  position: relative;
  width: 36px; height: 46px;
  transform-origin: 50% 100%;
  transition: transform 0.2s var(--ease);
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.28));
  animation: pin-pop 0.4s var(--ease) both;
}
.pin-inner svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.pin-icon {
  position: absolute;
  top: 7px; left: 50%;
  width: 22px; height: 22px;
  margin-left: -11px;
  display: grid; place-items: center;
  font-size: 13px;
  line-height: 1;
}
.leaflet-marker-icon:hover .pin-inner { transform: scale(1.12); }
.pin.active .pin-inner { transform: scale(1.18); }
.pin.editing .pin-inner { animation: pin-bob 1.2s ease-in-out infinite; }

@keyframes pin-pop { from { transform: scale(0.3); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pin-bob { 0%, 100% { transform: translateY(0) scale(1.15); } 50% { transform: translateY(-5px) scale(1.15); } }

/* ---------- Popup ---------- */

.leaflet-popup-content-wrapper {
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 0;
  overflow: hidden;
}
.leaflet-popup-content { margin: 0; width: 280px !important; font-family: inherit; }
.leaflet-popup-tip { box-shadow: none; }
.leaflet-container a.leaflet-popup-close-button {
  top: 10px; right: 10px;
  width: 28px; height: 28px;
  border-radius: 8px;
  font: 400 20px/26px system-ui, sans-serif;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.8);
}
.leaflet-container a.leaflet-popup-close-button:hover { background: var(--surface-2); color: var(--ink); }

.pop { padding: 0; }
.pop-band { height: 6px; background: var(--c); }
.pop-main { padding: 14px 18px 4px; }
.pop-cat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--c) 13%, white);
  color: color-mix(in srgb, var(--c) 75%, black);
  font-size: 12px;
  font-weight: 700;
}
.pop-cat .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.pop h3 { margin: 10px 30px 6px 0; font-size: 17px; font-weight: 800; letter-spacing: -0.015em; line-height: 1.3; }
.pop p {
  margin: 0 0 4px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 200px;
  overflow-y: auto;
}
.pop p.empty { font-style: italic; color: var(--ink-faint); }
.pop-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px 12px 18px;
  font-size: 12px;
  color: var(--ink-faint);
}
.pop-foot .btn { height: 34px; }
.pop-foot .btn svg { width: 15px; height: 15px; margin-right: 6px; }

/* ---------- Leaflet chrome ---------- */

.leaflet-control-zoom {
  border: 0 !important;
  border-radius: 12px !important;
  overflow: hidden;
  box-shadow: var(--shadow) !important;
}
.leaflet-control-zoom a {
  width: 40px !important; height: 40px !important;
  line-height: 40px !important;
  color: var(--ink) !important;
  border-bottom-color: var(--line) !important;
}
.leaflet-control-layers {
  border: 0 !important;
  border-radius: 12px !important;
  box-shadow: var(--shadow) !important;
  font-family: inherit;
}
.leaflet-control-attribution { font-size: 11px; background: rgba(255, 255, 255, 0.75) !important; border-top-left-radius: 8px; }
.leaflet-bottom.leaflet-left .leaflet-control-zoom { margin-bottom: 28px; margin-left: 20px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  top: 84px;
  z-index: 900;
  transform: translate(-50%, -16px);
  opacity: 0;
  pointer-events: none;
  padding: 11px 18px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: opacity 0.25s, transform 0.3s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ---------- Mobile ---------- */

@media (max-width: 720px) {
  .topbar { flex-direction: column; gap: 8px; }
  .brand { padding: 7px 14px 7px 9px; }
  .brand-logo { width: 26px; height: 26px; }
  .filters { width: 100%; }
  .brand-sub { display: none; }

  .panel {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%;
    max-width: none;
    max-height: 66vh;
    border-radius: 22px 22px 0 0;
    transform: translateY(105%);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel-grip {
    display: block;
    width: 40px; height: 5px;
    margin: 8px auto 0;
    border-radius: 3px;
    background: #d6d9df;
  }
  .panel-head { padding-top: 10px; }
  .panel-head h2 { font-size: 20px; }
  .panel-body { gap: 16px; }
  .field textarea { min-height: 80px; }
  .topbar { transition: opacity 0.25s, transform 0.3s var(--ease); }
  body.panel-open .topbar { opacity: 0; transform: translateY(-12px); pointer-events: none; }
  body.panel-open .topbar > * { pointer-events: none; }

  .place-bar { flex-direction: column; align-items: stretch; gap: 10px; padding: 14px; width: calc(100vw - 32px); }
  .place-actions .btn { flex: 1; }
  .leaflet-bottom.leaflet-left .leaflet-control-zoom { display: none; }
  .fab-stack { right: 16px; }
}
