/**
 * Universal AI — Frontend Widget stylesheet (v2.5).
 *
 * Features:
 *   - Vazirmatn font (loaded from Google Fonts CDN) for beautiful Persian text
 *   - Modern, polished design with smooth animations
 *   - RTL-aware, mobile-friendly, accessible (ARIA, keyboard nav)
 *   - Dark mode support via `prefers-color-scheme: dark`
 *   - Safe-area insets for iPhone notch / home indicator
 *   - Adjusts for WordPress admin bar height (32px desktop / 46px mobile)
 *   - Auto-direction per message (using `dir="auto"` set via JS)
 *   - Product card rendering (when WooCommerce tools return product data)
 *   - Mobile breakpoints at 600px and 768px (tablet)
 *
 * Layout:
 *   .uaic-widget               outer container (holds launcher + panel)
 *     .uaic-launcher            floating button (with notification dot)
 *     .uaic-panel               chat panel (hidden until .uaic-panel-open)
 *       .uaic-header             top bar (gradient + avatar + title)
 *         .uaic-title            site name
 *         .uaic-close            × button
 *       .uaic-messages           scrollable message list
 *         .uaic-msg               single message bubble
 *         .uaic-msg-user          user message
 *         .uaic-msg-assistant     AI message
 *         .uaic-msg-error         error bubble (with optional Retry button)
 *         .uaic-product-card      product card (image, name, price, link)
 *         .uaic-product-grid      grid of product cards
 *       .uaic-input-row         textarea + voice + send buttons
 *         .uaic-voice-btn         voice input (Web Speech API)
 *         .uaic-send              send button
 *         .uaic-char-counter      live character counter
 *       .uaic-error             inline error toast (hidden by default)
 */

/* ============================================================
   Vazirmatn font — load from Google Fonts
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');

.uaic-widget {
    /* Light mode defaults (overridden by dark mode media query). */
    --uaic-color: #6366F1;
    --uaic-color-dark: #4F46E5;
    --uaic-color-light: #818CF8;
    --uaic-color-gradient: linear-gradient(135deg, #6366F1 0%, #8B5CF6 50%, #EC4899 100%);
    --uaic-bg: #ffffff;
    --uaic-bg-elevated: #ffffff;
    --uaic-bg-muted: #f9fafb;
    --uaic-text: #111827;
    --uaic-text-secondary: #4b5563;
    --uaic-muted: #6b7280;
    --uaic-border: #e5e7eb;
    --uaic-border-light: #f3f4f6;
    --uaic-bubble-user-bg: linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%);
    --uaic-bubble-user-fg: #ffffff;
    --uaic-bubble-ai-bg: #f3f4f6;
    --uaic-bubble-ai-fg: #1f2937;
    --uaic-error-bg: #fee2e2;
    --uaic-error-fg: #991b1b;
    --uaic-success: #10B981;
    --uaic-warning: #F59E0B;
    --uaic-radius: 16px;
    --uaic-radius-sm: 10px;
    --uaic-radius-xs: 6px;
    --uaic-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --uaic-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --uaic-shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.2);
    --uaic-panel-w: 400px;
    --uaic-panel-h: 600px;
    --uaic-launcher-size: 62px;
    --uaic-gap: 8px;
    --uaic-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    /* WP admin bar heights — adjusted via media query. */
    --uaic-admin-bar-h: 0px;

    font-family: "Vazirmatn", -apple-system, BlinkMacSystemFont, "Segoe UI", "Tahoma", sans-serif;
    color: var(--uaic-text);
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Account for the WP admin bar on front-end views for logged-in admins. */
body.admin-bar .uaic-widget {
    --uaic-admin-bar-h: 32px;
}
@media (max-width: 782px) {
    body.admin-bar .uaic-widget {
        --uaic-admin-bar-h: 46px;
    }
}

.uaic-widget *,
.uaic-widget *::before,
.uaic-widget *::after {
    box-sizing: border-box;
}

