/**
 * Météo Centre - Frontend Map CSS
 * @version 3.1.0 - Cleanup: removal of obsolete popup styles
 *
 * Contents: Map container, Controls, Leaflet popup (minimal), Legend
 * Loaded: Only when the rsmc/forecast-map block is present
 *
 * CHANGES v3.1:
 * - ✅ Removal of .rsmc-popup-main, .rsmc-popup-desc, .rsmc-popup-details, etc. styles
 * - ✅ The popup now reuses .rsmc-hour-card (core.css)
 * - ✅ Only the Leaflet wrapper and the button are kept
 */

/* ========================================================================
 * WRAPPER CARTE
 * ======================================================================== */

.rsmc-map-wrapper {
    background: #fff;
    border-radius: var(--rsmc-radius);
    box-shadow: var(--rsmc-shadow);
    overflow: hidden;
    position: relative;
}

.alignfull .rsmc-map-wrapper {
    border-radius: 0;
}

/* ========================================================================
 * MAP CONTAINER
 * ======================================================================== */

.rsmc-map-container {
    width: 100%;
    min-height: 400px;
    position: relative;
    z-index: 1;
}

/* ========================================================================
 * FLOATING CONTROLS
 * ======================================================================== */

.rsmc-floating-controls {
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: var(--rsmc-radius-sm);
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    width: auto;
    max-width: 250px; /* no labels → tighter box; the date select still fits "D dd/mm/yyyy" */
    transition: var(--rsmc-transition);
}

.rsmc-control-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    white-space: nowrap;
}

.rsmc-control-row:last-child {
    margin-bottom: 0;
}

.rsmc-control-row label {
    font-size: 10px;
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    min-width: 35px;
    flex-shrink: 0;
}

