/* ── Reset & Layout ──────────────────────────────────── */
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, sans-serif;
  background: #e9eef5;
  color: #18202a;
}

body {
  --panel-bg: rgba(255, 255, 255, 0.94);
  --panel-border: rgba(27, 39, 53, 0.12);
  --text-color: #18202a;
  --muted-color: #5d6b7a;
  --surface: #ffffff;
  --surface-hover: #eef5ff;
  --input-bg: #ffffff;
  --input-border: #c7d1de;
  --primary: #0078d7;
  --primary-text: #ffffff;
  --shadow: 0 10px 30px rgba(22, 34, 45, 0.16);
}

body[data-theme='dark'] {
  --panel-bg: rgba(17, 24, 33, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-color: #eff4fb;
  --muted-color: #a7b3c2;
  --surface: #111a24;
  --surface-hover: #1b2a3a;
  --input-bg: #0f1720;
  --input-border: #334155;
  --primary: #4ea1ff;
  --primary-text: #06121f;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.38);
  background: #0b1118;
  color: var(--text-color);
}

h2 {
  margin-top: 0;
  margin-bottom: 0;
}

#map {
  width: 100%;
  height: 100%;
  position: relative;
}

/* ── Control Panel ───────────────────────────────────── */
#controls {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 20;
  background: var(--panel-bg);
  padding: 12px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 13px;
  min-width: 180px;
  backdrop-filter: blur(16px);
  color: var(--text-color);
}

#controls label {
  font-weight: 600;
  margin-bottom: -4px;
  color: var(--muted-color);
}

#controls select,
#controls button,
#controls input {
  padding: 4px 8px;
  font-size: 13px;
  border: 1px solid #ccc;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-color);
  cursor: pointer;
}

#controls-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--text-color);
  padding: 0;
  box-shadow: none;
}

.icon-btn:hover,
.icon-btn:focus-visible,
#controls select:hover,
#controls button:hover,
#controls input:hover {
  border-color: var(--primary);
}

.slider-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted-color);
}

#menu-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  overflow: visible;
  max-height: 700px;
  opacity: 1;
  transition: max-height 0.3s ease, opacity 0.2s ease, margin-top 0.25s ease;
}

#menu-content.hidden {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  overflow: hidden;
  pointer-events: none;
}

#controls select,
#city-search,
#address-search {
  width: 100%;
}

#controls input[type="range"] {
  width: 100%;
}

/* Basemap toggle buttons */
.basemap-group {
  display: flex;
  gap: 4px;
}

.basemap-group button {
  flex: 1;
  padding: 4px 8px;
}

.basemap-group button.active {
  background: #0078d7;
  color: #fff;
  border-color: #005ba1;
}

/* ── Address Search ─────────────────────────────────── */
#search-wrapper {
  position: relative;
}

#address-search {
  padding: 5px 28px 5px 8px;
  cursor: text;
}

#city-search-wrapper {
  position: relative;
}

#city-search {
  padding: 5px 28px 5px 8px;
  box-sizing: border-box;
  outline: none;
  cursor: text;
}

.clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted-color);
  font-size: 18px;
  line-height: 1;
  padding: 0;
  display: none;
  align-items: center;
  justify-content: center;
}

.clear-btn:hover,
.clear-btn:focus-visible {
  color: var(--text-color);
  background: var(--surface-hover);
}

.clear-btn.visible {
  display: inline-flex;
}

#address-search:focus,
#city-search:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 25%, transparent);
}

#search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 100;
  max-height: 220px;
  overflow-y: auto;
}

#city-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 100;
  max-height: 220px;
  overflow-y: auto;
}

#search-results.open {
  display: block;
}

#city-results.open {
  display: block;
}

#search-results li,
#city-results li {
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
  line-height: 1.4;
  border-bottom: 1px solid var(--panel-border);
  color: var(--text-color);
}

#search-results li:last-child,
#city-results li:last-child {
  border-bottom: none;
}

#search-results li:hover,
#search-results li[aria-selected="true"],
#city-results li:hover,
#city-results li[aria-selected="true"] {
  background: var(--surface-hover);
}

