/* Full-screen Map Layout */
.map-page {
    position: fixed;
    top: var(--nav-height);
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    overflow: hidden;
}

@media (max-width: 768px) {
    .map-page {
        top: calc(var(--nav-height) + env(safe-area-inset-top, 0px));
    }
}

/* 隐藏footer和tab bar避免覆盖地图控件 */
.fb-footer,
.fb-tab-bar {
    display: none !important;
}

.map-fullscreen {
    flex: 1;
    position: relative;
}

#map-main {
    width: 100%;
    height: 100%;
}

/* Left Panel */
.map-panel {
    position: absolute;
    top: 16px;
    left: 16px;
    bottom: 16px;
    width: 200px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
    pointer-events: none;
}

.map-panel > * {
    pointer-events: auto;
}

/* Search Card */
.map-search-card {
    background: var(--fb-surface);
    border-radius: var(--fb-radius-lg);
    box-shadow: 0 4px 20px rgba(31, 42, 36, 0.12);
    overflow: hidden;
}

.map-search-header {
    padding: 16px;
    border-bottom: var(--fb-border);
}

.map-search-input {
    width: 100%;
    padding: 12px 16px;
    border: var(--fb-border);
    border-radius: var(--fb-radius-pill);
    font-size: 15px;
    background: var(--fb-white);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.map-search-input:focus {
    border-color: var(--fb-blue);
    box-shadow: 0 0 0 3px rgba(58, 111, 140, 0.12);
}

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

/* Custom search suggestions dropdown */
.map-search-header {
    position: relative;
}

.map-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border-radius: 0 0 var(--fb-radius-md) var(--fb-radius-md);
    box-shadow: 0 8px 24px rgba(31, 42, 36, 0.15);
    max-height: 240px;
    overflow-y: auto;
    z-index: 10;
    display: none;
    -webkit-overflow-scrolling: touch;
}

.map-suggestions.visible {
    display: block;
}

.map-suggestion-item {
    padding: 10px 16px;
    font-size: 14px;
    color: var(--fb-ink);
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--fb-gray-100);
}

.map-suggestion-item:last-child {
    border-bottom: none;
}

.map-suggestion-item:hover,
.map-suggestion-item.highlighted {
    background: var(--fb-gray-100);
}

.map-suggestion-item .suggestion-match {
    font-weight: 700;
    color: var(--fb-blue);
}

/* Quick Filters */
.map-quick-filters {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-chip {
    padding: 6px 14px;
    border-radius: var(--fb-radius-pill);
    border: var(--fb-border);
    background: var(--fb-white);
    color: var(--fb-ink);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    box-sizing: border-box;
    text-align: left;
}

.filter-chip:hover {
    background: var(--fb-gray-100);
}

.filter-chip.active {
    background: var(--fb-ink-strong);
    color: var(--fb-white);
    border-color: transparent;
}

.filter-chip select {
    border: none;
    background: transparent;
    font-size: 13px;
    font-weight: 500;
    color: inherit;
    cursor: pointer;
    padding: 4px 4px 4px 4px;
    min-height: 32px;
    width: 100%;
}

/* Map Layers Toggle */
.map-layers-card {
    background: var(--fb-surface);
    border-radius: var(--fb-radius-lg);
    box-shadow: 0 4px 20px rgba(31, 42, 36, 0.12);
    padding: 12px 16px;
    pointer-events: auto !important;
    position: relative;
    z-index: 1001;
}

.map-layers-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--fb-gray-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.map-layer-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    pointer-events: auto !important;
    position: relative;
}

.map-layer-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--fb-ink);
    display: flex;
    align-items: center;
    gap: 8px;
}

.map-layer-label .layer-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 52px;
    height: 30px;
    display: inline-block;
    cursor: pointer;
}

.toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 2;
    margin: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--fb-gray-200);
    transition: 0.3s;
    border-radius: 999px;
    pointer-events: none;
    z-index: 1;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 24px;
    width: 24px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--fb-blue);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(22px);
}

