/* === AI Sales Agent Chat Widget === */

:root {
    --aisa-primary: #0073aa;
    --aisa-primary-dark: color-mix(in srgb, var(--aisa-primary) 80%, black);
    --aisa-primary-light: color-mix(in srgb, var(--aisa-primary) 15%, white);
    --aisa-bg: #ffffff;
    --aisa-text: #1e1e1e;
    --aisa-text-light: #666666;
    --aisa-border: #e0e0e0;
    --aisa-user-bg: var(--aisa-primary);
    --aisa-user-text: #ffffff;
    --aisa-bot-bg: #f0f2f5;
    --aisa-bot-text: #1e1e1e;
    --aisa-radius: 16px;
    --aisa-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
}

/* =========================================
   FLOATING BUBBLE (agent photo)
   ========================================= */

.aisa-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--aisa-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--aisa-shadow);
    z-index: 99999;
    transition: transform 0.3s ease, opacity 0.3s ease;
    animation: aisa-pulse 2.5s infinite;
    -webkit-tap-highlight-color: transparent;
    border: none;
    padding: 0;
    overflow: hidden;
}

.aisa-bubble:hover {
    transform: scale(1.08);
}

.aisa-bubble:active {
    transform: scale(0.95);
}

.aisa-bubble.aisa-left {
    right: auto;
    left: 24px;
}

.aisa-bubble.aisa-hidden {
    transform: scale(0) !important;
    opacity: 0;
    pointer-events: none;
    animation: none;
}

