/**
 * Map Component Styles
 * Based on Design System: pages/Search.html
 * Uses Leaflet + OpenStreetMap
 */

/* ── Map Layout (split-view) ── */
.map-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 0;
  border: 1px solid var(--sam-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 560px;
}

.map-pane {
  background: linear-gradient(135deg, #e4ddcc, #d4c9b8);
  position: relative;
  min-height: 400px;
}

.map-pane .map-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(49, 49, 49, 0.35);
  pointer-events: none;
  z-index: 1;
}

/* ── Map Pin Markers ── */
.map-pin {
  position: absolute;
  background: var(--color-action);
  color: #fff;
  border: 2.5px solid var(--sam-white);
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-2);
  transition: transform 0.15s, box-shadow 0.15s;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transform: translate(-50%, -50%);
}

.map-pin:hover,
.map-pin.sel {
  transform: translate(-50%, -50%) scale(1.1);
  box-shadow: var(--shadow-3);
  z-index: 1000 !important;
}

/* Leaflet marker overrides */
.leaflet-marker-icon.map-pin-marker {
  background: transparent;
  border: none;
}

.leaflet-div-icon {
  background: transparent;
  border: none;
}

/* ── Map Controls ── */
.map-ctrl {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--sam-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 1000;
}

.map-ctrl button {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  border-bottom: 1px solid var(--sam-light);
  color: var(--text-primary);
  transition: background 0.12s;
}

.map-ctrl button:hover {
  background: var(--sam-brown-light);
}

.map-ctrl button:last-child {
  border-bottom: none;
}

/* ── Map List (right sidebar) ── */
.map-list {
  overflow-y: auto;
  max-height: 560px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--sam-light);
  background: var(--sam-white);
}

.map-list .list-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--sam-light);
  font-size: 14px;
  color: var(--sam-dark);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--sam-brown-light) 0%, #f5f0ea 100%);
}

.map-list .list-head::before {
  content: '';
  width: 18px;
  height: 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23C8553D' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z'/%3E%3Ccircle cx='12' cy='10' r='3'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  flex-shrink: 0;
}

.map-row {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--sam-light);
  cursor: pointer;
  align-items: center;
  text-decoration: none;
  color: inherit;
  transition: background 0.12s;
}

.map-row:hover,
.map-row.sel {
  background: var(--sam-brown-light);
}

.map-row .thumb-sm {
  width: 72px;
  height: 54px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
  background-color: var(--sam-light);
}

.map-row .details {
  flex: 1;
  min-width: 0;
}

.map-row .details .area {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sam-medium);
}

.map-row .details h4 {
  font-size: 14px;
  font-weight: 700;
  margin: 2px 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-row .details .specs {
  font-size: 12.5px;
  color: var(--sam-medium);
}

.map-row .price-sm {
  font-size: var(--text-base);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-left: auto;
}

/* ── Map Modal ── */
.map-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.map-modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.map-modal-box {
  background: var(--sam-white);
  border-radius: var(--radius-xl);
  width: 95vw;
  max-width: 1200px;
  height: 85vh;
  max-height: 800px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-3);
}

.map-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--sam-light);
}

.map-modal-head h3 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.map-modal-close {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--sam-brown-light);
  border-radius: var(--radius-md);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: background 0.12s;
}

.map-modal-close:hover {
  background: var(--sam-light);
}

.map-modal-content {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 380px;
  min-height: 0;
}

.map-modal-map {
  position: relative;
  background: linear-gradient(135deg, #e4ddcc, #d4c9b8);
}

.map-modal-list {
  overflow-y: auto;
  border-left: 1px solid var(--sam-light);
  display: flex;
  flex-direction: column;
}

/* ── Leaflet Customizations ── */
.leaflet-container {
  font-family: inherit;
  background: linear-gradient(135deg, #e4ddcc, #d4c9b8);
}

/* Hide default Leaflet controls - we use custom */
.leaflet-control-zoom {
  display: none !important;
}

/* Attribution styling */
.leaflet-control-attribution {
  font-size: 10px;
  background: rgba(255, 255, 255, 0.8) !important;
  padding: 2px 6px;
}

.leaflet-control-attribution a {
  color: var(--sam-medium);
}

/* Popup styling */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
}

.leaflet-popup-content {
  margin: 12px 14px;
  font-size: 13px;
}

.leaflet-popup-tip {
  box-shadow: none;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .map-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 400px auto;
  }

  .map-list {
    border-left: none;
    border-top: 1px solid var(--sam-light);
    max-height: 300px;
  }

  .map-modal-content {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .map-modal-list {
    border-left: none;
    border-top: 1px solid var(--sam-light);
    max-height: 200px;
  }
}

/* ── Loading State ──
   The Maps API is fetched on first use now, so there is a real gap between the click
   and the first tile. `aria-busy` on the map element announces it; this paints it. */
.map-pane.is-loading,
.map-modal-map.is-loading {
  position: relative;
}

.map-pane.is-loading::after,
.map-modal-map.is-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 500;
  /* Shimmer over the same fill the idle pane uses — one layered background, because a
     `background` shorthand after a `background-image` would drop the shimmer. */
  background-image:
    linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.45) 50%, transparent 100%),
    linear-gradient(135deg, #e4ddcc, #d4c9b8);
  background-size: 200% 100%, 100% 100%;
  background-repeat: no-repeat, no-repeat;
  animation: map-loading-shimmer 1.4s ease-in-out infinite;
}