/* Spot Detail Card */
/* ── Spot Modal Overlay (mobile backdrop) ── */
.spot-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1199;
    animation: overlayIn 0.2s ease;
}
.spot-modal-overlay.visible { display: block; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Spot Card — desktop: right-side slide-in panel ── */
.map-spot-card {
    position: fixed;
    top: calc(var(--nav-height) + 12px);
    right: -420px;                              /* starts off-screen */
    bottom: 12px;
    width: 400px;
    background: var(--fb-surface);
    border-radius: var(--fb-radius-lg);
    box-shadow: 0 8px 40px rgba(31, 42, 36, 0.18);
    overflow-y: auto;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.map-spot-card.visible {
    right: 12px;
    pointer-events: auto;
}

.spot-card-drag-handle { display: none; }

.spot-card-header {
    padding: 20px 20px 16px;
    border-bottom: var(--fb-border);
    position: sticky;
    top: 0;
    background: var(--fb-surface);
    z-index: 1;
    flex-shrink: 0;
}

.spot-card-title {
    font-size: 18px;
    font-weight: 800;
    color: var(--fb-ink-strong);
    margin-bottom: 4px;
}

.spot-card-subtitle {
    font-size: 13px;
    color: var(--fb-gray-text);
}

.spot-card-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--fb-gray-100);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.spot-card-close:hover {
    background: var(--fb-gray-200);
}

.spot-card-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.spot-index-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--fb-radius-pill);
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 12px;
}

.spot-index-badge.high {
    background: rgba(43, 124, 96, 0.15);
    color: var(--map-marker-high);
}

.spot-index-badge.mid {
    background: rgba(58, 111, 140, 0.15);
    color: var(--map-marker-mid);
}

.spot-index-badge.low {
    background: rgba(214, 165, 76, 0.15);
    color: var(--map-marker-low);
}

.spot-index-badge.poor {
    background: rgba(227, 107, 107, 0.15);
    color: var(--map-marker-poor);
}

.spot-metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
    max-height: 200px;
    overflow-y: auto;
}

.spot-metric {
    background: var(--fb-white);
    border: var(--fb-border);
    border-radius: var(--fb-radius-md);
    padding: 8px 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.spot-metric:hover {
    border-color: var(--fb-blue);
    background: rgba(58, 111, 140, 0.05);
}

.spot-metric.active {
    border-color: var(--fb-blue);
    background: rgba(58, 111, 140, 0.1);
    box-shadow: 0 0 0 2px rgba(58, 111, 140, 0.2);
}

.spot-metric-label {
    font-size: 11px;
    color: var(--fb-gray-text);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.spot-metric-value {
    font-size: 16px;
    font-weight: 800;
    color: var(--fb-ink-strong);
}

.spot-metric-unit {
    font-size: 10px;
    font-weight: 400;
    color: var(--fb-gray-text);
}

/* 数据源标签 */
.spot-data-source {
    font-size: 11px;
    color: var(--fb-gray-text);
    margin-top: 8px;
    padding: 4px 8px;
    background: var(--fb-gray-100);
    border-radius: var(--fb-radius-sm);
    display: inline-block;
}

.spot-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--fb-ink);
    margin: 16px 0 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.spot-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.spot-tag {
    padding: 4px 10px;
    border-radius: var(--fb-radius-pill);
    font-size: 12px;
    background: var(--fb-gray-100);
    color: var(--fb-ink);
}

.spot-tag.warning {
    background: rgba(244, 183, 64, 0.2);
    color: #b8860b;
}

.spot-tag.good {
    background: rgba(42, 124, 95, 0.15);
    color: var(--map-marker-high);
}

.spot-chart-container {
    margin-top: 8px;
    height: 120px;
    background: var(--fb-gray-100);
    border-radius: var(--fb-radius-md);
    padding: 8px;
}

.spot-card-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: var(--fb-border);
}