.rsmc-control-buttons {
    display: flex;
    gap: 3px;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.rsmc-display-btn {
    width: 26px;
    height: 26px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    color: #2b2f38;                 /* drives the monochrome SVG icon (currentColor) */
    border: 2px solid rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s, transform 0.1s;
}

.rsmc-display-btn:hover {
    border-color: var(--rsmc-primary, #2271b1);
}

/* Accent (never black) on keyboard/click focus — replaces the browser's default dark outline. */
.rsmc-display-btn:focus,
.rsmc-display-btn:focus-visible {
    outline: none;
    border-color: var(--rsmc-primary, #2271b1);
}

/* Selected mode: filled brand box with a white icon — clear visual feedback. */
.rsmc-display-btn.is-active {
    background: var(--rsmc-primary, #2271b1);
    border-color: var(--rsmc-primary, #2271b1);
    color: #fff;
}

.rsmc-display-glyph {
    pointer-events: none;
    display: inline-flex;
}

.rsmc-display-glyph svg {
    width: 60%;
    height: 60%;
    display: block;
}

/* Display-mode switcher: a top bar of big icons sitting just right of the +/- zoom control. */
.rsmc-display-control {
    position: absolute;
    top: 10px;
    left: 52px;
    z-index: 1000;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    max-width: calc(100% - 64px);
}

/* Big display buttons in the top bar (same size/look as the fullscreen toggle, defined below). */
.rsmc-display-control .rsmc-display-btn {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
}

/* Selected mode — scoped so the brand fill wins over the white idle background above. */
.rsmc-display-control .rsmc-display-btn.is-active {
    background: var(--rsmc-primary, #2271b1);
    border-color: var(--rsmc-primary, #2271b1);
    color: #fff;
}

.rsmc-display-control .rsmc-display-glyph svg {
    width: 22px;
    height: 22px;
}

@media (max-width: 768px) {
    /* Keep the switcher clear of the bigger top-right fullscreen button (≈44px + margins) — it
     * wraps to a second row instead of running over the fullscreen control. */
    .rsmc-display-control {
        max-width: calc(100% - 112px);
    }
    .rsmc-display-control .rsmc-display-btn {
        width: 44px;
        height: 44px;
    }
    .rsmc-display-control .rsmc-display-glyph svg {
        width: 26px;
        height: 26px;
    }
    /* The zoom/coords readout is a desktop info/debug aid — hide it on the cramped mobile layout
     * (the credits "i" stays, since it's a sibling in the same row). */
    .rsmc-map-info {
        display: none;
    }
}

.rsmc-control-prev,
.rsmc-control-next {
    width: 34px;
    height: 34px;
    padding: 0;
    background: #fff;
    border: 2px solid rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    user-select: none;
}

.rsmc-control-prev:hover,
.rsmc-control-next:hover {
    background: #f4f4f4;
    border-color: rgba(0, 0, 0, 0.3);
}

.rsmc-control-prev:active,
.rsmc-control-next:active {
    background: #e8e8e8;
    transform: scale(0.95);
}

.rsmc-control-prev:disabled,
.rsmc-control-next:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #fafafa;
}

.rsmc-floating-controls select {
    flex: 1;
    min-width: 0;
    padding: 7px 9px;
    border: 2px solid rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    font-size: 14px;
    background: #fff;
    transition: all 0.2s ease;
    font-weight: 500;
}

/* Roomier date/hour controls, with comfortable touch targets on mobile. */
.rsmc-control-row label {
    font-size: 11px;
}

@media (max-width: 768px) {
    .rsmc-floating-controls {
        padding: 12px;
    }
    .rsmc-control-prev,
    .rsmc-control-next {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    .rsmc-floating-controls select {
        padding: 9px 11px;
        font-size: 15px;
    }
    .rsmc-control-row {
        gap: 8px;
        margin-bottom: 10px;
    }
}

.rsmc-floating-controls select:focus {
    outline: none;
    border-color: var(--rsmc-primary);
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

/* Controls container while loading */
.rsmc-floating-controls.is-loading {
    pointer-events: none;
    opacity: 0.7;
}

/* Select while loading - shimmer effect */
.rsmc-floating-controls select.is-loading {
    cursor: wait;
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
    color: transparent;
}

/* Shimmer animation */
@keyframes loading-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Disabled buttons during loading */
.rsmc-floating-controls button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: #fafafa;
}

/* Alternative: spinner on the container */
.rsmc-floating-controls.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid rgba(102, 126, 234, 0.3);
    border-top-color: var(--rsmc-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: translateY(-50%) rotate(360deg);
    }
}

/* Hover disabled during loading */
.rsmc-floating-controls.is-loading select:hover,
.rsmc-floating-controls.is-loading button:hover {
    border-color: rgba(0, 0, 0, 0.2);
    background: #f0f0f0;
    transform: none;
}

/* ========================================================================
 * LEAFLET POPUP (Minimal styles)
 * The popup now reuses .rsmc-hour-card (defined in core.css)
 * ======================================================================== */

.leaflet-popup-pane {
    z-index: 700;
}

.rsmc-popup .leaflet-popup-content-wrapper {
    border-radius: var(--rsmc-radius);
    padding: 0;
}

.rsmc-popup .leaflet-popup-content {
    margin: 0;
    width: 20em !important; /* 320px fluid */
    max-width: 90vw; /* Never exceed 90% of screen width */
}

.leaflet-bottom {
    padding-bottom: 10px;
}

/* Native MapLibre popup — mirror the Leaflet popup chrome (content reuses .rsmc-hour-card). */
.maplibregl-popup.rsmc-popup {
    z-index: 700;
}

.rsmc-popup .maplibregl-popup-content {
    margin: 0;
    padding: 0;
    border-radius: var(--rsmc-radius);
    width: 20em; /* 320px fluid */
    max-width: 90vw;
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.4);
    /* Fade the card in on open (rsmcCardIn defined in frontend-core.css). Animate the content, not the
     * popup container, so MapLibre's positioning transform isn't disturbed. */
    animation: rsmcCardIn 0.16s ease both;
}

@media (prefers-reduced-motion: reduce) {
    .rsmc-popup .maplibregl-popup-content { animation: none; }
}

.rsmc-popup .maplibregl-popup-close-button {
    width: 28px;
    height: 28px;
    font-size: 20px;
    line-height: 1;
    color: var(--rsmc-dark);
}

/* Popup container */
.rsmc-popup-content {
    padding: 20px;
}

.rsmc-popup-content h3 {
    margin: 0 0 15px;
    color: var(--rsmc-dark);
    text-align: center;
}

/* ✅ The hourly card is displayed inside the popup. Reset the font base to 1rem so it
 * matches the 7-day modal exactly — Leaflet's .leaflet-container forces 12px, which would
 * otherwise shrink the card's em-based sizing and make the text hard to read. */
.rsmc-popup-content {
    font-size: 1rem;
}

.rsmc-popup-content .rsmc-hour-card {
    margin-bottom: 15px;
    /* Inherits all styles from core.css */
}

/* "View 7-day forecast" button */
.rsmc-btn-details {
    width: 100%;
    padding: 10px;
    background: var(--rsmc-primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--rsmc-transition);
}

.rsmc-btn-details:hover {
    background: var(--rsmc-primary-dark);
}

/* (The old bottom legend/credits bar was removed 2026-06-10 — all credits now live in the map's "i"
 * credits popup; see .rsmc-attrib-panel above and MapEngine.addTopRightInfo.) */

/* ========================================================================
 * MARKERS
 * ======================================================================== */

.rsmc-marker {
    background: transparent !important;
    border: none !important;
    cursor: pointer;
    transition: opacity 0.12s ease;
}

/* The fullscreen control sits in a bare MapLibre ctrl wrapper (not ctrl-group), so .rsmc-fs-btn keeps its look. */
.maplibregl-ctrl.rsmc-fs-ctrl {
    background: transparent;
    box-shadow: none;
    border: none;
}

/* MapLibre's `.maplibregl-ctrl-top-right` corner is `position:absolute; z-index:2`, which forms a
 * stacking context — so a child's z-index can't escape it. Raise the whole top-right corner above the
 * top-left display switcher (z-index 1000) so the open credits panel covers those buttons on mobile. */
.maplibregl-ctrl-top-right {
    z-index: 1004;
}

/* Top-right info row: the coords readout (desktop) + the credits "i" toggle to its right.
 * One flex row so they sit side by side; the credits panel opens only on click. */
.maplibregl-ctrl.rsmc-map-info-ctrl {
    position: relative;
    display: flex;
    align-items: center;
    gap: 5px;
    background: transparent;
    box-shadow: none;
    border: none;
}

/* The "i" credits toggle — a rounded square matching the other map buttons (no circle). */
.rsmc-attrib-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.96);
    color: #2b2f38;
    border: 2px solid rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
    font: italic 700 13px/1 Georgia, "Times New Roman", serif;
    cursor: pointer;
}

.rsmc-attrib-panel {
    position: absolute;
    top: 30px;
    right: 0;
    z-index: 1003; /* over the top-left display switcher (1000) on mobile */
    max-width: min(300px, 80vw);
    width: max-content;
    max-height: min(60vh, 380px);
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.97);
    color: #333;
    font-size: 11px;
    line-height: 1.45;
    padding: 8px 11px;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    white-space: normal;
}

.rsmc-attrib-panel a {
    color: var(--rsmc-primary, #2271b1);
}

/* Forecast credits + run card appended under the basemap attribution, with a divider. */
.rsmc-attrib-base + .rsmc-attrib-extra {
    margin-top: 7px;
    padding-top: 7px;
    border-top: 1px solid rgba(0, 0, 0, 0.12);
}

.rsmc-credits-line {
    margin-bottom: 2px;
}

/* The run/provenance card (CardConfig::data_info) sits inline in the panel — keep it compact. */
.rsmc-attrib-extra .rsmc-feels-overlay {
    margin-top: 6px;
    font-size: 11px;
}

.rsmc-attrib-extra .rsmc-feels-overlay-title {
    margin-bottom: 0.35em;
}

/* Small live zoom + coordinates readout (info / debugging) — the left part of the top-right info row. */
.rsmc-map-info {
    font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: rgba(255, 255, 255, 0.82);
    color: #2b2f38;
    padding: 2px 7px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    user-select: none;
    white-space: nowrap;
}

/* Inner wrapper: the icon is rendered at a reference size and CSS-scaled to the live zoom.
 * The engine updates this scale every render frame (MapEngine._applyScales), so there is NO
 * transition — the icon tracks the continuous GL zoom 1:1 (a transition would lag behind it). */
.rsmc-marker-inner {
    display: block;
    transform-origin: center center;
    will-change: transform;
}

/* Appear/disappear animation wrapper. The style is chosen per-block via a container class
 * (.rsmc-anim-none | -fade | -pop | -bounce); "none" leaves the classes inert.
 * Flex column + center so the icon (and the optional city label) stay centred on the marker point —
 * otherwise a label wider than the icon stretches the block and the icon left-aligns. */
.rsmc-marker-fx {
    display: flex;
    flex-direction: column;
    align-items: center;
    transform-origin: center center;
    position: relative; /* anchor for the absolutely-positioned city label below */
}

/* Optional city-name label, absolutely positioned UNDER the icon so it never shifts the icon or
 * overlaps it (incl. the cumul view's km/h / mm text). It sits inside .rsmc-marker-inner, so it
 * **scales together with the icon** (stays proportional as you zoom) and fades with the marker.
 * No box — white text + dark outline reads over any basemap. Fixed width + centred (translateX(-50%));
 * wraps to ~2 lines (breaks on spaces/hyphens). */
.rsmc-marker-label {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 3px;
    width: 150px;
    max-height: 2.4em; /* ~2 lines */
    overflow: hidden;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.15;
    text-align: center;
    color: #fff;
    text-shadow:
        -1px -1px 0 rgba(0, 0, 0, 0.9),
        1px -1px 0 rgba(0, 0, 0, 0.9),
        -1px 1px 0 rgba(0, 0, 0, 0.9),
        1px 1px 0 rgba(0, 0, 0, 0.9),
        0 0 4px rgba(0, 0, 0, 0.55);
    white-space: normal;
    overflow-wrap: anywhere;
    pointer-events: none;
}

/* Snappy appear/disappear — kept short so markers feel near-instant on hour/day/zoom changes. */
.rsmc-anim-fade .rsmc-fx-enter { animation: rsmcFxFadeIn 0.14s ease both; }
.rsmc-anim-fade .rsmc-fx-leave { animation: rsmcFxFadeOut 0.12s ease both; }
.rsmc-anim-pop .rsmc-fx-enter { animation: rsmcFxPopIn 0.16s ease both; }
.rsmc-anim-pop .rsmc-fx-leave { animation: rsmcFxPopOut 0.12s ease both; }
.rsmc-anim-bounce .rsmc-fx-enter { animation: rsmcFxBounceIn 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.rsmc-anim-bounce .rsmc-fx-leave { animation: rsmcFxPopOut 0.12s ease both; }

@keyframes rsmcFxFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rsmcFxFadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes rsmcFxPopIn { from { opacity: 0; transform: scale(0.4); } to { opacity: 1; transform: scale(1); } }
@keyframes rsmcFxPopOut { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(0.4); } }
@keyframes rsmcFxBounceIn {
    0% { opacity: 0; transform: scale(0.3); }
    60% { opacity: 1; transform: scale(1.15); }
    100% { opacity: 1; transform: scale(1); }
}

/* ========================================================================
 * FULLSCREEN
 * ======================================================================== */

/* Fullscreen toggle — same box size/look as the display-mode buttons, with a bold matching icon. */
.rsmc-fs-btn {
    width: 38px;
    height: 38px;
    padding: 0;
    color: #2b2f38;
    background: rgba(255, 255, 255, 0.96);
    border: 2px solid rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.rsmc-fs-btn svg {
    width: 24px;
    height: 24px;
    display: block;
}

/* ── Custom MapLibre control buttons: keep them solid (never transparent) on hover/active ──
 * MapLibre's own `.maplibregl-ctrl button:not(:disabled):hover` (specificity 0,3,1) swaps the
 * background for a 5%-black wash, which reads as "transparent" over the map. Every custom control
 * button we add MUST carry the `rsmc-ctrl-btn` class so this one rule (specificity 0,4,1) outranks
 * it everywhere — add the class to any new control button and the bug can't come back. */
.maplibregl-ctrl button.rsmc-ctrl-btn {
    background: rgba(255, 255, 255, 0.96);
}

.maplibregl-ctrl button.rsmc-ctrl-btn:not(:disabled):hover,
.maplibregl-ctrl button.rsmc-ctrl-btn:not(:disabled):active,
.maplibregl-ctrl button.rsmc-ctrl-btn:focus,
.maplibregl-ctrl button.rsmc-ctrl-btn:focus-visible {
    background: rgba(255, 255, 255, 0.96);
    border-color: var(--rsmc-primary, #2271b1); /* accent, never black */
    outline: none;
}

@media (max-width: 768px) {
    .rsmc-fs-btn { width: 44px; height: 44px; }
    .rsmc-fs-btn svg { width: 28px; height: 28px; }
}

.rsmc-map-wrapper:fullscreen {
    width: 100%;
    height: 100%;
    background: #fff;
}

.rsmc-map-wrapper:fullscreen .rsmc-map-container {
    height: 100% !important;
}

.rsmc-map-wrapper:-webkit-full-screen {
    width: 100%;
    height: 100%;
    background: #fff;
}

.rsmc-map-wrapper:-webkit-full-screen .rsmc-map-container {
    height: 100% !important;
}
