/* =========================================================================
   Night map — map page chrome ("Noc zniczy").
   Offsets derive from --header-h (style.css); never hard-code the height.
   ========================================================================= */

#map {
    height: calc(100vh - var(--header-h));
    height: calc(100dvh - var(--header-h));  /* iOS URL-bar-safe; older browsers ignore */
    width: 100%;
    background: var(--bg-page);
    /* z-index:0 contains ALL Leaflet chrome (.leaflet-top/.leaflet-bottom are
       z 1000) inside the map's own stacking context (position set explicitly —
       Leaflet only writes its inline position:relative after init). Root-level
       z-scale above the map: #map-panels 900 < #join-overlay/#join-reopen 950
       < #map-status 990 < #search-bar 1000 < .site-header 2000 < .skip-link
       3000. */
    position: relative;
    z-index: 0;
}

/* Dark tiles: luminance-preserving invert pulls standard OSM tiles into the
   warm near-black family. Applies to the tile pane only — markers, popups
   and controls are untouched. */
.leaflet-tile-pane {
    filter: invert(1) hue-rotate(180deg) brightness(.72) contrast(.92) saturate(.45) sepia(.18);
}

.leaflet-control-zoom {
    transition: margin-top 0.3s;
}

/* Pushed below the open search bar via --search-h (set by toggleSearch in
   map.html — never as an inline style on the Leaflet node). Ties leaflet.css's
   .leaflet-top .leaflet-control margin at (0,2,0); this file loads later, so
   it wins. Closed: 10px (Leaflet's default). */
.leaflet-top .leaflet-control-zoom {
    margin-top: calc(10px + var(--search-h, 0px));
}

/* OSM attribution — visible at all times (OSM policy), styled as a quiet chip.
   Duplicated in pin_form.css (same pattern as the tile filter): leaflet.css
   declares the same selector at equal specificity, so the override must load
   after it — style.css loads before. */
.leaflet-container .leaflet-control-attribution {
    background: rgba(23, 18, 14, 0.85);
    color: var(--text-muted);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: var(--radius-s) 0 0 0;
}

.leaflet-container .leaflet-control-attribution a {
    color: var(--bronze);
    text-decoration: underline;
    text-underline-offset: 2px;
}


/* Baseline look (font, color, hover) comes from .header-actions button in
   style.css — keep only what that rule doesn't provide. */
#search-expand-btn {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    box-shadow: none;
    padding: 8px;
}

#search-expand-btn path {
    transition: stroke 0.2s;
}

#search-expand-btn:hover {
    color: var(--bronze);
    cursor: pointer;
}

#search-expand-btn:hover path {
    stroke: var(--bronze);
}

#search-bar {
    position: absolute;
    top: var(--header-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-hairline);
    z-index: 1000;
    right: 0;
    width: 100%;
    /* Hidden state: lifted fully above the viewport regardless of the bar's
       height (the old top:-20px trick only worked while the bar was shorter
       than the header it hid behind). visibility:hidden removes its ~20
       controls from the tab order and AT tree while closed (same pattern as
       the mobile nav) — without it keyboard focus vanishes off-screen. */
    transform: translateY(calc(-100% - var(--header-h) - 20px));
    visibility: hidden;
    transition: transform 0.3s, visibility 0s linear 0.3s;
}
#search-bar.open {
    transform: translateY(0);
    visibility: visible;
    transition: transform 0.3s;
}

/* Search field — single source of truth (was two conflicting blocks) */
#pin-search {
    width: -moz-available;
    width: -webkit-fill-available;
    margin: 10px 56px 10px 10px; /* clears the 44px close button at any width */
    padding: 12px 18px;
    font-size: 1.15rem;
    font-family: var(--font);
    color: var(--text-primary);
    background: var(--bg-inset);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill);
    transition: border-color 0.2s, box-shadow 0.2s;
}
#pin-search:focus {
    outline: none;
    border-color: var(--flame);
    box-shadow: var(--glow-focus);
}

#search-bar ::placeholder {
    color: #9A8D7B;
    opacity: 1;
}

