/**
 * Estilos do Chatbot
 * Simple AI Engine
 */

/* ========================================
   VARIÁVEIS CSS (Padrões - sobrescritas pelo tema)
   ======================================== */
.sai-chatbot-container {
    --sai-primary-color: #0073aa;
    --sai-secondary-color: #005177;
    --sai-bg-color: #ffffff;
    --sai-text-color: #333333;
    --sai-border-color: #e0e0e0;
    --sai-user-msg-bg: #0073aa;
    --sai-user-msg-text: #ffffff;
    --sai-bot-msg-bg: #f5f5f5;
    --sai-bot-msg-text: #333333;
    --sai-width: 400px;
    --sai-height: 600px;
    --sai-font-size: 14px;
    --sai-msg-padding: 12px 16px;
    --sai-msg-spacing: 12px;
    --sai-msg-border-radius: 18px;
    --sai-header-bg: #0073aa;
    --sai-header-text: #ffffff;
    --sai-header-height: 60px;
    --sai-toggle-bg: #0073aa;
    --sai-toggle-size: 60px;
}

/* ========================================
   CONTAINER BASE
   ======================================== */
.sai-chatbot-container {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

.sai-chatbot-container *,
.sai-chatbot-container *::before,
.sai-chatbot-container *::after {
    box-sizing: border-box;
}

/* ========================================
   POSICIONAMENTO
   ======================================== */
.sai-chatbot-position-inline {
    position: relative;
    width: var(--sai-width);
    max-width: 100%;
    margin: 20px auto;
}

/* Posições Flutuantes (Botão Toggle) */
.sai-chatbot-position-floating-bottom-right,
.sai-chatbot-position-floating-bottom-left,
.sai-chatbot-position-floating-top-right,
.sai-chatbot-position-floating-top-left {
    position: fixed;
    z-index: 9999;
}

.sai-chatbot-position-floating-bottom-right {
    bottom: 20px;
    right: 20px;
}

.sai-chatbot-position-floating-bottom-left {
    bottom: 20px;
    left: 20px;
}

.sai-chatbot-position-floating-top-right {
    top: 20px;
    right: 20px;
}

.sai-chatbot-position-floating-top-left {
    top: 20px;
    left: 20px;
}

.sai-chatbot-position-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    margin: 0 !important;
    z-index: 999999 !important;
    background: var(--sai-bg-color) !important;
}

/* ========================================
   BOTÃO DE TOGGLE
   ======================================== */
.sai-chatbot-toggle {
    width: var(--sai-toggle-size);
    height: var(--sai-toggle-size);
    border-radius: 50%;
    background: var(--sai-toggle-bg);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.sai-chatbot-toggle:hover {
    background: var(--sai-secondary-color);
    transform: scale(1.1);
}

.sai-chatbot-toggle svg {
    width: 28px;
    height: 28px;
}

/* ========================================
   JANELA DO CHATBOT
   ======================================== */
.sai-chatbot-window {
    width: var(--sai-width);
    max-width: calc(100vw - 40px);
    height: var(--sai-height);
    max-height: calc(100vh - 100px);
    background: var(--sai-bg-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sai-chatbot-position-floating-bottom-right .sai-chatbot-window,
.sai-chatbot-position-floating-bottom-left .sai-chatbot-window {
    position: absolute;
    bottom: 80px;
}

.sai-chatbot-position-floating-top-right .sai-chatbot-window,
.sai-chatbot-position-floating-top-left .sai-chatbot-window {
    position: absolute;
    top: 80px;
}

.sai-chatbot-position-floating-bottom-right .sai-chatbot-window,
.sai-chatbot-position-floating-top-right .sai-chatbot-window {
    right: 0;
}

.sai-chatbot-position-floating-bottom-left .sai-chatbot-window,
.sai-chatbot-position-floating-top-left .sai-chatbot-window {
    left: 0;
}

.sai-chatbot-position-fullscreen .sai-chatbot-window {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    margin: 0 !important;
}

.sai-chatbot-position-fullscreen .sai-chatbot-toggle {
    display: none !important;
}

/* ========================================
   HEADER
   ======================================== */
.sai-chatbot-header {
    background: var(--sai-header-bg);
    color: var(--sai-header-text);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    min-height: var(--sai-header-height);
}

.sai-chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.sai-chatbot-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    flex: 1;
}

.sai-chatbot-close {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.sai-chatbot-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ========================================
   ÁREA DE MENSAGENS
   ======================================== */
.sai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: var(--sai-msg-spacing);
}

.sai-chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.sai-chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.sai-chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--sai-border-color);
    border-radius: 3px;
}

