* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Avatar sizing variables and utility classes
   Use CSS variables to control sizes globally or per-element.
   Examples:
     .avatar { --avatar-size: 48px; }            -> set header/avatar size
     .bot-avatar { --bot-avatar-size: 36px; }    -> set bot avatar size
     .avatar--small { --avatar-size: 36px; }
     .avatar--medium { --avatar-size: 50px; }
     .avatar--large { --avatar-size: 64px; }
     .bot-avatar--small { --bot-avatar-size: 20px; }
     .bot-avatar--default { --bot-avatar-size: 32px; }
*/
:root {
    --avatar-size: 50px;       /* header avatar */
    --bot-avatar-size: 32px;   /* bot message avatar */
    --inline-avatar-size: 18px;/* inline avatar inside text */
}

.avatar--small { --avatar-size: 36px; }
.avatar--medium { --avatar-size: 50px; }
.avatar--large { --avatar-size: 64px; }

.bot-avatar--small { --bot-avatar-size: 20px; }
.bot-avatar--default { --bot-avatar-size: 50px; }
.bot-avatar--large { --bot-avatar-size: 40px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Botão Flutuante */
.chat-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    z-index: 9998;
    color: white;
    font-size: 28px;
}

.chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.5);
}

.chat-button.hidden {
    display: none;
}

/* Widget do Chat */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    /* responsive: allow shrinking on small viewports but cap max width */
    width: 100%;
    max-width: 420px;
    height: 600px;
    max-height: calc(100vh - 48px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    animation: slideUp 0.3s ease;
}

.chat-widget.open {
    display: flex;
}

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

/* Cabeçalho */
.chat-header {
    background: linear-gradient(135deg, #1e5aff 0%, #00d4ff 100%);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    color: white;
}

.header-content {
    display: flex;
    gap: 12px;
    align-items: center;
}

.avatar {
    width: var(--avatar-size);
    height: var(--avatar-size);
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid rgba(255, 255, 255, 0.3);
}

.avatar img {
    width: var(--avatar-size) !important;
    height: var(--avatar-size) !important;
    aspect-ratio: 1/1 !important;
    display: block !important;
    object-fit: cover !important;
    border-radius: 50% !important;
}

.header-info h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.status {
    font-size: 13px;
    opacity: 0.9;
}

.close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: background 0.2s;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Formulário Inicial */
.initial-form {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background: #f8f9fa;
}

.form-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.bot-message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.bot-avatar {
    /*width: var(--avatar-size);*/
    height: var(--avatar-size);
    border-radius: 50%;
}

.bot-avatar img {
    width: var(--bot-avatar-size) !important;
    height: var(--bot-avatar-size) !important;
    aspect-ratio: 1/1 !important;
    display: block !important;
    object-fit: cover !important;
    border-radius: 50% !important;
}

/* inline avatar used inside text */
.inline-bot-avatar {
    width: 18px;
    height: 18px;
    object-fit: cover;
    vertical-align: middle;
    border-radius: 50%;
    margin: 0 6px;
}

.message-bubble {
    background: white;
    padding: 12px 16px;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.message-bubble p {
    font-size: 14px;
    line-height: 1.5;
    color: #333;
}

.form-intro {
    font-size: 14px;
    color: #666;
    margin-top: 8px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: #1e5aff;
}

/* Phone group with country code selector */
.phone-group {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.country-code-select {
    padding: 12px 8px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    transition: border-color 0.2s;
    min-width: 90px;
}

.country-code-select:focus {
    outline: none;
    border-color: #1e5aff;
}

.phone-group input {
    flex: 1;
}

.validation-error {
    display: block;
    color: #e74c3c;
    font-size: 12px;
    margin-top: 4px;
}

.submit-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, #1e5aff 0%, #00d4ff 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(30, 90, 255, 0.3);
}

/* Área do Chat */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
    /* allow flex child to shrink and enable internal scrolling */
    min-height: 0;
}

.message-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    min-height: 0;
    padding-right: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    /* ensure container does not exceed available space and hint overflow behavior */
    max-height: 100%;
    overflow-anchor: none;
}

/* Discrete, clean scrollbar for message container */
.message-container {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
}

/* WebKit-based browsers (Chrome, Edge, Safari) */
.message-container::-webkit-scrollbar {
    width: 8px;
}
.message-container::-webkit-scrollbar-track {
    background: transparent;
}
.message-container::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.12);
    border-radius: 999px;
}
.message-container::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.18);
}

/* Firefox */
@supports (scrollbar-width: thin) {
    .message-container {
        scrollbar-width: thin;
        scrollbar-color: rgba(0,0,0,0.12) transparent;
    }
}

.message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: fadeIn 0.3s ease;
}

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

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

.message-content {
    max-width: 90%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

/* Tags <br> dentro das mensagens */
.message-content br {
    display: block;
    content: "";
    margin: 0;
}

.message.bot .message-content {
    background: white;
    color: #333;
    border-top-left-radius: 2px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.message.user .message-content {
    background: linear-gradient(135deg, #1e5aff 0%, #00d4ff 100%);
    color: white;
    border-top-right-radius: 2px;
}

/* Quick Actions */
.quick-actions {
    padding: 12px 20px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    background: white;
    border-top: 1px solid #e0e0e0;
}

.quick-btn {
    padding: 8px 16px;
    background: white;
    border: 2px solid #1e5aff;
    color: #1e5aff;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.quick-btn:hover {
    background: #1e5aff;
    color: white;
}


/* Botões enviados pelo bot (para respostas rápidas / interativas)
   Renderizados dentro das bolhas de mensagem do bot.
*/
.widget-buttons {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.widget-btn {
    padding: 8px 12px;
    background: #fff;
    border: 1px solid rgba(0,0,0,0.08);
    color: #222;
    border-radius: 14px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.14s ease;
}

.widget-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.06);
}

.message.bot .message-bubble {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

/* Input de Mensagem */
.chat-input {
    padding: 16px 20px;
    background: white;
    display: flex;
    gap: 10px;
    align-items: center;
    border-top: 1px solid #e0e0e0;
    position: relative;
}

.document-btn,
.emoji-btn {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.document-btn:hover,
.emoji-btn:hover {
    color: #1e5aff;
}

/* Emoji Picker */
.emoji-picker {
    position: absolute;
    bottom: 65px;
    left: 60px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    z-index: 1000;
    min-width: 240px;
}

.emoji-item {
    font-size: 28px;
    cursor: pointer;
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 48px;
}

.emoji-item:hover {
    background: #f0f0f0;
    transform: scale(1.1);
}

.chat-input input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
}

.chat-input input:focus {
    outline: none;
    border-color: #1e5aff;
}

.send-btn {
    background: linear-gradient(135deg, #1e5aff 0%, #00d4ff 100%);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.send-btn:hover {
    transform: scale(1.1);
}

/* Powered By */
.powered-by {
    padding: 12px 20px;
    text-align: center;
    font-size: 11px;
    color: #999;
    background: white;
    border-top: 1px solid #e0e0e0;
}

/* Responsivo */
@media (max-width: 480px) {
    .chat-widget {
        /* keep some margin on mobile instead of full-screen */
        width: calc(100% - 32px);
        height: 80vh;
        bottom: 16px;
        right: 16px;
        border-radius: 12px;
        max-height: 80vh;
    }
    
    .chat-button {
        bottom: 16px;
        right: 16px;
    }
}

/* larger screens: ensure a fixed width for desktop */
@media (min-width: 481px) {
    .chat-widget { width: 400px; }
}
