/* Festival map page. Pin/label/popup rules are global because Leaflet injects
   that DOM via JS, where Blazor's scoped CSS does not reach. */

.map-page {
    padding: 16px 24px;
}

/* On phones the layout's side padding (article.px-4 = 1.5rem) plus the page's
   own wastes width and makes the map tall and narrow. Cancel the layout padding
   and trim the page's so the map runs nearly edge-to-edge. */
@media (max-width: 640px) {
    .map-page {
        padding-left: 8px;
        padding-right: 8px;
        /* Pull the toolbar up toward the top so the event name shares the band
           with the floating hamburger, maximizing the map area below. */
        padding-top: 6px;
        margin-top: -0.5rem;
        margin-left: -1.5rem;
        margin-right: -1.5rem;
    }

    .map-canvas {
        border-radius: 0;
    }

    /* Anchor the event menu to the left so a wide menu can't spill off the left
       edge when the (now left-aligned) selector sits near the screen edge. */
    .map-event-dropdown {
        left: 0;
        transform: none;
        animation-name: mapDropdownFadeIn;
    }
}

/* Header toolbar — mirrors the Home page's filter chrome, but with map-prefixed
   class names so the globally-loaded festival-map.css can't collide with Home's
   scoped styles. */
.map-toolbar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.map-title-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    /* Reserve space on the right for the floating hamburger toggle (mobile only,
       reset on desktop where the sidebar is always visible). */
    padding-right: 3rem;
}

/* Event selector (title acts as a dropdown trigger) */
.map-event-selector {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background-color 0.15s ease;
}

.map-event-selector:hover {
    background-color: var(--bg-secondary);
}

.map-event-title-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.map-event-title {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
    line-height: 1.2;
}

.map-event-dates {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary);
    line-height: 1.2;
    margin-top: 2px;
}

.map-chevron {
    font-size: 14px;
    color: var(--text-secondary);
    transition: transform 0.2s ease;
}

.map-chevron.open {
    transform: rotate(180deg);
}

/* Controls cluster (filters dropdown + toggle buttons). It's the positioning
   context for the filters menu, so the menu right-aligns to the whole cluster
   (always on-screen) rather than to the lone filters button — which, when the
   cluster is centered on mobile, would push a wide menu off the left edge. */
.map-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    position: relative;
    flex: 0 0 auto;
}

.map-dropdown-wrapper {
    display: flex;
}

.map-icon-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    /* Match the search box height so the row's controls line up. */
    width: 32px;
    height: 32px;
    padding: 0;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-normal, 200ms) var(--easing-default, ease);
}

.map-icon-toggle:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.map-icon-toggle:active {
    transform: scale(0.95);
}

.map-icon-toggle.active {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background-color: var(--bg-tertiary);
}

.map-icon-svg {
    width: 20px;
    height: 20px;
}

/* Vegetarian leaf toggle */
.veg-toggle .toggle-leaf {
    width: 22px;
    height: 22px;
    filter: grayscale(1) opacity(0.5);
    transition: filter var(--transition-normal, 200ms) var(--easing-default, ease);
}

.veg-toggle:hover .toggle-leaf {
    filter: grayscale(0.2) opacity(0.85);
}

.veg-toggle.active {
    border-color: #4CA71E;
    background-color: rgba(76, 167, 30, 0.1);
}

.veg-toggle.active .toggle-leaf {
    filter: none;
}

/* Favorites heart toggle */
.fav-toggle .toggle-heart {
    width: 22px;
    height: 22px;
    fill: rgba(127, 127, 127, 0.4);
    transition: fill var(--transition-normal, 200ms) var(--easing-default, ease);
}

.fav-toggle:hover .toggle-heart {
    fill: rgba(239, 68, 68, 0.7);
}

.fav-toggle.active {
    border-color: #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
}

.fav-toggle.active .toggle-heart {
    fill: #ef4444;
}

/* Dropdown menu (event list + filters) */
.map-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    min-width: 180px;
    max-width: calc(100vw - 16px);
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    /* Above Leaflet's panes and controls (which reach ~1000), so the menu isn't
       hidden behind the map or its zoom buttons. */
    z-index: 1200;
    overflow: hidden;
    animation: mapDropdownFadeIn 0.15s ease-out;
}

@keyframes mapDropdownFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.map-event-dropdown {
    left: 50%;
    transform: translateX(-50%);
}

