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

:root {
    --color-text-primary:   #ffffff;
    --color-text-secondary: rgba(255, 255, 255, 0.75);
    --color-text-muted:     rgba(255, 255, 255, 0.55);
    --color-card-bg:        rgba(255, 255, 255, 0.12);
    --color-card-border:    rgba(255, 255, 255, 0.22);
    --color-input-bg:       rgba(255, 255, 255, 0.18);
    --color-btn-bg:         rgba(255, 255, 255, 0.22);
    --color-btn-hover:      rgba(255, 255, 255, 0.32);
    --color-error-bg:       rgba(220, 38, 38, 0.85);
    --shadow-card:          0 8px 32px rgba(0, 0, 0, 0.25);
    --shadow-header:        0 2px 16px rgba(0, 0, 0, 0.2);
    --radius-card:          20px;
    --radius-sm:            10px;
    --transition:           all 0.25s ease;
}

/* ============================================================
   Dynamic Backgrounds
   ============================================================ */
body { background: linear-gradient(135deg, #1a6fc4, #56b4f5); }
body.bg-default { background: linear-gradient(135deg, #1a6fc4, #56b4f5); }
body.bg-sunny   { background: linear-gradient(135deg, #1a6fc4, #56b4f5); }
body.bg-cloudy  { background: linear-gradient(135deg, #4a5568, #718096); }
body.bg-foggy   { background: linear-gradient(135deg, #5a6478, #8fa3b1); }
body.bg-rainy   { background: linear-gradient(135deg, #2d3748, #4a6fa5); }
body.bg-snowy   { background: linear-gradient(135deg, #6b8f9e, #b8d4e3); }
body.bg-stormy  { background: linear-gradient(135deg, #1a1a2e, #4a0e8f); }
body.bg-night   { background: linear-gradient(135deg, #0d1b2a, #1b2d4a); }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: var(--color-text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background 0.6s ease;
}

/* ============================================================
   Utility
   ============================================================ */
.hidden { display: none !important; }

/* ============================================================
   Header
   ============================================================ */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 20px 32px;
    background: rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow-header);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-title {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.search-bar {
    display: flex;
    gap: 8px;
    align-items: center;
}

.search-bar input {
    padding: 10px 16px;
    font-size: 0.9rem;
    background: var(--color-input-bg);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    outline: none;
    width: 220px;
    transition: var(--transition);
}

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

.search-bar input:focus {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.25);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.15);
}

.search-bar input.input-error {
    border-color: #ff6b6b;
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.25);
}

.search-bar button,
.fav-panel-btn {
    padding: 10px 18px;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--color-btn-bg);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.search-bar button:hover,
.fav-panel-btn:hover {
    background: var(--color-btn-hover);
}

.search-bar button:active,
.fav-panel-btn:active {
    transform: scale(0.97);
}

/* ============================================================
   Map Section
   ============================================================ */
.map-section {
    animation: fadeSlideIn 0.4s ease;
}

.map-container {
    height: 340px;
    width: 100%;
    border-radius: var(--radius-card);
    overflow: hidden;
    border: 1px solid var(--color-card-border);
    box-shadow: var(--shadow-card);
}

/* ============================================================
   Favorites Container & Panel
   ============================================================ */
.fav-container {
    position: relative;
}

.fav-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 220px;
    max-width: 300px;
    background: rgba(20, 30, 50, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    z-index: 150;
    padding: 8px 0;
    animation: slideDown 0.2s ease;
}

.fav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 12px;
    gap: 8px;
}

.fav-item-load {
    flex: 1;
    background: none;
    border: none;
    color: var(--color-text-primary);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
    padding: 8px 4px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fav-item-load:hover {
    background: rgba(255, 255, 255, 0.1);
}

.fav-empty {
    padding: 16px;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    text-align: center;
}

/* ============================================================
   Star Toggle Button (on today card)
   ============================================================ */
.fav-toggle-btn {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    transition: color 0.2s ease, transform 0.15s ease;
    align-self: flex-start;
}

.fav-toggle-btn:hover {
    color: #f6c90e;
    transform: scale(1.15);
}

.fav-toggle-btn--active {
    color: #f6c90e;
}

#locate-btn {
    font-size: 1.2rem;
    padding: 8px 12px;
}

/* ============================================================
   Main layout
   ============================================================ */
.main {
    flex: 1;
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
}

/* ============================================================
   Error Banner
   ============================================================ */
.error-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--color-error-bg);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    backdrop-filter: blur(6px);
    animation: slideDown 0.25s ease;
}

.error-banner span {
    flex: 1;
}

.retry-btn {
    padding: 6px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    transition: var(--transition);
}

.retry-btn:hover { background: rgba(255, 255, 255, 0.4); }

.close-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 6px;
    transition: var(--transition);
}

.close-btn:hover { color: #fff; }

/* ============================================================
   Spinner
   ============================================================ */
.spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 48px 0;
    color: var(--color-text-secondary);
}

.spinner-ring {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: rgba(255, 255, 255, 0.85);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ============================================================
   Today Card
   ============================================================ */
.today-card {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    padding: 36px 40px;
    background: var(--color-card-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    animation: fadeSlideIn 0.4s ease;
}

.today-left {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.today-location {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--color-text-primary);
}

.today-date {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
}

.today-temp {
    font-size: clamp(4rem, 10vw, 7rem);
    font-weight: 300;
    line-height: 1;
    margin: 8px 0 4px;
    letter-spacing: -2px;
}

.today-condition {
    font-size: 1.1rem;
    color: var(--color-text-secondary);
    font-weight: 500;
}

.today-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 20px;
    flex-shrink: 0;
}

.today-icon {
    font-size: clamp(4rem, 8vw, 6.5rem);
    line-height: 1;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
}

.today-stats {
    display: flex;
    gap: 20px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    min-width: 72px;
}

.stat-value {
    font-size: 1rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================================
   Forecast Section
   ============================================================ */
.forecast-section {
    animation: fadeSlideIn 0.5s ease 0.1s both;
}

.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--color-text-secondary);
    margin-bottom: 16px;
}

.forecast-strip {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 10px;
}

.day-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 18px 10px;
    background: var(--color-card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    cursor: pointer;
    transition: var(--transition);
}

.day-card:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-3px);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.3);
}

.day-card.today-forecast {
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.2);
}

.day-name {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-secondary);
}

.day-icon {
    font-size: 1.9rem;
    line-height: 1;
}

.day-max {
    font-size: 1.05rem;
    font-weight: 700;
}

.day-min {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

.day-precip {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.day-detail-hint {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 0.3px;
    margin-top: 2px;
}

/* ============================================================
   Footer
   ============================================================ */
.footer {
    text-align: center;
    padding: 20px;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.footer a {
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
}

.footer a:hover {
    color: #fff;
    text-decoration: underline;
}

/* ============================================================
   Animations
   ============================================================ */
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

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

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
    .header { padding: 16px 20px; }
    .main { padding: 20px; }
    .today-card { padding: 28px 28px; }
    .today-stats { gap: 12px; }
}

@media (max-width: 700px) {
    .forecast-strip {
        grid-template-columns: repeat(7, 110px);
        overflow-x: auto;
        padding-bottom: 8px;
    }
}

/* ============================================================
   Hourly Modal
   ============================================================ */
.hourly-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
    padding: 20px;
}

.hourly-modal {
    background: rgba(20, 30, 50, 0.92);
    backdrop-filter: blur(20px);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-card);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
    width: 100%;
    max-width: 680px;
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.25s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 28px 16px;
    border-bottom: 1px solid var(--color-card-border);
    flex-shrink: 0;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text-primary);
}

.hourly-table-wrap {
    overflow-y: auto;
    flex: 1;
    padding: 8px 0;
}

.hourly-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.hourly-table thead th {
    position: sticky;
    top: 0;
    background: rgba(20, 30, 50, 0.98);
    padding: 10px 16px;
    text-align: left;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--color-text-muted);
    font-weight: 600;
}

.hourly-table tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    transition: background 0.15s;
}

.hourly-table tbody tr:last-child {
    border-bottom: none;
}

.hourly-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.06);
}

