/*
   LIVE WEATHER - EXPERT WEB TOOLS
*/

@font-face { font-family: 'Inter';       src: url('/fonts/inter-v20-latin-regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Orbitron';    src: url('/fonts/orbitron-v35-latin-700.woff2')  format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Roboto Mono'; src: url('/fonts/roboto-mono-v31-latin-regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }

:root {
    --bg-dark:          #0a0a0f;
    --primary-accent:   #3b82f6;
    --secondary-accent: #8b5cf6;
    --text-main:        #ffffff;
    --text-muted:       #94a3b8;
    --card-bg:          rgba(20, 20, 30, 0.75);
    --card-border:      rgba(255, 255, 255, 0.12);
    --input-bg:         rgba(0, 0, 0, 0.4);
    --font-heading:     'Orbitron', sans-serif;
    --font-body:        'Inter', sans-serif;
    --font-code:        'Roboto Mono', monospace;
    /* FIX #32/#41: dynamic bg via CSS custom property — set by JS, no inline style needed */
    --weather-bg-url:   none;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; max-width: 100vw; overflow-x: hidden; }

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    line-height: 1.6;
}

/* --- Accessibility --- */
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border-width: 0;
}

/* --- Dynamic Weather Background (FIX #32/#41: CSS var, not inline style) --- */
.weather-bg {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background-image: var(--weather-bg-url);
    background-size: cover; background-position: center;
    filter: brightness(0.35) blur(8px);
    transition: background-image 1s ease-in-out;
    z-index: -2;
}

.background-glow {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(to bottom, rgba(10,10,15,0.5), var(--bg-dark));
    z-index: -1; pointer-events: none;
}

/* Scrollbars */
.custom-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.custom-scroll::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 4px; }
.custom-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }
.custom-scroll::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.4); }

/* --- Header --- */
.tool-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1.5rem 5%; max-width: 1400px; margin: 0 auto; width: 100%;
    flex-wrap: wrap; gap: 8px;
}
.back-btn {
    color: var(--text-muted); text-decoration: none;
    display: flex; align-items: center; gap: 8px; transition: color 0.3s;
    border-radius: 4px; padding: 2px 4px;
}
.back-btn:hover         { color: var(--primary-accent); }
.back-btn:focus-visible { outline: 2px solid var(--primary-accent); color: var(--primary-accent); }
.logo      { font-family: var(--font-heading); font-size: 1.2rem; }
.logo span { color: var(--primary-accent); }

/* --- Main --- */
.main-content   { flex-grow: 1; padding: 1rem 5% 3rem; max-width: 900px; margin: 0 auto; width: 100%; }
.tool-container { display: flex; flex-direction: column; gap: 1.5rem; }

/* --- Cards --- */
.card {
    background: var(--card-bg); border: 1px solid var(--card-border);
    border-radius: 16px; padding: 1.5rem;
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

/* --- Controls --- */
.controls-card  { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; padding: 1.2rem 1.5rem; }
.search-row     { display: flex; gap: 10px; flex-grow: 1; max-width: 500px; flex-wrap: wrap; }
.input-group    { position: relative; flex-grow: 1; min-width: 180px; }
.location-icon  { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }

#cityInput {
    width: 100%; background: var(--input-bg); border: 1px solid var(--card-border);
    padding: 12px 12px 12px 38px; border-radius: 8px; color: #fff;
    font-size: 1rem; font-family: var(--font-body); outline: none; transition: border-color 0.2s;
    /* FIX #27: tap target */
    min-height: 44px;
}
#cityInput:focus         { border-color: var(--primary-accent); }
#cityInput:focus-visible { outline: 2px solid var(--primary-accent); }

/* FIX #24: font-family base */
button { font-family: var(--font-body); }

