/**
 * SMAI Chatbot Frontend Styles
 *
 * Uses CSS Custom Properties for theming:
 *   --smai-window-height, --smai-header-bg, --smai-header-text,
 *   --smai-chatbox-bg, --smai-user-msg-bg, --smai-user-msg-text,
 *   --smai-bot-msg-bg, --smai-bot-msg-text, --smai-link-color,
 *   --smai-send-btn-bg, --smai-send-btn-text
 */

/* ============================
   Container & Toggle
   ============================ */
#smai-chatbot-wrap {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

#smai-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: var(--smai-header-bg, #038AF9);
    cursor: pointer;
    padding: 5px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#smai-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

#smai-toggle-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
}

/* ============================
   Chatbox Window
   ============================ */
#smai-chatbox {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 420px;
    height: var(--smai-window-height, 600px);
    max-height: calc(100vh - 120px);
    background: var(--smai-chatbox-bg, #fff);
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#smai-chatbox.smai-hidden {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
}

#smai-chatbox.smai-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ============================
   Header
   ============================ */
#smai-header {
    background: var(--smai-header-bg, #038AF9);
    color: var(--smai-header-text, #fff);
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    border-radius: 16px 16px 0 0;
}

#smai-header-title {
    font-weight: 600;
    font-size: 15px;
}

#smai-close-btn {
    background: none;
    border: none;
    color: var(--smai-header-text, #fff);
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}

#smai-close-btn:hover {
    opacity: 1;
}

/* ============================
   Messages Area
   ============================ */
#smai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

#smai-messages::-webkit-scrollbar {
    width: 6px;
}

#smai-messages::-webkit-scrollbar-track {
    background: transparent;
}

#smai-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* ============================
   Messages
   ============================ */
.smai-msg {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    max-width: 88%;
}

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

.smai-msg-bot {
    align-self: flex-start;
}

.smai-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
}

.smai-msg-content {
    padding: 10px 14px;
    border-radius: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.smai-msg-user .smai-msg-content {
    background: var(--smai-user-msg-bg, #add8e6);
    color: var(--smai-user-msg-text, #000);
    border-bottom-right-radius: 4px;
}

.smai-msg-bot .smai-msg-content {
    background: var(--smai-bot-msg-bg, #ffc0cb);
    color: var(--smai-bot-msg-text, #000);
    border-bottom-left-radius: 4px;
}

/* Animate new messages */
.smai-msg-animate {
    animation: smaiMsgIn 0.3s ease-out;
}

@keyframes smaiMsgIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Markdown content in bot messages */
.smai-msg-bot .smai-msg-content p {
    margin: 0 0 8px 0;
}

.smai-msg-bot .smai-msg-content p:last-child {
    margin-bottom: 0;
}

.smai-msg-bot .smai-msg-content ul,
.smai-msg-bot .smai-msg-content ol {
    margin: 4px 0;
    padding-left: 20px;
}

.smai-msg-bot .smai-msg-content a,
.smai-msg-user .smai-msg-content a {
    color: var(--smai-link-color, #0066cc);
    text-decoration: underline;
}

.smai-msg-bot .smai-msg-content strong {
    font-weight: 600;
}

.smai-msg-bot .smai-msg-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 13px;
}

.smai-msg-bot .smai-msg-content pre {
    background: rgba(0, 0, 0, 0.06);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
}

.smai-msg-bot .smai-msg-content pre code {
    background: none;
    padding: 0;
}

/* Product images (standalone via appendImage) */
.smai-msg-image {
    padding: 4px;
}

.smai-product-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 10px;
    display: block;
}

/* Product images in bot messages (from markdown) */
.smai-msg-bot .smai-msg-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    background: #fff;
    padding: 4px;
    border: 1px solid #e8e8e8;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    display: block;
    margin: 6px 0;
}

/* Archive/navigation link buttons */
.smai-archive-link {
    display: inline-block;
    padding: 8px 16px;
    margin: 4px 4px 4px 0;
    background: var(--smai-header-bg, #038AF9);
    color: #fff !important;
    border-radius: 20px;
    text-decoration: none !important;
    font-size: 13px;
    font-weight: 500;
    transition: opacity 0.2s, transform 0.15s;
    line-height: 1.4;
}

.smai-archive-link:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

/* Product card styling in bot messages */
.smai-msg-bot .smai-msg-content ol > li,
.smai-msg-bot .smai-msg-content ul > li {
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.smai-msg-bot .smai-msg-content ol > li:last-child,
.smai-msg-bot .smai-msg-content ul > li:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

/* ============================
   Typing Indicator
   ============================ */
#smai-typing {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.smai-typing-dots {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    background: var(--smai-bot-msg-bg, #ffc0cb);
    border-radius: 14px;
}

.smai-typing-dots span {
    width: 7px;
    height: 7px;
    background: var(--smai-bot-msg-text, #000);
    border-radius: 50%;
    opacity: 0.4;
    animation: smaiDot 1.4s infinite ease-in-out;
}

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

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

@keyframes smaiDot {
    0%, 80%, 100% { opacity: 0.4; transform: scale(1); }
    40% { opacity: 1; transform: scale(1.2); }
}

#smai-typing-wait {
    font-size: 12px;
    color: var(--smai-bot-msg-text, #666);
    opacity: 0.7;
    margin-top: 4px;
    padding-left: 4px;
    animation: smaiFadeIn 0.3s ease-in;
}

@keyframes smaiFadeIn {
    from { opacity: 0; }
    to { opacity: 0.7; }
}

/* ============================
   Input Area
   ============================ */
#smai-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    background: var(--smai-chatbox-bg, #fff);
}

#smai-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 100px;
    min-height: 20px;
    line-height: 1.4;
    transition: border-color 0.2s;
}

#smai-input:focus {
    border-color: var(--smai-header-bg, #038AF9);
}

#smai-send-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    border: none;
    background: var(--smai-send-btn-bg, #dc3232);
    color: var(--smai-send-btn-text, #fff);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, background 0.2s;
}

#smai-send-btn:hover {
    transform: scale(1.05);
}

#smai-send-btn:active {
    transform: scale(0.95);
}

#smai-send-btn svg {
    display: block;
    pointer-events: none;
}

/* ============================
   Footer
   ============================ */
#smai-footer {
    text-align: center;
    padding: 6px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}

