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

:root {
    --primary: #4a90d9;
    --primary-dark: #3a7bc8;
    --primary-light: #e8f0fe;
    --secondary: #5c7cfa;
    --accent: #ff6b6b;
    --success: #34d399;
    --warning: #fbbf24;

    --bg: #f0f4f8;
    --bg-card: #ffffff;
    --bg-card-alt: #f8fafc;

    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;

    --border: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.08);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;

    --transition: all 0.25s ease;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
                 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background: var(--bg);
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--text-primary);
    overflow-x: hidden;
}

/* ==================== Header ==================== */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    padding: max(env(safe-area-inset-top), 10px) 16px 10px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    box-shadow: 0 2px 12px rgba(74, 144, 217, 0.3);
}

.location-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: white;
}

.location-icon {
    font-size: 1.1rem;
    opacity: 0.9;
}

.location-text {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.refresh-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: var(--transition);
    margin-left: 8px;
}

.refresh-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: rotate(180deg);
}

.refresh-btn:active {
    transform: rotate(360deg) scale(0.92);
}

.refresh-btn.loading i {
    animation: spin 0.8s linear infinite;
}

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

/* ==================== 加载状态 ==================== */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    opacity: 1;
    transition: opacity 0.5s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    color: var(--text-secondary);
    font-size: 0.95rem;
    letter-spacing: 0.5px;
}