.spot-action-btn {
    flex: 1;
    padding: 12px 16px;
    border-radius: var(--fb-radius-pill);
    font-weight: 700;
    font-size: 14px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.spot-action-btn.primary {
    background: var(--fb-ink-strong);
    color: var(--fb-white);
}

.spot-action-btn.primary:hover {
    background: var(--fb-navy);
}

.spot-action-btn.secondary {
    background: var(--fb-white);
    border: var(--fb-border);
    color: var(--fb-ink);
}

.spot-action-btn.secondary:hover {
    background: var(--fb-gray-100);
}

.spot-action-btn.secondary.active {
    background: var(--fb-blue);
    border-color: transparent;
    color: var(--fb-white);
}

/* Legend Card */
.map-legend-card {
    position: absolute;
    bottom: 28px;
    left: 16px;
    background: var(--fb-surface);
    border-radius: var(--fb-radius-lg);
    box-shadow: 0 4px 20px rgba(31, 42, 36, 0.12);
    padding: 12px 16px;
    z-index: 1000;
}

.map-legend-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px 16px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--fb-ink);
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.legend-dot.high { background: var(--map-marker-high); }
.legend-dot.mid { background: var(--map-marker-mid); }
.legend-dot.low { background: var(--map-marker-low); }
.legend-dot.poor { background: var(--map-marker-poor); }

/* Map Controls */
.map-controls {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
}