/* ---- Dark mode ---- */
@media (prefers-color-scheme: dark) {
    .uaic-widget {
        --uaic-bg: #1a1b26;
        --uaic-bg-elevated: #24253b;
        --uaic-bg-muted: #1e1f2e;
        --uaic-text: #e5e7eb;
        --uaic-text-secondary: #9ca3af;
        --uaic-muted: #9ca3af;
        --uaic-border: #2d2e42;
        --uaic-border-light: #24253b;
        --uaic-bubble-ai-bg: #24253b;
        --uaic-bubble-ai-fg: #e5e7eb;
        --uaic-error-bg: #7f1d1d;
        --uaic-error-fg: #fecaca;
        --uaic-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
        --uaic-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
        --uaic-shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.6);
    }
}

/* ============================================================
   Launcher button
   ============================================================ */
.uaic-launcher {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    width: var(--uaic-launcher-size);
    height: var(--uaic-launcher-size);
    border-radius: 50%;
    background: var(--uaic-color-gradient);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.45), 0 0 0 0 rgba(99, 102, 241, 0.5);
    transition: transform var(--uaic-transition), box-shadow var(--uaic-transition);
    z-index: 99998;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    animation: uaic-launcher-pulse 3s ease-in-out infinite;
}

.uaic-launcher:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 32px rgba(99, 102, 241, 0.55), 0 0 0 8px rgba(99, 102, 241, 0.1);
}

.uaic-launcher:active {
    transform: translateY(-1px) scale(1.02);
}

.uaic-launcher:focus-visible {
    outline: 3px solid rgba(99, 102, 241, 0.5);
    outline-offset: 3px;
}

@keyframes uaic-launcher-pulse {
    0%, 100% { box-shadow: 0 8px 24px rgba(99, 102, 241, 0.45), 0 0 0 0 rgba(99, 102, 241, 0.4); }
    50% { box-shadow: 0 8px 24px rgba(99, 102, 241, 0.45), 0 0 0 12px rgba(99, 102, 241, 0); }
}

.uaic-pos-bottom_left .uaic-launcher { left: calc(24px + env(safe-area-inset-left, 0px)); }
.uaic-pos-bottom_right .uaic-launcher { right: calc(24px + env(safe-area-inset-right, 0px)); }

/* Launcher icon transition */
.uaic-launcher-icon svg {
    transition: transform var(--uaic-transition);
}
.uaic-panel-open ~ .uaic-launcher .uaic-launcher-icon svg,
.uaic-widget:has(.uaic-panel-open) .uaic-launcher-icon svg {
    transform: rotate(90deg);
}

/* ============================================================
   Chat panel
   ============================================================ */
.uaic-panel {
    position: fixed;
    bottom: calc(100px + var(--uaic-admin-bar-h) + env(safe-area-inset-bottom, 0px));
    width: var(--uaic-panel-w);
    max-width: calc(100vw - 32px);
    height: var(--uaic-panel-h);
    max-height: calc(100vh - 140px - var(--uaic-admin-bar-h));
    background: var(--uaic-bg);
    border-radius: var(--uaic-radius);
    box-shadow: var(--uaic-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99999;
    border: 1px solid var(--uaic-border);
    animation: uaic-panel-slide-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.uaic-pos-bottom_left .uaic-panel { left: calc(24px + env(safe-area-inset-left, 0px)); }
.uaic-pos-bottom_right .uaic-panel { right: calc(24px + env(safe-area-inset-right, 0px)); }

.uaic-panel[hidden] {
    display: none;
}

@keyframes uaic-panel-slide-in {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================================
   Header (with gradient background + avatar)
   ============================================================ */
.uaic-header {
    background: var(--uaic-color-gradient);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
}

.uaic-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: rgba(255, 255, 255, 0.15);
}

.uaic-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    backdrop-filter: blur(8px);
}

.uaic-header-avatar svg {
    width: 22px;
    height: 22px;
    color: #fff;
}

.uaic-header h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.uaic-header-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    opacity: 0.85;
    font-weight: 500;
}

.uaic-header-status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ADE80;
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.6);
    animation: uaic-status-blink 2s ease-in-out infinite;
}

@keyframes uaic-status-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.uaic-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--uaic-transition), transform var(--uaic-transition);
    flex-shrink: 0;
}

.uaic-close:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: rotate(90deg);
}

.uaic-close:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.6);
    outline-offset: 2px;
}

