/* ==========================================================================
   PhotoSite – Map
   ========================================================================== */

/*
 * Den här filen ansvarar för:
 *
 * - kartsidans layout
 * - kartans storlek
 * - Leaflet-anpassningar
 * - bildmarkörer
 * - popup-innehåll
 *
 * Generella kort, färger, radier, skuggor och spacing hämtas från
 * PhotoSites befintliga komponenter och design tokens.
 */


/* ==========================================================================
   Kartsida
   ========================================================================== */

.map-page {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);

    padding-bottom: var(--page-padding-block);
}


/* ==========================================================================
   Sidhuvud
   ========================================================================== */

.map-page-header {
    gap: var(--space-4);
}

.map-page-heading {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);

    min-width: 0;
}

.map-page-heading h1,
.map-page-heading p,
.map-page-count {
    margin: 0;
}

.map-page-heading h1 {
    color: var(--color-text);

    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-tight);
}

.map-page-heading p,
.map-page-count {
    color: var(--color-text-muted);

    font-size: var(--font-size-sm);
    line-height: var(--line-height-base);
}

.map-page-count {
    flex: 0 0 auto;

    white-space: nowrap;
}


/* ==========================================================================
   Kartsökning
   ========================================================================== */

.map-search {
    position: relative;
    z-index: 20;

    width: min(100%, 28rem);
}

.map-search__control {
    display: flex;
    align-items: center;
    gap: var(--space-2);

    min-height: 2.65rem;
    padding-inline: var(--space-3);

    border: var(--border-soft);
    border-radius: var(--radius-md);

    background: var(--color-surface);
    color: var(--color-text-secondary);

    box-shadow: var(--shadow-soft);

    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast),
        background-color var(--transition-fast);
}

.map-search__control:focus-within {
    border-color: var(--color-focus);
    box-shadow: var(--shadow-focus);
}

.map-search__icon {
    flex: 0 0 auto;

    width: var(--icon-size-sm);
    height: var(--icon-size-sm);

    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
}

.map-search__input {
    width: 100%;
    min-width: 0;
    padding: 0;

    border: 0;
    outline: 0;

    background: transparent;
    color: var(--color-text);

    font: inherit;
}

.map-search__input::placeholder {
    color: var(--color-text-muted);
}

.map-search__results {
    position: absolute;
    z-index: var(--z-index-dropdown);
    top: calc(100% + var(--space-2));
    right: 0;
    left: 0;

    display: flex;
    flex-direction: column;
    gap: var(--space-1);

    max-height: 18rem;
    padding: var(--space-2);

    overflow-y: auto;

    border: var(--border-soft);
    border-radius: var(--radius-lg);

    background: var(--color-surface);
    box-shadow: var(--shadow-soft);
}

.map-search__results[hidden] {
    display: none;
}

.map-search__result {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);

    width: 100%;
    min-height: 2.5rem;
    padding: var(--space-2) var(--space-3);

    border: 0;
    border-radius: var(--radius-sm);

    background: transparent;
    color: var(--color-text);

    font: inherit;
    text-align: left;

    cursor: pointer;

    transition:
        background-color var(--transition-fast),
        color var(--transition-fast);
}

.map-search__result:hover,
.map-search__result:focus-visible {
    background: var(--color-surface-hover);
}

.map-search__result:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-ring-offset);
}

.map-search__result-label {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);

    min-width: 0;
}

.map-search__result-title {
    overflow: hidden;

    color: var(--color-text);

    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);

    text-overflow: ellipsis;
    white-space: nowrap;
}

.map-search__result-meta {
    color: var(--color-text-muted);

    font-size: var(--font-size-xs);
}

.map-search__result-count {
    flex: 0 0 auto;

    color: var(--color-text-muted);

    font-size: var(--font-size-xs);
    white-space: nowrap;
}

.map-search__empty {
    margin: 0;
    padding: var(--space-3);

    color: var(--color-text-muted);

    font-size: var(--font-size-sm);
}


/* ==========================================================================
   Kartkort
   ========================================================================== */

.map-card {
    min-height: 0;
}


/* ==========================================================================
   Huvudkarta
   ========================================================================== */

.gallery-map {
    width: 100%;
    height: clamp(28rem, 72vh, 52rem);
    min-height: 0;

    background: var(--color-surface-muted);
}

.gallery-map img {
    max-width: none;
    border-radius: 0;
}


/* ==========================================================================
   Leaflet lagerordning
   ========================================================================== */

/*
 * Leaflet använder egna z-index-värden.
 * Dessa ska ligga under PhotoSites meny och andra globala overlays.
 */

.gallery-map .leaflet-pane {
    z-index: 1;
}

.gallery-map .leaflet-top,
.gallery-map .leaflet-bottom {
    z-index: 10;
}


/* ==========================================================================
   Leaflet kontroller
   ========================================================================== */

