﻿:root {
    --ws-map-blue: #2563eb;
    --ws-map-blue-soft: rgba(37, 99, 235, 0.18);
    --ws-map-red: #dc2626;
    --ws-map-red-soft: rgba(220, 38, 38, 0.18);
    --ws-map-green: #22c55e;
    --ws-map-bg: rgba(15, 23, 42, 0.96);
    --ws-map-text: #f8fafc;
    --ws-map-muted: #94a3b8;
    --ws-map-border: rgba(255, 255, 255, 0.1);
    --ws-map-shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.42);
    --ws-map-shadow-md: 0 14px 30px rgba(15, 23, 42, 0.32);
}

/* Page */

.ws-building-marker {
    background: transparent;
    border: 0;
}

.ws-marker-building-img {
    width: 27px;
    height: 27px;
    object-fit: contain;
    display: block;
}

.ws-map-popup-building-img {
    width: 25px;
    height: 25px;
    object-fit: contain;
    display: block;
}

/* Manufacturer marker colors */
.ws-marker-istobal .ws-marker-icon,
.ws-marker-istobal .ws-marker-point,
.ws-map-popup-icon.ws-marker-istobal,
.ws-map-popup-pill.ws-marker-istobal {
    background: linear-gradient(135deg, #ef4444, #b91c1c);
}

.ws-marker-washtec .ws-marker-icon,
.ws-marker-washtec .ws-marker-point,
.ws-map-popup-icon.ws-marker-washtec,
.ws-map-popup-pill.ws-marker-washtec {
    background: linear-gradient(135deg, #0f2a5f, #071a3f);
}

.ws-marker-unknown .ws-marker-icon,
.ws-marker-unknown .ws-marker-point,
.ws-map-popup-icon.ws-marker-unknown,
.ws-map-popup-pill.ws-marker-unknown {
    background: linear-gradient(135deg, #64748b, #334155);
}


.ws-map-page {
    height: calc(100dvh - 78px);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    box-sizing: border-box;
}

.ws-map-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.ws-map-heading {
    min-width: 0;
}

.ws-map-label {
    margin-bottom: 0.35rem;
    color: #60a5fa;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.ws-map-title {
    margin: 0;
    color: var(--ws-map-text);
    font-size: clamp(1.5rem, 3vw, 2.15rem);
    font-weight: 850;
    line-height: 1.05;
    letter-spacing: -0.035em;
}

.ws-map-header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.ws-map-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.9rem;
    border: 1px solid rgba(96, 165, 250, 0.28);
    border-radius: 999px;
    background: linear-gradient( 135deg, rgba(59, 130, 246, 0.18), rgba(14, 165, 233, 0.08) );
    color: #bfdbfe;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

.ws-map-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--ws-map-green);
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.14), 0 0 12px rgba(34, 197, 94, 0.8);
}

/* Loading / empty */

.ws-map-loading,
.ws-map-empty {
    flex: 1;
    min-height: 320px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--ws-map-border);
    border-radius: 24px;
    background: rgba(15, 23, 42, 0.45);
    color: var(--ws-map-muted);
    font-size: 0.95rem;
    font-weight: 700;
}

/* Map shell */

.ws-map-card {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--ws-map-border);
    border-radius: 24px;
    background: rgba(15, 23, 42, 0.35);
    box-shadow: var(--ws-map-shadow-lg);
}