/* ============================================================
   Messages list
   ============================================================ */
.uaic-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    background: var(--uaic-bg);
}

/* Custom scrollbar */
.uaic-messages::-webkit-scrollbar {
    width: 6px;
}
.uaic-messages::-webkit-scrollbar-track {
    background: transparent;
}
.uaic-messages::-webkit-scrollbar-thumb {
    background: var(--uaic-border);
    border-radius: 3px;
}
.uaic-messages::-webkit-scrollbar-thumb:hover {
    background: var(--uaic-muted);
}

/* ============================================================
   Message bubbles
   ============================================================ */
.uaic-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    word-break: break-word;
    animation: uaic-msg-in 0.3s ease-out;
    white-space: pre-wrap;
}

@keyframes uaic-msg-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.uaic-msg-user {
    background: var(--uaic-bubble-user-bg);
    color: var(--uaic-bubble-user-fg);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

.uaic-msg-assistant {
    background: var(--uaic-bubble-ai-bg);
    color: var(--uaic-bubble-ai-fg);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: var(--uaic-shadow-sm);
}

.uaic-msg-error {
    background: var(--uaic-error-bg);
    color: var(--uaic-error-fg);
    align-self: center;
    text-align: center;
    border-radius: 10px;
    font-size: 13px;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* ============================================================
   Product cards — horizontally scrollable, image-dominant design.
   Matches widget UI: white bg, subtle border, 16-20px radius, soft shadow.
   Cards animate in with Fade+Slide for a live, interactive feel.
   ============================================================ */

/* Horizontal scroll container — the row of product cards */
.uaic-product-grid {
    display: flex;
    gap: 10px;
    margin: 10px 0 6px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    scrollbar-width: thin;
    scrollbar-color: var(--uaic-border) transparent;
}

/* Custom scrollbar for the product row */
.uaic-product-grid::-webkit-scrollbar {
    height: 4px;
}
.uaic-product-grid::-webkit-scrollbar-track {
    background: transparent;
}
.uaic-product-grid::-webkit-scrollbar-thumb {
    background: var(--uaic-border);
    border-radius: 2px;
}
.uaic-product-grid::-webkit-scrollbar-thumb:hover {
    background: var(--uaic-muted);
}

/* Individual product card — image-dominant, clean design */
.uaic-product-card {
    flex: 0 0 150px;
    background: var(--uaic-bg-elevated);
    border: 1px solid var(--uaic-border);
    border-radius: 18px;
    overflow: hidden;
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1), box-shadow 0.25s ease, border-color 0.25s ease;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    opacity: 0;
    transform: translateY(12px);
    animation: uaic-card-enter 0.4s ease-out forwards;
}

/* Stagger animation — each card appears slightly later */
.uaic-product-card:nth-child(1) { animation-delay: 0.05s; }
.uaic-product-card:nth-child(2) { animation-delay: 0.12s; }
.uaic-product-card:nth-child(3) { animation-delay: 0.19s; }
.uaic-product-card:nth-child(4) { animation-delay: 0.26s; }
.uaic-product-card:nth-child(5) { animation-delay: 0.33s; }
.uaic-product-card:nth-child(6) { animation-delay: 0.40s; }

@keyframes uaic-card-enter {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.uaic-product-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
    border-color: var(--uaic-color-light);
}

.uaic-product-card:active {
    transform: translateY(-1px) scale(0.99);
}

/* Product image — the main focus of the card */
.uaic-product-card-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--uaic-bg-muted);
    display: block;
}

/* Image placeholder (when no image available) */
.uaic-product-card-placeholder {
    width: 100%;
    aspect-ratio: 1;
    background: linear-gradient(135deg, var(--uaic-bg-muted), var(--uaic-border-light));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--uaic-muted);
}

/* Card body — compact, clean info below the image */
.uaic-product-card-body {
    padding: 8px 10px 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.uaic-product-card-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--uaic-text);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    min-height: 34px;
}

.uaic-product-card-price {
    font-size: 13px;
    font-weight: 700;
    color: var(--uaic-color);
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.uaic-product-card-price del {
    color: var(--uaic-muted);
    font-size: 11px;
    font-weight: 400;
    text-decoration: line-through;
}

.uaic-product-card-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 600;
    background: rgba(16, 185, 129, 0.1);
    color: var(--uaic-success);
    margin-top: 2px;
}

