﻿/* =========================================================
   WASH SUPPORT — MAP PAGE

   MudBlazor theme-aware version.

   IMPORTANT:
   Do not detect dark mode with:
   .mud-theme-dark
   html.dark
   body.dark

   Instead, use MudBlazor's theme CSS variables directly.
   They automatically change when MudThemeProvider changes
   between light and dark mode.
   ========================================================= */


/* =========================================================
   THEME TOKENS
   ========================================================= */

.ws-map-page {
    /* Accent */
    --ws-map-blue: var(--mud-palette-primary);
    --ws-map-green: var(--mud-palette-success);
    --ws-map-red: var(--mud-palette-error);
    /* Surfaces */
    --ws-map-page-bg: var(--mud-palette-background);
    --ws-map-surface: var(--mud-palette-surface);
    --ws-map-surface-soft: var(--mud-palette-background-gray);
    /* Text */
    --ws-map-text: var(--mud-palette-text-primary);
    --ws-map-muted: var(--mud-palette-text-secondary);
    /* Borders */
    --ws-map-border: var(--mud-palette-lines-default);
    --ws-map-border-strong: var(--mud-palette-lines-inputs);
    /* Soft semantic backgrounds */
    --ws-map-blue-soft: color-mix( in srgb, var(--mud-palette-primary) 14%, transparent );
    --ws-map-green-soft: color-mix( in srgb, var(--mud-palette-success) 14%, transparent );
    --ws-map-red-soft: color-mix( in srgb, var(--mud-palette-error) 15%, transparent );
    --ws-map-warning-soft: color-mix( in srgb, var(--mud-palette-warning) 14%, transparent );
    /* Shadows */
    --ws-map-shadow-lg: 0 18px 46px rgba(0, 0, 0, 0.16);
    --ws-map-shadow-md: 0 10px 28px rgba(0, 0, 0, 0.18);
}


/* =========================================================
   PAGE
   ========================================================= */

.ws-map-page {
    display: flex;
    height: calc(100dvh - 78px);
    min-width: 0;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    box-sizing: border-box;
    background: var(--ws-map-page-bg);
    color: var(--ws-map-text);
    transition: background-color 180ms ease, color 180ms ease;
}


/* =========================================================
   HEADER
   ========================================================= */

.ws-map-header {
    display: flex;
    flex-shrink: 0;
    min-width: 0;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.25rem;
}


.ws-map-heading {
    min-width: 0;
}


.ws-map-label {
    margin-bottom: 0.35rem;
    color: var(--mud-palette-primary);
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1.4;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}


.ws-map-title {
    margin: 0;
    color: var(--ws-map-text);
    font-size: clamp( 1.75rem, 3vw, 2.35rem );
    font-weight: 850;
    line-height: 1.1;
    letter-spacing: -0.035em;
}


.ws-map-subtitle {
    max-width: 58ch;
    margin: 0.5rem 0 0;
    color: var(--ws-map-muted);
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.6;
}


/* =========================================================
   HEADER ACTIONS
   ========================================================= */

.ws-map-header-actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 0.75rem;
}


.ws-map-badge {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.85rem;
    border: 1px solid color-mix( in srgb, var(--mud-palette-primary) 30%, transparent );
    border-radius: 999px;
    background: var(--ws-map-blue-soft);
    color: var(--ws-map-text);
    font-size: 0.84rem;
    font-weight: 750;
    line-height: 1.2;
    white-space: nowrap;
}


.ws-map-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 999px;
    background: var(--mud-palette-success);
    box-shadow: 0 0 0 4px var(--ws-map-green-soft);
}


/* =========================================================
   LOADING / EMPTY
   ========================================================= */

.ws-map-loading,
.ws-map-empty {
    display: flex;
    min-height: 320px;
    flex: 1;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--ws-map-border);
    border-radius: 20px;
    background: var(--ws-map-surface);
    color: var(--ws-map-muted);
    box-shadow: var(--ws-map-shadow-lg);
    transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease;
}


.ws-map-state-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px;
    text-align: left;
}


    .ws-map-state-content > div {
        display: flex;
        flex-direction: column;
        gap: 3px;
    }


    .ws-map-state-content strong {
        color: var(--ws-map-text);
        font-size: 1rem;
        font-weight: 750;
        line-height: 1.35;
    }


    .ws-map-state-content span {
        color: var(--ws-map-muted);
        font-size: 0.875rem;
        line-height: 1.5;
    }


/* =========================================================
   MAP CARD
   ========================================================= */

