/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #1a1a2e;
    color: #e0e0e0;
}

/* ===== Back Button ===== */
.back-btn {
    position: fixed;
    top: 12px;
    right: 16px;
    left: auto;
    z-index: 1100;
    background: rgba(20, 20, 40, 0.85);
    color: #a78bfa;
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 500;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(167, 139, 250, 0.3);
    transition: background 0.2s, color 0.2s;
}
.back-btn:hover {
    background: rgba(167, 139, 250, 0.2);
    color: #c4b5fd;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    background: rgba(15, 15, 30, 0.96);
    backdrop-filter: blur(8px);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 18px 16px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: relative;
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #e0e0ff;
    letter-spacing: 0.02em;
}

.sidebar-subtitle {
    font-size: 0.78rem;
    color: #888;
    margin-top: 2px;
}

.sidebar-toggle {
    display: none;
    position: absolute;
    top: 14px;
    right: 14px;
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    color: #ccc;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.sidebar-content::-webkit-scrollbar {
    width: 4px;
}
.sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
}

.sidebar-hint {
    font-size: 0.78rem;
    color: #888;
    line-height: 1.5;
}

/* ===== Category Tree (group -> type, collapsible) ===== */
.category-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.group-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.group-btn, .category-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--cat-color, rgba(255,255,255,0.08));
    border-radius: 8px;
    padding: 9px 12px;
    cursor: pointer;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    text-align: left;
    transition: background 0.15s;
    width: 100%;
    background: color-mix(in srgb, var(--cat-color, transparent) 10%, rgba(255,255,255,0.03));
}

.group-btn:hover, .category-btn:hover {
    background: color-mix(in srgb, var(--cat-color, transparent) 20%, rgba(255,255,255,0.06));
}

.group-btn {
    font-weight: 700;
}

.type-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px 6px;
    padding-left: 14px;
}

.type-list .category-btn {
    font-weight: 500;
    font-size: 0.8rem;
    padding: 7px 8px;
    gap: 6px;
    /* Grid items default to min-width:auto (won't shrink below content's
       min-content size) -- with a nowrap label inside, that min-content
       size is the label's FULL unwrapped width, which silently defeated
       the 1fr column tracks and the label's own min-width:0/ellipsis
       below. Confirmed live: without this, each button rendered ~187px
       wide (its natural content width) inside a ~120px column instead of
       being clamped to it. */
    min-width: 0;
}

/* Two narrow columns instead of one wide row -- label needs to truncate
   rather than wrap or push the count/chevron out, and min-width:0 is
   required for a flex child to actually shrink below its content size. */
.type-list .cat-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.type-list .cat-count {
    padding: 1px 5px;
}

.group-chevron {
    color: #888;
    font-size: 0.75rem;
    width: 12px;
    flex-shrink: 0;
    text-align: center;
}

.cat-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cat-color, #ccc);
}
.cat-icon svg {
    width: 100%;
    height: 100%;
    /* fill comes from the fill="currentColor" attribute set in JS on the
       <svg> element itself, NOT here -- a CSS fill rule would win over a
       child path's own explicit fill (e.g. the hospital glyph's cutout),
       since CSS always beats SVG presentation attributes. */
}

.cat-count {
    font-size: 0.75rem;
    color: #888;
    background: rgba(255,255,255,0.06);
    padding: 1px 7px;
    border-radius: 10px;
    flex-shrink: 0;
    margin-left: auto;
}
.group-btn .cat-count {
    margin-left: 0;
}

.ai-tag {
    display: inline-block;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #a78bfa;
    background: rgba(167, 139, 250, 0.15);
    border-radius: 6px;
    padding: 1px 5px;
    vertical-align: middle;
}

/* ===== Detail View ===== */
.detail-back-btn {
    background: none;
    border: none;
    color: #a78bfa;
    font-size: 0.82rem;
    cursor: pointer;
    padding: 0 0 12px 0;
    display: block;
    transition: color 0.15s;
}
.detail-back-btn:hover {
    color: #c4b5fd;
}

.detail-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 10px;
}

.detail-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #e0e0ff;
    flex: 1;
}

.address-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.address-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    padding: 9px 12px;
    cursor: pointer;
    text-align: left;
    width: 100%;
    transition: background 0.15s;
}
.address-item:hover {
    background: rgba(255,255,255,0.09);
}

.address-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: #e0e0ff;
}

.address-detail {
    font-size: 0.75rem;
    color: #888;
}

/* ===== Result Summary ===== */
.result-summary {
    font-size: 0.78rem;
    color: #888;
    line-height: 1.5;
}

