/* Pist Map Widget — kabdalis2 design system.
   Colour tokens used:
     --ink, --ink-soft  (text / shadow tints)
     --surface, --surface2 (backgrounds)
     --line             (border colour)
     --radius           (corner radius)
     --accent           (focus ring)
     --ok / --ok-bg     (open status)
     --no  / --no-bg    (closed status)
   Everything else is bespoke because the map composes marker/popup/location
   visuals that have no token-equivalents in the design system.
   view.js adds .pm at runtime. No .b-card — the map is its own surface. */

/* ═══════════════════════════════════════════ OUTER BLOCK ═══════════════ */

.kabdalis-pist-map {
    position: relative;
    width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    box-sizing: border-box;
}

.kabdalis-pist-map[data-full-width="true"] {
    width: 100%;
}

.gridContainer.pist-map-fullwidth {
    max-width: none;
    width: 100%;
    padding-left: 0;
    padding-right: 0;
}

/* Mobile: full-width breakout */
@media (max-width: 768px) {
    .kabdalis-pist-map {
        width: 100vw;
        margin-left:  calc(-50vw + 50%);
        margin-right: calc(-50vw + 50%);
        position: relative;
        left: 0;
        right: 0;
    }

    .kabdalis-pist-map,
    .kabdalis-pist-map * {
        max-width: 100vw !important;
    }

    .gridContainer:has(.kabdalis-pist-map),
    .gridContainer .kabdalis-pist-map {
        max-width: 100vw !important;
        width: 100vw !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left:  calc(-50vw + 50%) !important;
        margin-right: calc(-50vw + 50%) !important;
    }

    .pist-map-mobile-fullwidth {
        max-width: 100vw !important;
        width: 100vw !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left:  calc(-50vw + 50%) !important;
        margin-right: calc(-50vw + 50%) !important;
    }

    .kabdalis-pist-map.touching {
        touch-action: none;
    }
}

/* ═══════════════════════════════════════════ TOOLBAR ═══════════════════ */

.pist-map-toolbar {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 5;
    align-items: center;
    box-shadow: 0 2px 12px color-mix(in srgb, var(--ink) 15%, transparent);
}

.pist-map-toolbar.preview {
    position: static;
    margin-bottom: 8px;
}

.pist-map-toolbar-label {
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
}

.pist-map-toolbar-hint {
    color: var(--ink-soft);
    font-size: 13px;
}

/* ─── Action buttons ────────────────────────────────────────────────── */

.pist-map-action {
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--ink);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    line-height: 1;
    position: relative;
    box-shadow: 0 2px 8px color-mix(in srgb, var(--ink) 15%, transparent);
}

.pist-map-action:hover,
.pist-map-action:focus {
    background: #fff;
    outline: none;
    box-shadow: 0 4px 12px color-mix(in srgb, var(--ink) 20%, transparent);
}

.pist-map-action:active {
    transform: scale(0.95);
}

.pist-map-action:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Hover tooltip — CSS-only */
.pist-map-action[data-tooltip]:hover::before {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: color-mix(in srgb, var(--ink) 95%, transparent);
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 4px 12px color-mix(in srgb, var(--ink) 25%, transparent);
    opacity: 0;
    animation: pistMapTooltipFadeIn 0.2s ease forwards;
}

.pist-map-action[data-tooltip]:hover::after {
    content: '';
    position: absolute;
    top: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid color-mix(in srgb, var(--ink) 95%, transparent);
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    animation: pistMapTooltipFadeIn 0.2s ease forwards;
}

@keyframes pistMapTooltipFadeIn {
    to { opacity: 1; }
}

.pist-map-action i.fa {
    display: inline-block;
    font-size: 14px;
    line-height: 1;
    color: var(--ink);
    visibility: visible;
    opacity: 1;
}

.pist-map-action .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Locate button states */
.pist-map-action.is-loading i.fa {
    animation: b-spin 1s linear infinite;
}
.pist-map-action.is-active {
    background: #0078d7;
}
.pist-map-action.is-active i.fa {
    color: #fff;
}
.pist-map-action.is-error {
    background: var(--no);
}
.pist-map-action.is-error i.fa {
    color: #fff;
}