.ws-map-card {
    min-width: 0;
    min-height: 0;
    flex: 1;
    overflow: hidden;
    border: 1px solid var(--ws-map-border);
    border-radius: 20px;
    background: var(--ws-map-surface);
    box-shadow: var(--ws-map-shadow-lg);
    transition: background-color 180ms ease, border-color 180ms ease;
}


.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;
        font-size: 14px;
        background: var(--ws-map-surface-soft);
        outline: none;
    }


/* =========================================================
   BUILDING MARKERS
   ========================================================= */

.ws-building-marker {
    border: 0;
    background: transparent;
}


.ws-marker-building-img {
    display: block;
    width: 27px;
    height: 27px;
    object-fit: contain;
}


.ws-map-popup-building-img {
    display: block;
    width: 25px;
    height: 25px;
    object-fit: contain;
}


/* =========================================================
   LEGACY MANUFACTURER 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 );
}


/* =========================================================
   LEAFLET DIV ICON
   ========================================================= */

#mapContainer .ws-map-pin-icon {
    border: 0 !important;
    background: transparent !important;
}


/* =========================================================
   MAP PIN
   ========================================================= */

#mapContainer .ws-map-pin {
    position: relative;
    width: 42px;
    height: 52px;
    cursor: pointer;
    user-select: none;
    pointer-events: auto;
}


/* =========================================================
   MARKER LOGO

   Stable horizontal position.

   We deliberately do NOT use:
   transform: translateX(-50%)

   because changing transform during hover can cause a small
   subpixel horizontal jump.
   ========================================================= */

#mapContainer .ws-map-pin-logo {
    position: absolute;
    top: 0;
    left: 50%;
    z-index: 3;
    display: flex;
    width: 38px;
    height: 38px;
    margin-left: -19px;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    overflow: hidden;
    padding: 6px;
    border: 2px solid var(--ws-map-blue);
    border-radius: 999px;
    /*
       Logos remain on white deliberately.
       Both manufacturer SVGs are considerably easier to
       recognize on a neutral white marker background.
    */
    background: #ffffff;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22), 0 0 0 4px var(--ws-map-blue-soft);
    transform: translateY(0);
    transition: transform 140ms ease, filter 140ms ease, box-shadow 140ms ease;
}


#mapContainer
.ws-map-pin:hover
.ws-map-pin-logo {
    /*
       Vertical only.
       Horizontal position never changes.
    */
    transform: translateY(-2px);
    filter: brightness(1.035);
}


/* =========================================================
   MARKER IMAGE
   ========================================================= */

#mapContainer
.ws-map-pin-logo
img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    pointer-events: none;
    user-select: none;
}


/* =========================================================
   MARKER GPS POINT
   ========================================================= */

#mapContainer .ws-map-pin-tip {
    position: absolute;
    left: 50%;
    bottom: 0;
    z-index: 2;
    width: 12px;
    height: 12px;
    margin-left: -6px;
    box-sizing: border-box;
    border: 3px solid #ffffff;
    border-radius: 999px;
    background: var(--ws-map-blue);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25), 0 0 0 4px var(--ws-map-blue-soft);
}


    /* =========================================================
   CONNECTOR
   ========================================================= */

    #mapContainer
    .ws-map-pin-tip::before {
        content: "";
        position: absolute;
        left: 50%;
        bottom: 8px;
        width: 3px;
        height: 10px;
        margin-left: -1.5px;
        border-radius: 999px;
        background: var(--ws-map-blue);
    }


/* =========================================================
   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%;
}


/* =========================================================
   ACTIVE ALARM MARKER
   ========================================================= */

#mapContainer
.ws-map-pin.has-alarm
.ws-map-pin-logo {
    border-color: var(--ws-map-red);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22), 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(0, 0, 0, 0.25), 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);
    }


/* =========================================================
   ALARM COUNT BADGE
   ========================================================= */

#mapContainer .ws-map-pin-alarm {
    position: absolute;
    top: -7px;
    right: -4px;
    z-index: 5;
    min-width: 20px;
    height: 20px;
    box-sizing: border-box;
    padding: 0 5px;
    border: 2px solid #ffffff;
    border-radius: 999px;
    background: var(--mud-palette-error);
    color: #ffffff;
    font-size: 11px;
    font-weight: 900;
    line-height: 16px;
    text-align: center;
    pointer-events: none;
}


/* =========================================================
   LEAFLET POPUP
   ========================================================= */

