:root {
    /* Tema Escuro (Padrão) */
    --primary-bg: #0a0a0a;
    --secondary-bg: #111111;
    --sidebar-bg: #1a1a1a;
    --accent-purple: #7C27E3;
    --accent-pink: #FF2D75;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --user-message: #7C27E3;
    --bot-message: #1e1e1e;
    --message-shadow: rgba(0, 0, 0, 0.2);
    --input-bg: rgba(255, 255, 255, 0.03);
    --suggestion-bg: rgba(124, 39, 227, 0.1);
    --hover-bg: rgba(255, 255, 255, 0.05);
    --code-bg: #2d2d2d;
    --code-text: #f8f8f2;
    --message-gap: 12px;
}

/* Tema Claro */
.light-theme {
    --primary-bg: #f5f5f7;
    --secondary-bg: #ffffff;
    --sidebar-bg: #f8f9fa;
    --accent-purple: #7C27E3;
    --accent-pink: #FF2D75;
    --text-primary: #1a1a1a;
    --text-secondary: #64748b;
    --user-message: #7C27E3;
    --bot-message: #ffffff;
    --message-shadow: rgba(0, 0, 0, 0.05);
    --input-bg: rgba(0, 0, 0, 0.03);
    --suggestion-bg: rgba(124, 39, 227, 0.08);
    --hover-bg: rgba(0, 0, 0, 0.03);
    --code-bg: #f0f0f0;
    --code-text: #333333;
}

/* Tema Azul (Dark) */
.blue-theme {
    --primary-bg: #0f172a;
    --secondary-bg: #1e293b;
    --sidebar-bg: #1e293b;
    --accent-purple: #3b82f6;
    --accent-pink: #60a5fa;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --user-message: #3b82f6;
    --bot-message: #1e293b;
    --message-shadow: rgba(0, 0, 0, 0.2);
    --input-bg: rgba(255, 255, 255, 0.05);
    --suggestion-bg: rgba(59, 130, 246, 0.1);
    --hover-bg: rgba(255, 255, 255, 0.05);
    --code-bg: #334155;
    --code-text: #f8f8f2;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--primary-bg);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Layout Principal */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    height: 100%;
    overflow-y: auto;
    transition: transform 0.3s ease, background 0.3s ease;
    z-index: 20;
    position: absolute;
    left: 0;
    top: 0;
    transform: translateX(-100%);
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-actions {
    display: flex;
    gap: 0.5rem;
}

.theme-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    transition: color 0.2s;
}

.theme-toggle:hover {
    color: var(--accent-purple);
}

.search-container {
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
}

