/**
 * KASA ESPANA — property maps: the search map view (/search) and the
 * "objektai žemėlapyje" section on the homepage. Both pages link this file.
 *
 * Hand-written on purpose: Tailwind is compiled on the developer's machine only,
 * so classes that are not already in app.css do nothing. Everything here is
 * either impossible in the compiled build (map height, price pin, line clamp)
 * or has to outrank leaflet.css.
 *
 * Load order: app.css -> leaflet.css -> this file.
 * Every rule touching a .leaflet-* class is scoped with .km-map so it wins on
 * specificity too, not just on order.
 *
 * Colours match the Tailwind theme: accent #e2ab2c, primary #233039,
 * night-card #1b262e, gray-300 #9ca3af.
 */

/* ---------- Map container ---------- */
.km-map {
    height: 420px;
}

@media (min-width: 1024px) {
    .km-map {
        height: calc(100vh - 13rem);
        min-height: 480px;
        max-height: 760px;
    }
}

/* Homepage variant. On /search the map IS the page, so it takes the viewport;
   on the homepage it is one section among many and keeps a fixed height.
   Both selectors weigh (0,1,0) and media queries add no specificity, so this
   wins on source order alone — it has to stay below the .km-map rules above.
   min/max-height are reset explicitly, because the lg rule above sets them and
   would otherwise stretch the section back to 760px. */
.km-map--home {
    height: 420px;
}

@media (min-width: 1024px) {
    .km-map--home {
        height: 560px;
        min-height: 0;
        max-height: none;
    }
}

/* ---------- Price pin ----------
   L.divIcon is created with iconSize:null, so Leaflet sets no width/height and
   no margins on the host. The host stays 0x0 at the exact coordinate and the
   inner <span> is offset from it — the transform must live on the child,
   because Leaflet writes translate3d() onto the host for positioning. */
.km-pin {
    width: 0;
    height: 0;
}

.km-pin > span {
    position: absolute;
    left: 0;
    top: 0;
    transform: translate(-50%, -100%);
    display: inline-block;
    white-space: nowrap;
    background: #e2ab2c;
    color: #233039;
    border: 2px solid #fff;
    border-radius: 9999px;
    padding: 3px 9px;
    font: 600 12px/1.2 "Open Sans", Arial, sans-serif;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
    transition: background-color .2s, color .2s;
}

.km-pin > span::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -6px;
    margin-left: -4px;
    border: 4px solid transparent;
    border-top-color: #fff;
}

.km-pin:hover > span,
.km-pin:focus > span {
    background: #233039;
    color: #fff;
}

.dark .km-pin > span {
    border-color: #1b262e;
}

.dark .km-pin > span::after {
    border-top-color: #1b262e;
}

/* ---------- Popup card ----------
   leaflet.css pads .leaflet-popup-content and rounds the wrapper; both have to
   go for an edge-to-edge photo. */
.km-map .leaflet-popup-content {
    margin: 0;
    width: 232px !important;
    line-height: 1.4;
}

.km-map .leaflet-popup-content-wrapper {
    padding: 0;
    border-radius: 1rem;
    overflow: hidden;
}

/* leaflet.css sets .leaflet-container a{color:#0078A8} at a higher specificity
   than any Tailwind text-* utility — without this every popup link is blue. */
.km-map .leaflet-popup-content a {
    color: inherit;
    text-decoration: none;
}

/* Leaflet's close button sits over the photo — give it contrast and a hit area.
   NOTE the compound selector: #search-map carries BOTH .km-map and
   .leaflet-container, so ".km-map .leaflet-container" (descendant) matches nothing. */
.km-map.leaflet-container a.leaflet-popup-close-button {
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    padding: 0;
    border-radius: 9999px;
    background: rgba(35, 48, 57, .6);
    color: #fff;
    font-size: 18px;
    line-height: 24px;
    text-align: center;
}

.km-map.leaflet-container a.leaflet-popup-close-button:hover {
    background: rgba(35, 48, 57, .85);
    color: #fff;
}

/* The base colour lives here on purpose: the rule above resets popup links to
   `inherit`, so anchors inside the card (title, CTA, photo) take this value
   rather than Leaflet's #333. */
.km-pop {
    position: relative;
    font-family: "Open Sans", Arial, sans-serif;
    color: #233039;
}

.km-pop__img {
    display: block;
    aspect-ratio: 4 / 3;
    overflow: hidden;
}

.km-pop__img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Top-LEFT, not top-right like the grid card: leaflet.css puts its own close
   button at top:0/right:0 as a later sibling, so a right-aligned heart would sit
   underneath it and lose part of its hit area. */
.km-pop__fav {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 9999px;
    background: rgba(35, 48, 57, .6);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color .2s;
}

.km-pop__fav:hover {
    background: rgba(35, 48, 57, .85);
}

.km-pop__body {
    padding: 12px 14px 14px;
}

.km-pop__price {
    display: block;
    font-family: "DM Serif Display", Georgia, serif;
    font-size: 18px;
    color: #e2ab2c;
    margin-bottom: 2px;
}

/* replaces the line-clamp-2 utility, which is not in the compiled build.
   Colour is inherited from .km-pop — see the note there. */
.km-pop__title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
}

.km-pop__meta {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: rgba(35, 48, 57, .6);
    margin-bottom: 10px;
}

.km-pop__cta {
    display: inline-block;
    background: #e2ab2c;
    color: #233039 !important;
    border-radius: .5rem;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    transition: background-color .2s;
}

.km-pop__cta:hover {
    background: #c9961f;
}

/* ---------- Dark mode ----------
   .dark is a class on <html>, so plain descendant selectors are enough
   (the compiled build has only dark:hidden and dark:inline). */
/* leaflet.css paints .leaflet-container #ddd behind the tiles; a filter on the
   tile pane cannot reach it, so it flashes light grey while tiles load. */
.dark .km-map {
    background: #1b262e;
}

.dark .km-map .leaflet-tile-pane {
    filter: brightness(.74) saturate(.85) contrast(1.06);
}

.dark .km-map .leaflet-popup-content-wrapper,
.dark .km-map .leaflet-popup-tip {
    background: #1b262e;
    color: #f3f4f6;
}

.dark .km-pop {
    color: #f3f4f6;
}

.dark .km-pop__meta {
    color: #9ca3af;
}

.dark .km-map.leaflet-container a.leaflet-popup-close-button {
    background: rgba(0, 0, 0, .45);
    color: #f3f4f6;
}

.dark .km-map .leaflet-control-zoom a {
    background: #1b262e;
    color: #f3f4f6;
    border-color: rgba(255, 255, 255, .15);
}

.dark .km-map .leaflet-control-attribution {
    background: rgba(27, 38, 46, .85);
    color: #9ca3af;
}

.dark .km-map .leaflet-control-attribution a {
    color: #e2ab2c;
}

/* ---------- Keyboard focus ----------
   The view radios are sr-only, so the visible pill has to carry the ring
   (focus-visible:ring-* is not in the compiled build). */
[data-view-switch] input:focus-visible + span {
    outline: 2px solid #e2ab2c;
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .km-pin > span,
    .km-pop__fav,
    .km-pop__cta {
        transition: none;
    }
}
