/* ============================================================
   Map Component — Layout & Styles
   Depends on shared/shared.css being loaded first.
   ============================================================ */

/* ---- Root layout ------------------------------------------ */
html, body {
  height: 100%;
  /* Prevent overscroll bounce interfering with map pan on iOS */
  overscroll-behavior: none;
}

#map-wrapper {
  position: relative;
  display: flex;
  height: 100vh;
  height: 100dvh; /* dynamic viewport height — fixes mobile Safari address bar */
  overflow: hidden;
}

/* ---- Map -------------------------------------------------- */
#map {
  flex: 1;
  z-index: 0;
  background: #e8eef3;
  /* Leaflet needs a defined height */
  min-height: 0;
}

/* Override Leaflet's default focus ring with our brand one */
.leaflet-container a:focus-visible,
.leaflet-interactive:focus-visible {
  outline: 3px solid var(--color-secondary);
  outline-offset: 2px;
}

/* ---- Map controls (location + fit buttons) --------------- */
#map-controls {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: var(--z-panel);
}

.map-control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: #ffffff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-primary);
  box-shadow: var(--shadow);
  transition: background var(--transition), color var(--transition),
              box-shadow var(--transition);
}

.map-control-btn:hover,
.map-control-btn:focus-visible {
  background: var(--color-primary);
  color: #ffffff;
  box-shadow: var(--shadow-heavy);
  outline: none;
}

.map-control-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ---- Custom marker pins ----------------------------------- */
.door-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 40px;
  position: relative;
}

.door-marker svg {
  width: 32px;
  height: 40px;
  drop-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.door-marker-label {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  color: #ffffff;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

/* Marker cluster overrides */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background-color: rgba(0, 74, 124, 0.15);
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background-color: var(--color-primary);
  color: #ffffff;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
}

/* ---- Detail panel — shared base -------------------------- */
#detail-panel {
  background: var(--color-bg);
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: var(--z-panel);
  -webkit-overflow-scrolling: touch;
}

#panel-inner {
  padding-bottom: 2rem;
}

/* ---- Panel — desktop (side panel) ------------------------ */
@media (min-width: 768px) {
  #detail-panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 380px;
    max-width: 42%;
    border-left: 1px solid var(--color-border);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.08);
    transform: translateX(100%);
    transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
  }

  #detail-panel.is-open {
    transform: translateX(0);
  }

  /* Move map controls left so they don't sit behind the open panel */
  #map-wrapper.panel-open #map-controls {
    right: calc(380px + 1rem);
    right: calc(min(380px, 42%) + 1rem);
  }

  /* Keep trail controls centred over the map portion only */
  #map-wrapper.panel-open #trail-controls {
    left: calc(50% - min(380px, 42%) / 2);
    transform: translateX(-50%);
  }
}

@media (min-width: 1024px) {
  #detail-panel {
    width: 420px;
  }
}

/* ---- Panel — mobile (bottom sheet) ----------------------- */
@media (max-width: 767px) {
  #map-controls {
    top: auto;
    bottom: calc(1rem + env(safe-area-inset-bottom));
    right: 1rem;
  }

  #detail-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 65vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -4px 28px rgba(0, 0, 0, 0.18);
    transform: translateY(100%);
    transition: transform 320ms cubic-bezier(0.4, 0, 0.2, 1);
    padding-bottom: env(safe-area-inset-bottom);
  }

  #detail-panel.is-open {
    transform: translateY(0);
  }

  /* Drag handle — visual affordance for bottom sheet */
  .drag-handle {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
  }
}

.drag-handle {
  display: none;
}

@media (max-width: 767px) {
  .drag-handle {
    display: block;
  }
}

/* ---- Panel close / back button --------------------------- */
.panel-close-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 1rem 1rem 0.5rem;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  transition: color var(--transition);
  width: 100%;
}

.panel-close-btn:hover,
.panel-close-btn:focus-visible {
  color: var(--color-primary);
  outline: none;
}

.panel-close-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ---- Panel photo + before/after toggle ------------------- */
.panel-photo-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--color-bg-soft);
}

#panel-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 200ms ease;
}

#panel-photo.is-loading {
  opacity: 0;
}









/* ---- Panel content --------------------------------------- */
.panel-content {
  padding: 1rem 1.25rem;
}

.panel-location {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
}

.panel-location svg {
  flex-shrink: 0;
  color: var(--color-secondary);
}

.panel-artwork-name {
  font-size: 1.4rem;
  color: var(--color-primary);
  line-height: 1.2;
  margin-bottom: 0.2rem;
}

.panel-artist-name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 0;
}

.panel-divider {
  height: 1px;
  background: var(--color-border);
  margin: 1rem 0;
}

.panel-bio {
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--color-text);
}

/* ---- Trail controls wrapper (toggle + info strip) -------- */
#trail-controls {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  z-index: var(--z-panel);
  pointer-events: none; /* children re-enable as needed */
}

/* ---- Trail layer toggle ---------------------------------- */
#layer-toggle {
  display: flex;
  background: #ffffff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  pointer-events: auto;
}

/* ---- Trail info strip (distance + time) ------------------ */
.trail-info {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 0.2rem 0.65rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  pointer-events: none;
  min-height: 0;
  transition: opacity 200ms ease;
}

.trail-info:empty {
  display: none;
}

.layer-btn {
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.55em 1em;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.layer-btn + .layer-btn {
  border-left: 1px solid var(--color-border);
}

.layer-btn:hover {
  background: var(--color-bg-soft);
  color: var(--color-text);
}

.layer-btn.is-active {
  background: var(--color-primary);
  color: #ffffff;
}

/* When MUQY layer is active, highlight its button in teal */
#btn-layer-muqy.is-active {
  background: var(--color-secondary);
  color: var(--color-dark);
}

