/* ── Reset & tokens ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #111827;
  --surface:    #1f2937;
  --surface2:   #374151;
  --border:     #2d3f55;
  --accent:     #e94560;
  --text:       #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim:   #6b7280;
  --radius:     8px;
  --sidebar-w:  320px;
  --header-h:   52px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  height: var(--header-h);
  min-height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 1001;
  box-shadow: 0 2px 12px rgba(0,0,0,.45);
}

header h1 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: -.01em;
  flex-shrink: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

/* ── Filter pills ────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  min-width: 0;
}

.filter-bar::-webkit-scrollbar { display: none; }

.pill {
  flex-shrink: 0;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: background .12s, color .12s, border-color .12s;
  line-height: 1.5;
}

.pill:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

/* Active state — use the per-category --pill-color CSS variable */
.pill.active {
  background: color-mix(in srgb, var(--pill-color, var(--accent)) 18%, transparent);
  color: var(--pill-color, var(--accent));
  border-color: color-mix(in srgb, var(--pill-color, var(--accent)) 45%, transparent);
}

/* "All" pill has no --pill-color, use accent */
.pill[data-cat=""].active {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.header-actions button {
  padding: 5px 12px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: filter .12s;
  line-height: 1.4;
}

#nearby-btn {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}

#nearby-btn:hover { filter: brightness(1.2); }

#submit-btn {
  background: var(--accent);
  color: #fff;
}

#submit-btn:hover { filter: brightness(1.1); }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
  z-index: 100;
}

#sidebar-header {
  padding: 9px 14px 8px;
  font-size: 0.75rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 6px;
  align-items: baseline;
  flex-shrink: 0;
}

#sidebar-count { font-weight: 600; color: var(--text-muted); }
#sidebar-mode  { color: var(--text-dim); font-size: 0.7rem; }

#place-list {
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--surface2) transparent;
}

/* Place cards */
.place-card {
  padding: 12px 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  cursor: pointer;
  transition: background .13s;
}

.place-card:hover  { background: var(--surface2); }
.place-card.active { background: color-mix(in srgb, var(--accent) 10%, var(--surface2)); }

.card-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 99px;
  border: 1px solid;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.card-name {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 1px;
}

.card-namemm {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.card-address {
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.4;
}

.card-phone {
  font-size: 0.74rem;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ── Map ─────────────────────────────────────────────────────────────────── */
#map {
  flex: 1;
  z-index: 0;
}

/* ── Custom pin — suppress Leaflet's default icon background ─────────────── */
.place-pin {
  background: none !important;
  border: none !important;
}

.place-pin svg { display: block; overflow: visible; }

/* ── Cluster bubble ──────────────────────────────────────────────────────── */
.custom-cluster { background: none !important; border: none !important; }

.cluster-bubble {
  border-radius: 50%;
  border: 2px solid;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #111;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
  opacity: 0.93;
  transition: transform .1s;
}

.cluster-bubble:hover { transform: scale(1.08); }

/* ── Popup ───────────────────────────────────────────────────────────────── */
.leaflet-popup-content-wrapper,
.place-popup .leaflet-popup-content-wrapper {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-radius: var(--radius) !important;
  border: 1px solid var(--border) !important;
  box-shadow: 0 8px 32px rgba(0,0,0,.6) !important;
  padding: 0 !important;
}

.leaflet-popup-content { margin: 0 !important; width: auto !important; }

.leaflet-popup-tip-container { display: none; }

.popup-inner {
  padding: 14px 16px;
  min-width: 200px;
}

.popup-header { margin-bottom: 6px; }

.popup-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 99px;
  border: 1px solid;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.popup-title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 3px;
}

.popup-namemm {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.popup-row {
  display: flex;
  gap: 6px;
  font-size: 0.78rem;
  margin-bottom: 4px;
  line-height: 1.4;
}

.popup-label {
  color: var(--text-dim);
  flex-shrink: 0;
  min-width: 46px;
}

.popup-row a { color: #60a5fa; text-decoration: none; }
.popup-row a:hover { text-decoration: underline; }

/* Opening hours grid */
.popup-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  margin: 9px 0 5px;
}

.hours-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1px 8px;
  font-size: 0.76rem;
}

.hours-row { display: contents; }

.hours-day { color: var(--text-dim); white-space: nowrap; }
.hours-val { color: var(--text-muted); }

.hours-row.today .hours-day,
.hours-row.today .hours-val {
  color: var(--text);
  font-weight: 700;
}

/* Tags */
.popup-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.popup-tag {
  font-size: 0.68rem;
  background: var(--surface2);
  color: var(--text-dim);
  padding: 1px 7px;
  border-radius: 99px;
  border: 1px solid var(--border);
}

/* ── Loading overlay ─────────────────────────────────────────────────────── */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(17,24,39,.55);
  backdrop-filter: blur(2px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}

#loading-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 18px;
  font-size: 0.83rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  z-index: 3000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  white-space: nowrap;
}

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

/* ── Pick-mode banner ────────────────────────────────────────────────────── */
#pick-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-56px);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 8px 14px 8px 12px;
  font-size: 0.83rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,.55);
  z-index: 450;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .18s;
}

#pick-banner.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: all;
}

#pick-banner svg { color: var(--accent); flex-shrink: 0; }