#search-results li.no-results,
#city-results li.no-results {
  color: var(--muted-color);
  cursor: default;
  font-style: italic;
}

/* ── Swipe Handle — landscape (default) ─────────────── */
#swipe-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  /* positioned by JS */
  width: 44px;
  /* wide hit area; visual bar is in ::after */
  margin-left: -22px;
  background: transparent;
  cursor: ew-resize;
  z-index: 15;
}

/* Thin visual bar (paints behind the circle via z-index) */
#swipe-handle::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 3px;
  margin-left: -1.5px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  z-index: 0;
}

/* Drag pill — left/right arrows, elevated above the bar */
#swipe-handle::before {
  content: '◀ ▶';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 28px;
  background: #fff;
  border: 1.5px solid rgba(0, 0, 0, 0.4);
  border-radius: 14px;
  font-size: 11px;
  line-height: 28px;
  text-align: center;
  color: #333;
  letter-spacing: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  pointer-events: none;
  z-index: 1;
  /* above the ::after bar */
}

/* ── Swipe Handle — portrait mode ───────────────────── */
#swipe-handle.portrait {
  top: 0;
  /* positioned by JS */
  left: 0;
  bottom: auto;
  right: 0;
  width: auto;
  height: 44px;
  /* tall hit area for portrait */
  margin-left: 0;
  margin-top: -22px;
  cursor: ns-resize;
}

/* Portrait: thin horizontal visual bar */
#swipe-handle.portrait::after {
  top: 50%;
  bottom: auto;
  left: 0;
  right: 0;
  width: auto;
  height: 3px;
  margin-left: 0;
  margin-top: -1.5px;
}

/* Portrait: rotate pill so arrows point up/down */
#swipe-handle.portrait::before {
  transform: translate(-50%, -50%) rotate(90deg);
}


/* ── Active state for swipe toggle button ────────────── */
#swipe-toggle.active {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

/* ── Bottom Left Controls ────────────── */
#bottom-left-controls {
  position: absolute;
  bottom: 20px;
  left: 20px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
}

.fab-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

/* ── FAB intro labels ─────────────────────────────────── */
@keyframes fab-label-intro {
  0%   { opacity: 0; transform: translateX(-10px); }
  14%  { opacity: 1; transform: translateX(0); }
  78%  { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(-10px); }
}

.fab-label {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  border-radius: 14px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-color);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  animation: fab-label-intro 5s ease forwards;
}

.fab-row:nth-child(1) .fab-label { animation-delay: 0.0s; }
.fab-row:nth-child(2) .fab-label { animation-delay: 0.15s; }
.fab-row:nth-child(3) .fab-label { animation-delay: 0.3s; }
.fab-row:nth-child(4) .fab-label { animation-delay: 0.45s; }

/* ── Floating Action Button (Geolocation) ────────────── */
.fab {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background-color: var(--panel-bg);
  box-shadow: var(--shadow);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  color: var(--text-color);
}

.fab:hover {
  background-color: var(--surface-hover);
}

/* ── Info Modal ──────────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal.open {
  display: flex;
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 24px;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  color: var(--text-color);
  box-shadow: var(--shadow);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--surface-hover);
  border-radius: 50%;
  font-size: 18px;
  color: var(--text-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: var(--panel-border);
}

.modal-content h2 {
  margin-top: 0;
  margin-bottom: 12px;
  color: var(--text-color);
}

.modal-content h3 {
  margin-top: 16px;
  margin-bottom: 8px;
  color: var(--text-color);
}

.modal-content p {
  margin: 0 0 12px;
  line-height: 1.6;
  color: var(--muted-color);
  font-size: 13px;
}

/* ── FAB / button active state ───────────────────────── */
.fab.active,
#comments-toggle.active {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

#comments-toggle.no-city {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Prevent iOS native long-press callout on the map ── */
#map {
  -webkit-touch-callout: none;
  user-select: none;
}

/* ── Comment context menu ────────────────────────────── */
#comment-context-menu {
  position: fixed;
  z-index: 50;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  display: none;
  overflow: hidden;
}