.uaic-product-card-badge.out-of-stock {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* Single product — full width card with horizontal layout */
.uaic-product-card-single {
    flex: 0 0 100%;
    flex-direction: row;
    border-radius: 18px;
}

.uaic-product-card-single .uaic-product-card-image,
.uaic-product-card-single .uaic-product-card-placeholder {
    width: 110px;
    aspect-ratio: 1;
    flex-shrink: 0;
}

.uaic-product-card-single .uaic-product-card-body {
    padding: 12px 14px;
}

.uaic-product-card-single .uaic-product-card-name {
    font-size: 14px;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    min-height: 0;
}

/* ============================================================
   Typing indicator
   ============================================================ */
.uaic-typing {
    align-self: flex-start;
    background: var(--uaic-bubble-ai-bg);
    padding: 12px 16px;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 4px;
    box-shadow: var(--uaic-shadow-sm);
}

.uaic-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--uaic-muted);
    animation: uaic-typing-bounce 1.4s ease-in-out infinite;
}

.uaic-typing span:nth-child(1) { animation-delay: -0.32s; }
.uaic-typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes uaic-typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================================
   Retry button (in error messages)
   ============================================================ */
.uaic-retry {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: inherit;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    margin-top: 6px;
    transition: background var(--uaic-transition);
    font-family: inherit;
}

.uaic-retry:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ============================================================
   Input row (textarea + voice + send)
   ============================================================ */
.uaic-input-row {
    padding: 12px 16px;
    border-top: 1px solid var(--uaic-border);
    background: var(--uaic-bg-elevated);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

.uaic-input-row > .uaic-input-row-inner {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex: 1;
    background: var(--uaic-bg-muted);
    border: 1px solid var(--uaic-border);
    border-radius: 20px;
    padding: 4px 4px 4px 14px;
    transition: border-color var(--uaic-transition), box-shadow var(--uaic-transition);
}

.uaic-input-row > .uaic-input-row-inner:focus-within {
    border-color: var(--uaic-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.uaic-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--uaic-text);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 24px;
    padding: 6px 0;
}

.uaic-input::placeholder {
    color: var(--uaic-muted);
}

.uaic-send {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--uaic-color-gradient);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform var(--uaic-transition), opacity var(--uaic-transition);
}

.uaic-send:hover:not(:disabled) {
    transform: scale(1.08);
    opacity: 0.9;
}

.uaic-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.uaic-send:focus-visible {
    outline: 2px solid rgba(99, 102, 241, 0.4);
    outline-offset: 2px;
}

/* ---- Voice input button ---- */
.uaic-voice-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--uaic-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--uaic-transition), color var(--uaic-transition);
    margin-inline-end: 4px;
}

.uaic-voice-btn:hover {
    background: rgba(99, 102, 241, 0.1);
    color: var(--uaic-color);
}

.uaic-voice-btn.is-listening {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    animation: uaic-pulse 1.2s ease-in-out infinite;
}

.uaic-voice-btn:focus-visible {
    outline: 2px solid rgba(99, 102, 241, 0.4);
    outline-offset: 2px;
}

@keyframes uaic-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ---- Character counter ---- */
.uaic-char-counter {
    font-size: 11px;
    color: var(--uaic-muted);
    text-align: end;
    padding: 2px 16px;
    background: var(--uaic-bg-elevated);
    border-top: 1px solid var(--uaic-border-light);
}

.uaic-char-counter-over {
    color: #ef4444;
    font-weight: 600;
}

/* ============================================================
   Error bar
   ============================================================ */
.uaic-error {
    padding: 8px 16px;
    background: var(--uaic-error-bg);
    color: var(--uaic-error-fg);
    font-size: 12px;
    text-align: center;
    border-top: 1px solid rgba(239, 68, 68, 0.2);
}

/* ============================================================
   Inline widget (shortcode)
   ============================================================ */
.uaic-inline .uaic-panel {
    position: relative;
    bottom: auto;
    left: auto;
    right: auto;
    width: 100%;
    max-width: 100%;
    height: 500px;
    max-height: 100%;
    border-radius: var(--uaic-radius);
    box-shadow: var(--uaic-shadow);
    animation: none;
}

