.wp-block-navigation {

    &,
    &__responsive-container,
    &__responsive-container-open,
    &__responsive-container-close,
    &__responsive-dialog,
    &__container,
    &__responsive-close {
        all: unset;
        box-sizing: border-box;
    }
}

.wp-block-navigation-item,
.wp-block-navigation-link {
    all: unset;
    box-sizing: border-box;
}

header.wp-block-template-part {
    position: absolute;
    width: 100%;
    top: 0;
    padding: 24px 0px;
    z-index: 100;
}

.header .container {
    width: min(90%, var(--wp--custom--layout--content-size));
    margin: 0 auto;
}

// ======================== CUSTOM NAVIGATION ========================

.kordit-nav {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: 100%;

    // ========== DESKTOP MENU ==========
    &__desktop {
        display: flex;
        flex: 1;
        justify-content: flex-end;
    }

    &__list {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
        list-style: none;
        margin: 0;
        padding: 0;
    }

    &__item {
        position: relative;
        margin: 0;
        padding: 0;
        list-style: none;

        // Current/active item
        &.is-current>.kordit-nav__link {
            font-weight: 600;
            color: var(--wp--preset--color--primary, #000);
        }
    }

    &__link {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
        text-decoration: none;
        color: inherit;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: 0.375rem;
        transition: all 0.2s ease;
        white-space: nowrap;

        &:hover {
            color: var(--wp--preset--color--primary, #007bff);
            background-color: var(--wp--preset--color--base-3, #f8f9fa);
        }

        // Link w submenu - space-between + chevron w prawo
        .kordit-nav__submenu & {
            justify-content: space-between;

            .kordit-nav__chevron {
                margin-left: auto;
                transform: rotate(-90deg);
            }

            &:hover .kordit-nav__chevron {
                transform: rotate(-90deg);
            }
        }
    }

    // Chevron dla submenu
    &__chevron {
        width: 0;
        height: 0;
        border-left: 0.3rem solid transparent;
        border-right: 0.3rem solid transparent;
        border-top: 0.35rem solid currentColor;
        margin-left: 0.25rem;
        transition: transform 0.2s ease;
    }

    // ========== SUBMENU (DROPDOWN) ==========
    &__submenu {
        display: none;
        position: absolute;
        top: calc(100% - 0.5rem);
        left: 0;
        min-width: 220px;
        background: #fff;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        border-radius: 0.5rem;
        padding: 0.5rem;
        padding-top: 1rem;
        z-index: 1000;
        list-style: none;
        flex-direction: column;
        gap: 0.25rem;

        @media only screen and (min-width: 992px) {
            .kordit-nav__submenu {
                top: 0%;
                transform: translate(calc(100% - 200px), 0px);
            }
        }

        .kordit-nav__item {
            width: 100%; 
        }

        .kordit-nav__link {
            width: 100%;
            padding: 0.75rem 1rem;
            border-radius: 0.375rem;
            display: flex;  
        }

        // Nested submenu - rozwija się w prawo
        &--nested {
            top: -0.5rem;
            left: calc(100% - 0.5rem);
            padding-top: 0.5rem;
            padding-left: 1rem;
        }
    }

    // Show submenu on hover (desktop only)
    .has-children:hover>.kordit-nav__submenu {
        display: flex;
    }

    .has-children:hover>.kordit-nav__link .kordit-nav__chevron {
        transform: rotate(180deg);
    }

    // ========== MOBILE TOGGLE BUTTON ==========
    &__toggle {
        display: none;
        background: none;
        border: 2px solid currentColor;
        border-radius: 0.375rem;
        cursor: pointer;
        padding: 0.5rem;
        width: 2.75rem;
        height: 2.75rem;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 0.375rem;
        z-index: 1002;
        transition: all 0.3s ease;

        &:hover {
            background-color: var(--wp--preset--color--base-3, #f8f9fa);
        }

        &-line {
            width: 1.5rem;
            height: 2px;
            background-color: currentColor;
            transition: all 0.3s ease;
            display: block;
            border-radius: 2px;
        }

        // Hamburger -> X animation
        &[aria-expanded="true"] {
            .kordit-nav__toggle-line {
                &:first-child {
                    transform: translateY(0.4rem) rotate(45deg);
                }

                &:last-child {
                    transform: translateY(-0.4rem) rotate(-45deg);
                }
            }
        }
    }

    // ========== MOBILE MENU ==========
    &__mobile {
        display: none;
        position: fixed;
        top: 0;
        right: 0;
        width: 100%;
        max-width: 320px;
        height: 100vh;
        background: #fff;
        box-shadow: -4px 0 12px rgba(0, 0, 0, 0.2);
        z-index: 1001;
        overflow-y: auto;
        transition: transform 0.3s ease;
        transform: translateX(100%);

        // Hidden state
        &[hidden] {
            display: block;
            transform: translateX(100%);
        }

        // Visible state
        &:not([hidden]) {
            transform: translateX(0);
        }

        .kordit-nav__list {
            flex-direction: column;
            gap: 0;
            align-items: stretch;
        }

        .kordit-nav__item {
            width: 100%;
            border-bottom: 1px solid var(--wp--preset--color--base-3, #e9ecef);

            &:last-child {
                border-bottom: none;
            }
        }

        .kordit-nav__link {
            width: 100%;
            padding: 1rem 1.5rem;
            border-radius: 0;
            justify-content: space-between;
        }

        // Mobile submenu styling
        .kordit-nav__submenu {
            position: static;
            box-shadow: none;
            padding: 0;
            margin: 0;
            background: var(--wp--preset--color--base-2, #f8f9fa);
            border-radius: 0;

            .kordit-nav__link {
                padding-left: 2.5rem;
            }
        }

        // Show submenu on click (mobile)
        .has-children.is-open>.kordit-nav__submenu {
            display: flex;
        }

        .has-children.is-open>.kordit-nav__link .kordit-nav__chevron {
            transform: rotate(180deg);
        }
    }

    &__mobile-inner {
        padding: 5rem 1rem 2rem;
    }

    // ========== BACKDROP ==========
    &__backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.6);
        z-index: 1000;
        opacity: 0;
        transition: opacity 0.3s ease;
        pointer-events: none;

        &[aria-hidden="false"] {
            display: block;
            opacity: 1;
            pointer-events: auto;
        }
    }

    // ========== RESPONSIVE ==========
    @media (max-width: 781px) {
        &__desktop {
            display: none;
        }

        &__toggle {
            display: flex;
        }

        &__mobile {
            display: block;
        }
    }

    @media (min-width: 782px) {
        &__toggle {
            display: none;
        }

        &__mobile {
            display: none !important;
        }

        &__backdrop {
            display: none !important;
        }
    }
}