/* Grundlegende Gestaltung und Variablen */
:root {
    --bg: #f9f9fc;
    --bg-secondary: #ffffff;
    --text: #222222;
    --text-light: #555555;
    --accent: #007acc;
    --accent-light: #cce6ff;
    --border: #e0e0e0;
    --shadow: rgba(0, 0, 0, 0.05);
    --progress-track: #e6e6e6;
    --progress-fill: var(--accent);
}

body.dark {
    --bg: #1a202c;
    --bg-secondary: #252f3f;
    --text: #e6e8ed;
    --text-light: #a0aec0;
    --accent: #63b3ed;
    --accent-light: #2a4365;
    --border: #39445a;
    --shadow: rgba(0, 0, 0, 0.4);
    --progress-track: #39445a;
    --progress-fill: var(--accent);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background 0.3s ease, color 0.3s ease;
}

a {
    color: var(--accent);
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 2rem;
}

header.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

header.header h1 {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 600;
}

/* Container für die Buttons im Header (Dark/Light Mode & Einstellungen) */
.header-buttons {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.4rem;
    position: relative;
    width: 2.2rem;
    height: 2.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle .icon {
    position: absolute;
    transition: opacity 0.3s ease;
}

.theme-toggle .sun {
    opacity: 0;
}

body.dark .theme-toggle .sun {
    opacity: 1;
}

body.dark .theme-toggle .moon {
    opacity: 0;
}

main {
    background: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: 0 2px 6px var(--shadow);
    padding: 1.5rem;
}

/* Fortschrittsanzeige */
.progress-section {
    text-align: center;
    margin-bottom: 2rem;
}

.progress-circle {
    position: relative;
    width: 180px;
    height: 180px;
    margin: 0 auto;
}

.progress-circle svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.progress-circle .track {
    fill: none;
    stroke: var(--progress-track);
    stroke-width: 10;
}

.progress-circle .progress {
    fill: none;
    stroke: var(--progress-fill);
    stroke-width: 10;
    stroke-linecap: round;
    stroke-dasharray: 283; /* 2 * pi * r (approx for r=45) */
    stroke-dashoffset: 283;
    transition: stroke-dashoffset 0.5s ease-out;
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text);
    transition: color 0.3s ease;
}

.progress-section p {
    margin-top: 0.5rem;
    color: var(--text-light);
}

/* Eingabebereich */
.add-section {
    margin-bottom: 2rem;
}

.add-section h2 {
    margin-bottom: 0.5rem;
    font-size: 1.4rem;
}

/* Gruppe der Einheiten-Schaltflächen */
.buttons-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.drink-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    width: 80px;
    height: 80px;
    padding: 0.4rem;
    background: var(--accent-light);
    color: var(--accent);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.3s ease, transform 0.2s ease;
}

.drink-button:hover {
    background: var(--accent);
    color: #fff;
    transform: translateY(-2px);
}

.drink-button:active {
    transform: translateY(0);
}

.drink-button .icon-wrapper {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drink-button .icon {
    width: 100%;
    height: 100%;
    display: block;
    fill: currentColor;
    stroke: none;
}

/* Bilder für Icons */
.drink-button .icon-image {
    width: 32px;
    height: 32px;
    object-fit: contain;
    /* Standardfarbe: schwarze Linien auf transparentem Hintergrund */
    filter: none;
    transition: filter 0.3s ease;
}

/* Im Dark Mode: sorge dafür, dass die schwarzen PNG‑Icons zu hellen Symbolen
   werden. Durch die Kombination von invert, grayscale und brightness werden
   schwarze Linien weiß, und eventuelle Farbinformationen werden entfernt. */
body.dark .drink-button .icon-image {
    filter: invert(1) grayscale(1) brightness(2);
}

/* Beim Hover invertieren wir die Icons sowohl im Hell‑ als auch im Dunkel‑Modus.
   Dadurch erscheinen sie stets kontrastreich zum Hintergrund. */
.drink-button:hover .icon-image {
    filter: invert(1) grayscale(1) brightness(2);
}

.drink-button .caption {
    font-weight: 500;
    font-size: 0.85rem;
}

.drink-button.custom-toggle {
    background: var(--border);
    color: var(--text-light);
}

.drink-button.custom-toggle:hover {
    background: var(--accent);
    color: #fff;
}

/* Benutzerdefinierte Eingabeabschnitt */
.custom-input-section {
    margin-bottom: 1rem;
    padding: 0.5rem;
    border-radius: 6px;
    background: var(--bg-secondary);
    box-shadow: 0 1px 3px var(--shadow);
}

/* Versteckt Elemente mit der Klasse hidden */
.hidden {
    display: none !important;
}

.custom-input-section .input-group {
    margin-bottom: 0.5rem;
}

.input-group {
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
}

.input-group label {
    flex: 0 0 auto;
    margin-right: 0.5rem;
}

.input-group select,
.input-group input {
    flex: 1 1 auto;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    appearance: none;
}

.input-group select {
    margin-left: 0.3rem;
}

.custom-input.hidden {
    display: none;
}

.add-button,
.reset-button {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    margin-right: 0.6rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: filter 0.3s ease;
}

.add-button:hover,
.reset-button:hover {
    filter: brightness(0.92);
}

.reset-button {
    background: var(--text-light);
    color: var(--bg-secondary);
}

/* Verlaufsliste */
.history-section {
    margin-top: 2rem;
}

.history-section h2 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
}

.history-list {
    list-style: none;
    padding: 0;
    max-height: 200px;
    overflow-y: auto;
    margin: 0;
    border-top: 1px solid var(--border);
}

.history-list li {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
}