.gallery-map .leaflet-control {
    border: 0;
    border-radius: var(--radius-md);

    box-shadow: var(--shadow-soft);
}

.gallery-map .leaflet-control-zoom a {
    background: var(--color-surface);
    color: var(--color-text-secondary);

    border-color: var(--color-border-soft);

    transition:
        background-color var(--transition-fast),
        color var(--transition-fast);
}

.gallery-map .leaflet-control-zoom a:hover,
.gallery-map .leaflet-control-zoom a:focus-visible {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.gallery-map .leaflet-control-attribution {
    background: var(--color-surface);
    color: var(--color-text-muted);

    font-size: var(--font-size-xs);
}

.gallery-map .leaflet-control-attribution a {
    color: var(--color-text-secondary);
}


/* ==========================================================================
   Bildmarkörer
   ========================================================================== */

.photo-marker {
    border: 0;
    background: transparent;
}

.photo-marker-thumb {
    width: 38px;
    height: 38px;

    overflow: hidden;

    border:
        3px
        solid
        var(--color-text-inverse);
    border-radius: var(--radius-circle);

    background: var(--color-surface);

    box-shadow: var(--shadow-marker);

    transition:
        transform var(--transition-fast),
        box-shadow var(--transition-fast);
}

.photo-marker-thumb img {
    display: block;

    width: 100%;
    height: 100%;

    object-fit: cover;
    border-radius: 0;
}

.photo-marker-thumb:hover {
    transform: scale(1.15);
    box-shadow: var(--shadow-marker-hover);
}


/* ==========================================================================
   Marker clusters
   ========================================================================== */

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
    background: var(--color-overlay-soft);
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
    background: var(--color-surface);
    color: var(--color-text);

    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);

    box-shadow: var(--shadow-soft);
}


/* ==========================================================================
   Leaflet-popup
   ========================================================================== */

.leaflet-popup-content-wrapper {
    padding: 0;
    overflow: hidden;

    border: var(--border-soft);
    border-radius: var(--radius-lg);

    background: var(--color-surface);
    color: var(--color-text);

    box-shadow: var(--shadow-soft);
}

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

.leaflet-popup-tip {
    background: var(--color-surface);
}

.leaflet-popup-close-button {
    color: var(--color-text-secondary) !important;
}

.leaflet-popup-close-button:hover,
.leaflet-popup-close-button:focus-visible {
    color: var(--color-text) !important;
}


/* ==========================================================================
   Popupens innehåll
   ========================================================================== */

.map-popup {
    display: block;

    color: inherit;
    text-decoration: none;
}

.map-popup-image {
    display: block;

    width: 100%;
    height: 160px;

    object-fit: cover;
    border-radius: 0;

    background: var(--color-surface-muted);
}

.map-popup-content {
    padding:
        var(--space-3)
        var(--space-4)
        var(--space-4);
}

.map-popup-location {
    margin: 0;

    color: var(--color-text);

    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-tight);
}

.map-popup-date {
    margin-top: var(--space-1);

    color: var(--color-text-secondary);

    font-size: var(--font-size-sm);
    line-height: var(--line-height-base);
}

.map-popup-action {
    display: flex;
    align-items: center;
    justify-content: space-between;

    margin-top: var(--space-3);

    color: var(--color-text-secondary);

    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
}

.map-popup:hover .map-popup-action {
    color: var(--color-text);
    text-decoration: underline;
}


/* ==========================================================================
   Fokus och tangentbordsnavigering
   ========================================================================== */

.map-popup:focus-visible {
    outline: var(--focus-ring);
    outline-offset: calc(-1 * var(--focus-ring-width));
}


/* ==========================================================================
   Tablet
   ========================================================================== */

@media (max-width: 900px) {
    .gallery-map {
        height: 70dvh;
        min-height: 26rem;
    }
}


/* ==========================================================================
   Kompakt layout
   ========================================================================== */

@media (max-width: 700px) {
    .map-page-header {
        align-items: flex-start;
        flex-direction: column;
        gap: var(--space-2);
    }

    .gallery-map {
        height: 68dvh;
        min-height: 24rem;
    }

    .map-page-count {
        white-space: normal;
    }
}


/* ==========================================================================
   Mobil
   ========================================================================== */

@media (max-width: 560px) {
    .map-page {
        padding-inline: var(--page-padding-inline-mobile);
    }

    .gallery-map {
        height: 65dvh;
        min-height: 22rem;
    }

    .leaflet-popup-content {
        width: 220px !important;
    }

    .map-popup-image {
        height: 145px;
    }

    .photo-marker-thumb {
        width: 34px;
        height: 34px;
    }
}


/* ==========================================================================
   Minskad rörelse
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .photo-marker-thumb,
    .gallery-map .leaflet-control-zoom a {
        transition: none;
    }

    .photo-marker-thumb:hover {
        transform: none;
    }
}