/* ===== Map ===== */
#map {
    position: fixed;
    top: 0;
    left: 280px;
    right: 0;
    bottom: 0;
    z-index: 1;
}

/* ===== POI marker badges ===== */
.poi-marker { background: none; border: none; }
.poi-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--poi-color, #888);
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    color: #fff;
    transition: transform 0.15s;
}
.poi-badge:hover { transform: scale(1.12); }
.poi-badge svg { width: 16px; height: 16px; } /* fill set via the svg's own fill="currentColor" attribute -- see .cat-icon svg comment above */

/* ===== Manual "Search This Area" trigger ===== */
.search-area-btn {
    position: fixed;
    top: 14px;
    left: calc(280px + 50%);
    transform: translateX(-50%);
    z-index: 1050;
    background: #a78bfa;
    color: #1a1a2e;
    border: none;
    border-radius: 20px;
    padding: 9px 18px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    transition: background 0.15s, transform 0.1s;
}
.search-area-btn:hover { background: #c4b5fd; }
.search-area-btn:active { transform: translateX(-50%) scale(0.96); }
.search-area-btn:disabled { opacity: 0.6; cursor: default; }

/* ===== Out-of-coverage notice ===== */
.coverage-notice {
    position: fixed;
    bottom: 28px;
    left: calc(280px + 50%);
    transform: translateX(-50%);
    z-index: 1050;
    background: rgba(15, 15, 30, 0.95);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 14px;
    padding: 14px 18px;
    max-width: 360px;
    text-align: center;
    font-size: 0.82rem;
    color: #ddd;
    box-shadow: 0 6px 24px rgba(0,0,0,0.5);
    display: none;
}
.coverage-notice.visible { display: block; }
.city-jumps {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin-top: 10px;
}
.city-jump-btn {
    background: rgba(167, 139, 250, 0.15);
    border: 1px solid rgba(167, 139, 250, 0.35);
    color: #c4b5fd;
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: background 0.15s;
}
.city-jump-btn:hover { background: rgba(167, 139, 250, 0.28); }

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 280px;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 20, 0.55);
    z-index: 1200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}
.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}
.loading-overlay p {
    color: #ddd;
    font-size: 0.9rem;
}

.spinner {
    width: 38px;
    height: 38px;
    border: 3px solid rgba(255,255,255,0.15);
    border-top-color: #a78bfa;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Leaflet popup dark theme ===== */
.leaflet-popup-content-wrapper {
    background: #1e1e3a;
    color: #e0e0e0;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.5);
}
.leaflet-popup-tip {
    background: #1e1e3a;
}
.leaflet-popup-content {
    margin: 12px 16px;
    line-height: 1.5;
}
.popup-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: #e0e0ff;
    margin-bottom: 4px;
}
.popup-category {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}
.popup-detail {
    font-size: 0.8rem;
    color: #aaa;
    margin-bottom: 2px;
}
.popup-link {
    display: inline-block;
    margin-top: 6px;
    font-size: 0.8rem;
    color: #a78bfa;
    text-decoration: none;
}
.popup-link:hover {
    text-decoration: underline;
}

/* ===== No results message ===== */
.no-results-msg {
    background: rgba(15, 15, 30, 0.92);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 0.82rem;
    color: #aaa;
    line-height: 1.5;
}

/* ===== Mobile ===== */
@media (max-width: 700px) {
    .sidebar {
        width: 100%;
        height: auto;
        bottom: 0;
        top: auto;
        border-right: none;
        border-top: 1px solid rgba(255,255,255,0.08);
        max-height: 55vh;
        transform: translateY(calc(100% - 56px));
    }

    .sidebar.open {
        transform: translateY(0);
    }

    .sidebar-toggle {
        display: flex;
        /* The site-wide share FAB sits fixed at bottom:24px/right:24px
           (z-index 9000) -- on mobile the collapsed sidebar strip is the
           bottom 56px of the viewport, so a right-14px toggle here visually
           collides with it (confirmed live). Move to the left side instead
           of fighting the FAB's z-index -- see the matching header
           padding-left below so it doesn't overlap the title text. */
        left: 14px;
        right: auto;
    }

    .sidebar-header {
        padding-left: 52px;   /* room for the toggle button now on the left */
    }

    .back-btn {
        right: 12px;
        left: auto;
        top: 10px;
    }

    #map {
        left: 0;
        bottom: 56px;
    }

    .loading-overlay {
        left: 0;
        bottom: 56px;
    }

    .coverage-notice {
        left: 50%;
        bottom: calc(56px + 16px);
        transform: translateX(-50%);
    }

    .search-area-btn {
        left: 50%;
    }
}
