:root { 
    --bg: #0f172a;
    --card-bg: #1e293b;
    --border: #334155;
    --accent: #22d3ee; 
    --text-main: #f8fafc; 
    --text-dim: #94a3b8; 
    --sub-card: #334155;
    --text-on-accent: #0f172a;
    --glass-blur: 0px; 
}

/* Selettori universali */
.theme-dark { 
    --bg: #000000; --card-bg: #0a0a0a; --border: #1a1a1a; --accent: #3b82f6; --text-main: #ffffff; --text-dim: #a1a1aa; --sub-card: #111111; --text-on-accent: #ffffff;
}
.theme-midnight { 
    --bg: #0f172a; --card-bg: #1e293b; --border: #334155; --accent: #22d3ee; --text-main: #f8fafc; --text-dim: #94a3b8; --sub-card: #334155; --text-on-accent: #0f172a;
}
.theme-light { 
    --bg: #f4f4f5; --card-bg: #ffffff; --border: #e4e4e7; --accent: #2563eb; --text-main: #09090b; --text-dim: #71717a; --sub-card: #fafafa; --text-on-accent: #ffffff;
}

.theme-dark input[type="date"], 
.theme-midnight input[type="date"] {
    color-scheme: dark;
}
.theme-light input[type="date"] {
    color-scheme: light;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
button, a, select { -webkit-tap-highlight-color: transparent; outline: none; }

html { 
    background-color: var(--bg) !important; 
    max-width: 100%; 
    overflow-x: hidden;
    min-height: 100vh;
}

body { 
    background-color: transparent; 
    color: var(--text-main); 
    font-family: 'Inter', sans-serif; 
    min-height: 100vh; 
    max-width: 100%; 
    overflow-x: hidden;
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    padding-right: 20px;
    padding-left: calc(20px + (100vw - 100%) + env(safe-area-inset-left)); 
}

.container { max-width: 1100px; margin: 0 auto; width: 100%; position: relative; }

/* --- HEADER & NAV --- */
header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 30px; gap: 20px; position: relative; }
.station-title { font-size: 2.5rem; font-weight: 800; letter-spacing: -2px; font-style: italic; line-height: 1; }
.coords-info { color: var(--text-dim); font-size: 11px; font-family: monospace; margin-top: 8px; text-transform: uppercase; letter-spacing: 1px; }

.main-nav { display: flex; gap: 10px; margin-top: 15px; }
.nav-btn { background: transparent; border: none; color: var(--text-dim); font-size: 11px; font-weight: 800; cursor: pointer; padding: 6px 12px; text-transform: uppercase; border-radius: 8px; transition: 0.2s; }
.nav-btn.active { background: var(--sub-card); color: var(--accent); border: 1px solid var(--border); }

.theme-switcher { display: flex; background: var(--card-bg); border: 1px solid var(--border); padding: 4px; border-radius: 14px; }
.theme-btn { padding: 6px 12px; border: none; background: transparent; color: var(--text-dim); font-size: 9px; font-weight: 800; cursor: pointer; border-radius: 10px; transition: 0.3s; text-transform: uppercase; }
.theme-btn.active { background: var(--accent); color: var(--text-on-accent) !important; }

/* --- MOBILE MENU --- */
#mobile-menu-btn { display: none; background: none; border: none; color: var(--text-main); font-size: 26px; padding: 5px; position: absolute; right: 5px; top: 5px; z-index: 101; cursor: pointer; }
#mobile-menu-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.8); z-index: 200; display: none; padding: 80px 20px 20px 20px; }
#mobile-menu-overlay.open { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.mobile-menu-content { background: var(--card-bg); border: 1px solid var(--border); border-radius: 20px; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,0.5); }
.mobile-btn { width: 100%; text-align: left; padding: 15px; margin-bottom: 8px; background: var(--sub-card); border: 1px solid transparent; color: var(--text-main); font-weight: 700; border-radius: 12px; display: flex; align-items: center; gap: 12px; font-size: 16px; }
.mobile-btn.active { background: var(--sub-card); color: var(--accent); border-color: var(--accent); }

.mobile-themes { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; justify-content: flex-start; }
.mobile-themes .theme-btn { flex: 0 1 auto; min-width: 65px; padding: 8px 12px; }

/* --- GRID & CARDS --- */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; width: 100%; }