#smai-footer a {
    color: #999;
    font-size: 11px;
    text-decoration: none;
}

#smai-footer a:hover {
    color: #666;
}

/* ============================
   Pre-chat Form
   ============================ */
#smai-prechat-form {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px;
}

#smai-prechat-content {
    width: 100%;
    text-align: center;
}

#smai-prechat-title {
    margin: 0 0 8px;
    font-size: 18px;
    color: #333;
}

#smai-prechat-desc {
    margin: 0 0 20px;
    color: #666;
    font-size: 13px;
}

#smai-prechat-name,
#smai-prechat-email {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 10px;
    box-sizing: border-box;
    outline: none;
}

#smai-prechat-name:focus,
#smai-prechat-email:focus {
    border-color: var(--smai-header-bg, #038AF9);
}

#smai-prechat-submit {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: var(--smai-header-bg, #038AF9);
    color: var(--smai-header-text, #fff);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 5px;
    transition: opacity 0.2s;
}

#smai-prechat-submit:hover {
    opacity: 0.9;
}

/* ============================
   Proactive Bubble
   ============================ */
#smai-proactive-bubble {
    position: absolute;
    bottom: 8px;
    right: 72px;
    background: #fff;
    border-radius: 12px;
    padding: 12px 32px 12px 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    max-width: 280px;
    min-width: 120px;
    font-size: 13px;
    color: #333;
    animation: smaiPop 0.3s ease-out;
    white-space: normal;
    word-wrap: break-word;
}

#smai-proactive-bubble::after {
    content: '';
    position: absolute;
    top: 50%;
    right: -8px;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-left: 8px solid #fff;
}

@keyframes smaiPop {
    from { opacity: 0; transform: translateX(10px); }
    to { opacity: 1; transform: translateX(0); }
}

#smai-proactive-close {
    position: absolute;
    top: 2px;
    right: 6px;
    background: none;
    border: none;
    font-size: 16px;
    color: #999;
    cursor: pointer;
    line-height: 1;
    padding: 2px;
}

#smai-proactive-close:hover {
    color: #333;
}

/* ============================
   Mobile Responsive
   ============================ */
@media (max-width: 768px) {
    #smai-chatbot-wrap {
        bottom: 10px;
        right: 10px;
    }

    #smai-chat-toggle {
        width: 55px;
        height: 55px;
    }

    #smai-toggle-icon {
        width: 45px;
        height: 45px;
    }

    #smai-chatbox {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    #smai-header {
        border-radius: 0;
        padding: 16px;
    }

    #smai-close-btn {
        font-size: 30px;
        padding: 0 8px;
    }

    #smai-proactive-bubble {
        right: 65px;
        bottom: 5px;
        max-width: 220px;
    }
}
