/* AI Chat Widget - floating button and chat panel */
.ai-chat-widget {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 9999;
    font-family: inherit;
}

/* Launcher: button first, then label */
.ai-chat-launcher {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-direction: row;
}

.ai-chat-launcher-label {
    display: inline-flex;
    align-items: center;
    background: linear-gradient(135deg, #ffffff 0%, #e8f5fd 100%);
    color: #006699;
    font-size: 13px;
    font-weight: 700;
    padding: 9px 18px;
    border-radius: 24px;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(0,138,207,0.25), 0 1px 4px rgba(0,0,0,0.08);
    border: 1.5px solid rgba(0,138,207,0.3);
    pointer-events: none;
    letter-spacing: 0.02em;
    line-height: 1.4;
    visibility: visible;
    opacity: 1;
    position: relative;
    overflow: hidden;
}
.ai-chat-launcher-label::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(0,138,207,0.08) 0%, rgba(0,102,153,0.04) 100%);
    border-radius: inherit;
    pointer-events: none;
}
.ai-chat-launcher-label::after {
    content: '✦';
    font-size: 9px;
    color: #008ACF;
    margin-left: 6px;
    opacity: 0.7;
}

/* Toggle button */
.ai-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #008ACF 0%, #006699 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 138, 207, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}
.ai-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 138, 207, 0.5);
}
.ai-chat-toggle-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
    filter: brightness(0) invert(1);
}
.ai-chat-toggle .ai-chat-toggle-logo {
    display: block;
}

/* Chat panel */
.ai-chat-panel {
    position: absolute;
    bottom: 74px;
    left: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 500px;
    max-height: 70vh;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px) scale(0.96);
    transition: opacity 0.25s, visibility 0.25s, transform 0.25s;
}
.ai-chat-panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}
.ai-chat-panel[aria-hidden="false"] {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.ai-chat-header {
    padding: 14px 16px;
    background: linear-gradient(135deg, #008ACF 0%, #006699 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.ai-chat-header-logo {
    width: 26px;
    height: 26px;
    margin-right: 10px;
    object-fit: contain;
    flex-shrink: 0;
    filter: brightness(0) invert(1);
}
[dir="rtl"] .ai-chat-header-logo {
    margin-right: 0;
    margin-left: 10px;
}
.ai-chat-header-title {
    font-weight: 600;
    font-size: 16px;
    display: flex;
    align-items: center;
}
.ai-chat-close {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255,255,255,0.2);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.ai-chat-close:hover {
    background: rgba(255,255,255,0.35);
}

/* Messages area */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f5f6f8;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ai-chat-welcome {
    padding: 12px 14px;
    background: #e8eef2;
    border-radius: 12px;
    color: #333;
    font-size: 14px;
    line-height: 1.5;
}
.ai-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}
.ai-chat-msg.user {
    align-self: flex-end;
    background: #008ACF;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ai-chat-msg.assistant {
    align-self: flex-start;
    background: #fff;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}
.ai-chat-msg.error {
    align-self: flex-start;
    background: #ffebee;
    color: #c62828;
    border: 1px solid #ffcdd2;
}
.ai-chat-msg .ai-chat-link {
    color: #008ACF;
    text-decoration: underline;
    word-break: break-all;
}
.ai-chat-msg.user .ai-chat-link {
    color: #fff;
    text-decoration: underline;
}
.ai-chat-msg .ai-chat-link:hover {
    opacity: 0.9;
}

/* Product card — rendered for list-style product suggestions */
.ai-product-card {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #f0f9ff 0%, #e4f3fb 100%);
    border: 1px solid #b8ddf2;
    border-left: 3px solid #008ACF;
    border-radius: 10px;
    padding: 9px 12px;
    margin: 5px 0;
    text-decoration: none;
    color: #1a1a1a !important;
    font-size: 13px;
    transition: background 0.15s, border-color 0.15s, transform 0.12s;
    width: 100%;
    box-sizing: border-box;
}
.ai-product-card:hover {
    background: linear-gradient(135deg, #daf0ff 0%, #c8e6f8 100%);
    border-left-color: #005580;
    transform: translateX(3px);
    color: #000;
}
[dir="rtl"] .ai-product-card {
    border-left: 1px solid #b8ddf2;
    border-right: 3px solid #008ACF;
}
[dir="rtl"] .ai-product-card:hover {
    transform: translateX(-3px);
}
.ai-product-icon {
    font-size: 15px;
    flex-shrink: 0;
    line-height: 1;
}
.ai-product-name {
    font-weight: 600;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-transform: capitalize;
    color: #1a1a1a !important;
}
/* Ensure product card text is always dark (overrides any parent/theme) */
.ai-chat-msg .ai-product-card,
.ai-chat-msg .ai-product-card .ai-product-name {
    color: #1a1a1a !important;
}
.ai-product-price {
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    background: #008ACF;
    padding: 3px 9px;
    border-radius: 12px;
    white-space: nowrap;
    flex-shrink: 0;
}
.ai-chat-typing {
    align-self: flex-start;
    padding: 12px 18px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}
.ai-chat-typing span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #008ACF;
    margin: 0 2px;
    animation: ai-chat-bounce 0.6s ease-in-out infinite;
}
.ai-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-chat-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* Input area */
.ai-chat-input-area {
    padding: 12px;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}
.ai-chat-input {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 22px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
}
.ai-chat-input:focus {
    border-color: #008ACF;
}
.ai-chat-send {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: #008ACF;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}
.ai-chat-send:hover {
    background: #006699;
}
.ai-chat-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* RTL: panel still anchors to the left edge of the launcher */
[dir="rtl"] .ai-chat-panel {
    left: 0;
    right: auto;
}

/* Hide label on very small screens to save space */
@media (max-width: 360px) {
    .ai-chat-launcher-label {
        display: none;
    }
}
[dir="rtl"] .ai-chat-msg.user {
    border-bottom-right-radius: 14px;
    border-bottom-left-radius: 4px;
}
[dir="rtl"] .ai-chat-msg.assistant {
    border-bottom-left-radius: 14px;
    border-bottom-right-radius: 4px;
}
[dir="rtl"] .ai-chat-icon-header {
    margin-right: 0;
    margin-left: 10px;
}

/* Mobile: make panel feel native */
@media (max-width: 600px) {
    .ai-chat-widget {
        left: 16px;
        right: auto;
        bottom: calc(16px + env(safe-area-inset-bottom));
    }

    .ai-chat-panel {
        width: min(420px, calc(100vw - 32px));
        height: min(70vh, 540px);
        max-height: calc(100vh - 140px);
    }
}

@media (max-width: 420px) {
    .ai-chat-panel {
        width: calc(100vw - 24px);
        height: min(78vh, 560px);
        border-radius: 14px;
    }

    .ai-chat-messages {
        padding: 12px;
    }

    .ai-chat-header {
        padding: 12px 14px;
    }
}