.card { 
    background: var(--card-bg); 
    border: 1px solid var(--border); 
    border-radius: 30px; 
    padding: 22px; 
    backdrop-filter: blur(var(--glass-blur)); 
    transition: 0.3s ease; 
    width: 100%; 
    position: relative; 
    z-index: 1;         
}
.card:hover, .card:focus-within { z-index: 100; }
.grid .full-width-card { grid-column: span 4; }

/* --- MAIN WIDGETS --- */
.main-widget { grid-column: span 2; grid-row: span 2; min-height: 420px; display: flex; flex-direction: column; justify-content: space-evenly; }
.temp-badge { display: inline-flex; background: var(--sub-card); color: var(--accent); padding: 6px 16px; border-radius: 50px; font-size: 20px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; border: 1px solid var(--border); }
.temp-body-wrapper { display: flex; justify-content: space-between; align-items: center; width: 100%; margin: 10px 0; }
.temp-main-val { display: flex; align-items: flex-start; }
#temp-current { font-size: 110px; font-weight: 800; line-height: 0.75; letter-spacing: -6px; }
.temp-unit-and-second { display: flex; flex-direction: column; align-items: flex-start; margin-left: 5px; margin-top: -6px; }
.unit-accent-top { color: var(--accent); font-size: 32px; font-weight: 800; }
.second-val-box { display: flex; align-items: center; gap: 6px; font-size: 18px; font-weight: 800; color: var(--text-main); line-height: 1; }
#temp-second-box { margin-top: 32px; margin-left: 15px; }

.temp-extras-col { display: flex; flex-direction: column; gap: 12px; align-items: flex-end; }
.val-md-small { font-size: 22px; font-weight: 800; display: block; line-height: 1; }

.minmax-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.minmax-box { background: var(--sub-card); padding: 16px; border-radius: 22px; border: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.minmax-content { display: flex; justify-content: space-between; align-items: baseline; width: 100%; }

/* --- SMALL WIDGETS --- */
.split-layout { display: flex; justify-content: space-between; align-items: center; margin-top: 5px; width: 100%; }
.right-col-extras { display: flex; flex-direction: column; justify-content: center; gap: 8px; border-left: 1px solid var(--border); padding-left: 16px; margin-left: 12px; height: 70%; }
.sub-val-box { display: flex; flex-direction: column; align-items: flex-start; }
.label-xs-right { font-size: 9px; color: var(--text-dim); text-transform: uppercase; font-weight: 700; margin-bottom: 2px; }
.val-sm-right { font-size: 16px; font-weight: 700; color: var(--text-main); line-height: 1; }

.card-header { display: flex; justify-content: space-between; align-items: flex-start; width: 100%; }
#weather-icon-container { font-size: 70px !important; line-height: 1; margin-top: -5px; }
.graph-card { grid-column: span 2; height: 280px; }
.chart-header-home { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }

/* TYPOGRAPHY */
.label-xs { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--text-dim); margin-bottom: 5px; display: block; letter-spacing: 1px; }
.val-md { font-size: 26px; font-weight: 800; }
.time-xs { font-size: 11px; color: var(--text-dim); opacity: 0.6; font-family: monospace; font-weight: bold; }
.val-sm { font-size: 32px; font-weight: 800; }
.unit-inline { font-size: 12px; color: var(--accent); font-weight: 700; margin-left: 4px; }

/* WIND & ASTRO */
.wind-arrow-box { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; margin-left: 10px; }
#wind-icon { font-size: 2.2rem; color: var(--accent); transition: transform 1s ease; transform-origin: center center; }

.astro-container { display: flex; flex-direction: column; justify-content: center; gap: 10px; height: 100%; }
.astro-sun-row { display: flex; justify-content: space-between; align-items: center; padding: 2px 15px; border-radius: 18px; }
.astro-sun-item { display: flex; align-items: center; gap: 8px; }
.astro-sun-text { display: flex; flex-direction: column; line-height: 1.1; }
.astro-divider-v { width: 1px; height: 20px; background: var(--border); }
.val-astro { font-size: 14px; font-weight: 800; font-family: monospace; color: var(--text-main); }
.astro-moon-card { padding: 2px 15px; display: flex; align-items: center; }
.moon-icon-bg { width: 34px; height: 34px; background: rgba(255, 255, 255, 0.03); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.val-astro-moon { font-size: 12px; font-weight: 700; color: var(--accent);}

.status-bar { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--accent); font-weight: 700; margin-top: 12px; text-transform: uppercase; }
.pulse { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; animation: pulse-kf 2s infinite; }
@keyframes pulse-kf { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.4; transform: scale(1.2); } }
.canvas-container { height: 180px; width: 100%; margin-top: 10px; }

