/* =============================================
   生态向量 - 长三角臭氧监测系统
   样式表
   ============================================= */

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a1f2e;
    --bg-card-hover: #222940;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #00d4ff;
    --accent2: #00b4d8;
    --accent3: #0077b6;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #1e293b;
    --shadow: 0 4px 20px rgba(0,0,0,0.3);
    --radius: 12px;
    --radius-sm: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ========== 顶部导航 ========== */
#header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo i {
    font-size: 28px;
}

.logo h1 {
    font-size: 22px;
    font-weight: 700;
    background: linear-gradient(135deg, #00d4ff, #0077b6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 8px;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 20px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #555;
    display: inline-block;
}

.status-dot.online { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.degraded { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
.status-dot.offline { background: var(--danger); }

.update-time, .data-source {
    font-size: 13px;
    color: var(--text-secondary);
}

.update-time i, .data-source i {
    margin-right: 4px;
    color: var(--accent);
}

.refresh-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}
.refresh-btn:hover {
    background: var(--bg-card-hover);
    color: var(--accent);
    border-color: var(--accent);
}
.refresh-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ========== 主内容区 ========== */
#main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ========== 地图区 ========== */
#map-section {
    flex: 1;
    position: relative;
    min-width: 0;
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* 自定义 Leaflet 样式 */
.leaflet-container {
    background: var(--bg-primary) !important;
}

.leaflet-control-zoom {
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-sm) !important;
    overflow: hidden;
}

.leaflet-control-zoom a {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border-bottom: 1px solid var(--border) !important;
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-card-hover) !important;
}

/* 地图控制浮层 */
#map-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.map-control-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

.map-btn {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: none;
    padding: 10px 12px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
}

.map-btn:hover {
    background: var(--bg-card-hover);
    color: var(--accent);
}

.map-btn.active {
    color: var(--accent);
    background: rgba(0, 212, 255, 0.1);
}

/* 图例 */
#legend {
    position: absolute;
    bottom: 30px;
    left: 20px;
    z-index: 1000;
    background: rgba(17, 24, 39, 0.9);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    backdrop-filter: blur(10px);
}

.legend-title {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.legend-gradient {
    width: 200px;
    height: 10px;
    border-radius: 4px;
    background: linear-gradient(to right,
        #00e400, #ffff00, #ff7e00, #ff0000, #99004c, #7e0023
    );
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ========== 右侧面板 ========== */
#dashboard-panel {
    width: 380px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex-shrink: 0;
}

#dashboard-panel::-webkit-scrollbar {
    width: 4px;
}

#dashboard-panel::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

#dashboard-panel::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* ========== KPI 卡片 ========== */
#kpi-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    transition: all 0.3s;
}

.kpi-card:hover {
    background: var(--bg-card-hover);
}

.kpi-card.highlight {
    border-color: var(--accent3);
    background: linear-gradient(135deg, rgba(0, 119, 182, 0.1), transparent);
}

.kpi-card.wide {
    grid-column: 1 / -1;
}

.kpi-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.kpi-value {
    font-size: 28px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.kpi-unit {
    font-size: 11px;
    color: var(--text-muted);
}

/* 预警等级颜色 */
.alert-level-normal { color: var(--success); }
.alert-level-warning { color: var(--warning); }
.alert-level-alert { color: var(--danger); }

.trend-rising { color: var(--danger); }
.trend-falling { color: var(--success); }
.trend-stable { color: var(--text-secondary); }

/* ========== 趋势图 ========== */
#chart-section {
    flex: 1;
    min-height: 0;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.section-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.section-header h3 i {
    margin-right: 6px;
    color: var(--accent);
}

.chart-controls {
    display: flex;
    gap: 4px;
}

.chart-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.chart-btn:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.chart-btn.active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
    font-weight: 600;
}

#trendChart {
    width: 100%;
    height: 200px;
}

/* ========== 站点排名 ========== */
#ranking-section {
    flex-shrink: 0;
}

#stationRanking {
    max-height: 240px;
    overflow-y: auto;
}

#stationRanking::-webkit-scrollbar {
    width: 3px;
}

#stationRanking::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.ranking-item {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    font-size: 12px;
    transition: background 0.2s;
    cursor: pointer;
}

.ranking-item:hover {
    background: var(--bg-card);
}

.ranking-rank {
    width: 20px;
    font-weight: 700;
    color: var(--text-muted);
}

.ranking-rank.top-1 { color: #ffd700; }
.ranking-rank.top-2 { color: #c0c0c0; }
.ranking-rank.top-3 { color: #cd7f32; }

.ranking-name {
    flex: 1;
    color: var(--text-primary);
}

.ranking-city {
    font-size: 10px;
    color: var(--text-muted);
    margin-left: 4px;
}

.ranking-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    min-width: 50px;
    text-align: right;
}

.ranking-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    margin: 0 8px;
    overflow: hidden;
    min-width: 40px;
}

.ranking-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s;
}

.ranking-val {
    font-weight: 700;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    min-width: 32px;
    text-align: right;
}

/* ========== 加载/空状态 ========== */
.loading {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 13px;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

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

.error-state {
    text-align: center;
    padding: 20px;
    color: var(--danger);
}

.error-state i {
    font-size: 24px;
    margin-bottom: 8px;
}

/* ========== 底部 ========== */
#footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 8px 24px;
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ========== 站点点弹窗 ========== */
.station-popup .popup-header {
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 4px;
}

.station-popup .popup-city {
    font-size: 12px;
    color: #666;
    margin-bottom: 8px;
}

.station-popup .popup-value {
    font-size: 24px;
    font-weight: 700;
}

.station-popup .popup-value .unit {
    font-size: 14px;
    font-weight: 400;
    color: #666;
}

/* ========== 站点标记 ========== */
/* ========== 站点标记（带数值） ========== */
.station-marker {
    background: none !important;
    border: none !important;
    display: flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
}

.station-marker .station-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1.5px solid rgba(255,255,255,0.8);
    box-shadow: 0 0 4px rgba(0,0,0,0.5);
    flex-shrink: 0;
}

.station-marker .station-val {
    font-size: 11px;
    font-weight: 700;
    text-shadow: 0 0 4px rgba(0,0,0,0.9), 0 0 8px rgba(0,0,0,0.6);
    line-height: 1;
    letter-spacing: 0;
}

/* ========== 响应式 ========== */
@media (max-width: 900px) {
    #dashboard-panel {
        width: 300px;
    }
    .kpi-value {
        font-size: 22px;
    }
}

@media (max-width: 700px) {
    #main-content {
        flex-direction: column;
    }
    #dashboard-panel {
        width: 100%;
        height: 50%;
        border-left: none;
        border-top: 1px solid var(--border);
    }
    .subtitle { display: none; }
    .header-info { gap: 10px; }
    .data-source { display: none; }
}