/* Status filter — visible pill radios */
#status-filters {
    margin: 0 25px 12px 10px;
}
#status-filters fieldset {
    border: 0;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-evenly;
    gap: 8px;
}
#status-filters input {
    /* visually-hidden clip pattern: off-screen for eyes, still focusable */
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
#status-filters label {
    display: inline-flex;
    align-items: center;
    background: var(--bg-surface);
    color: var(--bronze);
    border: 1px solid var(--bronze);
    border-radius: var(--radius-pill);
    padding: 6px 14px;
    font-family: var(--font);
    font-size: var(--text-s);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
#status-filters label:hover {
    color: var(--text-primary);
    border-color: var(--text-primary);
}
#status-filters label:has(> input:checked) {
    background: var(--flame);
    border-color: var(--flame);
    color: var(--bg-page);
    font-weight: 700;
}
#status-filters label:has(> input:focus-visible) {
    outline: 2px solid var(--flame);
    outline-offset: 2px;
    box-shadow: var(--glow-focus);
}
#status-filters label:has(> input:disabled) {
    opacity: 0.45;
    cursor: not-allowed;
}
#status-filters label:has(> input:disabled):hover {
    color: var(--bronze);
    border-color: var(--bronze);
}

#close-search-bar {
    position: absolute;
    /* Inside the bar (the old top:-6px slice was painted over by the z-2000
       header and thus dead) and at the 44px tap-target floor. */
    top: 2px;
    right: 6px;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    transition: color 0.2s;
    font-family: arial;
}
#close-search-bar:hover {
    color: var(--bronze);
}

/* Advanced filters */
#advanced-filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 8px;
    padding: 0 25px 10px 10px;
}
#advanced-filters input,
#advanced-filters select {
    padding: 8px 14px;
    font-size: 1rem; /* ≥16px: iOS Safari zooms the page on focus below that */
    font-family: var(--font);
    color: var(--text-primary);
    background: var(--bg-inset);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill);
    transition: border-color 0.2s, box-shadow 0.2s;
}
#advanced-filters input:focus,
#advanced-filters select:focus {
    outline: none;
    border-color: var(--flame);
    box-shadow: var(--glow-focus);
}

/* Bronze-outline pill recipe for buttons floating over the tiles
   (opaque --bg-surface keeps them legible on any map background). */
#clear-filters,
.panel-toggle,
#join-reopen {
    background: var(--bg-surface);
    color: var(--bronze);
    border: 1px solid var(--bronze);
    border-radius: var(--radius-pill);
    padding: 6px 14px;
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.9rem;
    transition: background-color 0.2s, color 0.2s;
}
#clear-filters:hover,
.panel-toggle:hover,
#join-reopen:hover,
.panel-toggle[aria-expanded="true"] {
    background: var(--bronze);
    color: var(--bg-page);
}

/* Edition colors - one SVG, hue-rotated per year.
   2025 keeps the original orange flame (#E87816); the near-black candle body
   is achromatic, so hue-rotate leaves it alone. New edition = one line here
   plus the year in KNOWN_EDITIONS (map.js). Every candle gets an amber halo;
   per-edition rules place drop-shadow BEFORE hue-rotate so the glow
   is rotated together with the flame and each edition glows in its own hue. */
.candle-edition {
    filter: drop-shadow(0 0 6px rgba(242, 163, 60, 0.55));
}
.candle-edition-2026 {
    filter: drop-shadow(0 0 6px rgba(242, 163, 60, 0.55)) hue-rotate(180deg) saturate(1.1); /* blue flame, blue glow */
}

/* Cluster icon — do NOT rename (markercluster iconCreateFunction) */
.candle-cluster {
    background: none;
    border: none;
}
.candle-cluster-inner {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-circle);
    background: var(--bg-card);
    color: var(--text-primary);
    border: 2px solid var(--flame);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font);
    font-weight: 700;
    font-size: 1rem;
    box-shadow: 0 0 14px rgba(194, 87, 27, 0.6); /* static ember halo */
}

/* Marker hover tooltip — card recipe */
.leaflet-tooltip {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-2);
    font-family: var(--font);
    padding: 5px 10px;
}
.leaflet-tooltip-top::before {
    border-top-color: var(--border-hairline);
}
.tooltip-sub {
    font-size: 0.8rem;
    color: var(--bronze);
}