.uaic-inline .uaic-launcher {
    display: none;
}

.uaic-inline .uaic-input-row {
    border-radius: 0 0 var(--uaic-radius) var(--uaic-radius);
}

/* Loading state */
.uaic-is-loading .uaic-send {
    opacity: 0.5;
    pointer-events: none;
}

.uaic-is-loading .uaic-input {
    opacity: 0.7;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    .uaic-widget {
        --uaic-panel-w: 100vw;
        --uaic-panel-h: 100vh;
        --uaic-radius: 0;
    }

    .uaic-panel {
        bottom: 0;
        left: 0;
        right: 0;
        max-width: 100%;
        max-height: 100vh;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        padding-top: var(--uaic-admin-bar-h);
    }

    .uaic-launcher {
        bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    }

    .uaic-product-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .uaic-widget {
        --uaic-launcher-size: 56px;
    }

    .uaic-product-grid {
        grid-template-columns: 1fr;
    }

    .uaic-product-card-single {
        grid-column: span 1;
    }

    .uaic-msg {
        max-width: 92%;
        font-size: 13px;
    }

    .uaic-header {
        padding: 12px 14px;
    }

    .uaic-header h2 {
        font-size: 14px;
    }

    .uaic-input-row {
        padding: 10px 12px;
    }
}

/* ============================================================
   Bubble style variants (applied via JS based on settings)
   ============================================================ */

/* Flat style — solid colors, minimal shadows */
.uaic-bubble-flat .uaic-msg-user {
    background: var(--uaic-color);
    box-shadow: none;
}
.uaic-bubble-flat .uaic-msg-assistant {
    background: var(--uaic-bg-muted);
    box-shadow: none;
}
.uaic-bubble-flat .uaic-header {
    background: var(--uaic-color);
}
.uaic-bubble-flat .uaic-launcher {
    background: var(--uaic-color);
    animation: none;
}

/* Minimal style — no background on AI messages, borderless */
.uaic-bubble-minimal .uaic-msg-assistant {
    background: transparent;
    box-shadow: none;
    padding-inline-start: 0;
    padding-inline-end: 0;
    border-bottom: 1px solid var(--uaic-border-light);
    border-radius: 0;
}
.uaic-bubble-minimal .uaic-msg-user {
    background: var(--uaic-color);
    border-radius: 12px;
}
.uaic-bubble-minimal .uaic-typing {
    background: transparent;
    box-shadow: none;
}

/* ============================================================
   RTL Support — Persian/Arabic frontend widget
   WordPress adds dir="rtl" to <html> for RTL languages.
   ============================================================ */

html[dir="rtl"] .uaic-widget {
    direction: rtl;
}

html[dir="rtl"] .uaic-msg-user {
    align-self: flex-start;
    border-bottom-right-radius: 16px;
    border-bottom-left-radius: 4px;
}

html[dir="rtl"] .uaic-msg-assistant {
    align-self: flex-end;
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 4px;
}

html[dir="rtl"] .uaic-input-row {
    direction: rtl;
}

html[dir="rtl"] .uaic-header {
    direction: rtl;
}

html[dir="rtl"] .uaic-close {
    margin-inline-start: auto;
    margin-inline-end: 0;
}

html[dir="rtl"] .uaic-product-grid {
    direction: rtl;
}

html[dir="rtl"] .uaic-data-table {
    direction: rtl;
}

/* Fix voice button position for RTL */
html[dir="rtl"] .uaic-voice-btn {
    margin-inline-end: 4px;
    margin-inline-start: 0;
}

/* Fix char counter for RTL */
html[dir="rtl"] .uaic-char-counter {
    text-align: left;
}

/* Fix product card for RTL */
html[dir="rtl"] .uaic-product-card-single .uaic-product-card-image,
html[dir="rtl"] .uaic-product-card-single .uaic-product-card-placeholder {
    border-left: none;
    border-right: 1px solid var(--uaic-border-light);
}

/* ============================================================
   RTL class (applied when WordPress is fa_IR, ar, etc.)
   ============================================================ */
