/* --- BASIS UND TYPOGRAPHIE --- */
body {
    font-family: 'Inter', sans-serif;
    color: #333;
    background-color: #f4f7f6;
    margin: 0;
    padding: 20px;
    transition: background-color 0.3s, color 0.3s;
    line-height: 1.6;
}

h1 {
    text-align: center;
    color: #007bff;
    margin-bottom: 25px;
    font-weight: 800;
    font-size: 2.5em;
}

h2 {
    color: #1a1a1a;
    font-size: 1.5em;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 8px;
    margin-top: 0;
    margin-bottom: 15px;
}

h3 {
    color: #007bff;
    font-size: 1.1em;
    margin-top: 20px;
    margin-bottom: 10px;
}

/* --- GRID LAYOUT --- */
.main-grid {
    display: grid;
    gap: 20px; /* Standard-Abstand zwischen den Blöcken */
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

/* 3-spaltiges Layout für Desktop */
.three-col-layout {
    grid-template-columns: 2fr 1fr; /* Zwei Spalten: Sensordaten (2/3) + Wetter (1/3) */
    /* Original-Rows, die sich an der linken Spalte orientieren */
    grid-template-rows: auto auto auto; 
    /* Originale Grid-Areas */
    grid-template-areas: 
        "grid-area-sensors grid-area-current"
        "grid-area-sensors grid-area-forecast"
        "grid-area-longterm grid-area-longterm"
        "grid-area-webcams grid-area-webcams";
}

/* --- DATEN CONTAINER STYLING --- */
.data-container {
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    padding: 20px;
    margin-bottom: 0; /* Das Grid managed den Abstand */
}

/* WICHTIGE KORREKTUR FÜR DIE LANGZEITGRAPHEN BOX */
.grid-area-longterm { 
    grid-area: grid-area-longterm; 
    /* Verhindert horizontales Überlaufen des Inhalts (falls das Bild zu breit ist) */
    overflow-x: hidden; 
}


.grid-area-sensors { grid-area: grid-area-sensors; }
.grid-area-current { 
    grid-area: grid-area-current; 
    /* Stellt sicher, dass die Box nicht unnötig gestreckt wird */
    align-self: start; 
}
.grid-area-forecast { 
    grid-area: grid-area-forecast; 
    /* Stellt sicher, dass die Box nicht unnötig gestreckt wird */
    align-self: start;
}

.grid-area-webcams { grid-area: grid-area-webcams; }

/* --- SPEZIFISCHE INHALTS-STYLING --- */

/* Wir entfernen das Styling für .summary-section .data-point, da es jetzt die kompakte Ansicht nutzt */
.summary-section .data-point {
    /*display: flex; -> Entfernt, wird jetzt durch compact-data-row verwaltet */
    /*justify-content: space-between; -> Entfernt */
    margin: 5px 0;
    font-size: 1.1em;
    /*padding-bottom: 3px; -> Entfernt */
    /*border-bottom: 1px dotted #eee; -> Entfernt */
}

/* Der Bereich der vergrößerten Werte */
.summary-section strong {
    font-weight: 700;
}

/* WICHTIGE KORREKTUR FÜR GRAPHEN: Beseitigt das Überlaufen aus der Box */
.graph-section img {
    /* Stellt sicher, dass die Breite auf den Inhalt passt und nicht über das Elternelement-Padding hinausragt */
    width: 100%; 
    max-width: 100%; 
    height: auto;
    
    /* NEU: Wichtig. Entfernt jeglichen horizontalen Margin, der zum Überlaufen führen könnte. */
    margin-left: 0;
    margin-right: 0;
    /* Der vertikale Margin wird beibehalten oder unten neu gesetzt */
    margin-bottom: 15px; 
    margin-top: 0; 
    
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.graph-section img:hover {
    opacity: 0.9;
}

.current-weather-box {
    text-align: center;
}

.current-weather-icon {
    width: 100px;
    height: 100px;
    margin: 10px 0;
}

/* FORECAST GRID - Ein einfaches flexibles Layout für die Tagesvorschau */
.forecast-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
}

.day-forecast-box {
    flex-grow: 1;
    min-width: 150px;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px;
    background-color: #fcfcfc;
}

.day-forecast-box h3 {
    margin-top: 0;
    padding-bottom: 5px;
    border-bottom: 1px solid #eee;
}

.hourly-details p {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9em;
    margin: 3px 0;
}

.day-icon {
    width: 25px;
    height: 25px;
    margin: 0 5px;
}

/* --- STEUERELEMENTE / BUTTONS --- */
.controls {
    text-align: center;
    margin-bottom: 20px;
}

.toggle-button {
    background-color: #28a745;
    color: white;
    border: none;
    padding: 8px 15px;
    margin: 0 5px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s, box-shadow 0.2s;
}

.toggle-button:hover {
    background-color: #218838;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* --- MODAL (ZOOM) STYLING --- */
.modal {
    display: none; /* Versteckt das Modal standardmäßig */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.9); /* Schwarzer Hintergrund mit Transparenz */
    align-items: center;
    justify-content: center;
}

.modal-content {
    margin: auto;
    display: block;
    width: 100%; /* Volle Breite des Modals */
    max-width: 100%; /* Keine maximale Breite, nutzt den Platz aus */
    padding: 20px; /* Optional: Etwas Polsterung zum Rand */
}

.modal-image {
    width: 100%;
    height: auto;
    display: block;
    max-width: 100%; /* Das Bild selbst darf nicht über den Container hinaus */
}

.close-button {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
}

.close-button:hover,
.close-button:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

/* --- DARK MODE STYLING --- */
body.dark-mode {
    background-color: #1a1a1a;
    color: #e0e0e0;
}

body.dark-mode h1 {
    color: #4da6ff;
}

body.dark-mode h2 {
    color: #f4f7f6;
    border-bottom-color: #333;
}

body.dark-mode h3 {
    color: #4da6ff;
}

body.dark-mode .data-container {
    background-color: #2b2b2b;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

body.dark-mode .summary-section .data-point {
    /* border-bottom: 1px dotted #444; -> Wird jetzt durch compact-data-row verwaltet */
}

body.dark-mode .day-forecast-box {
    border: 1px solid #333;
    background-color: #383838;
}

/* Blink Effekt für hohe Luftfeuchtigkeit */
.blink {
    animation: blink-animation 1s steps(5, start) infinite;
}

@keyframes blink-animation {
    to {
        visibility: hidden;
    }
}


/* --- COMPACT VIEW STYLING (Die Lösung für "nicht das gelbe vom Ei") --- */

body.compact-view .main-grid {
    gap: 10px; /* Reduziere den Abstand zwischen den Boxen */
}

body.compact-view .data-container {
    padding: 12px; /* Reduziere den Innenabstand der Boxen */
}

body.compact-view h2 {
    font-size: 1.3em; /* Mache die Haupttitel kleiner */
    padding-bottom: 5px;
    margin-bottom: 10px;
}

body.compact-view h3 {
    font-size: 1em; /* Mache die Untertitel kleiner */
    margin-top: 10px;
    margin-bottom: 5px;
}

/* Reduziere den Abstand in der Datentabelle */
body.compact-view .summary-section .data-point {
    font-size: 0.9em;
    margin: 2px 0;
}

/* Die großen Werte sollen auch im Compact View gut lesbar bleiben, daher nur leicht reduzieren */
body.compact-view .summary-section span[style*="font-size: 32px"] {
    font-size: 24px !important; 
}

/* Reduziere den Abstand unter den Graphen */
body.compact-view .graph-section p {
    margin: 5px 0;
    font-size: 0.85em;
}

/* Reduziere den Abstand und die Größe in der Vorhersage */
body.compact-view .day-forecast-box {
    padding: 8px;
}

body.compact-view .hourly-details p {
    font-size: 0.8em;
}


/* --- RESPONSIVENESS: Media Queries für Mobilgeräte --- */

/* 2. ZUSÄTZLICHE MEDIA QUERY FÜR TABLETS / GROSSE HANDYS (bis 992px) */
@media (max-width: 992px) and (min-width: 769px) {
    .three-col-layout {
        grid-template-columns: 1fr;
        /* NEU: WUNSCH-REIHENFOLGE */
        grid-template-areas: 
            "grid-area-sensors"  /* 1. Lokale Sensordaten */
            "grid-area-current"  /* 2. Aktuelles OWM Wetter */
            "grid-area-forecast" /* 3. OWM Vorhersage */
            "grid-area-longterm" /* 4. Langzeitgraphen */
            "grid-area-webcams"; /* 5. Webcams */
    }
    
    /* Lässt die Sensorkarte im Tablet-Bereich das Desktop-Layout nutzen */
    .sensor-card .compact-value {
        flex: 1 1 18%; /* 4-5 Elemente pro Reihe, wie auf dem Desktop */
    }
}


/* 1. HAUPT MEDIA QUERY FÜR MOBILE (unter 768px) */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .main-grid {
        /* Mobile: Alle Spalten untereinander */
        grid-template-columns: 1fr;
        
        /* NEU: WUNSCH-REIHENFOLGE */
        grid-template-areas: 
            "grid-area-sensors"  /* 1. Lokale Sensordaten */
            "grid-area-current"  /* 2. Aktuelles OWM Wetter */
            "grid-area-forecast" /* 3. OWM Vorhersage */
            "grid-area-longterm" /* 4. Langzeitgraphen */
            "grid-area-webcams"; /* 5. Webcams */
    }

    h1 {
        font-size: 1.8em;
    }

    h2 {
        font-size: 1.3em;
    }

    /* Im Compact View auf Mobile noch enger */
    body.compact-view .data-container {
        padding: 8px;
    }
    
    /* Wichtig für Mobile: Stellt die Datenpunkte auf zwei Spalten */
    .sensor-card .compact-data-row {
        /* Erlaubt Flexbox, zwei Spalten zu bilden, wenn der Platz knapp wird */
        justify-content: space-around;
        gap: 5px; /* Fügt einen kleinen Abstand zwischen den Elementen hinzu */
    }

    .sensor-card .compact-value {
        /* Jedes Datenpunkt-Element nimmt ca. die Hälfte des Platzes ein */
        flex: 1 1 45%; 
        min-width: auto;
        margin-bottom: 10px;
        padding: 0 5px; 
        border-right: none !important; /* Entfernt die Trennlinie zwischen den Werten auf Mobile */
    }
}


/* --- KOMPAKTE DATEN-ROW STYLING (unverändert) --- */

.sensor-card .compact-data-row {
    /* Nutzt Flexbox, um alle Elemente in eine Reihe zu bringen */
    display: flex;
    justify-content: space-between; /* Verteilt den Platz gleichmäßig */
    flex-wrap: wrap; /* Erlaubt Umbruch auf kleineren Bildschirmen */
    margin-bottom: 10px;
}

.sensor-card .compact-value {
    /* Jedes Datenpunkt-Element nimmt gleich viel Platz ein (ca. 23% für 4 Spalten auf Desktop) */
    flex: 1 1 23%; 
    min-width: 100px; /* Mindestbreite, damit es nicht zu eng wird */
    text-align: center;
    border-right: 1px solid #e0e0e0; /* Trennlinie zwischen den Werten (Hellgrau) */
    padding: 0 5px;
}

/* Entferne die rechte Trennlinie beim letzten Element */
.sensor-card .compact-value:last-child {
    border-right: none;
}

/* Dark Mode Anpassung für die Trennlinie */
body.dark-mode .sensor-card .compact-value {
    border-right: 1px solid #444; 
}
body.dark-mode .sensor-card .compact-value:nth-child(odd) {
     border-right: 1px solid #444;
}

.sensor-card .data-label {
    display: block;
    font-size: 0.8em;
    opacity: 0.7;
    font-weight: 400;
    margin-bottom: 3px;
    color: #333; /* Standard-Farbe für Labels */
}

body.dark-mode .sensor-card .data-label {
    color: #e0e0e0;
}


.secondary-data-row {
    /* Stellt AQI und Zeitstempel/Valve in eine Zeile */
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding-top: 10px;
    border-top: 1px solid #e0e0e0; /* Trennlinie über den sekundären Daten */
}

body.dark-mode .secondary-data-row {
    border-top: 1px solid #444; 
}
