/* ============================================
   RESET E VARIÁVEIS
   ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6C3CE1;
    --primary-dark: #5A2FC7;
    --primary-light: #8B6BE8;
    --primary-gradient: linear-gradient(135deg, #6C3CE1 0%, #8B6BE8 100%);
    --background: #F6F8FC;
    --surface: #FFFFFF;
    --surface-hover: #F0F2F7;
    --text-primary: #1A1A2E;
    --text-secondary: #4A4A6A;
    --text-light: #8A8AA8;
    --border: #E4E7F0;
    --shadow: 0 8px 32px rgba(108, 60, 225, 0.15);
    --shadow-hover: 0 12px 48px rgba(108, 60, 225, 0.25);
    --radius: 16px;
    --radius-sm: 10px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--background);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

/* ============================================
   CHAT CONTAINER
   ============================================ */

.chat-container {
    width: 100%;
    max-width: 480px;
    height: 90vh;
    max-height: 800px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================
   HEADER
   ============================================ */

.chat-header {
    padding: 18px 24px;
    background: var(--primary-gradient);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 14px;
}

.avatar {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    backdrop-filter: blur(10px);
}

.header-info h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header-info p {
    font-size: 13px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #4ADE80;
    border-radius: 50%;
    display: inline-block;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.btn-clear {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.btn-clear:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: rotate(45deg);
}

/* ============================================
   MESSAGES AREA
   ============================================ */

.chat-messages {
    flex: 1;
    padding: 20px 20px 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #FAFBFD;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* ============================================
   MESSAGES
   ============================================ */

.message {
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.system {
    align-items: flex-start;
}

.message.user {
    align-items: flex-end;
}

.message-content {
    display: flex;
    gap: 10px;
    max-width: 85%;
}

.message.system .message-content {
    flex-direction: row;
}

.message.user .message-content {
    flex-direction: row-reverse;
}

.message-content > i {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.message.system .message-content > i {
    background: var(--primary-gradient);
    color: white;
}

.message.user .message-content > i {
    background: #E4E7F0;
    color: var(--text-secondary);
}

.message-text {
    background: var(--surface);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    line-height: 1.6;
    color: var(--text-primary);
    font-size: 14px;
    word-wrap: break-word;
}

.message.system .message-text {
    border-top-left-radius: 4px;
    background: var(--surface);
}

.message.user .message-text {
    border-top-right-radius: 4px;
    background: var(--primary-gradient);
    color: white;
}

.message-sender {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 4px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.message.user .message-sender {
    text-align: right;
    color: rgba(255, 255, 255, 0.7);
}

.message-time {
    font-size: 10px;
    color: var(--text-light);
    margin-top: 4px;
    opacity: 0.7;
}

.message.user .message-time {
    text-align: right;
}

/* Loading / Typing */
.message.typing .message-content {
    gap: 6px;
}

.message.typing .message-text {
    background: var(--surface);
    padding: 12px 20px;
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.3;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ============================================
   INPUT AREA
   ============================================ */

.chat-input-area {
    padding: 16px 20px 12px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.input-container {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--background);
    border-radius: var(--radius-sm);
    padding: 4px 4px 4px 12px;
    border: 2px solid transparent;
    transition: var(--transition);
}

.input-container:focus-within {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 4px rgba(108, 60, 225, 0.08);
}

.btn-emoji {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 20px;
    padding: 8px 4px;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.btn-emoji:hover {
    color: var(--primary);
    transform: scale(1.1);
}

#chatInput {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    padding: 10px 0;
    font-size: 14px;
    font-family: var(--font);
    color: var(--text-primary);
    resize: none;
    max-height: 100px;
    line-height: 1.5;
}

#chatInput::placeholder {
    color: var(--text-light);
}

.btn-send {
    background: var(--primary-gradient);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.btn-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(108, 60, 225, 0.35);
}

.btn-send:active {
    transform: scale(0.95);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-light);
    padding: 0 4px;
}

.input-footer span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.input-footer i {
    font-size: 10px;
}

#typingIndicator {
    color: var(--primary);
    font-weight: 500;
}

/* ============================================
   EMOJI PICKER (simples)
   ============================================ */

.emoji-picker {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    margin-bottom: 8px;
    gap: 4px;
    flex-wrap: wrap;
    max-height: 120px;
    overflow-y: auto;
}

.emoji-picker.active {
    display: flex;
}

.emoji-picker span {
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: var(--transition);
}

.emoji-picker span:hover {
    background: var(--surface-hover);
    transform: scale(1.2);
}

/* ============================================
   RESPONSIVO
   ============================================ */

@media (max-width: 600px) {
    body {
        padding: 0;
        background: var(--surface);
    }
    
    .chat-container {
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
        box-shadow: none;
    }
    
    .chat-header {
        padding: 14px 16px;
    }
    
    .chat-messages {
        padding: 16px 14px 8px;
    }
    
    .chat-input-area {
        padding: 12px 14px 10px;
    }
    
    .message-content {
        max-width: 90%;
    }
}

/* ============================================
   SCROLLBAR PERSONALIZADA
   ============================================ */

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}