/* ============ 基础样式 ============ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-q1: #22c55e;
    --color-q2: #84cc16;
    --color-q3: #eab308;
    --color-q4: #f97316;
    --color-q5: #ef4444;
    --color-q6: #7c3aed;
    --color-nodata: #9ca3af;

    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============ 顶部导航 ============ */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    height: 50px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    z-index: 1000;
}

/* 地图版权信息 - 透明背景 */
.leaflet-control-attribution {
    background: transparent !important;
    color: rgba(100, 116, 139, 0.5) !important;
    font-size: 10px !important;
}

.leaflet-control-attribution a {
    color: rgba(100, 116, 139, 0.5) !important;
}

/* 隐藏 Leaflet logo */
.leaflet-control-attribution a[href*="leaflet"] {
    display: none !important;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    text-decoration: none;
}

.header-logo-full {
    height: 40px;
    width: auto;
}

.header-slogan {
    font-size: 14px;
    font-weight: 500;
    background: linear-gradient(135deg, #0ea5e9, #3b82f6, #6366f1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 2px;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
}

.header-left .logo-link {
    font-size: 18px;
    font-weight: 600;
    text-decoration: none;
    color: var(--text-primary);
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    padding: 6px 12px;
    border-radius: 6px;
    transition: background 0.2s;
}

.nav-link:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* ============ 主容器 ============ */
.main-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ============ 左侧面板 ============ */
.sidebar {
    width: 280px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.panel {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 12px;
}

.panel h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

/* 搜索框 */
.search-panel input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    outline: none;
}

.search-panel input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.search-results {
    margin-top: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.search-result-item {
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 13px;
}

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

.search-result-item .province {
    font-size: 11px;
    color: var(--text-secondary);
}

.search-result-item .source-tag {
    font-size: 10px;
    padding: 1px 4px;
    border-radius: 3px;
    margin-left: 6px;
    font-weight: 500;
}

.source-national {
    background: #e3f2fd;
    color: #1565c0;
}

.source-provincial {
    background: #f3e5f5;
    color: #7b1fa2;
}

.source-seawater {
    background: #e0f7fa;
    color: #00838f;
}

/* 水质筛选按钮 */
.quality-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.quality-btn {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.quality-btn:hover {
    border-color: #94a3b8;
}

.quality-btn.active {
    background: var(--text-primary);
    color: white;
    border-color: var(--text-primary);
}

.quality-btn.q1 { border-left: 3px solid var(--color-q1); }
.quality-btn.q2 { border-left: 3px solid var(--color-q2); }
.quality-btn.q3 { border-left: 3px solid var(--color-q3); }
.quality-btn.q4 { border-left: 3px solid var(--color-q4); }
.quality-btn.q5 { border-left: 3px solid var(--color-q5); }
.quality-btn.q6 { border-left: 3px solid var(--color-q6); }

/* 下拉筛选 */
.filter-panel select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    background: var(--bg-primary);
    cursor: pointer;
}

/* 统计面板 */
.stats-panel .stat-item {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
}

.stats-panel .stat-item:last-child {
    border-bottom: none;
}

.stats-panel .stat-label {
    color: var(--text-secondary);
}

.stats-panel .stat-value {
    font-weight: 600;
}

.stats-panel .stat-value.small {
    font-size: 11px;
    font-weight: normal;
}

.stats-panel .stat-item.good .stat-value { color: var(--color-q2); }
.stats-panel .stat-item.warning .stat-value { color: var(--color-q4); }
.stats-panel .stat-item.danger .stat-value { color: var(--color-q5); }

/* 图例 */
.legend-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
}

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

.legend-dot.q1 { background: var(--color-q1); }
.legend-dot.q2 { background: var(--color-q2); }
.legend-dot.q3 { background: var(--color-q3); }
.legend-dot.q4 { background: var(--color-q4); }
.legend-dot.q5 { background: var(--color-q5); }
.legend-dot.q6 { background: var(--color-q6); }

/* ============ 地图 ============ */
#map {
    flex: 1;
    background: #e5e7eb;
}