/* Combined trail button */
#btn-layer-combined.is-active {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
  color: #ffffff;
}

@media (max-width: 480px) {
  .layer-btn {
    padding: 0.55em 0.7em;
    font-size: 0.75rem;
  }
  .layer-btn svg {
    display: none; /* hide icon on very small screens to save space */
  }
}

/* ---- Visited badge (above map) --------------------------- */
.visited-badge {
  background: rgba(42, 157, 92, 0.92);
  color: #ffffff;
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow);
}

.visited-badge:empty {
  display: none;
}

/* ---- Clear progress button (appears below visited badge) -- */
.reset-visited-btn {
  font-size: 0.7rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.65);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.1rem 0.2rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  pointer-events: auto;
  transition: color var(--transition);
}

.reset-visited-btn:hover,
.reset-visited-btn:focus-visible {
  color: #ffffff;
  outline: none;
}

/* ---- Panel actions row (directions + visited) ------------ */
.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

/* ---- Get Directions button ------------------------------- */
.btn-directions {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55em 1.1em;
  background: var(--color-secondary);
  color: var(--color-dark);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  transition: opacity var(--transition), transform var(--transition);
}

.btn-directions svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.btn-directions:hover,
.btn-directions:focus-visible {
  opacity: 0.85;
  transform: translateY(-1px);
  outline: none;
}

/* ---- Mark as Visited button ------------------------------ */
.btn-visited {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55em 1.1em;
  background: transparent;
  color: var(--color-text-muted);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), transform var(--transition);
}

.btn-visited svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.btn-visited:hover,
.btn-visited:focus-visible {
  background: #f0faf4;
  border-color: #2a9d5c;
  color: #2a9d5c;
  outline: none;
}

.btn-visited.is-visited {
  background: #2a9d5c;
  border-color: #2a9d5c;
  color: #ffffff;
}

.btn-visited.is-visited:hover,
.btn-visited.is-visited:focus-visible {
  background: #238a50;
  border-color: #238a50;
}

/* ---- Leaflet zoom — keep away from our bottom controls --- */
.leaflet-bottom.leaflet-right {
  margin-bottom: 0.5rem;
  margin-right: 0.5rem;
}

/* ---- Leaflet attribution overrides ----------------------- */
.leaflet-control-attribution {
  font-size: 0.7rem !important;
}

/* Ensure attribution WAX link is readable */
.leaflet-control-attribution a {
  color: inherit;
}

/* ---- Celebration modal ------------------------------------ */
.celebration-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.celebration-modal[hidden] {
  display: none;
}

.celebration-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
}

.celebration-content {
  position: relative;
  background: var(--color-primary);
  color: #ffffff;
  border-radius: 1.25rem;
  padding: 2rem 1.75rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  animation: celebration-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes celebration-pop {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.celebration-emoji {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 0.75rem;
}

.celebration-title {
  font-size: 1.8rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
  color: var(--color-secondary);
}

.celebration-message {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
  line-height: 1.4;
}

.celebration-sub {
  font-size: 0.88rem;
  opacity: 0.85;
  margin: 0 0 0.5rem;
  line-height: 1.5;
}

.celebration-from {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-secondary);
  margin: 0 0 1.5rem;
}

.celebration-close-btn {
  background: var(--color-secondary);
  color: var(--color-dark);
  border: none;
  font-weight: 700;
  padding: 0.75rem 2rem;
  border-radius: 2rem;
  cursor: pointer;
  font-size: 0.95rem;
  transition: transform 0.15s ease, background 0.15s ease;
}

.celebration-close-btn:hover,
.celebration-close-btn:focus-visible {
  background: #20bfb0;
  transform: scale(1.04);
  outline: none;
}

/* ---- Photo slider (map panel) ----------------------------- */
.photo-slider-controls {
  position: absolute;
  bottom: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 2rem;
  padding: 0.3rem 0.6rem;
  backdrop-filter: blur(4px);
}

.photo-nav-btn {
  background: none;
  border: none;
  color: #ffffff;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0 0.15rem;
  cursor: pointer;
  opacity: 0.9;
  transition: opacity 0.15s ease;
}

.photo-nav-btn:hover:not(:disabled) { opacity: 1; }
.photo-nav-btn:disabled { opacity: 0.35; cursor: default; }

.photo-counter {
  font-size: 0.75rem;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 0.03em;
  min-width: 2.5rem;
  text-align: center;
}

/* ---- Map link on vote card -------------------------------- */
.card-map-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  font-size: 0.78rem;
  color: var(--color-primary);
  text-decoration: none;
  margin-top: 0.35rem;
  font-weight: 600;
}

.card-map-link:hover { text-decoration: underline; }

/* ---- Lightbox -------------------------------------------- */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 1rem;
  cursor: zoom-out;
}
#lightbox[hidden] { display: none; }
.lightbox-img {
  max-width: 100%;
  max-height: 90dvh;
  object-fit: contain;
  border-radius: 6px;
  cursor: default;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}
.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  font-size: 1.1rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: background 0.2s;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.3); }

/* ---- Panel photo fullscreen button ----------------------- */
.photo-fullscreen-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(0, 0, 0, 0.5);
  border: none;
  color: #ffffff;
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: background 0.2s;
  z-index: 2;
}
.photo-fullscreen-btn:hover { background: rgba(0, 0, 0, 0.75); }
.photo-fullscreen-btn svg { width: 14px; height: 14px; }