#mapContainer
.leaflet-popup-content-wrapper {
    overflow: hidden;
    border: 1px solid var(--ws-map-border);
    border-radius: 16px;
    background: var(--ws-map-surface);
    color: var(--ws-map-text);
    box-shadow: var(--ws-map-shadow-md);
    transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease;
}


#mapContainer
.leaflet-popup-content {
    min-width: 250px;
    max-width: 310px;
    margin: 0;
    color: var(--ws-map-text);
}


#mapContainer
.leaflet-popup-tip {
    background: var(--ws-map-surface);
}


/* =========================================================
   POPUP CLOSE BUTTON
   ========================================================= */

#mapContainer
a.leaflet-popup-close-button {
    top: 9px;
    right: 9px;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    color: var(--ws-map-muted) !important;
    font-size: 20px;
    font-weight: 500;
    line-height: 28px;
    transition: background-color 140ms ease, color 140ms ease;
}


    #mapContainer
    a.leaflet-popup-close-button:hover {
        background: var(--ws-map-surface-soft);
        color: var(--ws-map-text) !important;
    }


/* =========================================================
   POPUP CONTENT
   ========================================================= */

#mapContainer .ws-map-popup {
    padding: 1rem;
    color: var(--ws-map-text);
}


#mapContainer .ws-map-popup-title {
    margin: 0 0 0.65rem;
    padding-right: 2rem;
    color: var(--ws-map-text);
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.35;
    letter-spacing: -0.015em;
    overflow-wrap: anywhere;
}


#mapContainer .ws-map-popup-text {
    color: var(--ws-map-muted);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.6;
    overflow-wrap: anywhere;
}


    #mapContainer
    .ws-map-popup-text
    strong {
        color: var(--ws-map-text);
        font-weight: 750;
    }


/* =========================================================
   POPUP ALARM
   ========================================================= */

#mapContainer .ws-map-popup-alarm {
    margin-top: 0.75rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid color-mix( in srgb, var(--mud-palette-error) 35%, transparent );
    border-radius: 10px;
    background: var(--ws-map-red-soft);
    color: var(--ws-map-text);
    font-size: 0.875rem;
    font-weight: 750;
    line-height: 1.45;
}


/* =========================================================
   POPUP ACTIONS
   ========================================================= */

#mapContainer
.ws-map-popup-actions {
    display: flex;
    gap: 0.55rem;
    margin-top: 0.9rem;
}


/* =========================================================
   POPUP BUTTON
   ========================================================= */

#mapContainer
.ws-map-popup-button {
    appearance: none;
    flex: 1;
    min-height: 40px;
    cursor: pointer;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--ws-map-border-strong);
    border-radius: 10px;
    background: var(--ws-map-surface-soft);
    color: var(--ws-map-text);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}


    #mapContainer
    .ws-map-popup-button:hover {
        border-color: color-mix( in srgb, var(--mud-palette-primary) 50%, transparent );
        background: var(--ws-map-blue-soft);
        color: var(--ws-map-text);
    }


    /* =========================================================
   PRIMARY BUTTON
   ========================================================= */

    #mapContainer
    .ws-map-popup-button.primary {
        border-color: var(--mud-palette-primary);
        background: var(--mud-palette-primary);
        color: var(--mud-palette-primary-text);
        box-shadow: 0 5px 14px var(--ws-map-blue-soft);
    }


        #mapContainer
        .ws-map-popup-button.primary:hover {
            border-color: var(--mud-palette-primary);
            background: var(--mud-palette-primary);
            color: var(--mud-palette-primary-text);
            filter: brightness(0.94);
            transform: translateY(-1px);
        }


    /* =========================================================
   DISABLED BUTTON
   ========================================================= */

    #mapContainer
    .ws-map-popup-button:disabled {
        cursor: default;
        opacity: 0.55;
        transform: none;
    }


    /* =========================================================
   FOCUS
   ========================================================= */

    #mapContainer
    .ws-map-popup-button:focus-visible,
    #mapContainer
    a.leaflet-popup-close-button:focus-visible,
    #mapContainer
    .leaflet-control-zoom a:focus-visible,
    #mapContainer
    .leaflet-control-fullscreen a:focus-visible {
        outline: 3px solid var(--mud-palette-primary);
        outline-offset: 2px;
    }


/* =========================================================
   LEAFLET ZOOM / FULLSCREEN CONTROLS
   ========================================================= */

