/* T-Diesel UX improvements: header navigation and WooCommerce. */

/* Keep the long "Інші послуги" dropdown attached to the header. */
@media (min-width: 1025px) {
    .elementor-element-79af412 .menu-item-19169 > .sub-menu,
    .elementor-widget-nav-menu .menu-item-19169 > .sub-menu {
        top: 100% !important;
        bottom: auto !important;
        transform: none !important;
        max-height: calc(100vh - 110px);
        max-height: calc(100dvh - 110px);
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-gutter: stable;
    }
}

/* Coupon controls must never crop the "Застосувати" label. */
@media (max-width: 767px) {
    .woocommerce-cart-form .coupon {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 10px;
        width: 100% !important;
    }

    .woocommerce-cart-form .coupon #coupon_code,
    .woocommerce-cart-form .coupon .button,
    .woocommerce-cart-form .coupon button[name="apply_coupon"] {
        box-sizing: border-box;
        float: none !important;
        width: 100% !important;
        max-width: none !important;
        min-height: 48px;
        margin: 0 !important;
        padding-right: 14px !important;
        padding-left: 14px !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
    }

    .wc-block-components-totals-coupon__button {
        min-width: max-content;
        white-space: normal;
    }

    /* Keep the cart control in the top header row, away from menu links. */
    .elementor-element-681d7d4e > .e-con-inner {
        position: relative;
    }

    .elementor-element-1b56cb89 {
        position: absolute !important;
        top: 12px !important;
        right: 84px !important;
        left: auto !important;
        z-index: 10002;
        width: auto !important;
        min-width: 44px;
        transform: none !important;
    }

    .elementor-element-dde32fd .elementor-menu-cart__toggle_button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 44px;
    }

    .elementor-element-dde32fd .elementor-button-text {
        display: none;
    }

    /* Elementor mini-cart: compact, centred, and fully visible. */
    .elementor-widget-woocommerce-menu-cart.elementor-menu-cart--cart-type-mini-cart .elementor-menu-cart__main,
    .tdiesel-mobile-cart-container .elementor-menu-cart__main {
        position: fixed !important;
        top: 50% !important;
        right: auto !important;
        bottom: auto !important;
        left: 50% !important;
        width: min(320px, calc(100vw - 32px)) !important;
        min-width: 0 !important;
        max-width: calc(100vw - 32px) !important;
        max-height: calc(100vh - 32px);
        max-height: calc(100dvh - 32px);
        min-height: 0 !important;
        padding: 16px !important;
        overflow-x: hidden;
        overflow-y: auto;
        border-radius: 8px;
        transform: translate(-50%, -50%) !important;
    }

    .tdiesel-mobile-cart-container.elementor-menu-cart__container {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        margin: 0 !important;
        z-index: 10020 !important;
    }

    .tdiesel-mobile-cart-container[aria-hidden="true"] {
        display: none !important;
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    .tdiesel-mobile-cart-container[aria-hidden="false"],
    .tdiesel-mobile-cart-container.elementor-menu-cart--shown {
        display: flex !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }

    .tdiesel-mobile-cart-container .elementor-menu-cart__footer-buttons .elementor-button {
        color: #fff !important;
        background: #d61817 !important;
    }

    .elementor-menu-cart__product {
        grid-template-columns: 64px minmax(0, 1fr) !important;
        column-gap: 12px !important;
    }

    .elementor-menu-cart__product-name,
    .elementor-menu-cart__product-name a {
        overflow-wrap: anywhere;
    }

    .elementor-menu-cart__footer-buttons {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    /* Fallback for the theme's alternate side-cart implementation. */
    .elth-mini-cart-side .mini-cart-content {
        top: 50% !important;
        right: auto !important;
        bottom: auto !important;
        left: 50% !important;
        width: min(320px, calc(100vw - 32px)) !important;
        max-width: calc(100vw - 32px) !important;
        max-height: calc(100dvh - 32px);
        overflow-y: auto;
        border-radius: 8px;
        transform: translate(120vw, -50%) !important;
    }

    .elth-mini-cart-side.open-side .mini-cart-content {
        transform: translate(-50%, -50%) !important;
    }
}

/* Make every mobile menu item with children visibly expandable. */
@media (max-width: 1024px) {
    .elementor-element-79af412 .elementor-nav-menu--dropdown .menu-item-has-children > a {
        position: relative;
        display: flex !important;
        align-items: center;
        padding-right: 48px !important;
    }

    .elementor-element-79af412 .menu-item-has-children > a > .sub-arrow,
    .elementor-element-79af412 .menu-item-has-children > a > .tdiesel-submenu-arrow {
        position: absolute !important;
        top: 50%;
        right: 18px;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 20px;
        height: 20px;
        margin: 0 !important;
        opacity: 1 !important;
        visibility: visible !important;
        transform: translateY(-50%);
    }

    .elementor-element-79af412 .menu-item-has-children > a > .tdiesel-submenu-arrow::before {
        width: 7px;
        height: 7px;
        content: '';
        border-right: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        transform: rotate(45deg) translate(-1px, -1px);
        transition: transform 160ms ease;
    }

    .elementor-element-79af412 .menu-item-has-children > a.highlighted > .tdiesel-submenu-arrow::before {
        transform: rotate(225deg) translate(-1px, -1px);
    }
}

/* Keep only the theme's real check icon after a successful AJAX add. */
.add_to_cart_button.added.tdiesel-has-theme-check::after,
.ajax_add_to_cart.added.tdiesel-has-theme-check::after {
    display: none !important;
    content: none !important;
}

/* The PHP filter removes this section; this is a cache-safe visual fallback. */
.woocommerce-checkout .woocommerce-shipping-fields {
    display: none !important;
}

/* The toast replaces the large in-content success notice on catalogue pages. */
body.post-type-archive-product .woocommerce-notices-wrapper .woocommerce-message,
body.tax-product_cat .woocommerce-notices-wrapper .woocommerce-message,
body.tax-product_tag .woocommerce-notices-wrapper .woocommerce-message {
    display: none !important;
}

/* Add-to-cart confirmation toast. */
.tdiesel-cart-toast {
    position: fixed;
    right: 20px;
    top: 110px;
    bottom: auto;
    z-index: 10010;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    width: min(390px, calc(100vw - 32px));
    padding: 14px;
    color: #1f2933;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-left: 4px solid #d61817;
    border-radius: 6px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
    opacity: 0;
    visibility: hidden;
    transform: translateY(18px);
    transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
}

.tdiesel-cart-toast.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.tdiesel-cart-toast.is-positioned {
    right: auto;
    transform: translateY(18px);
}

.tdiesel-cart-toast.is-positioned.is-visible {
    transform: translateY(0);
}

.tdiesel-cart-toast__thumb {
    width: 48px;
    height: 48px;
    overflow: hidden;
    background: #f4f4f4;
    border-radius: 4px;
}

.tdiesel-cart-toast__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tdiesel-cart-toast__title {
    display: block;
    margin: 0 0 3px;
    font-size: 15px;
    line-height: 1.25;
}

.tdiesel-cart-toast__text {
    margin: 0;
    font-size: 13px;
    line-height: 1.35;
}

.tdiesel-cart-toast__cart {
    display: inline-block;
    margin-top: 7px;
    color: #d61817;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.tdiesel-cart-toast__close {
    align-self: start;
    width: 32px;
    height: 32px;
    padding: 0;
    color: #111;
    background: transparent;
    border: 0;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

@media (max-width: 767px) {
    .tdiesel-cart-toast {
        right: auto;
        top: max(90px, calc(env(safe-area-inset-top) + 74px));
        bottom: auto;
        left: 50%;
        grid-template-columns: 42px minmax(0, 1fr) auto;
        width: calc(100vw - 32px);
        transform: translate(-50%, 18px);
    }

    .tdiesel-cart-toast.is-visible {
        transform: translate(-50%, 0);
    }

    .tdiesel-cart-toast__thumb {
        width: 42px;
        height: 42px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tdiesel-cart-toast {
        transition: none;
    }
}