.map-control-btn {
    width: 40px;
    height: 40px;
    background: var(--fb-surface);
    border: none;
    border-radius: var(--fb-radius-md);
    box-shadow: 0 2px 8px rgba(31, 42, 36, 0.12);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.map-control-btn:hover {
    background: var(--fb-gray-100);
}

.map-control-btn svg {
    width: 20px;
    height: 20px;
    color: var(--fb-ink);
}

/* Stats Bar */
.map-stats-bar {
    position: absolute;
    bottom: 32px;
    right: 16px;
    background: var(--fb-surface);
    border-radius: var(--fb-radius-lg);
    box-shadow: 0 4px 20px rgba(31, 42, 36, 0.12);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 1000;
    font-size: 13px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.stat-value {
    font-weight: 700;
    color: var(--fb-ink-strong);
}

.stat-label {
    color: var(--fb-gray-text);
}

/* Drawer handle for mobile */
.map-panel-handle {
    display: none;
}

/* Responsive - Mobile bottom drawer */
@media (max-width: 768px) {
    .map-panel {
        position: fixed;
        top: auto;
        bottom: env(safe-area-inset-bottom, 0px);
        left: 0;
        right: 0;
        width: 100%;
        max-height: 60vh;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        z-index: 1100;
        pointer-events: auto;
        background: var(--fb-surface);
        box-shadow: 0 -4px 20px rgba(31, 42, 36, 0.15);
        overflow-y: auto;
    }

    .map-panel.expanded {
        transform: translateY(0);
    }

    .map-panel-handle {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 10px 0 6px;
        cursor: pointer;
    }

    .map-panel-handle::before {
        content: "";
        width: 40px;
        height: 4px;
        background: var(--fb-gray-200);
        border-radius: 2px;
    }

    /* Hide the chevron arrow - FAB replaces it */
    .map-panel-handle::after {
        display: none;
    }

    .map-search-card {
        border-radius: 0;
        box-shadow: none;
    }

    .map-layers-card {
        border-radius: 0;
        box-shadow: none;
    }

    /* Mobile: spot card becomes a bottom sheet */
    .map-spot-card {
        top: auto;
        right: 0;
        left: 0;
        bottom: -100%;
        width: 100%;
        max-height: 75vh;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -4px 30px rgba(31, 42, 36, 0.2);
        transition: bottom 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .map-spot-card.visible {
        right: 0;
        bottom: 0;
    }

    .spot-card-drag-handle {
        display: block;
        width: 40px;
        height: 4px;
        background: var(--fb-gray-200);
        border-radius: 2px;
        margin: 10px auto 6px;
        flex-shrink: 0;
    }

    .spot-card-header {
        padding: 8px 20px 16px;
    }

    /* Show mobile overlay */
    .spot-modal-overlay { display: none; }
    .spot-modal-overlay.visible { display: block; }

    .map-legend-card {
        display: none;
    }

    .map-stats-bar {
        bottom: 64px;
        right: 8px;
        font-size: 12px;
        padding: 6px 12px;
        gap: 10px;
        z-index: 400;
    }

    /* Larger touch targets for map controls on mobile */
    .map-control-btn {
        width: 48px;
        height: 48px;
    }

    .map-control-btn svg {
        width: 24px;
        height: 24px;
    }

    /* Mobile spot card metrics: 2 columns for longer labels */
    .spot-metrics-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .spot-metric-label {
        white-space: normal;
        font-size: 12px;
    }

    .spot-metric-value {
        font-size: 15px;
    }

    /* Larger close button for spot card */
    .spot-card-close {
        width: 40px;
        height: 40px;
    }

}

/* Mobile Filter FAB */
.map-filter-fab {
    display: none;
}

@media (max-width: 768px) {
    .map-filter-fab {
        display: flex;
        align-items: center;
        gap: 6px;
        position: absolute;
        top: 12px;
        left: 12px;
        z-index: 1000;
        background: var(--fb-surface);
        border: none;
        border-radius: var(--fb-radius-pill);
        box-shadow: 0 2px 12px rgba(31, 42, 36, 0.15);
        padding: 10px 16px;
        font-size: 14px;
        font-weight: 600;
        color: var(--fb-ink);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .map-filter-fab svg {
        color: var(--fb-blue);
    }

    .map-filter-fab { animation: fabPulse 2s ease 2s 2; }
    @keyframes fabPulse { 0%,100% { box-shadow: 0 2px 12px rgba(31,42,36,0.15); } 50% { box-shadow: 0 2px 16px rgba(58,111,140,0.35); } }

    /* Hide FAB when panel is expanded */
    .map-panel.expanded ~ .map-controls ~ .map-filter-fab {
        display: none;
    }
}

/* Welcome Guide - top toast style */
.map-welcome-guide {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(47, 64, 56, 0.88);
    color: white;
    padding: 10px 20px;
    border-radius: var(--fb-radius-pill);
    font-size: 13px;
    z-index: 999;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    animation: toastAppear 0.4s ease 1s both, toastFade 0.6s ease 5.5s both;
    max-width: 420px;
    white-space: nowrap;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}
.map-welcome-guide svg { flex-shrink: 0; opacity: 0.7; width: 16px; height: 16px; }
@keyframes toastAppear { from { opacity: 0; transform: translateX(-50%) translateY(-8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes toastFade { to { opacity: 0; visibility: hidden; } }
@media (max-width: 768px) {
    .map-welcome-guide { top: 56px; font-size: 12px; padding: 8px 16px; white-space: normal; max-width: calc(100% - 100px); text-align: center; }
}

/* Loading State */
.map-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--fb-surface);
    padding: 16px 24px;
    border-radius: var(--fb-radius-lg);
    box-shadow: 0 4px 20px rgba(31, 42, 36, 0.12);
    font-size: 14px;
    color: var(--fb-ink);
    z-index: 1001;
}

/* 天地图标识样式 - 透明背景 */
.leaflet-control-attribution {
    font-size: 10px !important;
    background: transparent !important;
    color: #666 !important;
    text-shadow: 0 0 2px white, 0 0 2px white;
}
.leaflet-control-attribution a {
    color: #555 !important;
}

/* 聚合点 DOM 样式 */
.leaflet-marker-icon.cluster-dot {
    background: none !important;
    border: none !important;
}

/* 站点圆点 DOM 样式 */
.leaflet-marker-icon.station-dot {
    background: none !important;
    border: none !important;
}

/* 站点名称标签 */
.station-label {
    background: rgba(255, 255, 255, 0.9) !important;
    border: 1px solid #d1d5db !important;
    border-radius: 4px !important;
    padding: 1px 5px !important;
    font-size: 12px !important;
    color: #374151 !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
    white-space: nowrap !important;
    pointer-events: none !important;
}

