/* Import von Google Fonts und Normalize.css für einheitliches Styling */
@import url('https://fonts.googleapis.com/css2?family=Silkscreen:wght@400;700&display=swap');
@import 'normalize.css';

/* Grundlegende Stile für den Body: Zentriert den Inhalt und setzt ein festes Hintergrundbild */
body {
    font-family: "Silkscreen", sans-serif;
    display: flex;
    justify-content: center;
    align-items: start;
    min-height: 100vh;
    padding: 100px 30px;
    background: url(../images/background.jpg) no-repeat center center fixed;
    background-size: cover;
}

/* Übergangseffekte für Eingabefelder, Labels und Buttons */
input,
label,
button {
    transition-duration: 0.2s;
}

/* Fokus-Styling für Barrierefreiheit */
:focus-visible {
    outline: 2px dashed rgba(41, 94, 228, 0.3);
    outline-offset: 4px;
    transition-duration: 0s !important;
}

/* Hauptcontainer für die Todo-Liste: Flex-Layout mit abgerundeten Ecken und Hintergrundunschärfe */
.todo {
    display: flex;
    flex-direction: column;
    row-gap: 20px;
    width: 100%;
    max-width: 400px;
    min-height: 430px;
    padding: 24px;
    color: rgb(197 210 255);
    border-radius: 20px;
    box-shadow: 0 0 100px rgba(0, 0, 0, 0.5);
    border: 3px solid rgb(40, 48, 61);
    backdrop-filter: blur(10px);
}

/* Zentrierter Titel der Todo-Liste */
.todo__title {
    text-align: center;
    font-size: 2rem;
    line-height: 1.2;
}

/* Formular für Eingabe und Suche: Flex-Layout mit Abstand zwischen Elementen */
.todo__form {
    display: flex;
    column-gap: 16px;
}

/* Eingabefeldcontainer: Nimmt die volle Breite ein */
.todo__field {
    width: 100%;
}

/* Info-Bereich mit Gesamtanzahl der Aufgaben und Lösch-Button */
.todo__info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    column-gap: 16px;
    font-weight: 600;
}

/* Allgemeine Button-Stile: Runde Form, Hover- und Aktiv-Effekte */
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: rgb(13, 36, 113);
    background-color: rgba(41, 94, 228, 0.3);
    border: 3px solid rgba(255, 255, 255, 0.18);
    cursor: pointer;

    &:hover {
        transform: scale(1.1);
        background-color: rgb(197 210 255);
    }

    &:active {
        background-color: rgba(0, 16, 99, 0.908);
        color: rgba(255, 255, 255, 0.908);
    }
}

/* Spezifische Stile für den "Alle löschen"-Button */
.todo__delete-all_button {
    width: auto;
    padding: 10px 20px;
    background-color: transparent;
    border: none;
    border-radius: none;
    font-size: 16px;

    &:hover {
        transform: scale(1.1);
        background-color: transparent;
        color: rgb(168, 22, 22);
    }

    &:not(.is-visible) {
        opacity: 0;
        visibility: hidden;
    }
}

/* Versteckt leere Listen und leere Zustandsmeldungen */
.todo__list,
.todo__empty {
    &:empty {
        display: none;
    }
}

/* Aufgabenliste: Grid-Layout mit definiertem Abstand zwischen Elementen */
.todo__list {
    --todoListRowGap: 8px;
    display: grid;
    row-gap: 8px;
}