.primary-btn {
    background: var(--primary-accent); color: #fff; border: none; padding: 0 20px;
    border-radius: 8px; font-weight: 600; cursor: pointer; transition: background 0.2s;
    display: flex; align-items: center; gap: 8px;
    /* FIX #25 */
    min-height: 44px;
}
.primary-btn:hover         { background: #2563eb; }
.primary-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.geo-btn {
    background: rgba(255,255,255,0.05); border: 1px solid var(--card-border);
    color: var(--primary-accent); padding: 0 15px; border-radius: 8px;
    cursor: pointer; transition: background 0.2s, border-color 0.2s;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
    /* FIX #26 */
    min-height: 44px;
}
.geo-btn:hover         { background: rgba(59,130,246,0.1); border-color: var(--primary-accent); }
.geo-btn:focus-visible { outline: 2px solid var(--primary-accent); }
.geo-btn:disabled      { opacity: 0.5; cursor: not-allowed; }

/* Toggle Switch */
.settings-row  { display: flex; align-items: center; gap: 10px; font-weight: bold; color: var(--text-muted); }
.unit-label    { font-family: var(--font-heading); font-size: 1.1rem; }
.toggle-switch { position: relative; display: inline-block; width: 50px; height: 26px; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255,255,255,0.1); border: 1px solid var(--card-border);
    transition: background-color 0.3s, border-color 0.3s; border-radius: 26px;
}
.slider::before {
    position: absolute; content: ""; height: 18px; width: 18px;
    left: 3px; bottom: 3px; background-color: var(--text-muted);
    transition: transform 0.3s, background-color 0.3s; border-radius: 50%;
}
input:checked + .slider              { background-color: rgba(59,130,246,0.3); border-color: var(--primary-accent); }
input:checked + .slider::before      { transform: translateX(24px); background-color: var(--primary-accent); }
.toggle-switch:focus-within .slider  { outline: 2px solid var(--primary-accent); }

/* City Selection */
.selection-title { font-size: 1rem; color: var(--text-muted); margin-bottom: 1rem; }
.city-selection-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.city-selection-list li {
    padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--card-border);
    border-radius: 8px; cursor: pointer; transition: background 0.2s, border-color 0.2s;
    font-size: 0.95rem;
    min-height: 44px; display: flex; align-items: center;
}
.city-selection-list li:hover,
.city-selection-list li:focus-visible { background: rgba(59,130,246,0.1); border-color: var(--primary-accent); outline: none; }
.city-selection-list strong { color: #fff; font-size: 1.05rem; }
.country-code { color: var(--primary-accent); font-family: var(--font-code); font-size: 0.85rem; margin-left: 5px; }

/* Current Weather Card */
.current-header         { text-align: center; margin-bottom: 1rem; }
/* FIX #19: clamp h1 */
.current-header h1      { font-family: var(--font-heading); font-size: clamp(1.4rem, 5vw, 2.2rem); margin-bottom: 5px; }
.last-updated           { color: var(--text-muted); font-size: 0.9rem; }

.main-weather    { display: flex; align-items: center; justify-content: center; gap: 20px; margin-bottom: 2rem; flex-wrap: wrap; }
.weather-icon    { width: 130px; height: 130px; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5)); }
.temp-block      { display: flex; flex-direction: column; }
/* FIX: clamp temp size */
.temp-massive    { font-family: var(--font-heading); font-size: clamp(3rem, 10vw, 4.5rem); font-weight: 700; line-height: 1; text-shadow: 0 4px 10px rgba(0,0,0,0.3); }
.weather-desc    { font-size: 1.2rem; color: var(--primary-accent); text-transform: capitalize; font-weight: 600; margin-top: 5px; }

/* Details Grid */
.details-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 15px; }
.detail-item {
    background: rgba(0,0,0,0.25); border: 1px solid var(--card-border);
    padding: 12px 15px; border-radius: 12px; display: flex; align-items: center; gap: 15px;
}
.detail-item i       { font-size: 1.5rem; color: var(--primary-accent); width: 24px; text-align: center; flex-shrink: 0; }
.det-text            { display: flex; flex-direction: column; min-width: 0; }
.det-text span       { color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }
.det-text strong     { font-size: 1.1rem; font-family: var(--font-code); margin-top: 2px; }

/* Forecast Cards */
.forecast-card h2 {
    font-family: var(--font-heading); font-size: 1.1rem; margin-bottom: 1rem;
    border-bottom: 1px solid var(--card-border); padding-bottom: 10px;
    display: flex; align-items: center; gap: 10px;
}
.forecast-card h2 i { color: var(--primary-accent); }

.hourly-grid {
    display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: auto;
}

.hourly-item, .daily-item {
    background: rgba(0,0,0,0.2); border: 1px solid var(--card-border);
    padding: 15px; border-radius: 12px; text-align: center;
    min-width: 80px; flex-shrink: 0; transition: background 0.2s, border-color 0.2s, transform 0.2s;
    cursor: pointer;
}
.hourly-item:hover, .daily-item:hover           { background: rgba(255,255,255,0.05); border-color: var(--primary-accent); transform: translateY(-3px); }
.hourly-item:focus-visible, .daily-item:focus-visible { outline: 2px solid var(--primary-accent); transform: translateY(-3px); }
.hourly-item.selected, .daily-item.selected     { background: rgba(59,130,246,0.2); border-color: var(--primary-accent); }

