:root {
    --primary-color: #2196f3;
    --primary-hover: #1976d2;
    --text-main: #202124;
    --text-secondary: #5f6368;
    --bg-white: rgba(255, 255, 255, 0.95);
    --bg-blur: 12px;
    --shadow-sm: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    --shadow-md: 0 4px 6px rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15);
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-pill: 999px;
    --font-family: 'Inter', 'Noto Sans SC', system-ui, -apple-system, sans-serif;
    --transition-speed: 0.3s;
}

html,
body {
    height: 100%;
    margin: 0;
    font-family: var(--font-family);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#map {
    width: 100%;
    height: 100%;
    background: #f8f9fa;
    /* Fallback color */
    z-index: 1;
}

/* =========================================
   UI Component: Search Bar
   ========================================= */
#search-container {
    position: absolute;
    top: 16px;
    left: 16px;
    /* Left aligned usually looks better on desktop map apps, or center? User had center. Let's stick to center but make it floaty */
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;

    background: var(--bg-white);
    backdrop-filter: blur(var(--bg-blur));
    -webkit-backdrop-filter: blur(var(--bg-blur));

    height: 48px;
    min-width: 320px;
    max-width: 90vw;
    padding: 0 16px;

    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 12px;
    box-sizing: border-box;
    transition: all var(--transition-speed);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#search-container:hover,
#search-container:focus-within {
    box-shadow: var(--shadow-md);
    background: #fff;
}

#search-icon {
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    font-family: var(--font-family);
    color: var(--text-main);
    background: transparent;
    height: 100%;
    line-height: 48px;
    /* Match container height */
    margin-top: 1px;
}

#search-input::placeholder {
    color: #9aa0a6;
}

#search-clear {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 8px;
    margin-right: -8px;
    display: none;
    /* Logic controlled by JS */
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

#search-clear:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-main);
}

/* Search Dropdown */
#search-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: #fff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    max-height: 320px;
    overflow-y: auto;
    display: none;
    z-index: 1001;
    padding: 8px 0;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.search-result-item {
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f1f3f4;
    transition: background-color 0.1s;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: #f8f9fa;
}

.search-result-name {
    color: var(--text-main);
    font-weight: 500;
    font-size: 15px;
}

.search-result-code {
    color: var(--text-secondary);
    font-size: 12px;
    margin-top: 2px;
}

/* =========================================
   UI Component: Info Panel
   ========================================= */
.info-panel {
    background: var(--bg-white);
    backdrop-filter: blur(var(--bg-blur));
    -webkit-backdrop-filter: blur(var(--bg-blur));

    padding: 16px 20px;
    border-radius: var(--radius-lg);
    margin-top: 80px !important;
    /* Avoid search bar */
    margin-right: 16px !important;
    box-shadow: var(--shadow-md);

    /* Adaptive Width */
    min-width: 200px;
    width: fit-content;
    max-width: 400px;

    font-size: 14px;
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.5);
    display: none;
    /* Logic controlled by JS */
    position: relative;
    animation: slideInRight 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.info-panel h3 {
    margin: 0 0 12px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    padding-bottom: 8px;
    padding-right: 24px;
}

.info-panel div {
    margin-bottom: 6px;
    line-height: 1.5;
}

.info-panel b {
    color: var(--text-secondary);
    font-weight: 500;
    margin-right: 6px;
}

.info-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 15px;
    color: var(--text-main);
}

.color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
    /* Ring effect */
}

.info-panel-close {
    position: absolute;
    top: 12px;
    right: 12px;
    cursor: pointer;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-secondary);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    line-height: 1;
    transition: all 0.2s;
}

.info-panel-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: var(--text-main);
}

/* =========================================
   UI Component: Leaflet Controls Overrides
   ========================================= */
.leaflet-control-container .leaflet-right {
    right: 16px;
}

.leaflet-control-container .leaflet-bottom {
    bottom: 24px;
}

/* =========================================
   Unified Modern Control Styles
   ========================================= */

/* Zoom Controls */
.leaflet-bar {
    border: none !important;
    box-shadow: var(--shadow-sm) !important;
    border-radius: var(--radius-md) !important;
    overflow: hidden;
}

.leaflet-bar a {
    background-color: var(--bg-white) !important;
    backdrop-filter: blur(var(--bg-blur));
    -webkit-backdrop-filter: blur(var(--bg-blur));
    color: var(--text-main) !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
    font-weight: 300;
    transition: all 0.2s ease;
    display: flex !important;
    align-items: center;
    justify-content: center;
}

