:root {
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --card-bg: rgba(255,255,255,0.95);
    --card-shadow: 0 10px 40px rgba(0,0,0,0.15);
    --purple-gradient: linear-gradient(135deg, #667eea, #764ba2);
    --radius: 24px;
    --tab-height: 60px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    min-height: 100dvh;
    color: #333;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

.app {
    max-width: 800px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.app-content {
    flex: 1;
    padding: 16px 16px 0;
    padding-top: max(16px, env(safe-area-inset-top, 16px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.page-header h1 {
    text-align: center; color: white; font-size: 1.5em;
    margin-bottom: 16px; text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Tab bar */
.tab-bar {
    display: flex;
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0,0,0,0.08);
    padding-bottom: var(--safe-bottom);
    position: sticky;
    bottom: 0;
    z-index: 100;
}
.tab-btn {
    flex: 1;
    background: none; border: none;
    padding: 8px 0 6px;
    font-size: 11px;
    font-weight: 600;
    color: #999;
    cursor: pointer;
    transition: color 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    line-height: 1.3;
    min-height: 56px;
}
.tab-btn .tab-icon { font-size: 24px; }
.tab-btn.active { color: #764ba2; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Search */
.search-box { display: flex; gap: 10px; margin-bottom: 16px; }
.search-box input {
    flex: 1; padding: 12px 20px; border: none; border-radius: 50px;
    font-size: 16px; background: rgba(255,255,255,0.95); outline: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.search-box input:focus { box-shadow: 0 4px 20px rgba(0,0,0,0.2); }
.search-box button {
    padding: 12px 24px; border: none; border-radius: 50px;
    background: white; color: #764ba2; font-size: 16px; font-weight: 600;
    cursor: pointer; box-shadow: 0 4px 15px rgba(0,0,0,0.1); transition: transform 0.2s;
}
.search-box button:hover { transform: scale(1.05); }

/* Current weather */
.current-weather {
    background: var(--card-bg); border-radius: var(--radius);
    padding: 24px; margin-bottom: 16px; box-shadow: var(--card-shadow);
    display: flex; align-items: center; justify-content: space-between;
}
.current-left { display: flex; flex-direction: column; }
.current-city { font-size: 1.2em; color: #666; margin-bottom: 4px; }
.current-temp {
    font-size: 3.5em; font-weight: 700; line-height: 1;
    background: var(--purple-gradient); -webkit-background-clip: text;
    -webkit-text-fill-color: transparent; background-clip: text;
}
.current-desc { font-size: 1.2em; color: #555; margin-top: 4px; }
.current-icon { display: flex; align-items: center; justify-content: center; }

.current-sun { font-size: 0.9em; color: #888; margin-top: 6px; }

.current-details {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 12px; margin-bottom: 16px;
}
.detail-item {
    text-align: center; padding: 10px;
    background: var(--card-bg); border-radius: 16px;
}
.detail-label { font-size: 0.78em; color: #999; margin-bottom: 3px; }
.detail-value { font-size: 1.1em; font-weight: 600; color: #555; }
.wind-arrow { display: inline-block; transition: transform 0.3s; }

.uv-value { font-weight: 700; display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 0.95em; }
.uv-low { background: #4caf50; color: white; }
.uv-moderate { background: #ff9800; color: white; }
.uv-high { background: #f44336; color: white; }
.uv-very-high { background: #9c27b0; color: white; }
.uv-extreme { background: #6a0dad; color: white; }

/* Forecast */
.forecast-city {
    font-size: 1.1em; color: white; text-align: center;
    margin-bottom: 12px; text-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.forecast {
    background: var(--card-bg); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--card-shadow); margin-bottom: 16px;
}
.forecast h2 { font-size: 1.1em; color: #666; margin-bottom: 12px; }
.forecast-row {
    display: flex; align-items: center; padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
}
.forecast-row:last-child { border-bottom: none; }
.forecast-date { width: 130px; min-width: 130px; font-weight: 500; color: #555; font-size: 0.88em; }
.forecast-icon { width: 44px; min-width: 44px; display: flex; align-items: center; justify-content: center; }
.forecast-desc { flex: 1; color: #777; font-size: 0.82em; padding: 0 6px; min-width: 0; }
.forecast-temps { display: flex; gap: 6px; min-width: 80px; justify-content: flex-end; }
.temp-max { font-weight: 700; color: #333; }
.temp-min { color: #aaa; }
.forecast-extra {
    display: grid; grid-template-columns: 50px 36px 60px;
    min-width: 160px; font-size: 0.78em; color: #999; text-align: right;
}
.forecast-extra2 {
    display: grid; grid-template-columns: repeat(4, auto);
    min-width: 210px; font-size: 0.78em; color: #999; text-align: right;
    gap: 6px;
}

/* Buttons */
.btn-nav {
    display: block; text-align: center; padding: 14px 28px; border: none;
    border-radius: 50px; background: rgba(255,255,255,0.95); color: #764ba2;
    font-size: 16px; font-weight: 600; cursor: pointer; margin: 16px auto;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1); transition: transform 0.2s;
    text-decoration: none; max-width: 320px;
}
.btn-nav:hover { transform: scale(1.03); }

.empty-hint {
    text-align: center; color: rgba(255,255,255,0.7);
    font-size: 0.95em; margin-bottom: 20px; padding: 20px;
}

.error {
    background: rgba(255,100,100,0.9); color: white;
    padding: 12px 20px; border-radius: 12px; margin-bottom: 12px; text-align: center;
}

/* Cards */
.card {
    background: var(--card-bg); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--card-shadow); margin-bottom: 16px;
}

/* Tables */
.history-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.88em; }
th {
    background: var(--purple-gradient); color: white;
    padding: 10px 8px; text-align: left; font-weight: 500; white-space: nowrap;
}
th:first-child { border-radius: 12px 0 0 0; }
th:last-child { border-radius: 0 12px 0 0; }
td { padding: 8px; border-bottom: 1px solid #f0f0f0; white-space: nowrap; }
tr:hover td { background: #f8f8ff; }

/* Charts */
.chart-card {
    background: var(--card-bg); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--card-shadow); margin-bottom: 16px;
}
.chart-card h2 { font-size: 1.1em; color: #666; margin-bottom: 12px; }
.chart-container { position: relative; width: 100%; max-height: 360px; }

/* Loading */
.loading { text-align: center; color: white; font-size: 1.2em; padding: 40px; }
.loading-spinner {
    display: inline-block; width: 40px; height: 40px;
    border: 4px solid rgba(255,255,255,0.3); border-top-color: white;
    border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.footer {
    text-align: center; padding: 16px 0; color: rgba(255,255,255,0.4);
    font-size: 0.75em;
}

/* Mobile: tablet */
@media (max-width: 700px) {
    .app-content { padding: 12px 12px 0; padding-top: max(12px, env(safe-area-inset-top, 12px)); }
    .page-header h1 { font-size: 1.3em; margin-bottom: 12px; }

    .current-weather { flex-direction: column; text-align: center; padding: 18px 14px; }
    .current-temp { font-size: 3em; }
    .current-desc { font-size: 1.05em; }
    .current-sun { font-size: 0.82em; }
    .weather-icon--lg svg { width: 60px; height: 60px; }
    .current-icon { margin-top: 6px; }

    .current-details { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .detail-item { padding: 10px 6px; border-radius: 12px; }
    .detail-label { font-size: 0.7em; }
    .detail-value { font-size: 0.95em; word-break: break-word; }

    .forecast { padding: 14px 10px; }
    .forecast-row { flex-wrap: wrap; align-items: center; padding: 10px 4px; gap: 2px 4px; }
    .forecast-date { width: auto; min-width: unset; font-size: 0.88em; font-weight: 600; flex-shrink: 0; }
    .forecast-icon { width: 36px; min-width: 36px; }
    .forecast-desc { flex: 1; font-size: 0.82em; padding: 0 4px; min-width: 60px; }
    .forecast-temps { min-width: unset; width: auto; }
    .forecast-extra {
        display: flex; flex-wrap: wrap; gap: 6px; min-width: unset; width: 100%;
        font-size: 0.76em; margin-top: 4px; padding-top: 4px; border-top: 1px solid #f0f0f0;
    }
    .forecast-extra2 {
        display: flex; flex-wrap: wrap; gap: 6px; min-width: unset; width: 100%;
        font-size: 0.76em; margin-top: 2px;
    }

    .card { padding: 14px 10px; }
    .chart-card { padding: 14px 10px; }
    .chart-container { max-height: 280px; }
}

/* Mobile: small phones */
@media (max-width: 420px) {
    .page-header h1 { font-size: 1.15em; margin-bottom: 10px; }

    .current-temp { font-size: 2.6em; }
    .current-city { font-size: 1em; }
    .detail-item { padding: 8px 4px; }
    .detail-label { font-size: 0.65em; }
    .detail-value { font-size: 0.85em; }

    .forecast-temps span { font-size: 0.88em; }

    table { font-size: 0.72em; }
    th, td { padding: 5px 3px; }
}