/* Edition legend — card recipe */
.edition-legend {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-2);
    padding: 6px 10px;
    font-family: var(--font);
    font-size: 0.85rem;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    max-width: calc(100vw - 20px);
}
.edition-legend:empty {
    display: none;
}
.legend-candle {
    height: 26px;
    width: auto;
    vertical-align: middle;
}
.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* Floating fetch-status chip (loading / empty / error) */
#map-status {
    position: fixed;
    top: calc(var(--header-h) + 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 990; /* above the map panes, below #search-bar (1000) */
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: calc(100vw - 24px);
    background: rgba(36, 29, 23, 0.95); /* --bg-surface #241D17 at .95 */
    color: var(--text-primary);
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-2);
    padding: 8px 18px;
    font-family: var(--font);
    font-size: var(--text-s);
}
#map-status button {
    flex-shrink: 0;
    background: transparent;
    color: var(--bronze);
    border: 1px solid var(--bronze);
    border-radius: var(--radius-pill);
    padding: 4px 12px;
    font-family: var(--font);
    font-size: var(--text-xs);
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}
#map-status button:hover {
    background: var(--bronze);
    color: var(--bg-page);
}

/* Right-side panels. The container box spans the widest child — without the
   pointer-events pass-through it silently swallows taps meant for markers
   and map beneath it. */
#map-panels {
    position: absolute;
    top: calc(var(--header-h) + 12px);
    right: 10px;
    z-index: 900; /* below #search-bar (1000) */
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    font-family: var(--font);
    pointer-events: none;
}
#map-panels > * {
    pointer-events: auto;
}
.map-panel {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-m);
    padding: 14px 18px;
    width: 280px;
    max-height: 55vh;
    max-height: 55dvh; /* iOS: the vh unit overshoots the visible area */
    overflow-y: auto;
    box-shadow: var(--shadow-2);
}
.map-panel h2 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}
.map-panel h3 {
    font-size: 0.95rem;
    margin: 10px 0 4px;
    color: var(--bronze);
}
.map-panel ul,
.map-panel ol {
    padding-left: 18px;
    font-size: 0.9rem;
}
#recent-list {
    list-style: none;
    padding: 0;
}
.recent-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border-hairline);
    color: var(--text-primary);
    padding: 8px 2px;
    cursor: pointer;
    font-family: var(--font);
}
.recent-item:hover .recent-title {
    color: var(--bronze);
}
.recent-title {
    display: block;
    font-weight: 700;
}
.recent-meta {
    display: block;
    font-size: 0.8rem;
    color: var(--bronze);
}
.recent-empty {
    color: var(--bronze);
}
.stat-big {
    margin-bottom: 4px;
}
.stat-nr {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--flame);
}

/* "Dołącz w 3 krokach" overlay — card recipe */
#join-overlay {
    position: absolute;
    left: 50%;
    bottom: 40px;
    transform: translateX(-50%);
    z-index: 950;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-m);
    padding: 18px 44px 18px 22px;
    max-width: 640px;
    width: calc(100% - 40px);
    font-family: var(--font);
    box-shadow: var(--shadow-2);
}
#join-overlay h2 {
    font-size: 1.15rem;
    margin-bottom: 10px;
}
.join-steps {
    list-style: none;
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
}
.join-steps li {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 160px;
}
.join-steps a {
    color: var(--bronze);
}
.join-step-nr {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-circle);
    background: var(--gradient-flame);
    color: var(--bg-page);
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
#join-close {
    position: absolute;
    top: 6px;
    right: 10px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.4rem;
    cursor: pointer;
}
#join-close:hover {
    color: var(--bronze);
}
#join-reopen {
    position: absolute;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    z-index: 950;
    padding: 6px 16px;
}

/* Popup height: viewport-derived cap; desktop viewports ≥ ~640px tall resolve
   to the original flat 400px. Same specificity as style.css's cap — this file
   loads later, so it wins (the style.css line was removed). */
.memorial-popup .leaflet-popup-content {
    max-height: min(400px, calc(100vh - var(--header-h) - 160px));
    max-height: min(400px, calc(100dvh - var(--header-h) - 160px));
}

/* Guard: several rules above set display:flex, which would override the
   hidden attribute without this. */
[hidden] {
    display: none !important;
}

/* Responsive */

/* Below ~1080px the centered join overlay's left edge ((vw - 640px)/2) reaches
   into the bottom-left legend's column — lift the overlay above the legend row.
   (≤850px sets the same value again as part of the full mobile bottom band.) */