/* Styling für den leeren Zustand der Liste */
.todo__empty {
    text-align: center;
    color: rgb(126 146 211);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.todo__empty img {
    width: 250px;
    height: auto;
}

/* Container für Eingabefelder mit dynamischem Label-Verhalten */
.field {
    position: relative;

    
    /* Skaliert das Label, wenn das Eingabefeld nicht leer ist */
     /* Wenn .field__input nicht leer ist , wird .field__label auf 70 % skaliert, nach links und oben verschoben und die Farbe wird geändert. */
    &:has(.field__input:not(:placeholder-shown)) .field__label {
        scale: 0.7;
        translate: -1.75em -2.6em;
        color: rgb(86, 108, 178);
    }
}

/* Positionierung und Styling des Labels */
.field__label {
    position: absolute;
    top: 50%;
    left: 17px;
    color: rgb(126 146 211);
    translate: 0 -50%;
}

/* Styling für Eingabefelder, einschließlich Suchfeld mit Icon */
.field__input {
    --fieldSearchInputIconSize: 16px;
    --fieldInputPaddingX: 16px;

    width: 100%;
    height: 40px;
    padding-inline: var(--fieldInputPaddingX);
    border: 3px solid rgba(255, 255, 255, 0.18);
    border-radius: 17px;
    background: rgba(41, 94, 228, 0.3);
    color: rgb(13, 36, 113);

    &:hover,
    &:focus {
        color: rgb(13, 36, 113);
    }

    &:focus {
        background-color: rgba(198, 211, 255, 0.575);
        outline: none;
    }

    &[type="search"] {
        &:placeholder-shown {
            padding-right: calc(var(--fieldInputPaddingX) * 2 + var(--fieldSeachInputIconSize));
            background-image: url('../icons/search.svg');
            background-position: calc(100% - var(--fieldInputPaddingX)) 50%;
            background-size: var(--fieldSearchInputIconSize);
            background-repeat: no-repeat;
        }
    }
}

/* Styling für einzelne Aufgaben: Flex-Layout mit Umbruch für langen Text */
.todo-item {
    display: flex;
    align-items: center;
    column-gap: 12px;
    padding-left: 10px;
    border: 3px solid rgba(255, 255, 255, 0.18);
    border-radius: 17px;
    background: rgba(41, 94, 228, 0.3);
    color: rgb(13, 36, 113);
    transition-duration: 0.2s;
    max-width: 100%; /* Verhindert Überlaufen des Containers */
    box-sizing: border-box; /* Berücksichtigt Padding und Border in der Breite */

    &:hover {
        background-color: rgba(198, 211, 255, 0.575);
    }

    &.is-disappearing {
        opacity: 0;
        translate: 0 -75%;
        transition-duration: 0.4;
        pointer-events: none;
       /* (~) wählt alle .todo-item-Elemente aus, die nach dem angegebenen Element in der gleichen Hierarchieebene folgen
        translate verschiebt diese Elemente vertikal um -(100% + var(--todoListRowGap)), um einen gestapelten Effekt zu erzeugen, wobei der Abstand zwischen den Elementen berücksichtigt wird.
        /* Verschiebt nachfolgende Aufgaben bei Lösch-Animation */
        &~.todo-item {
            translate: 0 calc((100% + var(--todoListRowGap)) * -1);
            transition-delay: 0.2s;
            transition-duration: 0.2s;
            pointer-events: none;
        }
    }
}

/* Styling für den Löschen-Button in Aufgaben */
.todo-item__delete-button {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin-left: auto;
    padding: 0;
    border: none;
    background-color: transparent;

    &:hover {
        transform: scale(1.5);
        background-color: transparent;
    }

    &:active {
        color: rgb(168, 22, 22);
    }

    * {
        pointer-events: none;
    }
}

/* Checkbox für Aufgaben: Benutzerdefiniertes Styling */
.todo-item__checkbox {
    flex-shrink: 0;
    appearance: none;
    position: relative;
    width: 20px;
    height: 20px;
    margin: 0;
    border: 1px solid rgba(13, 36, 113, 0.554);
    border-radius: 6px;
    background: rgba(198, 211, 255, 0.575);

    &:not(:checked) {
        &::after {
            opacity: 0;
        }
    }

    &:checked {
        background-color: rgba(13, 36, 113, 0.554);

        &+.todo-item__label {
            color: rgba(13, 36, 113, 0.554);
            text-decoration: line-through;
        }
    }

    &::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        translate: -50% -50%;
        width: 16px;
        height: 16px;
        background: url('../icons/check.svg') center/contain no-repeat;
    }
}

/* Label für Aufgaben: Unterstützt Textumbruch bei langen Texten */
.todo-item__label {
    width: 100%;
    pointer-events: none;
    word-break: break-word; /* Bricht lange Wörter um */
    overflow-wrap: break-word; /* Unterstützt modernen Textumbruch */
    white-space: normal; /* Erlaubt Zeilenumbrüche */
    max-width: calc(100% - 80px); /* Begrenzt die Breite, um Platz für Checkbox und Button zu lassen */
}

/* Responsive Anpassungen für Bildschirme bis 480px */

@media (max-width: 480px) {
    /* Reduziert die Padding-Werte für kleinere Bildschirme */
    body {
        padding: 30px 15px;
    }

    /* Kompakteres Layout für den Todo-Container */
    .todo {
        padding: 12px;
        row-gap: 12px;
    }

    /* Kleinere Schriftgröße für den Titel */
    .todo__title {
        font-size: 1.2rem;
    }

    /* Kleinere Schrift für Labels */
    .field__label {
        font-size: 0.8rem;
    }

    /* Kleinere Eingabefelder und Placeholder */
    .field__input {
        font-size: 0.75rem;
        height: 32px;
        padding-inline: 10px;
    }

    .field__input::placeholder {
        font-size: 0.75rem;
    }

    /* Kleinere Buttons */
    button {
        width: 32px;
        height: 32px;
        padding: 6px;
    }

    /* Anpassung des "Alle löschen"-Buttons */
    .todo__delete-all_button {
        font-size: 0.8rem;
        padding: 6px 12px;
    }

    /* Kleinere Schrift für den Info-Bereich */
    .todo__info {
        font-size: 0.75rem;
    }

    /* Kleinere Schrift und Elemente für Aufgaben */
    .todo-item__label {
        font-size: 0.75rem;
    }

    .todo-item__checkbox {
        width: 14px;
        height: 14px;
    }

    .todo-item__delete-button {
        width: 32px;
        height: 32px;
    }

    /* Kleinere Schrift und Bild für leeren Zustand */
    .todo__empty {
        font-size: 0.75rem;
    }

    .todo__empty img {
        width: 150px;
    }
}