/* FORECAST & SLIDER */
.forecast-split-layout { display: grid; grid-template-columns: 420px minmax(0, 1fr); gap: 20px; align-items: stretch; }
.forecast-split-layout > .card { height: 100%; display: flex; flex-direction: column; }
.forecast-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; flex-grow: 1; }
.forecast-day-card { background: var(--sub-card); border: 1px solid var(--border); border-radius: 16px; padding: 10px 8px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; transition: transform 0.2s ease; }
.forecast-day-card:hover { transform: translateY(-3px); }
.forecast-date { font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); }
.forecast-icon { font-size: 26px; margin: 2px 0; filter: drop-shadow(0px 3px 4px rgba(0,0,0,0.2)); }
.forecast-temps { display: flex; justify-content: center; gap: 8px; font-weight: 800; font-size: 15px; width: 100%; }
.forecast-max { color: #f97316; }
.forecast-min { color: #3b82f6; opacity: 0.8; }
.forecast-extra { font-size: 9px; color: var(--text-main); display: flex; justify-content: space-around; width: 100%; font-weight: 600; background: var(--card-bg); padding: 4px; border-radius: 6px; border: 1px solid var(--border); }
#hourly-container { flex-grow: 1; display: flex; flex-direction: column; justify-content: center; }
.hourly-day-block { margin-bottom: 15px; min-width: 0; }
.hourly-day-title { font-size: 11px; font-weight: 700; color: var(--accent); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 1px; }
.slider-wrapper { position: relative; width: 100%; display: flex; align-items: center; gap: 10px; }
.hourly-scroll-wrapper { flex-grow: 1; width: 0; padding-bottom: 5px; overflow-x: auto; display: flex; gap: 8px; -webkit-overflow-scrolling: touch; scroll-snap-type: x mandatory; scroll-behavior: smooth; scrollbar-width: none; }
.hourly-scroll-wrapper::-webkit-scrollbar { display: none; }
.hourly-card { padding: 10px 4px; min-width: 54px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px; border-radius: 14px; scroll-snap-align: start; background: var(--sub-card); border: 1px solid var(--border); transition: transform 0.2s ease, background 0.2s ease; flex-shrink: 0; }
.h-time { font-size: 10px; font-weight: 600; color: var(--text-dim); }
.h-icon { font-size: 18px; margin: 2px 0; filter: drop-shadow(0px 2px 4px rgba(0,0,0,0.25)); }
.h-temp { font-size: 14px; font-weight: 800; color: var(--text-main); }
.slider-nav-btn { position: static; flex-shrink: 0; z-index: 2; background: var(--sub-card); border: 1px solid var(--border); color: var(--text-main); width: 32px; height: 60px; border-radius: 10px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s ease; }
.slider-nav-btn.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

/* CHARTS STYLES */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.chart-card { height: 266px; display: flex; flex-direction: column; padding: 15px 20px !important; }
.chart-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.chart-range-select { background: var(--sub-card); color: var(--text-main); border: 1px solid var(--border); padding: 4px 8px; border-radius: 8px; font-size: 11px; font-weight: 700; outline: none; cursor: pointer; }
.multi-chart-container { flex-grow: 1; position: relative; width: 100%; min-height: 0; overflow: hidden; }

/* TOOLTIP & ZENIT */
.info-wrapper { display: inline-flex; align-items: center; position: relative; margin-left: 4px; cursor: help; }
.info-icon-img { font-size: 10px; color: var(--text-dim); opacity: 0.7; transition: 0.2s; }
.tooltip-box { visibility: hidden; opacity: 0; position: absolute; bottom: 140%; left: 50%; transform: translateX(-50%); width: 160px; background: var(--sub-card); border: 1px solid var(--accent); color: var(--text-main); padding: 8px 10px; border-radius: 8px; font-size: 10px; line-height: 1.3; font-weight: 400; text-transform: none; box-shadow: 0 5px 15px rgba(0,0,0,0.3); z-index: 999; transition: all 0.2s ease-in-out; pointer-events: none; backdrop-filter: blur(10px); }
.tooltip-box::after { content: ""; position: absolute; top: 100%; left: 50%; border-width: 5px; border-style: solid; border-color: var(--accent) transparent transparent transparent; }
.info-wrapper:hover .tooltip-box { visibility: visible; opacity: 1; transform: translateX(-50%) translateY(-5px); }

.zenith-graph { width: 16px; height: 16px; border-left: 2px solid var(--text-dim); border-bottom: 2px solid var(--text-dim); position: relative; margin-left: 8px; box-sizing: border-box; }
.zenith-ray { position: absolute; bottom: -2px; left: -2px; width: 140%; height: 2px; background-color: var(--accent); transform-origin: left center; transition: transform 1s ease-out; border-radius: 2px; }

/* --- TABELLE (HILOW & ARCHIVIO) --- */
.hilow-container { padding: 0; overflow: hidden; border-radius: 30px; background: var(--card-bg); }
.hilow-table-wrapper { 
    overflow: auto; 
    width: 100%; 
    background: var(--card-bg); 
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
    
    /* FIX MOBILE SCROLLING + ZOOM */
    -webkit-overflow-scrolling: touch;
    
    /* AGGIUNTO 'pinch-zoom' per permettere l'ingrandimento con le dita */
    touch-action: pan-x pan-y pinch-zoom; 
    
    /* Impedisce solo il pull-to-refresh della pagina intera quando arrivi a fine tabella */
    overscroll-behavior: auto; 
}
.hilow-table-wrapper::-webkit-scrollbar { width: 6px; height: 6px; }
.hilow-table-wrapper::-webkit-scrollbar-track { background: transparent; }
.hilow-table-wrapper::-webkit-scrollbar-corner { background: transparent; }
.hilow-table-wrapper::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2); 
    border-radius: 10px;
    border: 1px solid transparent;
    background-clip: padding-box;
}
.hilow-table-wrapper::-webkit-scrollbar-thumb:hover { background-color: var(--accent); }

