/* Prevent horizontal overflow on the page */
html:has(.ah-assistant-container),
body:has(.ah-assistant-container) {
    overflow-x: hidden !important;
    max-width: 100vw !important;
}

.ah-assistant-container {
    width: 100%;
    max-width: 100vw;
    height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
    position: relative;
}

.ah-assistant-container * {
    box-sizing: border-box;
}

.ah-assistant-window {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12), 0 2px 10px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

/* Header z gradientem */
.ah-assistant-header {
    background: linear-gradient(135deg, var(--ah-assistant-primary, #0073aa) 0%, color-mix(in srgb, var(--ah-assistant-primary, #0073aa) 80%, #000) 100%);
    color: white;
    padding: 18px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.ah-assistant-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
}

.ah-assistant-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.ah-assistant-new-chat {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.ah-assistant-new-chat:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

/* Obszar wiadomości */
.ah-assistant-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: linear-gradient(180deg, #f8f9fa 0%, #f0f2f5 100%);
    box-sizing: border-box;
}

/* Wiadomość */
.ah-message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: messageSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-sizing: border-box;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.ah-message.ah-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

/* Avatar */
.ah-message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ah-message-avatar img.ah-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ah-message.ah-bot .ah-message-avatar {
    background: linear-gradient(135deg, var(--ah-assistant-primary, #0073aa), color-mix(in srgb, var(--ah-assistant-primary, #0073aa) 70%, #6366f1));
    color: white;
}

.ah-message.ah-user .ah-message-avatar {
    background: linear-gradient(135deg, #e2e8f0, #cbd5e1);
    color: #475569;
}

/* Treść wiadomości */
.ah-message-content {
    background: white;
    padding: 14px 18px;
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: min(70vw, calc(100vw - 100px));
    box-sizing: border-box;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    overflow-x: hidden;
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.ah-message.ah-user .ah-message-content {
    background: linear-gradient(135deg, var(--ah-assistant-primary, #0073aa), color-mix(in srgb, var(--ah-assistant-primary, #0073aa) 85%, #6366f1));
    color: white;
    border: none;
}

.ah-message-text {
    font-size: 14px;
    color: inherit;
}

/* Produkty wrapper */
.ah-products-wrapper {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    padding: 14px;
    border-radius: 12px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
    overflow-x: auto;
    overflow-y: hidden;
    box-sizing: border-box;
}

.ah-products-wrapper::-webkit-scrollbar {
    height: 6px;
}

.ah-products-wrapper::-webkit-scrollbar-thumb {
    background: var(--ah-assistant-primary, #0073aa);
    border-radius: 3px;
}

.ah-products-wrapper::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

.ah-products-wrapper ul.products {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 12px !important;
    padding: 0 !important;
    margin: 0 !important;
    list-style: none;
}

.ah-products-wrapper ul.products li.product {
    flex: 0 0 auto !important;
    width: 180px !important;
    height: auto !important;
    margin: 0 !important;
    background: white;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
}

.ah-products-wrapper ul.products li.product:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

/* Karty produktów */
.ah-products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
    margin-top: 14px;
}

.ah-product-card {
    display: flex;
    flex-direction: column;
    border: none;
    padding: 14px;
    border-radius: 14px;
    background: white;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.ah-product-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 30px rgba(0, 115, 170, 0.2);
}

.ah-product-image {
    width: 100%;
    height: 110px;
    object-fit: contain;
    border-radius: 10px;
    margin-bottom: 12px;
    background: #f8f9fa;
    padding: 8px;
    box-sizing: border-box;
}

.ah-product-name {
    font-size: 13px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #1e293b;
    min-height: 36px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ah-product-price {
    font-weight: 700;
    font-size: 15px;
    color: var(--ah-assistant-primary, #0073aa);
    margin-bottom: 12px;
}

.ah-product-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ah-product-btn {
    flex: 1 1 auto;
    font-size: 12px;
    font-weight: 600;
    padding: 10px 14px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: all 0.2s ease;
}

.ah-add-to-cart {
    background: linear-gradient(135deg, var(--ah-assistant-primary, #0073aa), color-mix(in srgb, var(--ah-assistant-primary, #0073aa) 80%, #000));
    color: white;
    box-shadow: 0 2px 8px rgba(0, 115, 170, 0.3);
}

.ah-add-to-cart:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 115, 170, 0.4);
}

.ah-add-to-cart:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ah-add-to-cart.ah-added {
    background: linear-gradient(135deg, #10b981, #059669);
}

.ah-view-product {
    background: #f1f5f9;
    color: #475569;
}

.ah-view-product:hover {
    background: #e2e8f0;
    color: #1e293b;
}

/* Input area */
.ah-assistant-input-wrapper {
    display: flex;
    gap: 12px;
    padding: 18px 20px;
    background: white;
    border-top: 1px solid #e2e8f0;
}

.ah-assistant-input {
    flex-grow: 1;
    font-size: 14px;
    padding: 14px 16px;
    border-radius: 12px;
    border: 2px solid #e2e8f0;
    resize: none;
    font-family: inherit;
    max-height: 120px;
    transition: all 0.2s ease;
    background: #f8f9fa;
}

.ah-assistant-input:focus {
    border-color: var(--ah-assistant-primary, #0073aa);
    outline: none;
    background: white;
    box-shadow: 0 0 0 4px rgba(0, 115, 170, 0.1);
}

.ah-assistant-send {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--ah-assistant-primary, #0073aa), color-mix(in srgb, var(--ah-assistant-primary, #0073aa) 80%, #000));
    color: white;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 115, 170, 0.3);
}

.ah-assistant-send:hover:not(:disabled) {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 115, 170, 0.4);
}

.ah-assistant-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Typing indicator */
.ah-typing-indicator {
    display: flex;
    flex-direction: row !important;
    align-items: center;
    gap: 6px;
    padding: 16px 20px !important;
}

.ah-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--ah-assistant-primary, #0073aa);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.ah-typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.ah-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ah-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Toast notification */
.ah-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 25px rgba(16, 185, 129, 0.3);
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

.ah-toast.ah-toast-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.ah-toast.ah-toast-error {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    box-shadow: 0 8px 25px rgba(239, 68, 68, 0.3);
}

/* Variable product badge */
.ah-variable-badge {
    font-size: 10px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    padding: 3px 8px;
    border-radius: 6px;
    margin-bottom: 8px;
    display: inline-block;
}

/* Responsive */
@media (max-width: 768px) {
    .ah-assistant-container {
        height: 100vh;
        height: 100dvh;
        overflow-x: hidden;
    }

    .ah-assistant-window {
        border-radius: 0;
        height: 100%;
    }

    .ah-assistant-header {
        padding: 14px 16px;
    }

    .ah-assistant-header h3 {
        font-size: 16px;
    }

    .ah-assistant-new-chat {
        width: 34px;
        height: 34px;
    }

    .ah-assistant-messages {
        padding: 16px;
        gap: 12px;
    }

    .ah-message {
        max-width: 92%;
        gap: 8px;
    }

    .ah-message-avatar {
        width: 32px;
        height: 32px;
        border-radius: 8px;
        font-size: 14px;
    }

    .ah-message-content {
        padding: 10px 12px;
        border-radius: 12px;
        font-size: 14px;
        line-height: 1.4;
    }

    .ah-message-text {
        font-size: 14px;
    }

    /* Products - horizontal scroll on mobile */
    .ah-products-wrapper {
        margin: 8px -12px 0;
        padding: 10px 12px;
        border-radius: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .ah-products-grid {
        display: flex;
        flex-wrap: nowrap;
        gap: 10px;
        margin-top: 0;
    }

    .ah-product-card {
        flex: 0 0 140px;
        min-width: 140px;
        padding: 10px;
        border-radius: 10px;
    }

    .ah-product-image {
        height: 80px;
        border-radius: 6px;
        margin-bottom: 8px;
    }

    .ah-product-name {
        font-size: 12px;
        min-height: 32px;
        margin-bottom: 4px;
        -webkit-line-clamp: 2;
    }

    .ah-product-price {
        font-size: 13px;
        margin-bottom: 8px;
    }

    .ah-product-actions {
        gap: 6px;
    }

    .ah-product-btn {
        font-size: 11px;
        padding: 8px 6px;
        border-radius: 6px;
    }

    /* Input area */
    .ah-assistant-input-wrapper {
        padding: 12px;
        gap: 10px;
        border-top: 1px solid #e5e7eb;
    }

    .ah-assistant-input {
        padding: 10px 12px;
        font-size: 16px;
        /* prevent iOS zoom */
        border-radius: 10px;
        border-width: 1px;
    }

    .ah-assistant-send {
        width: 42px;
        height: 42px;
        border-radius: 10px;
    }

    /* Toast on mobile */
    .ah-toast {
        bottom: 80px;
        left: 16px;
        right: 16px;
        transform: translateY(20px);
        text-align: center;
    }

    .ah-toast.ah-toast-show {
        transform: translateY(0);
    }
}

/* Extra small screens */
@media (max-width: 380px) {
    .ah-message {
        max-width: 95%;
    }

    .ah-product-card {
        flex: 0 0 120px;
        min-width: 120px;
    }

    .ah-product-image {
        height: 60px;
    }

    .ah-product-name {
        font-size: 11px;
        min-height: 28px;
    }

    .ah-product-price {
        font-size: 12px;
    }

    .ah-product-btn {
        font-size: 10px;
        padding: 6px 4px;
    }
}

/* Scrollbary */
.ah-assistant-messages::-webkit-scrollbar {
    width: 6px;
}

.ah-assistant-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.ah-assistant-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.ah-assistant-messages::-webkit-scrollbar-track {
    background: transparent;
}