.uaic-widget.uaic-rtl {
    direction: rtl;
}

.uaic-widget.uaic-rtl .uaic-msg-user {
    align-self: flex-start;
    border-bottom-right-radius: 16px;
    border-bottom-left-radius: 4px;
}

.uaic-widget.uaic-rtl .uaic-msg-assistant {
    align-self: flex-end;
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 4px;
}

.uaic-widget.uaic-rtl .uaic-input-row {
    direction: rtl;
}

.uaic-widget.uaic-rtl .uaic-header {
    direction: rtl;
}

.uaic-widget.uaic-rtl .uaic-close {
    margin-inline-start: auto;
    margin-inline-end: 0;
}

.uaic-widget.uaic-rtl .uaic-product-grid {
    direction: rtl;
}

.uaic-widget.uaic-rtl .uaic-char-counter {
    text-align: left;
}

.uaic-widget.uaic-rtl .uaic-voice-btn {
    margin-inline-end: 4px;
    margin-inline-start: 0;
}

.uaic-widget.uaic-rtl .uaic-product-card-single .uaic-product-card-image,
.uaic-widget.uaic-rtl .uaic-product-card-single .uaic-product-card-placeholder {
    border-left: none;
    border-right: 1px solid var(--uaic-border-light);
}

/* ============================================================
   Human Handoff bar + form
   ============================================================ */
.uaic-handoff-bar {
    padding: 8px 16px;
    border-top: 1px solid var(--uaic-border);
    background: var(--uaic-bg-elevated);
    display: flex;
    justify-content: center;
}

.uaic-handoff-btn {
    background: transparent;
    border: 1px solid var(--uaic-color);
    color: var(--uaic-color);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background var(--uaic-transition), color var(--uaic-transition);
    font-family: inherit;
}

.uaic-handoff-btn:hover {
    background: var(--uaic-color);
    color: #fff;
}

.uaic-handoff-form {
    padding: 16px;
    background: var(--uaic-bg);
    border-top: 1px solid var(--uaic-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.uaic-handoff-form-header {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--uaic-text);
}

.uaic-handoff-form input,
.uaic-handoff-form textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--uaic-border);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    background: var(--uaic-bg-elevated);
    color: var(--uaic-text);
}