.hilow-table { width: 100%; border-collapse: separate; border-spacing: 0; }

.hilow-table th.sticky-col, 
.hilow-table td:first-child { 
    position: sticky; 
    left: 0; 
    z-index: 10; 
    background-color: var(--card-bg) !important; 
    min-width: 170px; 
    width: 170px; 
    padding-left: 20px; 
    padding-right: 15px; 
    border-bottom: 1px solid var(--border); 
}
.hilow-table th.sticky-col { z-index: 11; background-color: var(--sub-card) !important; }

/* Ombra sullo sticky */
.hilow-table th.sticky-col::after, 
.hilow-table td:first-child::after { 
    content: ""; 
    position: absolute; 
    right: -1px; 
    top: 0; 
    bottom: 0; 
    width: 1px; 
    background-color: var(--border);
    box-shadow: 2px 0 5px rgba(0,0,0,0.2);
}
.theme-light .hilow-table th.sticky-col::after,
.theme-light .hilow-table td:first-child::after {
    box-shadow: 2px 0 5px rgba(0,0,0,0.05);
}

.hilow-table th { background-color: var(--sub-card); padding: 15px 20px; color: var(--accent); text-transform: uppercase; font-size: 11px; font-weight: 800; border-bottom: 1px solid var(--border); white-space: nowrap; }
.hilow-table td { padding: 10px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.row-label {
    font-weight: 600;
    font-size: 13px;
    display: flex;
    align-items: flex-start; /* Allinea l'icona con la PRIMA riga di testo */
    gap: 10px;
    color: var(--text-main);
    /* white-space: nowrap; è stato rimosso per permettere il wrapping */
    padding-top: 4px; /* Aggiunge un po' di aria sopra per centrare meglio visivamente */
    padding-bottom: 4px;
}
.row-label i { font-size: 15px; width: 20px; text-align: center; }
.cell-content { display: flex; flex-direction: column; gap: 2px; min-width: 90px; }
.hi-val .v, .lo-val .v { font-size: 15px; font-weight: 700; line-height: 1.2; }
.hi-val .v { color: #f97316; } 
.lo-val .v { color: #3b82f6; } 
.row-rain .hi-val .v { color: #0ea5e9 !important; } 
.row-et .hi-val .v { color: #22c55e !important; }
.hi-val .t, .lo-val .t { font-size: 10px; color: var(--text-dim); opacity: 0.6; margin-top: 2px; display: block; transition: color 0.2s ease, opacity 0.2s ease; }
body.theme-light .hi-val .t, body.theme-light .lo-val .t { color: #4b5563; }
.hilow-table tr:hover td { background-color: rgba(255, 255, 255, 0.02); }
.hilow-table tr:hover .t { opacity: 1; color: var(--accent); }

/* --- WINDY & FOOTER --- */
#forecast-map-card { padding: 0 !important; overflow: hidden; min-height: 250px; max-height: 900px; transition: none; }
.resize-handle-bar { height: 30px; background: var(--sub-card); border-top: 1px solid var(--border); display: flex; justify-content: center; align-items: center; color: var(--text-dim); font-size: 16px; cursor: ns-resize; user-select: none; touch-action: none; width: 100%; z-index: 100; }
.is-dragging iframe { pointer-events: none; }

footer { margin-top: 40px; padding: 20px 0; border-top: 1px solid var(--border); display: flex; justify-content: space-between; font-size: 11px; color: var(--text-main); font-weight: 600; letter-spacing: 0.5px; }
.footer-brand { text-decoration: none; font-weight: 800; color: var(--accent); transition: opacity 0.2s ease; }
.footer-brand:hover { opacity: 0.7; }

/* TOOLTIP FIXES */
.right-col-extras .tooltip-box, #cloud-base-display .tooltip-box, .wind-arrow-box + div .tooltip-box { left: auto !important; right: 0 !important; transform: none !important; }
.right-col-extras .tooltip-box::after, #cloud-base-display .tooltip-box::after, .wind-arrow-box + div .tooltip-box::after { left: auto !important; right: 10px !important; transform: none !important; }
.split-layout > div:first-child .tooltip-box, #air-density-box .tooltip-box { left: 0 !important; right: auto !important; transform: none !important; }
.split-layout > div:first-child .tooltip-box::after, #air-density-box .tooltip-box::after { left: 10px !important; right: auto !important; transform: none !important; }

/* --- MEDIA QUERIES (MOBILE < 850PX) --- */
@media (max-width: 850px) {
    body { padding: 12px; }
    header { flex-direction: row; align-items: flex-start; }
    .station-info { width: 100%; padding-right: 20px; }
    .station-title { font-size: 1.8rem; line-height: 1; }
    .desktop-only { display: none !important; }
    #mobile-menu-btn { display: block !important; }
    
    .grid { grid-template-columns: 1fr !important; gap: 15px; }
    .main-widget, .graph-card, .card { grid-column: span 1 !important; grid-row: span 1 !important; width: 100% !important; margin-bottom: 0; }
    
    .card { padding: 16px !important; border-radius: 24px; }
    .main-widget { min-height: auto; gap: 20px; }

    #temp-current { font-size: 62px; letter-spacing: -3px; line-height: 0.8; }
    .unit-accent-top { font-size: 20px; margin-top: 4px; }
    .temp-unit-and-second { margin-left: 12px; margin-top: 2px; }
    #temp-second-box { margin-top: 6px; margin-left: 0; }
    .val-md-small { font-size: 19px; }

    .minmax-row { gap: 8px; }
    .minmax-box { padding: 12px; }
    .minmax-box .val-md { font-size: 22px; }
    .minmax-box .time-xs { font-size: 11px; opacity: 0.7; }

    .forecast-split-layout { grid-template-columns: 1fr !important; width: 100%; }
    .forecast-grid { grid-template-columns: repeat(2, 1fr) !important; }
    .charts-grid { grid-template-columns: 1fr !important; }
    .chart-card { height: 266px; margin-bottom: 0 !important; }
    .slider-nav-btn { display: none !important; }

    /* Rimuove il padding solo alle card che contengono tabelle/mappe */
    #forecast-map-card,
    .hilow-container,
    #view-tables .card {
        padding: 0 !important;
        overflow: hidden !important;
    }

    /* Aggiunge un padding interno solo alle testate delle card senza padding */
    #view-tables .card > div:first-child {
        padding: 15px 16px;
    }

    .hilow-table th.sticky-col, .hilow-table td:first-child { 
        min-width: 120px; 
        width: 120px; 
        padding-left: 15px; 
        padding-right: 10px;
    }
    .hilow-table th { padding: 12px 8px; font-size: 10px; }
    .hilow-table td { padding: 10px 8px; font-size: 11px; }
    
    .row-label { font-size: 11px; }
    .hi-val .v, .lo-val .v { font-size: 14px; }
    
    .tooltip-box { width: 140px; font-size: 9px; }
    .temp-badge { font-size: 17px; padding: 4px 12px; max-width: 160px; }
    #weather-icon-container { font-size: 60px !important; }
}

@keyframes fadeSlideUp { 0% { opacity: 0; transform: translateY(20px); } 100% { opacity: 1; transform: translateY(0); } }