#comment-context-menu.open {
  display: block;
}

#context-menu-add {
  display: block;
  width: 100%;
  padding: 10px 18px;
  background: none;
  border: none;
  font-size: 13px;
  color: var(--text-color);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}

#context-menu-add:hover {
  background: var(--surface-hover);
}

/* ── Comment form modal ──────────────────────────────── */
#comment-form-content {
  max-width: 360px;
  width: 90vw;
}

#comment-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

#comment-form label {
  font-weight: 600;
  font-size: 12px;
  color: var(--muted-color);
}

#comment-form input[type="text"],
#comment-form textarea {
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text-color);
  box-sizing: border-box;
  font-family: inherit;
}

#comment-form textarea {
  resize: vertical;
  min-height: 80px;
}

#comment-form input:focus,
#comment-form textarea:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 25%, transparent);
}

#comment-char-count {
  font-size: 11px;
  color: var(--muted-color);
  margin: -4px 0 0;
  text-align: right;
}

#comment-char-count.over {
  color: #e53935;
}

.modal-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

#comment-submit {
  flex: 1;
  padding: 8px;
  background: var(--primary);
  color: var(--primary-text);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#comment-submit:hover { opacity: 0.9; }
#comment-submit:disabled { opacity: 0.55; cursor: default; }

#comment-cancel {
  flex: 1;
  padding: 8px;
  background: var(--surface);
  color: var(--text-color);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

#comment-cancel:hover { border-color: var(--primary); }

#comment-status {
  margin: 0;
  font-size: 12px;
  color: var(--muted-color);
  min-height: 16px;
}

/* ── Comment read popover ────────────────────────────── */
#suggestion-popover {
  position: absolute;
  z-index: 30;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  padding: 12px 14px;
  width: 260px;
  max-height: 300px;
  overflow-y: auto;
  display: none;
  color: var(--text-color);
  font-size: 13px;
}

#suggestion-popover.open {
  display: block;
}

#popover-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  background: var(--surface-hover);
  border-radius: 50%;
  font-size: 13px;
  color: var(--text-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

#popover-close:hover { background: var(--panel-border); }

.popover-header {
  font-weight: 700;
  font-size: 13px;
  color: var(--text-color);
  padding-right: 28px;
  margin-bottom: 6px;
}

.popover-item {
  padding: 7px 0;
  border-top: 1px solid var(--panel-border);
}

.popover-item:first-of-type {
  border-top: none;
  padding-top: 0;
}

.popover-meta {
  font-size: 11px;
  color: var(--muted-color);
  margin-bottom: 4px;
}

.popover-text {
  margin: 0;
  line-height: 1.5;
  color: var(--text-color);
  font-size: 13px;
  word-break: break-word;
}

/* ── Mobile: centre popover instead of pixel-positioning ── */
@media (max-width: 640px) {
  #suggestion-popover {
    position: fixed !important;
    left: 16px !important;
    right: 16px !important;
    top: auto !important;
    bottom: 88px;
    width: auto;
    max-width: none;
    transform: none;
  }
}

/* ── Add-comment FAB ─────────────────────────────────── */
#add-comment-fab:hover {
  transform: scale(1.06);
}

#add-comment-fab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── "Tap on map" hint toast ─────────────────────────── */
#add-comment-hint {
  position: absolute;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 13px;
  padding: 8px 18px;
  border-radius: 20px;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
}

#add-comment-hint.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── "Select a city" toast ───────────────────────────── */
#city-required-toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  background: rgba(24, 32, 42, 0.88);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 18px;
  border-radius: 20px;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
}

#city-required-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── City search pulse highlight ─────────────────────── */
@keyframes city-search-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(0, 120, 215, 0.5); border-color: var(--primary); }
  50%  { box-shadow: 0 0 0 6px rgba(0, 120, 215, 0); border-color: var(--primary); }
  100% { box-shadow: 0 0 0 0 rgba(0, 120, 215, 0); border-color: var(--input-border); }
}

#city-search.pulse-highlight {
  animation: city-search-pulse 0.6s ease-out 3;
  border-color: var(--primary);
  outline: none;
}