.aisa-bubble-avatar {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.aisa-bubble-avatar .aisa-avatar {
    width: 100% !important;
    height: 100% !important;
    border: none;
    border-radius: 50%;
}

.aisa-bubble-avatar .aisa-avatar-initials {
    background: transparent;
    font-size: 26px;
}

/* Online dot on bubble */
.aisa-bubble-dot {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 14px;
    height: 14px;
    background: #31c652;
    border-radius: 50%;
    border: 3px solid #fff;
}

@keyframes aisa-pulse {
    0%, 100% { box-shadow: var(--aisa-shadow); }
    50% { box-shadow: var(--aisa-shadow), 0 0 0 10px rgba(0, 115, 170, 0.12); }
}

/* =========================================
   GREETING TOOLTIP (next to bubble)
   ========================================= */

.aisa-greeting {
    position: fixed;
    bottom: 36px;
    right: 100px;
    z-index: 99998;
    opacity: 0;
    transform: translateX(10px);
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.aisa-greeting.aisa-left {
    right: auto;
    left: 100px;
    transform: translateX(-10px);
}

.aisa-greeting.aisa-greeting-visible {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

.aisa-greeting.aisa-greeting-hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translateX(10px);
}

.aisa-greeting.aisa-left.aisa-greeting-hidden {
    transform: translateX(-10px);
}

.aisa-greeting-inner {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    padding: 12px 16px;
    max-width: 260px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;
    position: relative;
}

.aisa-greeting-inner::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
    border-left: 7px solid #fff;
}

.aisa-greeting.aisa-left .aisa-greeting-inner::after {
    right: auto;
    left: -6px;
    border-left: none;
    border-right: 7px solid #fff;
}

.aisa-greeting-text {
    font-size: 14px;
    line-height: 1.45;
    color: #1e1e1e;
    flex: 1;
}

.aisa-greeting-close {
    color: #999;
    font-size: 14px;
    cursor: pointer;
    line-height: 1;
    flex-shrink: 0;
    padding: 0 0 0 4px;
    font-family: Arial, Helvetica, sans-serif;
}

.aisa-greeting-close:hover {
    color: #333;
}

/* =========================================
   CHAT WINDOW
   ========================================= */

.aisa-chat {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: 550px;
    max-height: calc(100vh - 48px);
    max-width: calc(100vw - 32px);
    background: var(--aisa-bg);
    border-radius: var(--aisa-radius);
    box-shadow: var(--aisa-shadow);
    display: flex;
    flex-direction: column;
    z-index: 99999;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.aisa-chat.aisa-left {
    right: auto;
    left: 24px;
}

.aisa-chat.aisa-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* =========================================
   HEADER — agent avatar + name + status
   ========================================= */

.aisa-chat-header {
    background: var(--aisa-primary);
    color: #fff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 8px;
}

.aisa-header-agent {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.aisa-header-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

/* Avatar (photo or initials) */

.aisa-avatar {
    display: block;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.aisa-avatar-initials {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-weight: 700;
    line-height: 1;
}

/* Message avatar (smaller, no border) */
.aisa-msg-avatar .aisa-avatar {
    border: none;
}

/* Online dot */

.aisa-online-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    background: #31c652;
    border-radius: 50%;
    border: 2px solid var(--aisa-primary);
}

/* Header text */

.aisa-header-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.aisa-header-name {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.aisa-header-status {
    font-size: 11px;
    opacity: 0.8;
    line-height: 1.3;
}

/* Close button */

.aisa-chat-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
    font-size: 18px;
    line-height: 1;
    font-family: Arial, Helvetica, sans-serif;
    padding: 0;
}

.aisa-chat-close:hover {
    background: rgba(255, 255, 255, 0.25);
}


/* =========================================
   MESSAGES AREA
   ========================================= */

.aisa-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
}

.aisa-chat-messages::-webkit-scrollbar {
    width: 4px;
}

.aisa-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.aisa-chat-messages::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 2px;
}

/* =========================================
   MESSAGE BUBBLES
   ========================================= */

.aisa-msg {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    max-width: 85%;
}

.aisa-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.aisa-msg-assistant {
    align-self: flex-start;
}

.aisa-msg-avatar {
    flex-shrink: 0;
    margin-bottom: 2px;
}

.aisa-msg-bubble {
    padding: 10px 14px;
    border-radius: var(--aisa-radius);
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.aisa-msg-user .aisa-msg-bubble {
    background: var(--aisa-user-bg);
    color: var(--aisa-user-text);
    border-bottom-right-radius: 4px;
}

.aisa-msg-assistant .aisa-msg-bubble {
    background: var(--aisa-bot-bg);
    color: var(--aisa-bot-text);
    border-bottom-left-radius: 4px;
}

.aisa-msg-bubble a {
    color: inherit;
    text-decoration: underline;
}

.aisa-msg-user .aisa-msg-bubble a {
    color: #fff;
}

/* =========================================
   MARKDOWN RENDERING IN BUBBLES
   ========================================= */

/* Headings */
.aisa-md-h1 {
    font-size: 16px;
    font-weight: 700;
    margin: 6px 0 4px;
    line-height: 1.3;
}

.aisa-md-h2 {
    font-size: 15px;
    font-weight: 700;
    margin: 5px 0 3px;
    line-height: 1.3;
}

.aisa-md-h3 {
    font-size: 14px;
    font-weight: 700;
    margin: 4px 0 2px;
    line-height: 1.3;
}

/* Lists */
.aisa-md-list {
    margin: 4px 0;
    padding-left: 18px;
    list-style: disc;
}

.aisa-md-list li {
    margin: 2px 0;
    line-height: 1.45;
}

/* Links */
.aisa-md-link {
    color: var(--aisa-primary) !important;
    text-decoration: underline !important;
    word-break: break-all;
}

.aisa-msg-user .aisa-md-link {
    color: #fff !important;
}

/* Images in chat */
.aisa-md-img {
    max-width: 100%;
    max-height: 160px;
    border-radius: 8px;
    margin: 4px 0;
    display: block;
    object-fit: cover;
}

.aisa-md-img-link {
    display: block;
    text-decoration: none !important;
}

/* Inline code */
.aisa-md-code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
}

/* Horizontal rule */
.aisa-md-hr {
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.12);
    margin: 6px 0;
}

/* Paragraph break */
.aisa-md-break {
    height: 6px;
}

/* Animation */

.aisa-msg-animate {
    animation: aisa-slide-in 0.3s ease;
}

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

/* =========================================
   TYPING INDICATOR
   ========================================= */

.aisa-typing-dots {
    display: flex;
    gap: 5px;
    padding: 4px 2px;
}

.aisa-typing-dots span {
    width: 7px;
    height: 7px;
    background: #999;
    border-radius: 50%;
    animation: aisa-dot-bounce 1.4s infinite both;
}

.aisa-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.aisa-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aisa-dot-bounce {
    0%, 80%, 100% { transform: scale(0.5); opacity: 0.3; }
    40%           { transform: scale(1);   opacity: 1;   }
}

/* =========================================
   INPUT AREA
   ========================================= */