@media (max-width: 1080px) {
    #join-overlay {
        bottom: 76px;
    }
}

@media (max-width: 1000px) {
    /* Tap-target floor across the whole mobile-header band — the hamburger
       header (style.css) extends to 1000px, not 850. */
    #search-expand-btn {
        min-width: 44px;
        min-height: 44px;
        justify-content: center;
    }
}

@media (max-width: 850px) {
    #status-filters label {
        padding: 5px 10px;
        font-size: 0.8rem; /* on the label, where it applies (the old
                              #status-filters rule never reached them) */
    }
    .map-panel {
        width: min(280px, calc(100vw - 20px));
        max-height: min(55dvh, calc(100dvh - var(--header-h) - 108px - var(--status-h, 0px)));
    }
    .join-steps {
        flex-direction: column;
        gap: 8px;
    }
    /* In column direction the 160px flex-basis would become item HEIGHT */
    .join-steps li {
        flex: 0 0 auto;
    }

    /* Search bar becomes a capped, internally scrollable sheet; the zoom
       control hides beneath it instead of being pushed off the bottom. */
    #search-bar {
        max-height: calc(100vh - var(--header-h));
        max-height: calc(100dvh - var(--header-h));
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    body.search-open .leaflet-control-zoom {
        visibility: hidden;
    }
    #advanced-filters {
        padding: 0 10px 10px;
    }
    #status-filters {
        margin: 0 10px 12px;
    }

    /* Status chip docks as a full-width strip glued to the header and pushes
       the top-band occupants down by its measured height (--status-h, set in
       map.js) — it no longer covers the zoom control or the panel toggles. */
    #map-status {
        top: var(--header-h);
        left: 0;
        right: 0;
        transform: none;
        max-width: none;
        justify-content: center;
        border-radius: 0;
        border-left: 0;
        border-right: 0;
    }
    .leaflet-top .leaflet-control-zoom {
        /* replaces the --search-h term: the zoom control is hidden while the
           search sheet is open on mobile */
        margin-top: calc(10px + var(--status-h, 0px));
    }
    #map-panels {
        top: calc(var(--header-h) + 12px + var(--status-h, 0px));
    }

    /* Tooltips may wrap on phones (leaflet.css forces nowrap — long cemetery
       names otherwise overflow a 320px viewport). */
    .leaflet-tooltip {
        white-space: normal;
        max-width: min(240px, calc(100vw - 24px));
    }

    /* Keep the bottom-right legend out of the bottom-left reopen pill's
       column (~130px incl. margins); flex-wrap grows it upward instead. */
    .edition-legend {
        max-width: calc(100vw - 140px);
    }

    /* Bottom band, disjoint homes: reopen pill bottom-LEFT, attribution
       bottom-right, edition legend stacked ABOVE the attribution (bottomright
       on mobile, set in map.js), join sheet floating above all three rows and
       scrolling internally when the viewport is short. */
    #join-overlay {
        /* 90px clears the bottom-right legend even when its capped width
           wraps it to two rows (~66px tall + attribution row). */
        bottom: 90px;
        width: calc(100% - 24px);
        padding: 16px 44px 14px 16px;
        max-height: calc(100vh - var(--header-h) - 120px);
        max-height: calc(100dvh - var(--header-h) - 120px);
        overflow-y: auto;
    }
    #join-close {
        top: 0;
        right: 0;
        width: 44px;
        height: 44px;
    }
    #join-reopen {
        left: 10px;
        transform: none;
        bottom: 10px;
    }
}

@media (max-width: 420px) {
    /* Icon-only search button; the accessible name survives via aria-label. */
    #search-expand-btn .search-label {
        display: none;
    }

    /* Compact single-row legend: two rows would climb into the join
       overlay's band (bottom: 90px). */
    .edition-legend {
        font-size: 0.78rem;
        gap: 8px;
        padding: 5px 8px;
    }
    .legend-candle {
        height: 18px;
    }
}

/* Reduced motion — must live at the END of this file: the base rules above
   re-declare these transitions at equal specificity, so a reduce block in
   style.css (loaded earlier) silently loses the cascade. */
@media (prefers-reduced-motion: reduce) {
    #search-bar,
    #search-bar.open,
    .leaflet-control-zoom {
        transition: none;
    }
}