.sai-chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}

/* ========================================
   MENSAGENS
   ======================================== */
.sai-message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sai-message-user {
    flex-direction: row-reverse;
}

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

.sai-message-content {
    max-width: 75%;
    padding: var(--sai-msg-padding);
    border-radius: var(--sai-msg-border-radius);
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: var(--sai-font-size);
}

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

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

.sai-message-error {
    background: #fee !important;
    color: #c33 !important;
    border: 1px solid #fcc;
}

/* Markdown em mensagens */
.sai-message-content strong {
    font-weight: 600;
}

.sai-message-content em {
    font-style: italic;
}

.sai-message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.sai-message-content a {
    color: inherit;
    text-decoration: underline;
}

/* ========================================
   BOTÕES DE SUGESTÃO
   ======================================== */
.sai-chatbot-suggestions {
    padding: 0 20px 10px;
    display: flex;
    flex-wrap: nowrap;
    /* Horizontal scroll */
    overflow-x: auto;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
    /* Smooth scroll iOS */
    scrollbar-width: none;
    /* Hide scrollbar Firefox */
}

.sai-chatbot-suggestions::-webkit-scrollbar {
    display: none;
    /* Hide scrollbar Chrome/Safari */
}

.sai-suggestion-button {
    flex: 0 0 auto;
    /* Prevent shrinking */
    background: var(--sai-bg-color);
    border: 1px solid var(--sai-border-color);
    color: var(--sai-text-color);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: normal;
    cursor: pointer;
    transition: all 0.2s;
}

.sai-suggestion-button:hover {
    background: var(--sai-primary-color);
    color: white;
    border-color: var(--sai-primary-color);
}

/* ========================================
   ÁREA DE INPUT
   ======================================== */
/* ========================================
   ÁREA DE INPUT
   ======================================== */
.sai-chatbot-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--sai-border-color);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--sai-bg-color);
    flex-shrink: 0;
}

.sai-input-wrapper {
    position: relative;
    flex: 1;
    display: flex;
}

.sai-chatbot-input {
    width: 100%;
    border: 1px solid var(--sai-border-color);
    border-radius: 20px;
    padding: 12px 16px;
    padding-right: 60px;
    /* Espaço para o microfone */
    font-family: inherit;
    font-size: 16px;
    /* 16px to prevent zoom on iOS */
    resize: none;
    max-height: 150px;
    overflow-y: auto;
    line-height: 1.5;
    background: var(--sai-bg-color);
    color: var(--sai-text-color);
    transition: border-color 0.3s;
}

.sai-chatbot-input:focus {
    outline: none;
    border-color: var(--sai-primary-color);
}

.sai-chatbot-send {
    width: 44px;
    /* Aumentado */
    height: 44px;
    border-radius: 50%;
    background: var(--sai-primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.sai-chatbot-send:hover:not(:disabled) {
    background: var(--sai-secondary-color);
    transform: scale(1.05);
}

.sai-chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Botão de Voz */
.sai-chatbot-voice {
    position: absolute;
    right: 6px;
    bottom: 4px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: transparent;
    color: var(--sai-text-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    opacity: 0.7;
}

.sai-chatbot-voice:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.05);
    color: var(--sai-primary-color);
    opacity: 1;
    transform: scale(1.1);
}

.sai-chatbot-voice.recording {
    background: #ef4444;
    border-color: #ef4444;
    color: white;
    animation: pulse 1.5s infinite;
}

.sai-chatbot-voice:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

/* ========================================
   LOADING
   ======================================== */
/* ========================================
   LOADING
   ======================================== */
.sai-chatbot-loading {
    display: flex;
    gap: 6px;
    padding: 12px 16px;
    align-items: center;
    background: var(--sai-bot-msg-bg);
    border-radius: var(--sai-msg-border-radius);
    border-bottom-left-radius: 4px;
    width: fit-content;
    margin-bottom: 10px;
    animation: slideIn 0.3s ease;
}

.sai-chatbot-loading span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--sai-text-color);
    opacity: 0.6;
    animation: bounce 1.4s infinite ease-in-out both;
}

.sai-chatbot-loading span:nth-child(1) {
    animation-delay: -0.32s;
}

