:root { 
    --bg: #000000; --card-bg: #0a0a0a; --border: #1a1a1a; --accent: #3b82f6; 
    --text-main: #ffffff; --text-dim: #a1a1aa; --sub-card: #111111; 
    --text-on-accent: #ffffff;
    --glass-blur: 0px; 
}
body.theme-midnight { 
    --bg: #020617; --card-bg: #0f172a; --border: #1e293b; --accent: #22d3ee; 
    --text-main: #f8fafc; --text-dim: #94a3b8; --sub-card: #1e293b;
    --text-on-accent: #020617;
}
body.theme-light { 
    --bg: #f4f4f5; --card-bg: #ffffff; --border: #e4e4e7; --accent: #2563eb; 
    --text-main: #09090b; --text-dim: #71717a; --sub-card: #fafafa;
    --text-on-accent: #ffffff;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
button, a, select { -webkit-tap-highlight-color: transparent; outline: none; }
html, body { max-width: 100%; overflow-x: hidden; }

body { 
    background: var(--bg); 
    background-attachment: fixed; 
    color: var(--text-main); 
    font-family: 'Inter', sans-serif; 
    padding-top: 20px;
    padding-bottom: 20px;
    padding-right: 20px;
    padding-left: calc(20px + (100vw - 100%)); 
    transition: background 0.5s ease; 
    min-height: 100vh; 
}

.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); }

/* Correzione Pillole Lingua Mobile */
.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: 26px; 
    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; 
}
.temp-unit-and-second .unit-accent-top { margin: 0; line-height: 1; }
.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; 
}

@media (max-width: 850px) {
    #temp-second-box {
        margin-top: 12px; 
    }
}
.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); text-transform: capitalize; }

.status-bar { display: flex; align-items: center; gap: 8px; font-size: 10px; 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; }

/* ------------------------------------------- */
/* --- PREVISIONI E SLIDER ORARI           --- */
/* ------------------------------------------- */

.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);
}

.forecast-split-layout > .card:last-child {
    display: flex;
    flex-direction: column;
}

#hourly-container {
    flex-grow: 1; 
    display: flex;
    flex-direction: column;
    justify-content: center; 
}

.hourly-day-block {
    margin-bottom: 15px; 
    min-width: 0;
}

.hourly-day-block:last-child {
    margin-bottom: 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; 
    -ms-overflow-style: 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;
}
.hourly-card:hover { transform: translateY(-2px); background: rgba(255, 255, 255, 0.03); }

.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:hover { 
    color: var(--accent); 
    border-color: var(--accent); 
    background: var(--card-bg);
}

.slider-nav-btn.hidden { 
    opacity: 0; 
    visibility: hidden; 
    pointer-events: none; 
}

@media (max-width: 850px) {
    .slider-nav-btn { display: none !important; }
}


/* --- GRAFICI STORICI --- */
.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; }
.info-wrapper:hover .info-icon-img { color: var(--accent); opacity: 1; }
.tooltip-box { 
    visibility: hidden; 
    opacity: 0; 
    position: absolute; 
    bottom: 140%; 
    left: 50%; 
    right: auto;
    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%; 
    right: auto;
    transform: translateX(-50%);
    border-width: 5px; 
    border-style: solid; 
    border-color: var(--accent) transparent transparent transparent; 
}

.info-wrapper:hover .tooltip-box, 
.info-wrapper:focus .tooltip-box, 
.info-wrapper:active .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; }

footer { margin-top: 40px; padding: 20px 0; border-top: 1px solid var(--border); display: flex; justify-content: space-between; font-size: 9px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }

/* TRANSIZIONI VISTE */
@keyframes fadeSlideUp { 0% { opacity: 0; transform: translateY(20px); } 100% { opacity: 1; transform: translateY(0); } }
#view-home, #view-charts, #view-forecast, #view-hilow { animation: fadeSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

