/* =========================================================
   TownConnect Category Map
   ========================================================= */

#townconnect-category-map,
.townconnect-category-map {
    width: 100vw;
    position: relative;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
    text-align: center;
    min-height: 500px;
    overflow: hidden;
    background: #f3f7f7;
}

/* =========================================================
   Shared Leaflet Control Basics
   ========================================================= */

.townconnect-map-location-control,
.townconnect-map-filter-control,
.townconnect-map-collapsible-control {
    width: auto;
    min-width: 0;
    max-width: none;
    background: transparent;
    box-shadow: none;
    padding: 0;
    font-family: inherit;
}

.townconnect-map-collapsible-control {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

/* =========================================================
   Small Icon Toggle Buttons
   ========================================================= */

.townconnect-map-control-toggle {
    appearance: none;
    width: 46px;
    min-width: 46px;
    max-width: 46px;
    height: 46px;
    padding: 0;
    flex: 0 0 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 5px;
    background: #ffffff;
    color: #2b3135;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.14);
    cursor: pointer;
    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease,
        background 0.18s ease,
        color 0.18s ease;
}

.townconnect-map-control-toggle:hover,
.townconnect-map-control-toggle:focus {
    outline: none;
    transform: translateY(-1px);
    background: #ffffff;
    color: #0f6b73;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.18);
}

.townconnect-map-control-toggle:active {
    transform: translateY(0);
}

.townconnect-map-control-icon {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.townconnect-map-control-icon svg {
    width: 24px;
    height: 24px;
    display: block;
}

.townconnect-map-control-icon svg circle,
.townconnect-map-control-icon svg path {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* =========================================================
   Location Control - 3 Step Behaviour

   Step 1: Icon only
   Step 2: Hover/click shows "SHOW MY LOCATION"
   Step 3: After location is active, show settings panel
   ========================================================= */

.townconnect-map-location-control {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.townconnect-map-location-content {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

/* Step 2 preview button */

.townconnect-map-location-preview {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 0 18px;
    border: 0;
    border-radius: 5px;
    background: #ffffff;
    color: #2f3133;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
    font-size: 12px;
    line-height: 1;
    font-weight: 800;
    letter-spacing: 0.04em;
    white-space: nowrap;
    cursor: pointer;

    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-8px) scale(0.98);
    transition:
        opacity 0.18s ease,
        transform 0.18s ease,
        visibility 0.18s ease,
        background 0.18s ease,
        color 0.18s ease;
}

.townconnect-map-location-control:not(.is-location-active):hover .townconnect-map-location-preview,
.townconnect-map-location-control:not(.is-location-active):focus-within .townconnect-map-location-preview,
.townconnect-map-location-control.is-peek-pinned:not(.is-location-active) .townconnect-map-location-preview {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0) scale(1);
}

.townconnect-map-location-preview:hover,
.townconnect-map-location-preview:focus {
    outline: none;
    background: #ffffff;
    color: #0f6b73;
}

/* Hide preview when location is active */

.townconnect-map-location-control.is-location-active .townconnect-map-location-preview {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Important: before location is active, the settings panel must not take space */

.townconnect-map-location-control:not(.is-location-active) .townconnect-map-control-panel {
    display: none;
}

/* Full location settings panel */

.townconnect-map-location-control .townconnect-map-control-panel {
    min-width: 210px;
    max-width: min(280px, calc(100vw - 36px));
    background: #ffffff;
    border: 1px solid rgba(15, 107, 115, 0.14);
    border-radius: 5px;
    padding: 14px;
    box-shadow: 0 14px 38px rgba(0, 0, 0, 0.16);

    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-6px) scale(0.98);
    transform-origin: top left;
    transition:
        opacity 0.18s ease,
        transform 0.18s ease,
        visibility 0.18s ease;
}

/* Show full panel only when location is active and panel is open */

.townconnect-map-location-control.is-location-active.is-open .townconnect-map-control-panel {
    display: block;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* Location panel buttons */

.townconnect-map-control-panel .townconnect-map-location-button {
    appearance: none;
    width: 100%;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 0 10px;
    border: 0;
    border-radius: 0;
    padding: 12px 14px;
    background: #0f6b73;
    color: #ffffff;
    font-size: 15px;
    line-height: 1.2;
    font-weight: 400;
    cursor: pointer;
    transition:
        background 0.18s ease,
        color 0.18s ease,
        opacity 0.18s ease;
}

.townconnect-map-control-panel .townconnect-map-location-button:hover,
.townconnect-map-control-panel .townconnect-map-location-button:focus {
    background: #0b555b;
    outline: none;
}

.townconnect-map-control-panel .townconnect-map-location-button:disabled {
    opacity: 0.65;
    cursor: wait;
}

.townconnect-map-control-panel .townconnect-map-location-button--reset {
    background: #d8dddf;
    color: #243338;
}

.townconnect-map-control-panel .townconnect-map-location-button--reset:hover,
.townconnect-map-control-panel .townconnect-map-location-button--reset:focus {
    background: #c9d1d4;
    color: #1c2a2e;
}

.townconnect-map-control-panel .townconnect-map-location-button--load-more {
    margin-bottom: 0;
    background: #123d4b;
}

.townconnect-map-control-panel .townconnect-map-location-button--load-more:hover,
.townconnect-map-control-panel .townconnect-map-location-button--load-more:focus {
    background: #0e303a;
}

/* Radius only visible when location is active */

.townconnect-map-location-control .townconnect-map-radius-wrap {
    display: none;
    gap: 6px;
    margin: 2px 0 12px;
}

.townconnect-map-location-control.is-location-active .townconnect-map-radius-wrap {
    display: grid;
}

.townconnect-map-radius-label {
    text-align: center;
    font-size: 16px;
    font-weight: 400;
    color: #506167;
}

.townconnect-map-radius-select {
    width: 100%;
    border: 1px solid rgba(15, 107, 115, 0.22);
    border-radius: 12px;
    padding: 11px 12px;
    background: #ffffff;
    color: #243338;
    font-size: 15px;
    text-align: center;
}

/* If location control is on the right, open inward */

.leaflet-right .townconnect-map-location-control {
    flex-direction: row-reverse;
}

.leaflet-right .townconnect-map-location-control .townconnect-map-control-panel {
    transform-origin: top right;
}

.leaflet-right .townconnect-map-location-control .townconnect-map-location-preview {
    transform: translateX(8px) scale(0.98);
}

.leaflet-right .townconnect-map-location-control:not(.is-location-active):hover .townconnect-map-location-preview,
.leaflet-right .townconnect-map-location-control:not(.is-location-active):focus-within .townconnect-map-location-preview,
.leaflet-right .townconnect-map-location-control.is-peek-pinned:not(.is-location-active) .townconnect-map-location-preview {
    transform: translateX(0) scale(1);
}

/* =========================================================
   Filter Control
   ========================================================= */

.townconnect-map-filter-control {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.townconnect-map-filter-control .townconnect-map-control-panel {
    min-width: 210px;
    max-width: min(280px, calc(100vw - 36px));
    max-height: calc(100vh - 180px);
    overflow-y: auto;
    background: #ffffff;
    border: 1px solid rgba(15, 107, 115, 0.14);
    border-radius: 5px;
    padding: 12px;
    box-shadow: 0 14px 38px rgba(0, 0, 0, 0.16);

    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-6px) scale(0.98);
    transform-origin: top right;
    transition:
        opacity 0.18s ease,
        transform 0.18s ease,
        visibility 0.18s ease;
}

.townconnect-map-filter-control.is-open .townconnect-map-control-panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.townconnect-map-filter-title {
    text-align: left;
    margin: 0 0 10px 0;
    font-size: 14px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 1px;
    color: #12343b;
}

.townconnect-map-filter-option {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 7px 4px;
    color: #12343b;
    font-size: 13px;
    line-height: 1.3;
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.townconnect-map-filter-option input {
    width: 16px !important;
    height: 16px;
    margin: 0 10px 0 0 !important;
    accent-color: #0f6b73;
}

.townconnect-map-filter-option span {
    flex: 1;
}

/* =========================================================
   User Location Marker
   ========================================================= */

.townconnect-user-location-icon span {
    display: block;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #1c8cff;
    border: 3px solid #ffffff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

/* =========================================================
   Temporary Map Messages
   ========================================================= */

.townconnect-map-location-message {
    position: absolute;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    z-index: 1000;
    max-width: calc(100% - 32px);
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(23, 63, 70, 0.92);
    color: #ffffff;
    font-size: 13px;
    font-weight: 700;
    pointer-events: none;
}

/* =========================================================
   Popup Details
   ========================================================= */

.townconnect-popup-distance {
    display: inline-block;
    margin: 3px 0 1px;
    color: #0f6b73;
    font-weight: 700;
}

.townconnect-popup-help {
    display: inline-block;
    max-width: 210px;
    color: #4f6670;
    font-size: 12px;
    line-height: 1.35;
}

/* =========================================================
   Mobile
   ========================================================= */

@media (max-width: 640px) {
    #townconnect-category-map,
    .townconnect-category-map {
        min-height: 360px;
        border-radius: 16px;
    }

    .townconnect-map-control-toggle {
        width: 42px;
        min-width: 42px;
        max-width: 42px;
        height: 42px;
        flex-basis: 42px;
    }

    .townconnect-map-control-icon,
    .townconnect-map-control-icon svg {
        width: 22px;
        height: 22px;
    }

    .townconnect-map-location-preview {
        min-height: 42px;
        padding: 0 14px;
        font-size: 11px;
    }

    .townconnect-map-location-control .townconnect-map-control-panel,
    .townconnect-map-filter-control .townconnect-map-control-panel {
        min-width: 200px;
        max-width: calc(100vw - 28px);
        padding: 12px;
        border-radius: 5px;
    }

    .townconnect-map-filter-control .townconnect-map-control-panel {
        max-height: 280px;
    }

    .townconnect-map-control-panel .townconnect-map-location-button {
        padding: 10px 12px;
        font-size: 13px;
    }
}