.uaic-handoff-form input:focus,
.uaic-handoff-form textarea:focus {
    outline: none;
    border-color: var(--uaic-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.uaic-handoff-send {
    background: var(--uaic-color-gradient);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.uaic-handoff-cancel {
    background: transparent;
    border: none;
    color: var(--uaic-muted);
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
}

/* Product section title (above the horizontal scroll row) */
.uaic-product-section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--uaic-muted);
    margin: 4px 0 2px;
    padding: 0;
    text-transform: none;
    letter-spacing: 0;
}

/* Responsive: cards slightly wider on small screens */
@media (max-width: 480px) {
    .uaic-product-card {
        flex: 0 0 130px;
    }
}

/* ============================================================
   Smooth UX Enhancements — applied v3.4.1
   These tweaks make the widget feel premium and buttery-smooth.
   ============================================================ */

/* 1. Smoother panel open/close with spring-like easing */
.uaic-panel {
    animation: uaic-panel-spring-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes uaic-panel-spring-in {
    0% {
        opacity: 0;
        transform: translateY(24px) scale(0.92);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 2. Message bubbles: spring entrance for a lively feel */
.uaic-msg {
    animation: uaic-msg-spring 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes uaic-msg-spring {
    0% {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 3. User messages slide from right, assistant from left */
.uaic-msg-user {
    animation: uaic-msg-slide-right 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes uaic-msg-slide-right {
    0% {
        opacity: 0;
        transform: translateX(20px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.uaic-msg-assistant {
    animation: uaic-msg-slide-left 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes uaic-msg-slide-left {
    0% {
        opacity: 0;
        transform: translateX(-15px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* RTL: swap directions */
.uaic-widget.uaic-rtl .uaic-msg-user {
    animation: uaic-msg-slide-left 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.uaic-widget.uaic-rtl .uaic-msg-assistant {
    animation: uaic-msg-slide-right 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 4. Smoother typing indicator with wave effect */
.uaic-typing {
    gap: 5px;
}

.uaic-typing span {
    width: 7px;
    height: 7px;
    animation: uaic-typing-wave 1.2s ease-in-out infinite;
}

.uaic-typing span:nth-child(1) { animation-delay: 0s; }
.uaic-typing span:nth-child(2) { animation-delay: 0.15s; }
.uaic-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes uaic-typing-wave {
    0%, 60%, 100% {
        transform: translateY(0) scale(0.7);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-6px) scale(1);
        opacity: 1;
    }
}

/* 5. Input focus: smooth glow transition */
.uaic-input-row > .uaic-input-row-inner {
    transition: border-color 0.2s ease, box-shadow 0.3s ease, background 0.2s ease;
}

.uaic-input-row > .uaic-input-row-inner:focus-within {
    border-color: var(--uaic-color);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.08);
    background: var(--uaic-bg-elevated);
}

/* 6. Send button: active feedback (press down) */
.uaic-send:active:not(:disabled) {
    transform: scale(0.92);
    transition: transform 0.08s ease;
}

.uaic-send:hover:not(:disabled) {
    transform: scale(1.1);
    transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 7. Launcher: more natural hover with bounce */
.uaic-launcher {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

.uaic-launcher:hover {
    transform: translateY(-4px) scale(1.06);
}

.uaic-launcher:active {
    transform: translateY(-1px) scale(0.98);
    transition: transform 0.1s ease;
}

/* 8. Close button: smooth rotation */
.uaic-close {
    transition: background 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.uaic-close:hover {
    transform: rotate(90deg);
    background: rgba(255, 255, 255, 0.3);
}

/* 9. Scroll smoothness for messages list */
.uaic-messages {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* 10. Product card hover: lift + shadow (smoother) */
.uaic-product-card {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.3s ease,
                border-color 0.3s ease;
}

.uaic-product-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 28px rgba(0,0,0,0.1);
}

.uaic-product-card:active {
    transform: translateY(-1px) scale(0.98);
    transition: transform 0.1s ease;
}

/* 11. Loading state: subtle pulse on input area */
.uaic-is-loading .uaic-input-row {
    animation: uaic-subtle-pulse 2s ease-in-out infinite;
}

@keyframes uaic-subtle-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.92; }
}

/* 12. Error messages: shake animation */
.uaic-msg-error {
    animation: uaic-shake 0.4s ease;
}

@keyframes uaic-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* 13. Handoff button: smooth press feedback */
.uaic-handoff-btn {
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.uaic-handoff-btn:active {
    transform: scale(0.95);
    transition: transform 0.08s ease;
}

/* 14. Voice button: active state smoothness */
.uaic-voice-btn {
    transition: background 0.2s ease, color 0.2s ease, transform 0.1s ease;
}

.uaic-voice-btn:active {
    transform: scale(0.9);
    transition: transform 0.08s ease;
}

/* 15. Header avatar: subtle float animation */
.uaic-header-avatar {
    animation: uaic-float 4s ease-in-out infinite;
}

@keyframes uaic-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px); }
}

/* 16. Online status dot: softer pulse */
.uaic-header-status::before {
    animation: uaic-status-pulse 2.5s ease-in-out infinite;
}

@keyframes uaic-status-pulse {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
    }
    50% {
        opacity: 0.7;
        box-shadow: 0 0 10px rgba(74, 222, 128, 0.3);
    }
}

/* 17. Char counter: smooth color transition */
.uaic-char-counter {
    transition: color 0.2s ease;
}

/* 18. Smooth scrollbar fade */
.uaic-messages::-webkit-scrollbar-thumb {
    transition: background 0.2s ease;
}

/* 19. Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .uaic-launcher,
    .uaic-panel,
    .uaic-msg,
    .uaic-msg-user,
    .uaic-msg-assistant,
    .uaic-typing span,
    .uaic-product-card,
    .uaic-header-avatar,
    .uaic-header-status::before,
    .uaic-is-loading .uaic-input-row {
        animation: none !important;
        transition: none !important;
    }
    
    .uaic-launcher:hover,
    .uaic-send:hover,
    .uaic-close:hover,
    .uaic-product-card:hover {
        transform: none !important;
    }
}