/* ═══════════════════════════════════════════ STAGE ════════════════════ */

.pist-map-stage {
    position: relative;
    width: 100%;
    /* aspect-ratio is set in JS from image.naturalWidth/naturalHeight so the
       stage height adapts to the actual image — no fixed height or hardcoded
       ratio needed here.  A fallback keeps things sane before the image loads. */
    aspect-ratio: 1920 / 885;
    /* Minimum height so the widget never collapses to nothing */
    min-height: 200px;
    border-radius: var(--radius);
    overflow: hidden;
    border: none;
    background: var(--surface);
    /* At base zoom a vertical swipe scrolls the page; view.js switches this
       to `none` while zoomed in so the map owns all gestures. */
    touch-action: pan-y;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.pist-map-stage:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* On mobile, let the stage height be driven by the image ratio too, but
   clamp to a sensible viewport fraction rather than forcing a fixed pixel
   height. When the clamps kick in the stage ratio diverges from the image —
   the JS letterbox-fit canvas keeps markers aligned regardless. */
@media (max-width: 768px) {
    .pist-map-stage {
        min-height: 220px;
        max-height: 70vh;
        border-radius: 0;
    }
}

/* ─── Transform layer ───────────────────────────────────────────────── */

.pist-map-transform {
    width: 100%;
    height: 100%;
    /* transform-origin: 0 0 is critical — the focal-point zoom formula in
       view.js computes translateX/Y assuming the origin is the stage top-left.
       Changing this to center would require a different formula and would cause
       the point under the cursor to drift toward the centre on every zoom step. */
    transform-origin: 0 0;
    transition: transform 0.16s cubic-bezier(0.2, 0.7, 0.3, 1);
    /* No will-change here on purpose: it pins a cached raster of the layer,
       so after a zoom the browser stretches the cache instead of re-rendering
       — labels stay permanently blurry. Without it the text re-rasterizes
       crisply once the transition settles. */
    cursor: grab;
}

/* Direct manipulation must track the finger/cursor 1:1 — no easing. */
.pist-map-stage.dragging .pist-map-transform,
.kabdalis-pist-map.touching .pist-map-transform {
    cursor: grabbing;
    transition: none;
}

/* ─── Canvas (letterbox-fit rect of the image, sized by view.js) ─────── */

.pist-map-canvas {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
}

/* ─── Map image ─────────────────────────────────────────────────────── */

.kabdalis-pist-map .pist-map-image {
    display: block;
    width: 100%;
    height: 100%;
    /* The canvas is sized to the image's exact aspect ratio, so contain
       fills it completely — and stays a safe fallback before layout runs. */
    object-fit: contain;
    object-position: center;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

/* Editor preview — no interactivity */
.pist-map-editor-preview .pist-map-stage {
    pointer-events: none;
}

/* ═══════════════════════════════════════════ MARKERS ══════════════════ */

.pist-map-markers {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
}

/* Markers live inside .pist-map-transform so they physically scale with the
   map image.  view.js applies a counter-scale (and counter-rotation) to their
   transform so the final on-screen size stays within
   [OVERLAY_MIN_SCALE … OVERLAY_MAX_SCALE] of the natural marker size and the
   labels stay upright when the map is rotated.  The base
   translate(-50%,-50%) centres the marker on its data point. */
.pist-map-marker {
    pointer-events: auto;
    position: absolute;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: #fff;
    font-weight: 500;
    font-size: 10px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.2px;
    cursor: pointer;
    transition: transform 0.16s cubic-bezier(0.2, 0.7, 0.3, 1);
    /* Generous touch area — intentionally invisible: hover/focus feedback is
       rendered on the label chip, never on this hit box. */
    min-height: 36px;
    min-width: 36px;
    padding: 8px;
    box-sizing: border-box;
}

.pist-map-stage.dragging .pist-map-marker,
.kabdalis-pist-map.touching .pist-map-marker {
    transition: none;
}

.pist-map-marker:hover {
    z-index: 3;
}

.pist-map-marker:focus-visible {
    outline: 2px solid #fff;
    outline-offset: -4px;
    z-index: 3;
}

.pist-map-marker-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 11px;
    line-height: 1;
    white-space: nowrap;
    box-sizing: border-box;
    padding: 2px 5px;
    border-radius: 4px;
    min-height: 16px;
    background-color: #3d4852;
    border: none;
    position: relative;
    box-shadow: 0 1px 4px rgba(6, 12, 16, 0.35);
    transition: box-shadow 0.15s ease;
}

/* Hover/keyboard feedback on the chip itself — the larger hit area around it
   stays invisible. A crisp ring, deliberately NOT a scale transform: scaling
   stretches the rasterized text and blurs it. Restaurants (type 3) are
   invisible targets and get none. */
.pist-map-marker:not([data-type="3"]):hover .pist-map-marker-label,
.pist-map-marker:not([data-type="3"]):focus-visible .pist-map-marker-label {
    box-shadow: 0 0 0 2px #fff, 0 3px 12px rgba(6, 12, 16, 0.5);
}

/* Special-color slopes (black2, red2, off-piste) — solid white chip */
.pist-map-marker[data-special-color="true"] .pist-map-marker-label {
    background-color: #fff;
    border: 2px solid;
}

/* Closed slopes — keep the pist colour at full opacity (translucency and
   desaturation both turn to mud over the map artwork; off-season every
   marker is closed and the map lost all its colour). A line-through on the
   number signals closed, matching the v1 widget. */
.pist-map-marker[data-closed="true"] .pist-map-marker-label {
    text-decoration: line-through;
}
.pist-map-marker[data-type="4"][data-closed="true"] .pist-map-marker-label {
    text-decoration: none;
}

/* Lifts (type=2) */
.pist-map-marker[data-type="2"] .pist-map-marker-label {
    padding: 2px 6px;
    min-height: 18px;
    min-width: 18px;
    border-radius: 4px;
}

/* Restaurants (type=3) — invisible touch target */
.pist-map-marker[data-type="3"] {
    min-height: 44px;
    min-width: 44px;
    padding: 4px;
}
.pist-map-marker[data-type="3"] .pist-map-marker-label {
    background-color: transparent !important;
    border: none !important;
    color: transparent !important;
    box-shadow: none !important;
    width: 100%;
    height: 100%;
}

/* Cross-country (type=4) */
.pist-map-marker[data-type="4"] .pist-map-marker-label {
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
    padding: 0;
    border-radius: 50%;
    font-size: 11px;
}

/* ═══════════════════════════════════════════ POPUP ════════════════════ */

.pist-map-popup {
    position: fixed;
    min-width: 200px;
    max-width: 280px;
    padding: 14px 16px;
    border-radius: 14px;
    background: color-mix(in srgb, var(--ink) 95%, transparent);
    color: #fff;
    font-size: 14px;
    line-height: 1.4;
    pointer-events: auto;
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
    z-index: 99999;
    box-shadow: 0 16px 30px color-mix(in srgb, var(--ink) 45%, transparent);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.pist-map-popup.is-visible {
    opacity: 1;
    visibility: visible;
    transform: none;
}

/* Arrow points at the marker; --arrow-x is set by view.js so it keeps
   pointing correctly when the popup is clamped at a viewport edge. */
.pist-map-popup::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: var(--arrow-x, 50%);
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid color-mix(in srgb, var(--ink) 95%, transparent);
}

/* Flipped below the marker when there is no room above */
.pist-map-popup.is-below::after {
    bottom: auto;
    top: -8px;
    border-top: none;
    border-bottom: 10px solid color-mix(in srgb, var(--ink) 95%, transparent);
}

.pist-map-popup .slope-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    font-weight: 600;
    margin-bottom: 8px;
}
.pist-map-popup .slope-chip strong { font-size: 16px; letter-spacing: 0.5px; }
.pist-map-popup .slope-chip span   { font-size: 13px; opacity: 0.9; }

