/* ===== CSS Variables - Dark Theme ===== */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-card: #1c2333;
    --bg-hover: #252d3a;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent-green: #00da3c;
    --accent-red: #ec0000;
    --accent-blue: #58a6ff;
    --accent-yellow: #f0b429;
    --border-color: #30363d;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --transition: all 0.2s ease;
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

a {
    color: var(--accent-blue);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button {
    cursor: pointer;
    border: none;
    outline: none;
    font-family: inherit;
}

/* ===== App Layout ===== */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ===== Header ===== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

.logo span {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-green));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
}

.header-right {
    flex-shrink: 0;
}

/* ===== Search ===== */
/* ===== Search Bar ===== */
.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-map {
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 18px;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
}

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

.search-container {
    position: relative;
    width: 280px;
}

.search-container input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    transition: var(--transition);
}

.search-container input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

.search-container input::placeholder {
    color: var(--text-muted);
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    pointer-events: none;
}

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    list-style: none;
    max-height: 240px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.search-results.visible {
    display: block;
}

.search-results li {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.search-results li:last-child {
    border-bottom: none;
}

.search-results li:hover {
    background: var(--bg-hover);
}

.search-results li .city-name-item {
    color: var(--text-primary);
    font-weight: 500;
}

.search-results li .city-detail {
    color: var(--text-muted);
    font-size: 12px;
    margin-left: 6px;
}

.search-results li .no-result {
    color: var(--text-muted);
    text-align: center;
    padding: 8px;
}

/* ===== City Info Bar ===== */
/* ===== Weather Info Bar ===== */
.weather-info-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.weather-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.city-name {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.city-country {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-card);
    padding: 2px 8px;
    border-radius: 4px;
}

.weather-icon {
    font-size: 22px;
    margin-left: 4px;
}

.weather-desc {
    font-size: 14px;
    color: var(--text-secondary);
}

.weather-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.weather-main {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.current-temp {
    font-size: 26px;
    font-weight: 700;
    color: var(--accent-yellow);
}

.feels-like {
    font-size: 13px;
    color: var(--text-muted);
}

.weather-details {
    display: flex;
    gap: 14px;
    font-size: 13px;
    color: var(--text-secondary);
}

/* ===== Mode Toggle ===== */
.controls {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.mode-toggle {
    display: flex;
    gap: 4px;
    background: var(--bg-card);
    padding: 4px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.mode-btn {
    padding: 6px 16px;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 6px;
    font-size: 13px;
    transition: var(--transition);
}

.mode-btn:hover {
    color: var(--text-primary);
}

.mode-btn.active {
    background: var(--accent-blue);
    color: #fff;
    font-weight: 500;
}

/* ===== Historical Date Picker ===== */
.historical-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.historical-picker label {
    color: var(--text-muted);
}

.historical-picker input[type="date"] {
    padding: 5px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
}

.historical-picker input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.7);
    cursor: pointer;
}

.btn-load-history {
    padding: 5px 14px;
    background: var(--accent-blue);
    color: #fff;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
}

.btn-load-history:hover {
    opacity: 0.85;
}

.legend {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-secondary);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.legend-up,
.legend-down {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.legend-up {
    background: var(--accent-red);
}

.legend-down {
    background: var(--accent-green);
}

/* ===== Chart ===== */
.chart-container {
    flex: 1;
    min-height: 0;
    padding: 8px 0;
}

#chart {
    width: 100%;
    height: 100%;
    min-height: 350px;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    font-size: 14px;
    z-index: 2000;
    transition: transform 0.3s ease;
    max-width: 400px;
    text-align: center;
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
}

.toast.error {
    border-color: var(--accent-red);
    color: var(--accent-red);
}

/* ===== Footer ===== */
.footer {
    padding: 8px 0;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.separator {
    margin: 0 8px;
    color: var(--border-color);
}

/* ===== Loading Overlay ===== */
.chart-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(13, 17, 23, 0.7);
    z-index: 100;
    border-radius: var(--radius);
}

.chart-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

    .search-bar {
        width: 100%;
    }

    .search-container {
        width: 100%;
    }

    .weather-info-bar {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

    .weather-right {
        width: 100%;
        justify-content: space-between;
    }

    .city-name {
        font-size: 18px;
    }

    .current-temp {
        font-size: 20px;
    }

    .controls {
        flex-direction: column;
        align-items: flex-start;
    }

    .historical-picker {
        flex-wrap: wrap;
    }

    .legend {
        display: none;
    }

    #chart {
        min-height: 300px;
    }
}

@media (max-width: 480px) {
    .app {
        padding: 0 8px;
    }

    .header-left {
        flex-direction: column;
        gap: 2px;
    }

    .subtitle {
        font-size: 11px;
    }

    .mode-btn {
        padding: 5px 12px;
        font-size: 12px;
    }

    .search-container {
        width: 200px;
    }

    .map-panel {
        width: 95vw;
        height: 85vh;
    }
}

/* Hide Leaflet attribution */
.leaflet-control-attribution {
    display: none !important;
}

/* ===== Map Overlay ===== */
.map-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 3000;
    justify-content: center;
    align-items: center;
}

.map-overlay.visible {
    display: flex;
}

.map-panel {
    width: 80vw;
    max-width: 900px;
    height: 70vh;
    max-height: 600px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.map-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    flex-shrink: 0;
}

.btn-map-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

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

#map-container {
    flex: 1;
    min-height: 0;
}

.map-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.map-coords {
    font-size: 13px;
    color: var(--text-secondary);
    font-family: monospace;
}

.btn-map-confirm {
    padding: 6px 20px;
    background: var(--accent-blue);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-map-confirm:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-map-confirm:not(:disabled):hover {
    opacity: 0.85;
}