.search-container input {
    width: 100%;
    padding: 0.7rem 1rem 0.7rem 2.5rem;
    background: var(--input-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: all 0.2s;
}

.search-container input:focus {
    outline: none;
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 2px rgba(124, 39, 227, 0.2);
}

.search-icon {
    position: absolute;
    left: 1.7rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

.conversation-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: background 0.2s;
}

.conversation-item:hover {
    background: var(--hover-bg);
}

.conversation-item.active {
    background: rgba(124, 39, 227, 0.1);
    border-left: 3px solid var(--accent-purple);
}

.conversation-title {
    font-weight: 500;
    margin-bottom: 0.25rem;
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

.conversation-preview {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.new-chat-btn {
    display: block;
    width: calc(100% - 2rem);
    padding: 0.75rem;
    margin: 1rem;
    background: var(--accent-purple);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.new-chat-btn:hover {
    background: #6a1fcb;
}

/* Chat Area */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    width: 100%;
    margin-left: 0;
    transition: margin-left 0.3s ease;
}

.sidebar-open .chat-container {
    margin-left: 280px;
}

.chat-header {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: var(--secondary-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: background 0.3s ease;
    height: 60px;
    z-index: 5;
}

.chat-header img {
    max-width: 100px;
    height: auto;
}

.chat-messages {
    flex: 1;
    padding: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    padding-top: 60px; /* Espaço para o cabeçalho */
    padding-bottom: 80px; /* Espaço para o input */
}

.message-container {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: var(--message-gap);
}

.message {
    max-width: 90%;
    padding: 12px 16px;
    border-radius: 12px;
    animation: fadeIn 0.3s ease;
    line-height: 1.6;
    font-size: 16px;
    position: relative;
    transition: background 0.3s ease, color 0.3s ease;
    word-break: break-word;
}

.user-message {
    align-self: flex-end;
    background: var(--user-message);
    color: white;
    border-radius: 18px 18px 4px 18px;
    margin-left: 20%;
}

.light-theme .user-message {
    color: white;
}

.bot-message {
    align-self: flex-start;
    background: var(--bot-message);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border-radius: 18px 18px 18px 4px;
    margin-right: 20%;
}

.message-content {
    overflow-x: auto;
}

.message-content p {
    margin-bottom: 0.5rem;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content pre {
    background: var(--code-bg);
    border-radius: 6px;
    padding: 0.75rem;
    overflow-x: auto;
    margin: 0.5rem 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
    color: var(--code-text);
}

.message-content code {
    background: var(--code-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
    color: var(--code-text);
}

.message-content ul,
.message-content ol {
    padding-left: 1.5rem;
    margin: 0.5rem 0;
}

.message-content li {
    margin-bottom: 0.25rem;
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.message-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .message-actions {
    opacity: 1;
}

.action-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.7rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 12px 16px;
    background: var(--bot-message);
    border-radius: 18px 18px 18px 4px;
    align-self: flex-start;
    margin: 0 16px 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    max-width: 80%;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typingAnimation 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

.suggestions-container {
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: background 0.3s ease;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--secondary-bg);
    z-index: 2;
}

.suggestion-btn {
    padding: 8px 12px;
    background: var(--suggestion-bg);
    color: var(--accent-purple);
    border: 1px solid rgba(124, 39, 227, 0.3);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    white-space: nowrap;
}

.suggestion-btn:hover {
    background: rgba(124, 39, 227, 0.2);
    border-color: var(--accent-purple);
}

.input-container {
    padding: 12px 16px;
    background: var(--secondary-bg);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    gap: 12px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    transition: all 0.3s ease;
    z-index: 10;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.input-wrapper {
    flex-grow: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.media-buttons {
    position: absolute;
    right: 0.5rem;
    display: flex;
    gap: 0.5rem;
}

.media-button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.3rem;
    border-radius: 50%;
    transition: all 0.2s;
}

.media-button:hover {
    color: var(--accent-purple);
    background: rgba(124, 39, 227, 0.1);
}

.media-button svg {
    width: 20px;
    height: 20px;
}

input[type="text"] {
    width: 100%;
    padding: 12px 40px 12px 16px;
    background: var(--input-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 16px;
    transition: all 0.2s;
    min-height: 48px;
    resize: none;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 3px rgba(124, 39, 227, 0.2);
}

button {
    padding: 12px 16px;
    background: var(--accent-purple);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 16px;
    white-space: nowrap;
}

button:hover {
    background: #6a1fcb;
}

/* Toggle Button */
.sidebar-toggle {
    display: block;
    position: fixed;
    left: 16px;
    top: 16px;
    z-index: 20;
    background: rgba(124, 39, 227, 0.9);
    padding: 8px;
    border-radius: 50%;
    border: none;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle:hover {
    background: rgba(124, 39, 227, 1);
}

.sidebar-toggle svg {
    width: 20px;
    height: 20px;
}

/* Posicionamento diferente quando a sidebar está aberta */
.sidebar-open .input-container {
    left: 280px; /* Mesma largura da sidebar */
    transition: left 0.3s ease;
}

/* Overlay para mobile */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 15;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-open .sidebar-overlay {
    opacity: 1;
    visibility: visible;
}

/* Modal de temas */
.theme-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--secondary-bg);
    border-radius: 12px;
    padding: 20px;
    z-index: 1000;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 400px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.theme-modal.active {
    opacity: 1;
    visibility: visible;
}

.theme-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.theme-modal-title {
    font-size: 18px;
    font-weight: 600;
}

.close-modal {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    transition: color 0.2s;
}

.close-modal:hover {
    color: var(--text-primary);
}

.theme-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.theme-option {
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
    background: var(--hover-bg);
}

.theme-option:hover {
    transform: translateY(-2px);
}

.theme-option.active {
    border-color: var(--accent-purple);
}

.theme-preview {
    width: 100%;
    height: 60px;
    border-radius: 4px;
    margin-bottom: 8px;
    display: flex;
    overflow: hidden;
}

.theme-preview-sidebar {
    width: 30%;
    height: 100%;
    background: var(--sidebar-bg);
}

.theme-preview-main {
    width: 70%;
    height: 100%;
    background: var(--primary-bg);
    position: relative;
}

.theme-preview-message {
    position: absolute;
    width: 60%;
    height: 20px;
    border-radius: 4px;
    background: var(--bot-message);
    top: 10px;
    left: 10px;
}

.theme-preview-message.user {
    background: var(--user-message);
    top: 35px;
    left: 30px;
}

.theme-name {
    font-weight: 500;
    text-align: center;
}

/* Animações */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes typingAnimation {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* Media Queries */
@media (min-width: 769px) {
    .sidebar {
        position: relative;
        transform: translateX(0) !important;
    }
    
    .sidebar-toggle {
        display: none;
    }
    
    .chat-header {
        padding: 1rem 2rem;
    }
    
    .chat-messages {
        padding: 0 2rem;
        padding-top: 0;
        padding-bottom: 0;
    }
    
    .input-container {
        padding: 1rem 2rem;
        position: sticky;
        bottom: 0;
        position: sticky;
        padding-bottom: 12px;
    }
    
    .suggestions-container {
        position: sticky;
        top: 0;
    }
    .sidebar-open .input-container {
        left: 0;
        right: 0;
    }
}

@media (max-width: 768px) {
    /* Espaço para o input na área de mensagens */
    .chat-messages {
        padding-bottom: 120px;
    }
    
    /* Sidebar deve ficar acima do input */
    .sidebar {
        z-index: 20; /* Superior ao input (z-index: 10) */
    }
    
    /* Quando sidebar está aberta, input não deve aparecer por baixo */
    .sidebar-open .input-container {
        left: 280px;
        right: -280px;
        transition: left 0.3s ease, right 0.3s ease;
    }
    
    /* Quando teclado está aberto (tela mais baixa) */
    @media (max-height: 500px) {
        .input-container {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
        
        /* Fecha sidebar automaticamente quando teclado abre */
        .sidebar-open .input-container {
            left: 0;
            right: 0;
        }
        
        .sidebar {
            transform: translateX(-100%);
        }
        
        .sidebar-overlay {
            opacity: 0;
            visibility: hidden;
        }
    }
}

@media (max-width: 480px) {
    .message {
        max-width: 90%;
        padding: 10px 14px;
        font-size: 15px;
    }
    
    .input-container {
        flex-direction: row;
        gap: 8px;
        padding: 10px 12px;
    }
    
    button {
        width: auto;
        padding: 0 14px;
        min-width: 48px;
    }
    
    .media-buttons {
        right: 0.3rem;
    }
    
    .media-button svg {
        width: 18px;
        height: 18px;
    }
    
    .suggestions-container {
        padding: 10px 12px;
        gap: 6px;
    }
    
    .suggestion-btn {
        padding: 6px 10px;
        font-size: 13px;
    }
    
    .theme-options {
        grid-template-columns: 1fr;
    }
    
    .sidebar-toggle {
        left: 12px;
        top: 12px;
        width: 36px;
        height: 36px;
    }
    
    .sidebar-open .sidebar-toggle {
        left: 292px;
    }
}

/* Melhorias para mobile */
@media (max-width: 768px) {
    .chat-messages {
        padding-bottom: 20px;
    }
    
    .message-container {
        padding: 12px;
    }
    
    .user-message {
        margin-left: 10%;
    }
    
    .bot-message {
        margin-right: 10%;
    }
    
    .new-chat-btn {
        margin: 12px;
        width: calc(100% - 24px);
    }
    
    .conversation-item {
        padding: 12px;
    }
}

/* Ajustes de acessibilidade */
button:focus, input:focus {
    outline: 2px solid var(--accent-purple);
    outline-offset: 2px;
}

/* Scrollbar personalizada */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}