.pist-map-popup .slope-color {
    font-size: 12px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    opacity: 0.8;
}

.pist-map-popup .slope-status {
    font-size: 12px;
    font-weight: 600;
    margin-top: 8px;
    padding: 4px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pist-map-popup .slope-status-open   { background-color: var(--ok-bg); color: var(--ok); }
.pist-map-popup .slope-status-closed { background-color: var(--no-bg); color: var(--no); }

/* ═══════════════════════════════════════════ STATUS LINE ═══════════════ */

.pist-map-status {
    margin-top: 12px;
    font-size: 14px;
    color: var(--ink-soft);
}
.pist-map-status:empty { display: none; }
.pist-map-status.error { color: var(--no); }

/* ═══════════════════════════════════════════ USER LOCATION ══════════════ */

.pist-map-user-marker {
    position: absolute;
    width: 24px;
    height: 24px;
    margin-left: -12px;
    margin-top: -12px;
    pointer-events: none;
    z-index: 4;
    /* transform (counter-scale) is managed by JS alongside the markers */
    transform-origin: center center;
}
.pist-map-user-marker .pist-map-user-dot {
    position: absolute;
    inset: 6px;
    border-radius: 50%;
    background: #0078d7;
    border: 2px solid #fff;
    box-shadow: 0 0 6px color-mix(in srgb, var(--ink) 40%, transparent);
}
.pist-map-user-marker .pist-map-user-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(0, 120, 215, 0.35);
    animation: pistMapUserPulse 1.8s ease-out infinite;
}
@keyframes pistMapUserPulse {
    0%   { transform: scale(0.5); opacity: 0.8; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* ═══════════════════════════════════════════ CONSENT DIALOG ═══════════ */

.pist-map-consent {
    position: fixed;
    inset: 0;
    background: color-mix(in srgb, var(--ink) 55%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    padding: 16px;
}
.pist-map-consent-card {
    background: var(--surface);
    color: var(--ink);
    border-radius: 12px;
    padding: 24px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 10px 40px color-mix(in srgb, var(--ink) 30%, transparent);
}
.pist-map-consent-card h3 {
    margin: 0 0 12px;
    font-size: 18px;
}
.pist-map-consent-card p {
    margin: 0 0 20px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink-soft);
}
.pist-map-consent-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.pist-map-consent-actions button {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
}
.pist-map-consent-cancel {
    background: transparent;
    color: var(--ink);
    border-color: var(--line);
}
.pist-map-consent-cancel:hover  { background: var(--surface2); }
.pist-map-consent-confirm       { background: #0078d7; color: #fff; }
.pist-map-consent-confirm:hover { background: #005fa3; }

/* ═══════════════════════════════════════════ FULLSCREEN ═══════════════ */
/* Last in the file on purpose: the mobile breakout rules above use
   !important margins, and these must win over them at equal specificity. */

.kabdalis-pist-map.is-fullscreen {
    background: #0e1418;
}

.kabdalis-pist-map.is-fullscreen,
.kabdalis-pist-map.is-fake-fullscreen {
    margin: 0 !important;
    width: auto !important;
    max-width: none !important;
    padding: 0 !important;
}

/* iOS Safari can't fullscreen arbitrary elements — CSS-only fallback */
.kabdalis-pist-map.is-fake-fullscreen {
    position: fixed !important;
    inset: 0;
    z-index: 99990;
}

html.pist-map-noscroll,
html.pist-map-noscroll body {
    overflow: hidden !important;
}

.kabdalis-pist-map.is-fullscreen .pist-map-stage {
    position: absolute;
    inset: 0;
    height: auto;
    min-height: unset;
    max-height: unset;
    /* !important so it beats the inline aspect-ratio view.js sets from the
       image's natural size — otherwise the ratio wins over the inset-derived
       height and the stage doesn't fill the screen. */
    aspect-ratio: auto !important;
    border-radius: 0;
    background: #0e1418;
}

/* Status becomes an overlay chip — below the stage it would be off-screen */
.kabdalis-pist-map.is-fullscreen .pist-map-status {
    position: absolute;
    left: 16px;
    bottom: 16px;
    margin: 0;
    z-index: 6;
    background: rgba(14, 20, 24, 0.85);
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
}

/* ═══════════════════════════════════════════ REDUCED MOTION ═══════════ */

@media (prefers-reduced-motion: reduce) {
    .pist-map-action.is-loading i.fa           { animation-duration: 1.6s; }
    .pist-map-user-marker .pist-map-user-pulse { animation: none; }
    .pist-map-transform,
    .pist-map-marker,
    .pist-map-marker-label,
    .pist-map-popup                            { transition: none; }
}