.hourly-table tbody tr.current-hour {
    background: rgba(255, 255, 255, 0.1);
}

.hourly-table tbody tr.current-hour td:first-child {
    font-weight: 700;
    color: var(--color-text-primary);
}

.hourly-table td {
    padding: 11px 16px;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.hourly-table td.hour-time {
    color: var(--color-text-primary);
    font-weight: 500;
    min-width: 60px;
}

.hourly-table td.hour-icon {
    font-size: 1.3rem;
    padding: 8px 12px;
}

.hourly-table td.hour-temp {
    font-weight: 700;
    color: var(--color-text-primary);
    font-size: 0.95rem;
}

.hourly-table td.hour-rain {
    color: #90cdf4;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

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

@media (max-width: 600px) {
    .header {
        flex-direction: column;
        align-items: stretch;
    }

    .search-bar {
        width: 100%;
    }

    .search-bar input {
        flex: 1;
        width: auto;
    }

    .today-card {
        flex-direction: column;
        align-items: flex-start;
        padding: 24px 22px;
    }

    .today-right {
        align-items: flex-start;
        flex-direction: row;
        align-items: center;
        width: 100%;
        justify-content: space-between;
    }

    .today-stats {
        flex-wrap: wrap;
        gap: 8px;
    }

    .stat {
        min-width: 64px;
    }

    .fav-panel {
        left: auto;
        right: 0;
    }
}