.aisa-chat-input-wrap {
    display: flex;
    padding: 10px 12px;
    border-top: 1px solid var(--aisa-border);
    gap: 8px;
    flex-shrink: 0;
    background: var(--aisa-bg);
    align-items: center;
}

.aisa-chat-input {
    flex: 1;
    border: 1px solid var(--aisa-border);
    border-radius: 20px;
    padding: 6px 14px !important;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    background: #f5f5f5;
    min-width: 0;
    resize: none;
    overflow-y: hidden;
    line-height: 1.3;
    height: 32px !important;
    min-height: 32px !important;
    max-height: 80px;
    box-sizing: border-box;
    margin: 0;
}

.aisa-chat-input:focus {
    border-color: var(--aisa-primary);
    background: #fff;
}

.aisa-chat-send {
    background: var(--aisa-primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    font-size: 20px;
    line-height: 1;
    font-family: Arial, Helvetica, sans-serif;
    padding: 0;
}

.aisa-chat-send:hover {
    background: var(--aisa-primary-dark);
}

.aisa-chat-send:active {
    transform: scale(0.92);
}


/* Closed state */

.aisa-closed-msg {
    padding: 14px 16px;
    font-size: 13px;
    color: var(--aisa-text-light);
    text-align: center;
    line-height: 1.5;
}

.aisa-closed-msg a {
    color: var(--aisa-primary);
    font-weight: 500;
}

/* =========================================
   PRODUCT CARDS
   ========================================= */

.aisa-products-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.aisa-product-card {
    display: flex;
    background: #fff;
    border: 1px solid var(--aisa-border);
    border-radius: 12px;
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.aisa-product-card:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.aisa-product-img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    flex-shrink: 0;
}

.aisa-product-info {
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 0;
}

.aisa-product-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--aisa-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.aisa-product-price {
    font-size: 14px;
    font-weight: 700;
    color: var(--aisa-primary);
}

.aisa-product-actions {
    display: flex;
    gap: 6px;
    margin-top: auto;
}

.aisa-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.aisa-btn-outline {
    background: transparent;
    color: var(--aisa-primary);
    border: 1px solid var(--aisa-primary);
}

.aisa-btn-outline:hover {
    background: var(--aisa-primary);
    color: #fff;
}

.aisa-btn-primary {
    background: var(--aisa-primary);
    color: #fff;
    border: 1px solid var(--aisa-primary);
}

.aisa-btn-primary:hover {
    background: var(--aisa-primary-dark);
    border-color: var(--aisa-primary-dark);
}

/* =========================================
   RESPONSIVE — Tablets
   ========================================= */

@media (max-width: 768px) {
    .aisa-chat {
        width: 340px;
        height: 500px;
    }
}

/* =========================================
   RESPONSIVE — Mobile (full screen)
   ========================================= */

@media (max-width: 480px) {
    .aisa-chat {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 0;
        max-width: 100%;
    }

    .aisa-chat.aisa-left {
        left: 0;
    }

    .aisa-chat-header {
        padding: 10px 12px;
        /* Safe area for notch phones */
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .aisa-chat-messages {
        padding: 12px 10px;
    }

    .aisa-msg {
        max-width: 90%;
    }

    .aisa-chat-input-wrap {
        padding: 8px 10px;
        /* Safe area for home bar */
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .aisa-chat-input {
        padding: 10px 14px;
        font-size: 16px; /* Prevent iOS zoom on focus */
    }

    .aisa-bubble {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .aisa-bubble.aisa-left {
        right: auto;
        left: 16px;
    }

    .aisa-greeting {
        bottom: 24px;
        right: 82px;
        max-width: calc(100vw - 100px);
    }

    .aisa-greeting.aisa-left {
        right: auto;
        left: 82px;
        max-width: calc(100vw - 100px);
    }

    .aisa-greeting-inner {
        max-width: 220px;
        padding: 10px 12px;
    }

    .aisa-greeting-text {
        font-size: 13px;
    }

    .aisa-product-card {
        border-radius: 10px;
    }

    .aisa-product-img {
        width: 70px;
        height: 70px;
    }
}

/* =========================================
   SMALL HEIGHT SCREENS (landscape mobile)
   ========================================= */

@media (max-height: 500px) {
    .aisa-chat {
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        bottom: 0;
        border-radius: 0;
    }

    .aisa-chat-header {
        padding: 8px 12px;
    }
}