.ws-map-container,
#mapContainer {
    width: 100%;
    height: 100%;
    min-height: 320px;
    border-radius: inherit;
}

    #mapContainer.leaflet-container,
    .ws-map-container.leaflet-container {
        font-family: Roboto, Arial, sans-serif;
        background: #dbeafe;
        outline: none;
    }

    /*
    Do not override Leaflet panes.
    No .leaflet-pane z-index rules.
    No .leaflet-marker-pane z-index rules.
*/

    /* Compact logo pin */

    #mapContainer .ws-map-pin-icon {
        background: transparent !important;
        border: 0 !important;
    }

    #mapContainer .ws-map-pin {
        position: relative;
        width: 42px;
        height: 52px;
        cursor: pointer;
        user-select: none;
        pointer-events: auto;
    }

    /*
    Exact anchor:
    JS iconSize: [42, 52]
    JS iconAnchor: [21, 52]
    Therefore the GPS point is the bottom-center of this marker.
*/

    #mapContainer .ws-map-pin-logo {
        position: absolute;
        top: 0;
        left: 50%;
        z-index: 3;
        width: 38px;
        height: 38px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 6px;
        box-sizing: border-box;
        overflow: hidden;
        border: 2px solid var(--ws-map-blue);
        border-radius: 999px;
        background: #ffffff;
        box-shadow: 0 8px 18px rgba(15, 23, 42, 0.28), 0 0 0 4px var(--ws-map-blue-soft);
        transform: translateX(-50%);
        transition: transform 140ms ease, filter 140ms ease;
    }

    #mapContainer .ws-map-pin:hover .ws-map-pin-logo {
        transform: translateX(-50%) translateY(-2px);
        filter: brightness(1.04);
    }

    #mapContainer .ws-map-pin-logo img {
        display: block;
        max-width: 100%;
        max-height: 100%;
        width: auto;
        height: auto;
        object-fit: contain;
        pointer-events: none;
        user-select: none;
    }

    /* Actual GPS point */

    #mapContainer .ws-map-pin-tip {
        position: absolute;
        left: 50%;
        bottom: 0;
        z-index: 2;
        width: 12px;
        height: 12px;
        border: 3px solid #ffffff;
        border-radius: 999px;
        background: var(--ws-map-blue);
        box-shadow: 0 6px 14px rgba(15, 23, 42, 0.35), 0 0 0 4px var(--ws-map-blue-soft);
        box-sizing: border-box;
        transform: translateX(-50%);
    }

        /* Small connector line */

        #mapContainer .ws-map-pin-tip::before {
            content: "";
            position: absolute;
            left: 50%;
            bottom: 8px;
            width: 3px;
            height: 10px;
            border-radius: 999px;
            background: var(--ws-map-blue);
            transform: translateX(-50%);
        }

    /* Manufacturer logo tuning */

    #mapContainer .ws-map-pin-istobal .ws-map-pin-logo img {
        max-width: 82%;
        max-height: 82%;
    }

    #mapContainer .ws-map-pin-washtec .ws-map-pin-logo img {
        max-width: 92%;
        max-height: 92%;
    }

    #mapContainer .ws-map-pin-unknown .ws-map-pin-logo img {
        max-width: 78%;
        max-height: 78%;
    }

    /* Alarm state */

    #mapContainer .ws-map-pin.has-alarm .ws-map-pin-logo {
        border-color: var(--ws-map-red);
        box-shadow: 0 8px 18px rgba(15, 23, 42, 0.28), 0 0 0 4px var(--ws-map-red-soft);
    }

    #mapContainer .ws-map-pin.has-alarm .ws-map-pin-tip {
        background: var(--ws-map-red);
        box-shadow: 0 6px 14px rgba(15, 23, 42, 0.35), 0 0 0 4px var(--ws-map-red-soft);
    }

        #mapContainer .ws-map-pin.has-alarm .ws-map-pin-tip::before {
            background: var(--ws-map-red);
        }

    #mapContainer .ws-map-pin-alarm {
        position: absolute;
        top: -7px;
        right: -4px;
        z-index: 5;
        min-width: 20px;
        height: 20px;
        padding: 0 5px;
        border: 2px solid #ffffff;
        border-radius: 999px;
        background: linear-gradient(180deg, #ef4444, #b91c1c);
        color: #ffffff;
        font-size: 11px;
        font-weight: 900;
        line-height: 16px;
        text-align: center;
        box-sizing: border-box;
    }

    /* Popup */

    #mapContainer .leaflet-popup-content-wrapper {
        overflow: hidden;
        border-radius: 18px;
        background: var(--ws-map-bg);
        color: var(--ws-map-text);
        box-shadow: var(--ws-map-shadow-md);
        backdrop-filter: blur(18px);
    }

    #mapContainer .leaflet-popup-content {
        margin: 0;
        min-width: 230px;
        max-width: 280px;
    }

    #mapContainer .leaflet-popup-tip {
        background: var(--ws-map-bg);
    }

    #mapContainer a.leaflet-popup-close-button {
        top: 8px;
        right: 8px;
        width: 26px;
        height: 26px;
        color: #cbd5e1;
        font-size: 18px;
        line-height: 24px;
    }

        #mapContainer a.leaflet-popup-close-button:hover {
            color: #ffffff;
        }

    #mapContainer .ws-map-popup {
        padding: 0.9rem;
    }

    #mapContainer .ws-map-popup-title {
        margin-bottom: 0.55rem;
        padding-right: 1.5rem;
        color: #f8fafc;
        font-size: 0.95rem;
        font-weight: 900;
    }

    #mapContainer .ws-map-popup-text {
        color: var(--ws-map-muted);
        font-size: 0.86rem;
        line-height: 1.45;
        word-break: break-word;
    }

    #mapContainer .ws-map-popup-alarm {
        margin-top: 0.65rem;
        padding: 0.55rem 0.65rem;
        border: 1px solid rgba(239, 68, 68, 0.22);
        border-radius: 12px;
        background: rgba(239, 68, 68, 0.13);
        color: #fecaca;
        font-size: 0.84rem;
        font-weight: 800;
    }

    #mapContainer .ws-map-popup-actions {
        display: flex;
        gap: 0.5rem;
        margin-top: 0.8rem;
    }

    #mapContainer .ws-map-popup-button {
        flex: 1;
        appearance: none;
        cursor: pointer;
        border: 1px solid rgba(255, 255, 255, 0.12);
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.08);
        color: #e2e8f0;
        font-family: inherit;
        font-size: 0.84rem;
        font-weight: 750;
        line-height: 1.2;
        padding: 0.55rem 0.7rem;
        white-space: nowrap;
    }

        #mapContainer .ws-map-popup-button:hover {
            background: rgba(255, 255, 255, 0.13);
        }

        #mapContainer .ws-map-popup-button.primary {
            border-color: rgba(59, 130, 246, 0.42);
            background: linear-gradient(135deg, #2563eb, #0ea5e9);
            color: #ffffff;
        }

            #mapContainer .ws-map-popup-button.primary:hover {
                background: linear-gradient(135deg, #1d4ed8, #0284c7);
            }

    /* Leaflet controls */

    #mapContainer .leaflet-control-zoom,
    #mapContainer .leaflet-control-fullscreen {
        overflow: hidden;
        border: 0 !important;
        border-radius: 12px;
        box-shadow: var(--ws-map-shadow-md);
    }

        #mapContainer .leaflet-control-zoom a,
        #mapContainer .leaflet-control-fullscreen a {
            border: 0 !important;
            background: rgba(15, 23, 42, 0.92) !important;
            color: #f8fafc !important;
        }

            #mapContainer .leaflet-control-zoom a:hover,
            #mapContainer .leaflet-control-fullscreen a:hover {
                background: rgba(30, 41, 59, 0.96) !important;
            }

    #mapContainer .leaflet-control-attribution {
        max-width: calc(100% - 16px);
        padding: 3px 8px !important;
        border-radius: 8px 0 0 0;
        background: rgba(255, 255, 255, 0.94) !important;
        color: #0f172a !important;
        font-size: 11px !important;
        font-weight: 600;
    }

        #mapContainer .leaflet-control-attribution a {
            color: #1d4ed8 !important;
            font-weight: 700;
            text-decoration: none;
        }

/* Mobile */

@media (max-width: 600px) {
    .ws-map-page {
        height: calc(100dvh - 72px);
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .ws-map-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .ws-map-header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .ws-map-card {
        border-radius: 18px;
    }

    #mapContainer .leaflet-popup-content {
        min-width: 220px;
        max-width: 240px;
    }

    #mapContainer .ws-map-popup-actions {
        flex-direction: column;
    }

    #mapContainer .ws-map-popup-button {
        width: 100%;
    }
}