/* ==================== 主内容 ==================== */
.main-content {
    padding: 12px 16px;
    padding-bottom: 80px;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ==================== 卡片通用 ==================== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    animation: fadeUp 0.5s ease forwards;
    opacity: 0;
    transform: translateY(12px);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

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

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

.card-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-header h2 i {
    color: var(--primary);
}

.update-time {
    font-size: 0.7rem;
    color: var(--text-tertiary);
}

/* ==================== 天气概览 ==================== */
.weather-overview {
    animation-delay: 0.05s;
    background: linear-gradient(135deg, #e8f0fe 0%, #f0e8fe 100%);
    border-color: rgba(74, 144, 217, 0.15);
    padding: 24px 20px 20px;
}

.weather-main {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    margin-bottom: 20px;
}

.weather-icon {
    font-size: 3.6rem;
    line-height: 1;
    flex-shrink: 0;
}

.weather-icon.sunny { color: #f59e0b; }
.weather-icon.cloudy { color: #94a3b8; }
.weather-icon.rainy { color: #3b82f6; }
.weather-icon.foggy { color: #94a3b8; }

.weather-temp-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.temperature {
    font-size: 4rem;
    font-weight: 200;
    color: var(--text-primary);
    line-height: 1;
    letter-spacing: -1px;
}

.temperature .unit {
    font-size: 1.5rem;
    font-weight: 400;
    color: var(--text-secondary);
    vertical-align: super;
}

.weather-desc {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.weather-details {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 4px;
    background: var(--bg-card-alt);
    border-radius: var(--radius-sm);
}

.detail-item i {
    font-size: 1rem;
    color: var(--primary);
    opacity: 0.7;
}

.detail-item .detail-label {
    font-size: 0.65rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.detail-item .detail-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ==================== 空气质量 ==================== */
.air-quality-card {
    animation-delay: 0.1s;
}

.aqi-display {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 18px;
}

.aqi-circle {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.aqi-value {
    font-size: 2.2rem;
    font-weight: 700;
    line-height: 1;
}

.aqi-label {
    font-size: 0.7rem;
    opacity: 0.85;
    letter-spacing: 0.3px;
}

.aqi-right {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.aqi-level {
    font-size: 1.3rem;
    font-weight: 700;
    line-height: 1.2;
}

.aqi-level-sub {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.aqi-circle.level-1 { background: linear-gradient(135deg, #22c55e, #4ade80); }
.aqi-circle.level-2 { background: linear-gradient(135deg, #eab308, #facc15); }
.aqi-circle.level-3 { background: linear-gradient(135deg, #f97316, #fb923c); }
.aqi-circle.level-4 { background: linear-gradient(135deg, #ef4444, #f87171); }
.aqi-circle.level-5 { background: linear-gradient(135deg, #a21caf, #d946ef); }
.aqi-circle.level-6 { background: linear-gradient(135deg, #881337, #dc2626); }

.level-1 { color: #16a34a; }
.level-2 { color: #ca8a04; }
.level-3 { color: #ea580c; }
.level-4 { color: #dc2626; }
.level-5 { color: #a21caf; }
.level-6 { color: #991b1b; }

.pollutants-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.pollutant-item {
    text-align: center;
    padding: 10px 4px;
    background: var(--bg-card-alt);
    border-radius: var(--radius-sm);
}

.pollutant-name {
    display: block;
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-bottom: 2px;
}

.pollutant-value {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ==================== 健康建议 ==================== */
.health-advice-card {
    animation-delay: 0.15s;
}

.advice-content {
    padding: 14px 16px;
    background: var(--bg-card-alt);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--primary);
}

.advice-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    line-height: 1.6;
}

.advice-list {
    list-style: none;
}

.advice-list li {
    padding: 5px 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    line-height: 1.5;
}

.advice-list li i {
    color: var(--success);
    font-size: 0.8rem;
    margin-top: 3px;
    flex-shrink: 0;
}

/* ==================== 预报图表 ==================== */
.forecast-chart-card {
    animation-delay: 0.2s;
}

.chart-container {
    position: relative;
    height: 200px;
}

/* ==================== 定位信息 ==================== */
.location-info-card {
    animation-delay: 0.25s;
}

.location-details {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-card-alt);
    border-radius: var(--radius-sm);
}

.info-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-tertiary);
    font-size: 0.8rem;
}

.info-label i {
    color: var(--primary);
    width: 16px;
    font-size: 0.85rem;
}

.info-value {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.85rem;
}

.server-status {
    display: flex;
    align-items: center;
    gap: 6px;
}

.server-status i {
    font-size: 0.55rem;
}

.server-status.synced i { color: var(--success); }
.server-status.pending i { color: var(--warning); }

/* ==================== 错误提示 ==================== */
.error-toast {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(-80px);
    background: #dc2626;
    color: white;
    padding: 10px 22px;
    border-radius: 100px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 20px rgba(220, 38, 38, 0.3);
    z-index: 300;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
    font-size: 0.9rem;
    white-space: nowrap;
}

.error-toast.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

/* ==================== 底部导航 ==================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: 6px 0;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 18px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: var(--transition);
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.nav-item i {
    font-size: 1.25rem;
    transition: var(--transition);
}

.nav-item span {
    font-size: 0.65rem;
    font-weight: 500;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item.active i {
    transform: scale(1.1);
}

.nav-item:active {
    transform: scale(0.92);
}

/* ==================== 响应式 ==================== */
@media screen and (max-width: 380px) {
    .temperature { font-size: 3.2rem; }
    .weather-icon { font-size: 2.8rem; }
    .weather-main { gap: 16px; }
    .weather-details { grid-template-columns: repeat(2, 1fr); }
    .pollutants-grid { grid-template-columns: repeat(2, 1fr); }
    .aqi-circle { width: 80px; height: 80px; }
    .aqi-value { font-size: 1.8rem; }
}

@media screen and (min-width: 481px) {
    .main-content {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
        max-width: 960px;
    }

    .weather-overview { grid-column: span 2; }
    .forecast-chart-card { grid-column: span 2; }
    .bottom-nav { display: none; }
    .main-content { padding-bottom: 20px; }
}

@media screen and (orientation: landscape) and (max-height: 500px) {
    .header { padding: 4px 16px; }
    .weather-icon { font-size: 2.5rem; }
    .temperature { font-size: 2.8rem; }
    .weather-main { margin-bottom: 12px; }
    .weather-details { grid-template-columns: repeat(4, 1fr); gap: 4px; }
    .detail-item { padding: 6px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
