@use '../abstracts/variables' as *;

.form {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 1rem;

    &--main-sidebar {
        display: grid;
        grid-template-columns: 2fr 1fr;
        grid-template-rows: masonry;
        gap: 1.25rem;
    }

    &--masonry {
        display: block;
        transition: height 0.3s ease-in-out; 
    }

    &__section {
        margin: 0;
        padding: 0.75rem;
        display: flex;
        flex-direction: column;
        border: 1px solid $color-border;
        position: relative;
        // I DODAJEMY TRANSITION TUTAJ:
        transition: top 0.4s ease-in-out, left 0.4s ease-in-out, width 0.4s ease-in-out;

        // DODAJEMY NOWĄ KLASĘ
        &.no-transition {
            transition: none !important;
        }
    }

    &__section-title {
        padding: 0;
        float: left;
        font-weight: 600;

        display: flex;
    }

    &__section-actions {
        margin-left: auto;
    }

    &__group {
        margin-bottom: 1.25rem;
        display: flex;
        flex-direction: column;

        &:last-child {
            margin-bottom: 0;
        }
    }

    &__group--error {
        .form__label {
            color: $color-danger;
        }
        .form__control {
            border-color: $color-danger;
        }
        .dropzone__container {
            border-color: $color-danger;
        }
    }

    &__input-group {
        position: relative;
        display: flex;
        gap: 1rem;

        // --- ZASTĄP POPRZEDNI KOD TYM FRAGMENTEM ---

        // Domyślnie, pozwól wszystkim elementom rosnąć i kurczyć się w razie potrzeby
        > .form__control {
            flex: 1 1 0;
            min-width: 0; // Zapobiega "wypychaniu" layoutu przez długą treść wewnątrz inputa

            &--auto {
                flex: 0 0 auto; // Pozwala na automatyczne dostosowanie szerokości
                width: auto; // Ustawia szerokość na auto
                // min-width: 160px;
            }
        }
    }

    &__note {
        margin: 0;
        margin-bottom: 0.5rem;
        font-size: 0.75rem;
        color: $color-text-muted-lighter;
    } 

    &__label {
        display: block;
        margin-bottom: 0.5rem;
        font-weight: 500;
        font-size: 0.85rem;
        color: $color-text-base;

        // Option 1: Use general sibling combinator instead of adjacent sibling
        &--required::after,
        &:has(~ input:required, ~ select:required)::after {
            content: "*";
            color: $color-danger;
            margin-left: 0.25rem;
            font-weight: bold;
        }
        
        // Option 2: For more complex nesting, add a class to parent
        // &.required::after {
        //     content: "*";
        //     color: $color-danger;
        //     margin-left: 0.25rem;
        //     font-weight: bold;
        // }

        &:has(+ .form__note) {
            margin-bottom: 0;
        }
    }

    

    &__control {
        display: block;
        width: 100%;
        // height: 3rem;
        padding: 0.5rem 0.75rem;

        font-size: 0.85rem;

        background-color: $color-bg-element;
        background-clip: padding-box; // Ważne dla poprawnego renderowania

        border-radius: 4px;
        border: 2px solid $color-border;

        transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;

        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;

        &::placeholder {
            color: $color-text-muted-lighter;
            font-weight: 400;
            opacity: 1;
        }

        &:focus {
            border-color: $color-main;
            outline: none;
        }

        &:disabled,
        &[disabled] {
            opacity: 0.6;
            cursor: not-allowed;
        }

        &--textarea {
            height: auto;
            resize: none;
        }
    }
}

.form-group {
    margin-bottom: 1.25rem;

    &:last-child {
        margin-bottom: 0;
    }

    &.has-error {
        .form-label {
            color: $color-danger;
        }
        .form-control {
            border-color: $color-danger;
        }
    }
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.85rem;
    color: $color-text-base;
}

.form-control {
    display: block;
    width: 100%;
    height: 3rem;
    padding: 0.5rem 0.75rem;

    font-size: 0.85rem;

    background-color: $color-bg-element;
    background-clip: padding-box; // Ważne dla poprawnego renderowania

    border-radius: 4px;
    border: 2px solid $color-border;

    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;

    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;

    &::placeholder {
        color: $color-text-muted-lighter;
        font-weight: 400;
        opacity: 1;
    }

    &:focus {
        border-color: $color-main;
        outline: none;
    }

    &:disabled,
    &[disabled] {
        opacity: 0.6;
        cursor: not-allowed;
    }
}

.form-error-message {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: $color-danger;
}

.form-password-requirements {
    margin-top: -0.5rem;
    margin-bottom: 1.25rem;
    font-size: 0.75rem;
    color: $color-text-muted;

    ul {
        list-style-type: none;
        padding-left: 0;

        li {
            display: flex;
            align-items: center;
            color: $color-danger;

            &.valid {
                color: $color-success;
            }
        }
    }
    
    &.hidden {
        visibility: hidden;
        opacity: 0;
        height: 0;
    }
}

.input-group {
    position: relative;
}

.input-toggle-password {
    top: 2px;
    right: 2px;
    padding: 0 0.75rem;
    height: calc(100% - 4px); // Adjust height to match the input field
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    cursor: pointer;
    background-color: $color-bg-element;
    border: none;
    outline: none;

    svg {
        width: 1.15rem;
        height: 1.15rem;
        stroke: $color-text-muted;

        transition: stroke 0.15s ease-in-out;
    }

    &:hover svg {
        stroke: $color-text-base;
    }
}

.form-note {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: $color-text-muted-lighter;
}



.smart-entry-input {
    position: relative; 

    &__selected {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    &__suggestions {
        position: absolute;
        top: 100%;
        left: 0;
        width: 100%;
        background: $white;
        border: 1px solid $color-border;
        border-top: none; /* Remove top border to merge with input */
        border-top-left-radius: 0; /* Remove top-left radius to merge with input */
        border-top-right-radius: 0; /* Remove top-right radius to merge with input */
        border-bottom-left-radius: 4px; /* Match input's border radius */
        border-bottom-right-radius: 4px; /* Match input's border radius */
        max-height: 200px;
        overflow-y: auto;
        z-index: 10;
        display: none;
        box-shadow: 0 4px 6px rgba(0,0,0,0.1); /* Add shadow for depth */

        &.is-active {
            display: block;
        }
    }
    
    &__suggestion-item {
        padding: 0.5rem 0.75rem;
        cursor: pointer;

        // Styl dla podświetlonego elementu
        &:hover, &.is-highlighted {
            background-color: $color-bg-element-hover;
        }
    }
}

.relations-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.relation-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 1rem;
    align-items: center;

    &__title {
        font-weight: 500;
    }
    
    .form__control {
        height: auto; // Dostosuj wysokość selecta
    }
}