.sai-chatbot-loading span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ========================================
   TEMA: MODERN
   ======================================== */
.sai-chatbot-theme-modern {
    --sai-primary-color: #667eea;
    --sai-secondary-color: #764ba2;
    --sai-user-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --sai-bot-bg: #f8f9fa;
}

.sai-chatbot-theme-modern .sai-chatbot-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.sai-chatbot-theme-modern .sai-chatbot-toggle {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.sai-chatbot-theme-modern .sai-chatbot-send {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.sai-chatbot-theme-modern .sai-message-user .sai-message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* ========================================
   TEMA: MINIMAL
   ======================================== */
.sai-chatbot-theme-minimal {
    --sai-primary-color: #000000;
    --sai-secondary-color: #333333;
    --sai-border-color: #e0e0e0;
    --sai-user-bg: #000000;
    --sai-bot-bg: #f9f9f9;
}

.sai-chatbot-theme-minimal .sai-chatbot-window {
    border: 1px solid var(--sai-border-color);
    border-radius: 0;
}

.sai-chatbot-theme-minimal .sai-chatbot-header {
    border-bottom: 1px solid var(--sai-border-color);
}

.sai-chatbot-theme-minimal .sai-chatbot-input {
    border-radius: 0;
}

.sai-chatbot-theme-minimal .sai-chatbot-send {
    border-radius: 0;
}

.sai-chatbot-theme-minimal .sai-message-content {
    border-radius: 0;
}

/* ========================================
   TEMA: DARK
   ======================================== */
.sai-chatbot-theme-dark {
    --sai-primary-color: #1e88e5;
    --sai-secondary-color: #1565c0;
    --sai-bg-color: #1e1e1e;
    --sai-text-color: #e0e0e0;
    --sai-border-color: #333333;
    --sai-user-bg: #1e88e5;
    --sai-user-text: #ffffff;
    --sai-bot-bg: #2d2d2d;
    --sai-bot-text: #e0e0e0;
}

.sai-chatbot-theme-dark .sai-chatbot-input {
    background: #2d2d2d;
    color: #e0e0e0;
}

.sai-chatbot-theme-dark .sai-suggestion-button {
    background: #2d2d2d;
    border-color: #444;
    color: #e0e0e0;
}

.sai-chatbot-theme-dark .sai-suggestion-button:hover {
    background: var(--sai-primary-color);
    color: white;
}

/* ========================================
   RESPONSIVO
   ======================================== */
@media (max-width: 768px) {
    .sai-chatbot-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        /* Remove bottom anchor to let height drive it */
        bottom: auto !important;
        width: 100% !important;
        /* Fallback for older browsers */
        height: 100vh !important;
        /* Modern mobile fix: Dynamic Viewport Height */
        height: 100dvh !important;
        max-width: 100% !important;
        max-height: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
        display: flex;
        flex-direction: column;
        z-index: 2147483647 !important;
    }

    /* Reset specific positioning classes to avoid conflicts */
    .sai-chatbot-position-floating-bottom-right .sai-chatbot-window,
    .sai-chatbot-position-floating-bottom-left .sai-chatbot-window,
    .sai-chatbot-position-floating-top-right .sai-chatbot-window,
    .sai-chatbot-position-floating-top-left .sai-chatbot-window {
        position: fixed !important;
        top: 0 !important;
        bottom: auto !important;
        left: 0 !important;
        right: 0 !important;
    }

    .sai-chatbot-messages {
        -webkit-overflow-scrolling: touch;
        /* Smooth scrolling on iOS */
    }

    .sai-chatbot-input-area {
        position: relative;
        /* Revert sticky, flex handles it */
        flex-shrink: 0;
        /* Prevent shrinking */
        width: 100%;
        background: var(--sai-bg-color);
        z-index: 10;
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        /* Increased padding */
    }

    .sai-message-content {
        max-width: 85%;
    }
}

/* ========================================
   BOTÃO ENVIAR PERSONALIZADO
   ======================================== */
.sai-chatbot-send span {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    padding: 0 4px;
}

/* Botão com texto precisa ser mais largo */
.sai-chatbot-send:has(span) {
    width: auto;
    min-width: 80px;
    padding: 0 16px;
    border-radius: 20px;
}

/* 
   Body Lock Class (adicionado via JS) 
   Prevents background scrolling and stabilizes address bar on iOS
*/
body.sai-chatbot-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    touch-action: none;
}