.leaflet-bar a:hover {
    background-color: rgba(33, 150, 243, 0.1) !important;
    color: var(--primary-color) !important;
    transform: scale(1.05);
}

.leaflet-bar a:active {
    transform: scale(0.95);
}

.leaflet-bar a:first-child {
    border-top-left-radius: var(--radius-md) !important;
    border-top-right-radius: var(--radius-md) !important;
}

.leaflet-bar a:last-child {
    border-bottom-left-radius: var(--radius-md) !important;
    border-bottom-right-radius: var(--radius-md) !important;
    border-bottom: none !important;
}

/* Layers Control */
.leaflet-control-layers {
    border: none !important;
    box-shadow: var(--shadow-sm) !important;
    border-radius: var(--radius-md) !important;
    background: var(--bg-white) !important;
    backdrop-filter: blur(var(--bg-blur));
    -webkit-backdrop-filter: blur(var(--bg-blur));
    overflow: hidden;
}

.leaflet-control-layers-toggle {
    width: 36px !important;
    height: 36px !important;
    background-size: 18px 18px !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    /* Custom modern layers icon using SVG data URI */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23202124' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='12 2 2 7 12 12 22 7 12 2'/%3E%3Cpolyline points='2 17 12 22 22 17'/%3E%3Cpolyline points='2 12 12 17 22 12'/%3E%3C/svg%3E") !important;
    transition: all 0.2s ease;
    cursor: pointer;
}

.leaflet-control-layers-toggle:hover {
    background-color: rgba(33, 150, 243, 0.1) !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232196f3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='12 2 2 7 12 12 22 7 12 2'/%3E%3Cpolyline points='2 17 12 22 22 17'/%3E%3Cpolyline points='2 12 12 17 22 12'/%3E%3C/svg%3E") !important;
    transform: scale(1.05);
}

.leaflet-touch .leaflet-control-layers,
.leaflet-touch .leaflet-bar {
    border: none !important;
}

/* =========================================
   UI Component: Fill Toggle Control (Icon Only)
   ========================================= */
.fill-toggle-control {
    background: var(--bg-white);
    backdrop-filter: blur(var(--bg-blur));
    -webkit-backdrop-filter: blur(var(--bg-blur));
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px !important;
    user-select: none;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.fill-toggle-control:hover {
    box-shadow: var(--shadow-md);
    background: rgba(33, 150, 243, 0.1);
    transform: scale(1.05);
}

.fill-toggle-control:active {
    transform: scale(0.95);
}

/* Hide original switch elements */
.fill-toggle-control .switch-wrapper,
.fill-toggle-control .switch-text {
    display: none;
}

/* Icon button using pseudo-element */
.fill-toggle-control::before {
    content: '';
    width: 20px;
    height: 20px;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    transition: all 0.3s ease;
    /* Fill icon - filled square with border */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232196f3' stroke='%232196f3' stroke-width='2'%3E%3Crect x='3' y='3' width='18' height='18' rx='2' ry='2'/%3E%3C/svg%3E");
}

.fill-toggle-control.fill-off::before {
    /* Border only icon - empty square */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23202124' stroke-width='2'%3E%3Crect x='3' y='3' width='18' height='18' rx='2' ry='2'/%3E%3C/svg%3E");
}

/* Tooltip on hover */
.fill-toggle-control::after {
    content: attr(data-tooltip);
    position: absolute;
    right: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: rgba(33, 33, 33, 0.9);
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.fill-toggle-control:hover::after {
    opacity: 1;
    visibility: visible;
}

/* =========================================
   UI Component: Loading Overlay
   ========================================= */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 1);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(33, 150, 243, 0.2);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spinner 0.8s ease-in-out infinite;
    margin-bottom: 16px;
}

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

#loading-text {
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.5px;
}

/* =========================================
   Mobile Optimization
   ========================================= */
@media (max-width: 600px) {
    #search-container {
        top: 12px;
        width: calc(100% - 24px);
        max-width: none;
    }

    .info-panel {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        width: auto;
        max-width: none;
        margin: 0 !important;
        border-radius: 16px 16px 0 0;
        z-index: 2000;
        /* On top of logic */
        box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
    }

    .leaflet-control-container .leaflet-bottom {
        bottom: 24px;
        /* Move up slightly to avoid bottom overlap overrides if needed */
    }
}

/* 区域名称 Tooltip 样式 */
.region-tooltip {
    background: transparent;
    border: none;
    box-shadow: none;
}

.region-tooltip-content {
    background: rgba(33, 33, 33, 0.9);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    font-weight: 500;
    font-size: 14px;
    padding: 6px 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}