#pick-cancel-btn {
  margin-left: 4px;
  padding: 3px 10px;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, color .12s;
}

#pick-cancel-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Map cursor during pick mode */
.pick-cursor { cursor: crosshair !important; }
.pick-cursor .leaflet-interactive { cursor: crosshair !important; }

/* Modal fades out while user picks */
#modal-overlay.picking {
  opacity: 0;
  pointer-events: none;
}

/* ── User location (you are here) ────────────────────────────────────────── */
.user-location {
  background: none !important;
  border: none !important;
  overflow: visible !important;
}

.user-location-dot {
  position: relative;
  width: 18px;
  height: 18px;
  background: #4285f4;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(66,133,244,.35),
              0 2px 6px rgba(0,0,0,.5);
}

.user-location-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin-top: -9px;
  margin-left: -9px;
  border-radius: 50%;
  background: rgba(66,133,244,.45);
  animation: user-pulse 1.8s ease-out infinite;
  pointer-events: none;
}

@keyframes user-pulse {
  0%   { transform: scale(0.6); opacity: 0.8; }
  100% { transform: scale(2.8); opacity: 0;   }
}

/* ── Draft marker (location pin while picking) ───────────────────────────── */
.draft-pin {
  background: none !important;
  border: none !important;
  overflow: visible !important;
}

.draft-pin svg { display: block; filter: drop-shadow(0 2px 4px rgba(0,0,0,.5)); }

.draft-ring {
  position: absolute;
  width: 44px;
  height: 44px;
  top: -19px;
  left: -8px;
  border: 2.5px solid #e94560;
  border-radius: 50%;
  animation: pulse-ring 1.4s ease-out infinite;
  pointer-events: none;
}

@keyframes pulse-ring {
  0%   { transform: scale(0.55); opacity: 1; }
  100% { transform: scale(1.6);  opacity: 0; }
}

/* ── Location picker (inside form) ──────────────────────────────────────── */
.location-section {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pick-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface2));
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: var(--radius);
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  line-height: 1.4;
}

.pick-btn:hover {
  background: color-mix(in srgb, var(--accent) 22%, var(--surface2));
  border-color: color-mix(in srgb, var(--accent) 65%, transparent);
}

.location-set {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: color-mix(in srgb, #4ade80 10%, var(--surface2));
  border: 1px solid color-mix(in srgb, #4ade80 30%, transparent);
  border-radius: var(--radius);
  padding: 5px 10px 5px 8px;
}

.location-set svg { flex-shrink: 0; }

.coords-text {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.78rem;
  color: #4ade80;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.75rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
  transition: color .12s;
  line-height: 1;
}

.link-btn:hover { color: var(--text); }

#coord-inputs-row { margin-top: 8px; }

/* ── Submit modal ────────────────────────────────────────────────────────── */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(3px);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 16px;
  transition: opacity .2s;
}

#modal-overlay.open { display: flex; }

#modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  width: min(500px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  box-shadow: 0 24px 64px rgba(0,0,0,.7);
}

#modal h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.modal-note {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 18px;
}

.form-group { margin-bottom: 12px; }

.form-group label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 500;
}

.req { color: var(--accent); }
.opt { color: var(--text-dim); font-weight: 400; }

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 0.875rem;
  transition: border-color .12s, box-shadow .12s;
  outline: none;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}

.form-group select { cursor: pointer; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.lat-lng-hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin: -6px 0 12px;
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}

.modal-actions button {
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: filter .12s;
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover { filter: brightness(1.2); }

#submit-submit-btn {
  background: var(--accent);
  color: #fff;
}

#submit-submit-btn:hover { filter: brightness(1.1); }
#submit-submit-btn:disabled { opacity: .55; cursor: not-allowed; }

#submit-result {
  margin-top: 10px;
  font-size: 0.82rem;
  padding: 9px 12px;
  border-radius: var(--radius);
  display: none;
  line-height: 1.4;
}

.result-success {
  background: color-mix(in srgb, #4ade80 12%, transparent);
  color: #4ade80;
  border: 1px solid color-mix(in srgb, #4ade80 35%, transparent);
}

.result-error {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: #f87171;
  border: 1px solid color-mix(in srgb, #f87171 35%, transparent);
}

/* ── Leaflet overrides ───────────────────────────────────────────────────── */
.leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--surface2) !important;
}

.leaflet-control-attribution {
  background: rgba(17,24,39,.75) !important;
  color: var(--text-dim) !important;
  font-size: 0.65rem !important;
}

.leaflet-control-attribution a { color: #60a5fa !important; }

/* Hide markercluster default styles that clash with our custom icons */
.leaflet-cluster-anim .leaflet-marker-icon,
.leaflet-cluster-anim .leaflet-marker-shadow {
  transition: left .3s ease-out, top .3s ease-out !important;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  :root { --sidebar-w: 0px; }
  #sidebar { display: none; }
  .header-right { gap: 6px; }
  .pill { padding: 3px 9px; font-size: 0.72rem; }
}

@media (max-width: 440px) {
  header { gap: 8px; padding: 0 10px; }
  header h1 { font-size: 0.9rem; }
  .header-actions button { padding: 4px 9px; font-size: 0.75rem; }
}