#mapContainer
.leaflet-control-zoom,
#mapContainer
.leaflet-control-fullscreen {
    overflow: hidden;
    border: 1px solid var(--ws-map-border) !important;
    border-radius: 10px;
    background: var(--ws-map-surface);
    box-shadow: var(--ws-map-shadow-md);
}


    #mapContainer
    .leaflet-control-zoom a,
    #mapContainer
    .leaflet-control-fullscreen a {
        border: 0 !important;
        border-bottom: 1px solid var(--ws-map-border) !important;
        background: var(--ws-map-surface) !important;
        color: var(--ws-map-text) !important;
        font-weight: 700;
        transition: background-color 140ms ease, color 140ms ease;
    }


        #mapContainer
        .leaflet-control-zoom a:last-child,
        #mapContainer
        .leaflet-control-fullscreen a:last-child {
            border-bottom: 0 !important;
        }


        #mapContainer
        .leaflet-control-zoom a:hover,
        #mapContainer
        .leaflet-control-fullscreen a:hover {
            background: var(--ws-map-surface-soft) !important;
            color: var(--mud-palette-primary) !important;
        }


/* =========================================================
   LEAFLET ATTRIBUTION

   This now follows MudBlazor too instead of always forcing
   a white attribution box.
   ========================================================= */

#mapContainer
.leaflet-control-attribution {
    max-width: calc(100% - 16px);
    padding: 4px 8px !important;
    border: 1px solid var(--ws-map-border);
    border-radius: 8px 0 0 0;
    background: color-mix( in srgb, var(--ws-map-surface) 94%, transparent ) !important;
    color: var(--ws-map-muted) !important;
    font-size: 11px !important;
    font-weight: 600;
    line-height: 1.35;
    backdrop-filter: blur(8px);
}


    #mapContainer
    .leaflet-control-attribution
    a {
        color: var(--mud-palette-primary) !important;
        font-weight: 700;
        text-decoration: none;
    }


/* =========================================================
   LEAFLET TOOLTIP

   Included so future tooltips also respect theme.
   ========================================================= */

#mapContainer .leaflet-tooltip {
    border: 1px solid var(--ws-map-border);
    border-radius: 8px;
    background: var(--ws-map-surface);
    color: var(--ws-map-text);
    box-shadow: var(--ws-map-shadow-md);
}


/* =========================================================
   TABLET
   ========================================================= */

@media (max-width: 900px) {

    .ws-map-page {
        padding: 0.875rem;
    }


    .ws-map-header {
        align-items: center;
    }


    .ws-map-subtitle {
        max-width: 46ch;
    }
}


/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 600px) {

    .ws-map-page {
        height: calc(100dvh - 72px);
        gap: 0.75rem;
        padding: 0.75rem;
    }


    .ws-map-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.75rem;
    }


    .ws-map-header-actions {
        width: 100%;
    }


    .ws-map-title {
        font-size: 1.75rem;
    }


    .ws-map-subtitle {
        margin-top: 0.35rem;
        font-size: 0.9rem;
    }


    .ws-map-badge {
        min-height: 36px;
        font-size: 0.8rem;
    }


    .ws-map-card {
        border-radius: 15px;
    }


    #mapContainer
    .leaflet-popup-content {
        min-width: 230px;
        max-width: 260px;
    }


    #mapContainer
    .ws-map-popup {
        padding: 0.9rem;
    }


    #mapContainer
    .ws-map-popup-actions {
        flex-direction: column;
    }


    #mapContainer
    .ws-map-popup-button {
        width: 100%;
    }
}


/* =========================================================
   VERY SMALL MOBILE
   ========================================================= */

@media (max-width: 400px) {

    .ws-map-page {
        padding: 0.6rem;
    }


    .ws-map-label {
        font-size: 0.72rem;
    }


    .ws-map-subtitle {
        font-size: 0.85rem;
    }


    #mapContainer
    .leaflet-popup-content {
        min-width: 210px;
        max-width: 235px;
    }
}


/* =========================================================
   REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {

    .ws-map-page,
    .ws-map-card,
    .ws-map-loading,
    .ws-map-empty,
    #mapContainer
    .ws-map-pin-logo,
    #mapContainer
    .leaflet-popup-content-wrapper,
    #mapContainer
    .ws-map-popup-button,
    #mapContainer
    a.leaflet-popup-close-button {
        transition: none !important;
    }


    #mapContainer
    .ws-map-pin:hover
    .ws-map-pin-logo {
        transform: none !important;
    }


    #mapContainer
    .ws-map-popup-button.primary:hover {
        transform: none !important;
    }
}