/* 自定义地图标记 */
.custom-marker {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* 聚合样式 */
.marker-cluster {
    background: rgba(59, 130, 246, 0.6);
}

.marker-cluster div {
    background: rgba(59, 130, 246, 0.8);
}

/* Leaflet 弹出框样式 */
.leaflet-popup-content-wrapper {
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    padding: 0;
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 0;
    font-size: 13px;
    width: 420px !important;
    max-width: 90vw;
}

.popup-header {
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, #f8fafc 0%, #fff 100%);
    border-radius: 12px 12px 0 0;
}

.popup-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.popup-location {
    color: var(--text-secondary);
    font-size: 12px;
    margin-bottom: 0;
}

.popup-quality {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: white;
    margin: 12px 16px;
}

.popup-quality.q1 { background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%); }
.popup-quality.q2 { background: linear-gradient(135deg, #84cc16 0%, #65a30d 100%); }
.popup-quality.q3 { background: linear-gradient(135deg, #eab308 0%, #ca8a04 100%); }
.popup-quality.q4 { background: linear-gradient(135deg, #f97316 0%, #ea580c 100%); }
.popup-quality.q5 { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); }
.popup-quality.q6 { background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%); }
.popup-quality.nodata { background: linear-gradient(135deg, #9ca3af 0%, #6b7280 100%); }

/* 参数容器 */
.popup-params {
    padding: 12px 16px;
    background: #fff;
    max-height: 350px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* 参数分类标题 */
.param-category {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 12px 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
}

.param-category:first-child {
    margin-top: 0;
}

/* 参数网格 */
.param-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

/* 单个参数项 */
.popup-param {
    display: flex;
    flex-direction: column;
    padding: 8px 10px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    transition: all 0.2s;
}

.popup-param:hover {
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.popup-param .label {
    color: var(--text-secondary);
    font-size: 10px;
    margin-bottom: 2px;
}

.popup-param .value {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
}

.popup-param .unit {
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: normal;
}

/* 重金属参数特殊样式 */
.popup-param.metal {
    border-left: 3px solid #f59e0b;
}

/* 有机物参数特殊样式 */
.popup-param.organic {
    border-left: 3px solid #8b5cf6;
}

/* 海洋参数特殊样式 */
.popup-param.marine {
    border-left: 3px solid #06b6d4;
}

/* 无数据提示 */
.popup-no-data {
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    padding: 20px;
}

/* 滚动条美化 */
.popup-params::-webkit-scrollbar {
    width: 4px;
}

.popup-params::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 2px;
}

.popup-params::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 2px;
}

.popup-params::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.popup-time {
    padding: 8px 16px;
    font-size: 11px;
    color: var(--text-secondary);
    background: #f8fafc;
    text-align: center;
}

.popup-actions {
    padding: 12px 16px;
    background: #fff;
    border-radius: 0 0 12px 12px;
    text-align: center;
}

.popup-btn {
    display: inline-block;
    padding: 8px 20px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.popup-btn:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.popup-btn-predict {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
    margin-left: 8px;
}

.popup-btn-predict:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.popup-loading {
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    padding: 20px 16px;
}

.popup-detail {
    background: #fff;
}

/* ============ 模态框 ============ */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
}

.modal-content {
    position: relative;
    background: var(--bg-primary);
    margin: 5% auto;
    padding: 20px;
    width: 90%;
    max-width: 600px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-close:hover {
    color: var(--text-primary);
}

/* 参数选择器 */
.param-selector {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
    padding: 10px;
    background: var(--bg-secondary);
    border-radius: 8px;
    max-height: 160px;
    overflow-y: auto;
}

.param-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.param-group-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
    min-width: 50px;
}

.param-checkbox {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: var(--bg-primary);
    border-radius: 12px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid var(--border-color);
}

.param-checkbox:hover {
    border-color: #3b82f6;
}

.param-checkbox input {
    display: none;
}

.param-checkbox input:checked + .param-color {
    box-shadow: 0 0 0 2px #fff, 0 0 0 3px currentColor;
}

.param-checkbox:has(input:checked) {
    border-color: #3b82f6;
    background: #eff6ff;
}

.param-color {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* 历史图表容器 */
.chart-container {
    position: relative;
    height: 280px;
    width: 100%;
    margin-top: 8px;
}

#historyChart {
    width: 100% !important;
    height: 100% !important;
}

/* ============ 关于页面 ============ */
.about-page {
    flex: 1;
    overflow-y: auto;
    padding: 40px 20px;
}

.about-content {
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg-primary);
    padding: 40px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.about-content h1 {
    font-size: 28px;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
}

.about-content section {
    margin-bottom: 30px;
}

.about-content h2 {
    font-size: 18px;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.about-content p {
    line-height: 1.8;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.about-content ul {
    padding-left: 20px;
    line-height: 1.8;
    color: var(--text-secondary);
}

.about-content a {
    color: #3b82f6;
    text-decoration: none;
}

.about-content a:hover {
    text-decoration: underline;
}

/* 水质标准表格 */
.quality-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.quality-table th,
.quality-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.quality-table th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.quality-table tr.q1 td:first-child { border-left: 4px solid var(--color-q1); }
.quality-table tr.q2 td:first-child { border-left: 4px solid var(--color-q2); }
.quality-table tr.q3 td:first-child { border-left: 4px solid var(--color-q3); }
.quality-table tr.q4 td:first-child { border-left: 4px solid var(--color-q4); }
.quality-table tr.q5 td:first-child { border-left: 4px solid var(--color-q5); }
.quality-table tr.q6 td:first-child { border-left: 4px solid var(--color-q6); }

/* ============ 汉堡菜单按钮 ============ */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--text-primary);
    border-radius: 6px;
    transition: background 0.2s;
}

.sidebar-toggle:hover {
    background: var(--bg-secondary);
}

/* 侧栏遮罩 */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 50px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 998;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.open {
    display: block;
}

/* ============ 水质说明文字 ============ */
.legend-desc {
    font-size: 10px;
    color: var(--text-secondary);
    opacity: 0.7;
    margin-left: 2px;
}

/* ============ 下载按钮 ============ */
.download-btn {
    display: block;
    text-align: center;
    margin-top: 10px;
    padding: 7px 0;
    font-size: 12px;
    color: #3b82f6;
    border: 1px solid #3b82f6;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.2s;
}

.download-btn:hover {
    background: #3b82f6;
    color: #fff;
}

/* ============ 告警面板 ============ */
.alerts-panel h3::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--color-q5);
    border-radius: 50%;
    margin-right: 6px;
    animation: pulse-alert 2s infinite;
}

@keyframes pulse-alert {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.alerts-list {
    max-height: 160px;
    overflow-y: auto;
}

.alerts-loading {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    padding: 8px;
}

.alert-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 12px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

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

.alert-item:hover {
    background: rgba(59, 130, 246, 0.05);
}

.alert-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 8px;
}

.alert-quality {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    color: #fff;
    flex-shrink: 0;
}

.alert-quality.q4 { background: var(--color-q4); }
.alert-quality.q5 { background: var(--color-q5); }
.alert-quality.q6 { background: var(--color-q6); }

.alerts-empty {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    padding: 12px 0;
}

/* ============ 无障碍 ============ */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 焦点可见性 */
:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.quality-btn:focus-visible {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.4);
}

/* 色盲友好：在颜色基础上添加形状区分 */
.legend-dot.q1::after { content: ''; }
.legend-dot.q2 { border: 2px solid var(--color-q2); background: transparent; }
.legend-dot.q3 { border-radius: 2px; }
.legend-dot.q4 { border-radius: 2px; border: 2px solid var(--color-q4); background: transparent; }
.legend-dot.q5 { clip-path: polygon(50% 0%, 100% 100%, 0% 100%); border-radius: 0; }
.legend-dot.q6 { clip-path: polygon(50% 0%, 100% 100%, 0% 100%); border-radius: 0; border: none; }

/* 高对比度模式 */
@media (prefers-contrast: high) {
    .custom-marker {
        border-width: 3px;
        box-shadow: 0 0 0 1px #000;
    }

    .quality-btn {
        border-width: 2px;
    }
}

/* 减少动画 */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============ 响应式 ============ */
@media (max-width: 768px) {
    .sidebar-toggle {
        display: flex;
        align-items: center;
    }

    .sidebar {
        position: fixed;
        left: -280px;
        top: 50px;
        height: calc(100vh - 50px);
        z-index: 999;
        transition: left 0.3s ease;
        box-shadow: none;
    }

    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    .about-content {
        padding: 20px;
    }

    /* 弹窗移动端优化 */
    .leaflet-popup-content {
        width: 300px !important;
        min-width: 280px;
    }

    .param-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .modal-content {
        margin: 2% auto;
        width: 95%;
        padding: 16px;
    }
}

/* ============ 加载状态 ============ */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-secondary);
}

.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 10px;
}

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