/* Löschbutton in der Verlaufsliste */
.history-list .delete-entry {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 1.1rem;
    margin-left: 0.5rem;
    cursor: pointer;
    padding: 0;
}
.history-list .delete-entry:hover {
    color: var(--text);
}

.history-list li:last-child {
    border-bottom: none;
}

/* Zeitangaben in der Verlaufsliste rechtsbündig ausrichten */
.history-list .entry-time {
    text-align: right;
    min-width: 3.5rem;
}

/* Wochenübersicht (letzte 7 Tage) */
.weekly-section {
    margin-top: 2rem;
    /* Verleiht der Wochenübersicht ein Kartenlayout und sorgt dafür,
       dass der Hintergrund im Dunkelmodus nicht weiß erscheint. */
    background: var(--bg-secondary);
    border-radius: 6px;
    padding: 0.75rem;
}
.weekly-section h2 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
}

/* Legende über dem Wochenchart für Ziel und Durchschnitt */
.weekly-legend {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-light);
    margin-bottom: 0.3rem;
}
.weekly-legend span::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 2px;
    margin-right: 4px;
    position: relative;
    top: -2px;
}
.weekly-legend .goal-legend::before {
    background: var(--border);
}
.weekly-legend .avg-legend::before {
    /*
     * Entferne die Linie vor dem Durchschnittseintrag vollständig. In der
     * ursprünglichen Umsetzung führte die Kombination aus border-top bzw.
     * einem eingefärbten Pseudo-Element zu einem störenden Artefakt vor
     * dem Durchschnittswert. Da die durchschnittliche Menge bereits durch
     * das Präfix „Ø:“ gekennzeichnet ist, ist ein zusätzlicher Strich
     * überflüssig. Durch das vollständige Ausblenden des ::before-Elements
     * verschwindet das Artefakt.
     */
    display: none;
    border-top: none;
    background: none;
}

/* Diagrammcontainer: Balken nebeneinander, unten ausgerichtet */
.weekly-chart {
    /* Der Wochenchart wird als Canvas umgesetzt. Diese Klasse sorgt dafür,
       dass das Canvas responsive ist und die richtige Höhe erhält. */
    width: 100%;
    height: 140px;
    display: block;
    position: relative;

    /* Der Canvas hat standardmäßig einen weißen Hintergrund. Damit der Chart
       im Dunkelmodus nicht weiß erscheint, geben wir ihm den gleichen
       Hintergrund wie die Karte. */
    background: var(--bg-secondary);
    border-radius: 4px;
}
.weekly-chart .bar-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    position: relative;
    height: 100%; /* damit die Balkenhöhe relativ zum Chartcontainer berechnet wird */
    overflow: visible; /* erlaube, dass Balken über den Wrapper hinaus ragen */
}
.weekly-chart .bar {
    width: 100%;
    max-width: 28px;
    background: var(--accent-light);
    border-radius: 4px 4px 0 0;
    transition: height 0.4s ease;
}
/* Heutiger Tag farblich hervorheben */
.weekly-chart .bar.current-day {
    background: var(--accent);
}
.weekly-chart .day-label {
    margin-top: 0.3rem;
    font-size: 0.75rem;
    color: var(--text-light);
    text-transform: capitalize;
}

/* Tooltip für Balken: Zeigt die konsumierte Menge bei Hover an */
.weekly-chart .tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 0.35rem;
    background: var(--bg-secondary);
    color: var(--text);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    box-shadow: 0 1px 3px var(--shadow);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    white-space: nowrap;
    z-index: 10;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.weekly-chart .bar-wrapper:hover .tooltip {
    opacity: 1;
    visibility: visible;
}

/* Linien für Ziel- und Durchschnittsanzeige */
.weekly-chart .goal-line,
.weekly-chart .avg-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 0;
    border-top: 2px solid;
    pointer-events: none;
}
.weekly-chart .goal-line {
    border-color: var(--border);
}
.weekly-chart .avg-line {
    border-color: var(--accent);
    border-style: dashed;
}
.weekly-chart .goal-line .line-label,
.weekly-chart .avg-line .line-label {
    position: absolute;
    left: 4px;
    top: -0.8rem;
    font-size: 0.65rem;
    color: var(--text-light);
}

/* Pulsierende Animation für die Fortschrittsanzeige */
@keyframes progress-pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.08);
    }
    100% {
        transform: scale(1);
    }
}

/* Wird via JS hinzugefügt, um die Fortschrittsanzeige kurz pulsieren zu lassen */
.pulse {
    animation: progress-pulse 0.6s ease-in-out;
}

/* Partikel für das Feuerwerk bei Erreichen des Ziels */
.firework-particle {
    position: fixed;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10000;
}

/* Einstellungen‑Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--bg-secondary);
    color: var(--text);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px var(--shadow);
    max-width: 320px;
    width: 90%;
}

.modal h2 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.4rem;
}

.modal label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: 500;
}

.modal input[type="number"] {
    width: 100%;
    padding: 0.5rem 0.6rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.modal-buttons button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95rem;
}

.modal-buttons .save-button {
    background: var(--accent);
    color: #fff;
}

.modal-buttons .cancel-button {
    background: var(--text-light);
    color: var(--bg-secondary);
}

.settings-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.4rem;
    margin-left: 0.5rem;
    color: var(--accent);
    transition: color 0.3s ease;
}
.settings-toggle:hover {
    color: var(--text);
}

/* Stil des Zahnrad‑Icons innerhalb des Einstellungs‑Buttons */
.settings-toggle .settings-icon {
    width: 1.3rem;
    height: 1.3rem;
    fill: currentColor;
}

/* Helferklasse für dark-mode Buttons */
/* In CSS können wir darken() nicht direkt verwenden, daher definieren wir leichte Schatteneffekte
   und lassen den Hover-Zustand im JS setzen, falls gewünscht. */