/* ECRN Members Map — Frontend Styles */

.ecrn-members-map {
    width: 100%;
    background: transparent;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    z-index: 0;
}

/* Wrapper layout */
.ecrn-map-wrapper {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
}

.ecrn-map-canvas {
    flex: 1;
    min-width: 0;
    height: 100%;
}

.ecrn-members-map .leaflet-container {
    touch-action: none !important;
}

/* Override Leaflet default background */
.ecrn-map-canvas .leaflet-container,
.ecrn-members-map .leaflet-container {
    background: transparent !important;
}

.ecrn-members-map .leaflet-top,
.ecrn-members-map .leaflet-bottom {
    z-index: 800;
}

.ecrn-members-map .leaflet-control {
    z-index: 800;
}

/* ── Popup ── */
.ecrn-popup {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    display: inline-block;
    max-width: min(var(--ecrn-popup-max-width, 360px), calc(100vw - 96px));
    max-height: min(420px, calc(100vh - 140px));
    overflow-y: auto;
    overflow-x: visible;
}

.ecrn-popup-header {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 2px solid #E0E0E0;
}

.ecrn-popup-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.ecrn-popup-scrollable {
    padding-right: 0;
}

.ecrn-popup-item {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    width: max-content;
    max-width: 100%;
}

.ecrn-popup-image-frame {
    display: flex;
    flex-shrink: 0;
    height: 50px;
    max-width: 25%;
}

.ecrn-popup-image {
    width: auto;
    height: 100%;
    border-radius: 6px;
    object-fit: contain;
    border: 1px solid #E0E0E0;
}

.ecrn-popup-info {
    flex: 1;
    min-width: 0;
    max-width: 100%;
}

.ecrn-popup-name {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.3;
    overflow-wrap: break-word;
}

.ecrn-popup-name a {
    text-decoration: none;
}

.ecrn-popup-name a:hover {
    text-decoration: underline;
}

.ecrn-popup-type {
    display: inline-block;
    box-sizing: border-box;
    max-width: 100%;
    font-size: 11px;
    padding: 2px 10px;
    border-radius: 10px;
    margin-top: 4px;
    font-weight: 500;
    white-space: nowrap;
}

.ecrn-popup-type--member_region {
    background: #E3F2FD;
    color: #0D47A1;
}

.ecrn-popup-type--affiliated_member {
    background: #E8F5E9;
    color: #2E7D32;
}

/* Counter badge */
.ecrn-marker-count {
    background: none !important;
    border: none !important;
}

.ecrn-marker-count span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: #0D47A1;
    color: #fff;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Leaflet popup overrides */
.ecrn-members-map .leaflet-popup-content-wrapper {
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
}

.ecrn-members-map .leaflet-popup-content {
    margin: 16px 12px;
    width: auto !important;
    max-width: min(var(--ecrn-popup-max-width, 360px), calc(100vw - 96px));
    overflow-x: visible;
    overflow-y: visible;
}

/* ── Sidebar ── */
.ecrn-sidebar {
    height: 100%;
    overflow-y: auto;
    flex-shrink: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

.ecrn-sidebar::-webkit-scrollbar {
    width: 4px;
}

.ecrn-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.ecrn-sidebar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

.ecrn-sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.ecrn-sidebar-inner {
    padding: 20px;
}

.ecrn-sidebar-section {
    margin-bottom: 24px;
}

.ecrn-sidebar-section:last-child {
    margin-bottom: 0;
}

.ecrn-sidebar-heading {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 12px 0;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ecrn-sidebar-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    background: #E3F2FD;
    color: #0D47A1;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
}

.ecrn-sidebar-list {
    list-style: none;
    margin: 0 !important;
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ecrn-sidebar-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.ecrn-sidebar-item:hover,
.ecrn-sidebar-item:focus-visible {
    background: rgba(0, 0, 0, 0.04);
    outline: 2px solid currentColor;
    outline-offset: -2px;
}

.ecrn-sidebar-image {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.ecrn-sidebar-info {
    flex: 1;
    min-width: 0;
}

.ecrn-sidebar-name {
    font-weight: 600;
    font-size: 14px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ecrn-sidebar-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    transition: background 0.15s;
    text-decoration: none;
}

.ecrn-sidebar-arrow:hover {
    background: rgba(0, 0, 0, 0.06);
}

/* Sidebar toggle button (mobile) */
.ecrn-sidebar-toggle {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: none;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #333;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .ecrn-map-wrapper.ecrn-has-sidebar {
        flex-direction: column;
    }

    .ecrn-has-sidebar .ecrn-map-canvas {
        height: 60%;
    }

    .ecrn-sidebar {
        width: 100% !important;
        height: 40%;
        border-left: none;
        border-top: 1px solid #E0E0E0;
    }

    /* Alternative: overlay sidebar on mobile */
    .ecrn-has-sidebar .ecrn-sidebar-toggle {
        display: flex;
    }

    .ecrn-has-sidebar .ecrn-sidebar {
        position: absolute;
        top: 0;
        right: 0;
        height: 100%;
        width: 85% !important;
        max-width: 360px;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        z-index: 999;
        box-shadow: -4px 0 16px rgba(0, 0, 0, 0.15);
        border-top: none;
        background: #fff;
    }

    .ecrn-has-sidebar .ecrn-map-canvas {
        height: 100%;
    }

    .ecrn-sidebar-open .ecrn-sidebar {
        transform: translateX(0);
    }

    .ecrn-members-map .leaflet-popup {
        max-width: calc(100vw - 56px) !important;
    }

    .ecrn-members-map .leaflet-popup-content-wrapper {
        max-width: calc(100vw - 72px) !important;
    }

    .ecrn-members-map .leaflet-popup-content {
        margin: 12px;
        max-width: min(var(--ecrn-popup-max-width, 360px), 300px, calc(100vw - 96px));
    }

    .ecrn-popup {
        max-width: min(var(--ecrn-popup-max-width, 360px), 300px, calc(100vw - 96px));
        max-height: min(320px, calc(100vh - 120px));
    }

    .ecrn-popup-item {
        gap: 10px;
    }
}
