/* =========================================================================
   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);
}

/* 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;
}


/* 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 25px 10px 10px;
    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;
    padding-top: 15px;
    top: -6px;
    right: 7px;
    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: 0.95rem;
    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;
    gap: 12px;
    align-items: center;
}
.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 */
#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);
}
.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;
    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;
}

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

/* Responsive */
@media (max-width: 850px) {
    #status-filters {
        font-size: 0.8rem;
    }
    #status-filters label {
        padding: 5px 10px;
    }
    #search-expand-btn {
        min-width: 44px;
        min-height: 44px;
        justify-content: center;
    }
    .map-panel {
        width: min(280px, calc(100vw - 20px));
    }
    .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;
    }
}

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

/* 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;
    }
}