/* --- MEDIA QUERY (MOBILE - SOTTO 850px) --- */
@media (max-width: 850px) {
    body { padding: 15px; }
    header { flex-direction: row; align-items: flex-start; }
    .station-info { width: 100%; padding-right: 60px; }
    .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; }
    .main-widget, .graph-card, .card { grid-column: span 1 !important; grid-row: span 1 !important; width: 100% !important; margin-bottom: 0; }
    #temp-current { font-size: 75px; letter-spacing: -3px; }

    .forecast-split-layout { grid-template-columns: minmax(0, 1fr) !important; width: 100%; }
    .forecast-split-layout > .card { margin-bottom: 20px; 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; }
}

/* --- FIX FINALE OVERFLOW TOOLTIP --- */

.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;
}
.info-wrapper:hover .tooltip-box { visibility: visible; opacity: 1; }
.info-wrapper:not(.right-col-extras *):not(.split-layout > div:first-child *) .tooltip-box {
    transform: translateX(-50%) translateY(-5px);
}
.right-col-extras .info-wrapper:hover .tooltip-box,
#cloud-base-display:hover .tooltip-box,
.wind-arrow-box + div .info-wrapper:hover .tooltip-box,
.split-layout > div:first-child .info-wrapper:hover .tooltip-box,
#air-density-box:hover .tooltip-box {
    transform: translateY(-5px) !important;
}

@media (max-width: 400px) {
    .tooltip-box { width: 140px; font-size: 9px; }
}

/* --- HILOW TABLE: STILE RIFINITO E BILANCIATO --- */

.hilow-container { 
    padding: 0; 
    overflow: hidden; 
    border-radius: 30px; 
    background: var(--card-bg); 
}

.hilow-table-wrapper { 
    overflow-x: auto; 
    width: 100%; 
    background: var(--card-bg);
}

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

/* PRIMA COLONNA FISSA */
.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);
}

/* Header angolo (Analisi Storica) */
.hilow-table th.sticky-col {
    z-index: 11;
    background-color: var(--sub-card) !important;
}

/* Bordo verticale separatore */
.hilow-table th.sticky-col::after,
.hilow-table td:first-child::after {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 1px;
    background-color: var(--border);
}

.hilow-table th {
    background-color: var(--sub-card);
    padding: 15px 20px; /* Ridotto padding */
    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; /* Ridotto padding per rendere la tabella più compatta */
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

/* LABEL SENSORI (Più piccole e leggere) */
.row-label { 
    font-weight: 600; /* Meno pesante di 800 */
    font-size: 13px;  /* Dimensione standard */
    display: flex; 
    align-items: center; 
    gap: 10px; 
    white-space: nowrap;
    color: var(--text-main);
}
.row-label i { font-size: 15px; width: 20px; text-align: center; }

/* VALORI (Ridimensionati per equilibrio) */
.cell-content { display: flex; flex-direction: column; gap: 2px; min-width: 90px; }

.hi-val .v, .lo-val .v { 
    font-size: 15px; /* Ridotto da 17px */
    font-weight: 700; 
    line-height: 1.2;
}

/* COLORI RECORD */
.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; }

/* ORARI (Ripristinata evidenziatura su Hover) */
.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;
}

/* Tema Light: orari più leggibili */
body.theme-light .hi-val .t, 
body.theme-light .lo-val .t { color: #4b5563; }

/* EVIDENZIATURA SU HOVER */
.hilow-table tr:hover td { background-color: rgba(255, 255, 255, 0.02); }
.hilow-table tr:hover td:first-child { background-color: var(--card-bg) !important; }

/* L'orario diventa del colore d'accento quando passi sopra la riga */
.hilow-table tr:hover .t { 
    opacity: 1; 
    color: var(--accent); 
}

/* RESPONSIVE MOBILE */
@media (max-width: 850px) {
    .hilow-table th.sticky-col,
    .hilow-table td:first-child {
        min-width: 130px; 
        width: 130px;
        padding-left: 15px;
    }
    .row-label { font-size: 11px; }
    .hi-val .v, .lo-val .v { font-size: 14px; }
}