.h-time, .d-day  { color: var(--text-muted); font-size: 0.9rem; font-weight: bold; margin-bottom: 5px; }
.h-icon          { width: 50px; height: 50px; margin: 0 auto; display: block; }
.h-temp, .d-temp { font-family: var(--font-code); font-size: 1.1rem; font-weight: bold; }
.d-desc          { font-size: 0.8rem; color: var(--text-muted); text-transform: capitalize; margin-top: 5px; }
/* FIX #35: tighter minmax for 360px */
.daily-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px; }

/* Skeleton Loader */
.skeleton-loader { display: flex; flex-direction: column; gap: 1.5rem; }
.skeleton {
    background: rgba(255,255,255,0.05); border-radius: 16px;
    position: relative; overflow: hidden; border: 1px solid var(--card-border);
}
.skeleton::after {
    content: ''; position: absolute; top: 0; left: -100%; width: 50%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
    animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 100% { left: 200%; } }
.s-main { height: 400px; }
.s-row  { height: 150px; }

/* Error & Utils */
.error-msg {
    background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3);
    color: #fca5a5; padding: 15px; border-radius: 12px; text-align: center;
}
.hidden { display: none !important; }

/* --- Toast (FIX #23/#40: class-based transitions) --- */
.toast {
    position: fixed; bottom: -60px; left: 50%; transform: translateX(-50%);
    background: #1e1e24; border: 1px solid var(--primary-accent);
    color: #fff; padding: 10px 20px; border-radius: 8px; z-index: 2000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5); font-size: 0.9rem;
    white-space: nowrap; opacity: 0; pointer-events: none;
    transition: opacity 0.3s, bottom 0.3s;
}
.toast.toast-visible { opacity: 1; pointer-events: auto; bottom: 20px; }
.toast.toast-error   { border-color: #ef4444; }
.toast.toast-success { border-color: #10b981; }

/* Geo button spin animation */
.fa-spin-fast { animation: spin 0.8s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* --- Info Section --- */
.info-section    { margin-top: 4rem; padding: 0 1rem; width: 100%; }
.info-section h2 { font-family: var(--font-heading); color: var(--text-main); margin-bottom: 2rem; font-size: 1.5rem; text-align: center; }
.info-grid       { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 2rem; margin-bottom: 2rem; }
.info-grid h3    { color: var(--primary-accent); font-family: var(--font-heading); font-size: 1.1rem; margin-bottom: 0.5rem; }
.info-grid i     { margin-right: 8px; }
.info-grid p     { color: var(--text-muted); font-size: 0.95rem; line-height: 1.6; }
.faq-container         { margin-top: 2rem; }
.faq-container h3      { font-family: var(--font-heading); color: var(--text-main); margin: 1.5rem 0 1rem; }
.faq-container h4      { color: var(--secondary-accent); font-size: 1rem; margin-bottom: 0.5rem; margin-top: 1.5rem; }
.faq-container p       { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 1rem; line-height: 1.6; }

/* --- Footer --- */
footer       { text-align: center; padding: 3rem 0; color: var(--text-muted); font-size: 0.9rem; border-top: 1px solid var(--card-border); margin-top: 3rem; }
footer a     { color: #fff; text-decoration: none; }
footer a:hover { color: var(--primary-accent); }

/* === RESPONSIVE === */

@media (max-width: 768px) {
    .controls-card      { flex-direction: column; align-items: stretch; }
    .search-row         { flex-wrap: wrap; max-width: 100%; }
    .settings-row       { justify-content: flex-end; }
    .current-header h1  { font-size: clamp(1.2rem, 5vw, 1.8rem); }
    .temp-massive       { font-size: clamp(2.5rem, 8vw, 3.5rem); }
    .input-group        { width: 100%; }
    .weather-icon       { width: 100px; height: 100px; }
    .daily-grid         { grid-template-columns: 1fr 1fr; }
    .geo-btn            { flex: 1; }
    .primary-btn        { flex: 3; justify-content: center; }
}

/* FIX #29: portrait 480px */
@media (max-width: 480px) {
    .main-content       { padding: 0.75rem 4% 2rem; }
    .card               { padding: 1rem; }
    .temp-massive       { font-size: clamp(2rem, 12vw, 2.8rem); }
    .weather-icon       { width: 80px; height: 80px; }
    .details-grid       { grid-template-columns: 1fr 1fr; }
    .detail-item        { padding: 10px; gap: 10px; }
    .detail-item i      { font-size: 1.2rem; }
    .det-text strong    { font-size: 1rem; }
    .search-row         { gap: 6px; }
}

@media (max-width: 360px) {
    .current-header h1  { font-size: 1.1rem; }
    .details-grid       { grid-template-columns: 1fr; }
    .daily-grid         { grid-template-columns: 1fr 1fr; }
    .tool-header        { flex-direction: column; align-items: flex-start; padding: 1rem; }
}

/* FIX #33: reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration:  0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}