/* ============================================
   CSS VARIABLES & THEMES
   ============================================ */
:root {
    --primary: #2563eb;
    --secondary: #1e40af;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius: 0.75rem;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --primary: #3b82f6;
    --secondary: #60a5fa;
    --bg: #0f172a;
    --card: #1e293b;
    --text: #f8fafc;
    --muted: #94a3b8;
    --border: #334155;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
}

/* ============================================
   RESET & BASE
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background 0.3s, color 0.3s;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
}

/* ============================================
   HEADER
   ============================================ */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    flex-wrap: wrap;
    gap: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: var(--shadow);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.logo p {
    font-size: 0.875rem;
    color: var(--muted);
}

.actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    font-size: 0.875rem;
}

.btn:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--secondary);
}

/* ============================================
   UNIT TOGGLE
   ============================================ */
.unit-toggle {
    display: flex;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
}

.unit-toggle button {
    padding: 0.5rem 0.75rem;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.unit-toggle button.active {
    background: var(--primary);
    color: #fff;
}

/* ============================================
   SEARCH SECTION
   ============================================ */
.search-section {
    margin: 1.5rem 0;
}

.search-wrap {
    max-width: 600px;
    margin: 0 auto;
    position: relative;
}

.search-box {
    display: flex;
    gap: 0.5rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem;
    box-shadow: var(--shadow);
}

.search-box input {
    flex: 1;
    padding: 0.75rem;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 1rem;
    outline: none;
}

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

.search-box button {
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s;
}

.search-box button:hover {
    background: var(--secondary);
}

.quick-actions {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.quick-actions button {
    padding: 0.4rem 0.9rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
    color: var(--text);
}

.quick-actions button:hover {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

/* ============================================
   AUTOCOMPLETE DROPDOWN
   ============================================ */
.dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    margin-top: 0.25rem;
    max-height: 300px;
    overflow-y: auto;
    display: none;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.dropdown.active {
    display: block;
}

.dropdown-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

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

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

.dropdown-item strong {
    display: block;
    color: var(--text);
}

.dropdown-item small {
    color: var(--muted);
    font-size: 0.875rem;
}

/* ============================================
   LOADING & ERROR STATES
   ============================================ */
.loading {
    text-align: center;
    padding: 3rem;
    display: none;
}

.loading.active {
    display: block;
}

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

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

.error {
    text-align: center;
    padding: 3rem;
    background: var(--card);
    border-radius: var(--radius);
    display: none;
    box-shadow: var(--shadow);
}

.error.active {
    display: block;
}

.error-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.error h3 {
    margin-bottom: 0.5rem;
}

.error p {
    color: var(--muted);
    margin-bottom: 1rem;
}

/* ============================================
   DASHBOARD
   ============================================ */
.dashboard {
    display: none;
}

.dashboard.active {
    display: block;
    animation: fadeIn 0.4s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   CURRENT WEATHER CARD
   ============================================ */
.current-card {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    border-radius: var(--radius);
    padding: 2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-lg);
}

.current-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.current-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
}

.current-header p {
    opacity: 0.9;
    font-size: 0.875rem;
}

.last-updated {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 0.25rem;
}

.current-main {
    display: flex;
    align-items: center;
    gap: 2rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.weather-icon {
    font-size: 5rem;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.temp-display .temp {
    font-size: 4rem;
    font-weight: 700;
    line-height: 1;
}

.temp-display .desc {
    font-size: 1.25rem;
    text-transform: capitalize;
    opacity: 0.95;
}

/* ============================================
   LIVE WEATHER METRICS
   ============================================ */
.live-metrics {
    margin-top: 1.5rem;
}

.metrics-title {
    font-size: 1rem;
    margin-bottom: 1rem;
    opacity: 0.95;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.metrics-title::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
}

.detail-item {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    padding: 1rem;
    border-radius: 0.5rem;
    text-align: center;
    transition: transform 0.2s, background 0.2s;
}

.detail-item:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.2);
}

.detail-item .label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.8;
    margin-bottom: 0.25rem;
}

.detail-item .value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    transition: all 0.3s;
}

.detail-item .value.updating {
    animation: valueUpdate 0.5s ease-in-out;
}

@keyframes valueUpdate {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); color: #fbbf24; }
    100% { transform: scale(1); }
}

.detail-item .trend {
    font-size: 0.75rem;
    opacity: 0.8;
    font-weight: 500;
}

.trend.up { color: #fca5a5; }
.trend.down { color: #86efac; }
.trend.stable { color: #fde68a; }

/* ============================================
   METRIC CARDS
   ============================================ */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.metric-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.metric-icon {
    width: 40px;
    height: 40px;
    background: var(--bg);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.metric-title {
    font-weight: 600;
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.metric-desc {
    font-size: 0.875rem;
    color: var(--muted);
}

/* ============================================
   SECTIONS
   ============================================ */
.section {
    margin-bottom: 1.5rem;
}

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

.section-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

/* ============================================
   HOURLY FORECAST
   ============================================ */
.hourly-scroll {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.hourly-scroll::-webkit-scrollbar {
    height: 6px;
}

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

.hourly-card {
    min-width: 100px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1rem;
    text-align: center;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.hourly-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.hourly-card .time {
    font-size: 0.875rem;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.hourly-card .icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.hourly-card .temp {
    font-weight: 600;
}

/* ============================================
   DAILY FORECAST
   ============================================ */
.daily-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
}

.daily-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.25rem;
    text-align: center;
    transition: transform 0.2s;
}

.daily-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.daily-card .date {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.daily-card .icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.daily-card .temps {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.daily-card .high {
    font-weight: 600;
}

.daily-card .low {
    color: var(--muted);
}

.daily-card .cond {
    font-size: 0.875rem;
    color: var(--muted);
    text-transform: capitalize;
}

/* ============================================
   TAGS & FAVORITES
   ============================================ */
.tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tag {
    padding: 0.4rem 0.9rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
    color: var(--text);
}

.tag:hover {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.fav-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
}

.fav-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1rem;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}

.fav-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.fav-remove {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    opacity: 0.6;
    color: var(--text);
}

.fav-remove:hover {
    opacity: 1;
    color: var(--danger);
}

.fav-card strong {
    display: block;
    margin-bottom: 0.25rem;
}

.fav-card p {
    color: var(--muted);
    font-size: 0.875rem;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 768px) {
    .current-main {
        flex-direction: column;
        text-align: center;
    }
    .temp-display .temp {
        font-size: 3rem;
    }
    .details-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .header {
        flex-direction: column;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .details-grid {
        grid-template-columns: 1fr;
    }
    .container {
        padding: 0.5rem;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

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

@media (prefers-contrast: high) {
    :root {
        --border: #000;
    }
    [data-theme="dark"] {
        --border: #fff;
    }
}