@keyframes map-loading-shimmer {
  0%   { background-position: 200% 0, 0 0; }
  100% { background-position: -200% 0, 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  .map-pane.is-loading::after,
  .map-modal-map.is-loading::after {
    animation: none;
  }
}

/* ── Cluster Markers ── */
.map-cluster-icon {
  background: transparent;
  border: none;
}

.map-cluster {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-action);
  color: var(--color-action-fg);
  border-radius: 50%;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow-2);
  border: 2.5px solid var(--sam-white);
  transition: transform 0.15s, box-shadow 0.15s;
}

.map-cluster:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-3);
}

.map-cluster--small {
  width: 36px;
  height: 36px;
  font-size: 12px;
}

.map-cluster--medium {
  width: 42px;
  height: 42px;
  font-size: 13px;
}

.map-cluster--large {
  width: 48px;
  height: 48px;
  font-size: 14px;
}

/* Override default MarkerCluster styles */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: transparent !important;
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: transparent !important;
}

/* ── Single Pin (for detail pages) ── */
.map-pin--single {
  background: var(--color-action);
  color: var(--color-action-fg);
  border-color: var(--sam-red);
}

.map-pin--single:hover {
  background: var(--sam-dark);
  border-color: var(--sam-dark);
}

/* ── Map Embed (for detail pages) ── */
.map-embed {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  height: 380px;
  isolation: isolate; /* Prevents Leaflet z-index from overlapping header */
}

.map-embed .leaflet-container {
  height: 100%;
  width: 100%;
}

.map-hood {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  background: rgba(255, 255, 255, 0.96);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 1000;
  backdrop-filter: blur(8px);
}

.map-hood strong {
  font-size: 14px;
  display: block;
  margin-bottom: 2px;
}

.map-hood span {
  font-size: 13px;
  color: var(--sam-brown-dark);
}

.map-attrib {
  position: absolute;
  bottom: 4px;
  right: 4px;
  font-size: 10px;
  color: var(--sam-medium);
  background: rgba(255, 255, 255, 0.7);
  padding: 2px 6px;
  border-radius: 3px;
  z-index: 1000;
}

.map-attrib a {
  color: inherit;
}

/* ── Map Block Fallback (no coordinates) ── */
.map-block {
  background: linear-gradient(135deg, #e8e0d4, #d4cbbf);
  border-radius: var(--radius-lg);
  height: 200px;
  display: flex;
  align-items: flex-end;
  position: relative;
  overflow: hidden;
}

.map-block .map-label {
  font-size: var(--text-xs);
  color: rgba(49, 49, 49, 0.4);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.map-block .map-hood {
  position: relative;
  bottom: auto;
  left: auto;
  right: auto;
  margin: 12px;
  width: calc(100% - 24px);
}

/* ── Map Failure State ──
   Shown in place of a map the Google Maps API could not deliver — offline, blocked,
   or a key that is over quota or not authorised for this referrer. Without it the
   "Visa karta" click was invisible: the panel stayed the empty gradient and nothing
   told the reader a retry was worth trying.

   The alert itself is the design system component (`.alert.alert--danger` with
   `.alert__body` / `.alert__title` / `.alert__text`, see `wwwroot/assets/_alert.css`);
   this wrapper only centres it in the map area and caps its width. */
.map-fallback {
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  gap:             var(--s-3);
  height:          100%;
  min-height:      200px;
  padding:         var(--s-5);
  text-align:      center;
}

.map-fallback .alert {
  max-width:  42ch;
  text-align: left;
}

/* Inside the detail page's placeholder the alert sits above the trigger rather than
   filling a pane, so it must not claim the full height. */
.map-placeholder .map-fallback {
  height:     auto;
  min-height: 0;
  padding:    0;
}

/* The placeholder centres a single trigger on one row. Once a failure state is added
   above that trigger the two have to stack, and the fixed height has to give way so
   the alert cannot be clipped. */
.map-placeholder.is-failed {
  flex-direction: column;
  gap:            var(--s-3);
  height:         auto;
  min-height:     280px;
  padding:        var(--s-4);
}