@keyframes mapDropdownFadeInCentered {
    from { opacity: 0; transform: translateX(-50%) translateY(-4px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.map-event-dropdown {
    animation-name: mapDropdownFadeInCentered;
}

.map-filters-dropdown {
    right: 0;
    min-width: 220px;
}

.map-dropdown-option {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    color: var(--text-primary);
    transition: background-color 0.1s ease;
}

.map-dropdown-option:hover {
    background-color: var(--bg-tertiary);
}

.map-dropdown-option.selected {
    background-color: var(--accent-primary);
    color: white;
}

.map-dropdown-option .option-icon {
    font-size: 13px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.map-dropdown-option .option-label {
    font-size: 14px;
    font-weight: 500;
}

.map-dropdown-section {
    padding: 8px 14px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.map-dropdown-section:not(:first-child) {
    margin-top: 4px;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
}

.map-score-slider {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px 12px;
}

.map-score-slider input[type="range"] {
    flex: 1;
    accent-color: var(--accent-primary);
}

.map-score-value {
    min-width: 30px;
    font-weight: 600;
    font-size: 13px;
    color: var(--accent-primary);
}

/* Backdrop that closes open dropdowns on outside click. Sits above the Leaflet
   controls (so a click on a zoom button closes the menu) but below the dropdown. */
.map-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1150;
}

/* Search row (always visible): search box + filter buttons share a line; the
   stall count wraps onto its own line beneath. */
.map-search-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.map-search {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 140px;
    min-width: 0;
    height: 32px;
    padding: 0 12px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.map-search:focus-within {
    border-color: var(--accent-primary);
}

.map-search-icon {
    font-size: 13px;
    opacity: 0.7;
    line-height: 1;
}

.map-search-input {
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    flex: 1;
    min-width: 0;
}

.map-search-input::placeholder {
    color: var(--text-secondary);
}

.map-search-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    border: none;
    background-color: var(--bg-tertiary);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 10px;
    transition: all 0.15s ease;
}

.map-search-clear:hover {
    background-color: var(--accent-primary);
    color: white;
}

.map-count {
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
    /* Full-width basis forces the count onto its own line beneath the search. */
    flex: 1 1 100%;
}

/* Desktop: no floating hamburger, so drop the reserved space; keep the toolbar
   from stretching the full page width. */
@media (min-width: 641px) {
    .map-title-bar {
        padding-right: 0;
    }

    .map-search-row {
        max-width: 560px;
    }
}

.map-canvas-wrapper {
    position: relative;
}

/* When the results list is showing, dock it beside the map on desktop. */
.map-canvas-wrapper.with-results {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.map-canvas-area {
    position: relative;
    flex: 1;
    min-width: 0;
}

.map-canvas {
    width: 100%;
    height: 78vh;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

/* Results list — desktop side panel (mobile bottom sheet overrides below). */
.map-results {
    flex: 0 0 280px;
    width: 280px;
    height: 78vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
}

.map-results-head {
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    flex: 0 0 auto;
}

.map-results-empty {
    padding: 16px 14px;
    font-size: 13px;
    color: var(--text-secondary);
}

.map-results-list {
    list-style: none;
    margin: 0;
    padding: 6px;
    overflow-y: auto;
    flex: 1 1 auto;
}

.map-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    background: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    color: var(--text-primary);
}

.map-result-item:hover {
    background: var(--bg-primary);
}

.map-result-pin {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 800;
    color: #fff;
}

.map-result-pin.score-good { background: #16a34a; }
.map-result-pin.score-mid { background: #f59e0b; }
.map-result-pin.score-low { background: #ef4444; }
.map-result-pin.score-none { background: #6b7280; }

.map-result-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.map-result-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-result-dish {
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Mobile: the list becomes a bottom sheet overlaying the lower part of the map. */
@media (max-width: 640px) {
    .map-canvas-wrapper.with-results {
        display: block; /* keep the map full-width; sheet overlays it */
    }

    .map-results {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        height: auto;
        max-height: 48%;
        border-radius: 14px 14px 0 0;
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.25);
        z-index: 1100; /* above Leaflet panes and controls (~1000) */
    }

    .map-results-head {
        position: relative;
        text-align: center;
        padding-top: 16px;
    }

    /* Drag-handle affordance at the top of the sheet. */
    .map-results-head::before {
        content: "";
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        border-radius: 2px;
        background: var(--border-color);
    }
}

/* Shown when the selected event has no stalls with coordinates. */
.map-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center;
    padding: 24px;
    background: var(--bg-secondary);
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.map-empty p {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.map-empty span {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Score pin (teardrop) */
.map-pin {
    width: 34px;
    height: 34px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

.map-pin-score {
    transform: rotate(45deg);
    font-size: 11px;
    font-weight: 800;
    color: #fff;
}

.map-pin.good { background: #16a34a; }
.map-pin.mid { background: #f59e0b; }
.map-pin.low { background: #ef4444; }
.map-pin.no-score { background: #6b7280; }

/* Name label beside the pin */
.leaflet-tooltip.map-label {
    background: rgba(20, 20, 20, 0.82);
    color: #fff;
    border: none;
    box-shadow: none;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 5px;
}

.leaflet-tooltip.map-label::before {
    display: none; /* hide the tooltip arrow */
}

/* Popup contents */
.map-popup-img {
    display: block;
    width: 100%;
    max-width: 220px;
    max-height: 140px;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 6px;
}

.map-popup-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.map-popup h4 {
    margin: 0;
    font-size: 15px;
}

/* "Want to try" heart in the popup. Outline by default, filled red when active. */
.map-popup-fav {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    padding: 4px;
    margin: -4px -4px 0 0;
    background: none;
    border: none;
    cursor: pointer;
    color: #b0b0b0;
    line-height: 0;
}

.map-popup-fav svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

.map-popup-fav:hover { color: #ef4444; }

.map-popup-fav.active {
    color: #ef4444;
}

.map-popup-fav.active svg {
    fill: currentColor;
    stroke: currentColor;
}

.map-popup p {
    margin: 2px 0;
    font-size: 13px;
}

.map-popup .muted { color: #888; }
.map-popup-dish { font-style: italic; }
.map-popup-score { font-weight: 700; }
.map-popup-stall { color: #666; font-size: 12px; }

.map-popup-reviews {
    margin-top: 8px;
    padding: 6px 12px;
    background: #007acc;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
}

.map-popup-reviews:hover { background: #005fa3; }
