/* --- CHAT CONTAINER --- */
#chat-container { 
    flex: 1; 
    padding: 30px; 
    overflow-y: auto; 
    display: flex; 
    flex-direction: column; 
    gap: 30px; 
    scroll-behavior: smooth; 
    align-items: center; 
}

.message { 
    max-width: 850px; 
    margin: 0 auto; 
    width: 100%; 
    display: flex; 
    flex-direction: column; 
}

.message.user { align-items: flex-end; }
.message.tutoria { align-items: flex-start; }

.message-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.message.user:hover .message-actions {
    opacity: 1;
}

.message.user.editing .message-actions {
    display: none;
}

.message-action-btn {
    border: 1px solid var(--border-color);
    background: rgba(255,255,255,0.04);
    color: var(--text-secondary);
    border-radius: 12px;
    padding: 3px 9px;
    font-size: 0.74rem;
    cursor: pointer;
}

.message-action-btn:hover {
    color: var(--accent-color);
    border-color: var(--accent-color);
}

.inline-edit-panel {
    width: min(620px, 72vw);
}

.inline-edit-textarea {
    width: 100%;
    min-height: 130px;
    max-height: 300px;
    resize: vertical;
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 8px;
    background: rgba(0,0,0,0.16);
    color: var(--msg-user-text);
    padding: 12px;
    font: inherit;
    line-height: 1.55;
    outline: none;
}

.inline-edit-textarea:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(var(--accent-color-rgb), 0.18);
}

.inline-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 10px;
}

.inline-edit-btn {
    border-radius: 8px;
    padding: 7px 12px;
    font-size: 0.82rem;
    cursor: pointer;
    border: 1px solid transparent;
}

.inline-edit-btn.ghost {
    background: transparent;
    border-color: rgba(255,255,255,0.18);
    color: var(--msg-user-text);
}

.inline-edit-btn.primary {
    background: var(--accent-color);
    color: var(--bg-body);
}

.inline-edit-btn:hover {
    filter: brightness(1.05);
}

/* --- BOLHA DE MENSAGEM (FRAME) --- */
.bubble { 
    padding: 18px 24px; 
    border-radius: 16px; 
    font-size: var(--chat-font-size, 16px); 
    line-height: 1.75; 
    max-width: 100%; 
    position: relative; 
    word-wrap: break-word; 
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    
    /* ESTÉTICA DE DOCUMENTO JURÍDICO (JUSTIFICADO COM HIFENIZAÇÃO) */
    text-align: justify;
    hyphens: auto;
    -webkit-hyphens: auto; /* Suporte para navegadores Safari/iOS */
    -ms-hyphens: auto;     /* Suporte para Edge legado */
}

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

.message.tutoria .bubble {
    background-color: var(--msg-ai-bg);
    color: var(--text-ai);
    padding-left: 0; 
}

[data-theme="light"] .message.tutoria .bubble {
    padding-left: 20px; 
    border: 1px solid var(--border-color); 
    border-bottom-left-radius: 4px; 
    background-color: #ffffff;
}

/* --- TIPOGRAFIA RICA (MARKDOWN) --- */
.bubble p { 
    margin-top: 0; 
    margin-bottom: 1.2em; 
}

.bubble p:last-child { 
    margin-bottom: 0; 
}

.bubble strong { 
    font-weight: 700; 
    color: inherit; 
    opacity: 1; 
}

.bubble em { 
    font-style: italic; 
    opacity: 0.9; 
}

.bubble ul, .bubble ol { 
    margin-bottom: 1.2em; 
    padding-left: 25px; 
    /* Listas normalmente ficam melhores alinhadas à esquerda, mas herdarão o justificado por padrão. 
       Se a leitura ficar ruim com marcadores justificados, podemos forçar left aqui depois. */
}

.bubble li { 
    margin-bottom: 0.5em; 
    padding-left: 5px; 
}

.bubble li::marker { 
    color: var(--accent-color); 
    font-weight: bold; 
}

.bubble h1, .bubble h2, .bubble h3 { 
    margin-top: 1.5em; 
    margin-bottom: 0.8em; 
    font-weight: 700; 
    line-height: 1.3; 
    color: var(--text-primary); 
    text-align: left; /* Títulos ficam à esquerda para dar âncora visual e não quebrarem o grid */
}

.bubble h1 { font-size: 1.4em; border-bottom: 1px solid var(--border-color); padding-bottom: 0.3em; }
.bubble h2 { font-size: 1.25em; }
.bubble h3 { font-size: 1.1em; text-transform: uppercase; letter-spacing: 1px; color: var(--accent-color); }

.bubble pre { 
    background: rgba(0, 0, 0, 0.3); 
    border: 1px solid var(--border-color); 
    padding: 15px; 
    border-radius: 10px; 
    overflow-x: auto; 
    margin: 1.2em 0; 
    font-family: 'Consolas', 'Monaco', monospace; 
    font-size: 0.9em; 
    text-align: left; /* Blocos de código NUNCA podem ser justificados */
}

[data-theme="light"] .bubble pre { background: #f5f0e6; border-color: #d4cab8; }

.bubble code { 
    font-family: 'Consolas', 'Monaco', monospace; 
    background: rgba(var(--accent-color-rgb), 0.1); 
    padding: 2px 6px; 
    border-radius: 6px; 
    font-size: 0.9em; 
    color: var(--accent-color); 
}

.bubble blockquote { 
    border-left: 4px solid var(--accent-color); 
    margin: 1.2em 0; 
    padding-left: 15px; 
    font-style: italic; 
    color: var(--text-secondary); 
    background: rgba(255,255,255,0.02); 
    padding: 10px 15px; 
    border-radius: 0 8px 8px 0; 
}

.bubble a { 
    color: var(--accent-color); 
    text-decoration: none; 
    border-bottom: 1px dotted var(--accent-color); 
    transition: 0.2s; 
}
.bubble a:hover { opacity: 0.8; border-bottom-style: solid; }

/* --- CONTROLES DE ÁUDIO (TTS) COMPACTOS --- */
.tts-controls {
    display: flex;
    gap: 4px; 
    margin-top: -5px;
    margin-bottom: 15px;
    align-self: flex-start;
}

.tts-btn { 
    background: rgba(255,255,255,0.03); 
    border: 1px solid transparent; 
    color: var(--text-secondary); 
    cursor: pointer; 
    font-size: 0.78em; 
    opacity: 0.7; 
    transition: 0.2s; 
    display: flex; 
    align-items: center; 
    gap: 4px; 
    padding: 4px 10px; 
    border-radius: 15px;
}

.tts-btn:hover { 
    opacity: 1; 
    color: var(--accent-color); 
    background: rgba(255,255,255,0.08);
    border-color: rgba(175, 144, 97, 0.3);
}

.message.user .tts-controls { display: none; }

.sent-attachments-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    max-width: min(100%, 640px);
}

.sent-attachment-card {
    width: 152px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px;
    border-radius: 8px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.14);
    overflow: hidden;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
}

.sent-attachment-card:hover {
    background: rgba(255,255,255,0.14);
    border-color: rgba(255,255,255,0.24);
    transform: translateY(-1px);
}

.sent-attachment-thumb {
    width: 42px;
    height: 42px;
    border-radius: 6px;
    background: rgba(0,0,0,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--msg-user-text);
}

.sent-attachment-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sent-attachment-meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sent-attachment-name,
.sent-attachment-type {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sent-attachment-name {
    font-size: 0.82rem;
    font-weight: 600;
}

.sent-attachment-type {
    font-size: 0.72rem;
    opacity: 0.72;
}

.sent-message-text {
    margin-top: 10px;
}

/* --- INPUT AREA --- */
.input-wrapper { 
    width: 100%; 
    padding: 20px; 
    padding-bottom: max(20px, var(--safe-bottom)); 
    background: var(--bg-body); 
    display: flex;
    flex-direction: column;
    align-items: center; 
    transition: padding 0.2s; 
}

#file-indicator { 
    width: 100%;
    max-width: 850px; 
    font-size: 0.85rem; 
    color: var(--accent-color); 
    padding: 8px 12px; 
    margin-bottom: 8px; 
    background: var(--bg-input); 
    border: 1px solid var(--border-color); 
    border-radius: 8px; 
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 54px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1); 
}

#file-preview-list {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow-x: auto;
    flex: 1;
    padding-bottom: 2px;
}

.file-chip {
    min-width: 148px;
    max-width: 220px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.file-thumb {
    width: 38px;
    height: 38px;
    border-radius: 6px;
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.file-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.file-loading-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.18);
    border-top-color: var(--accent-color);
    animation: fileSpin 0.8s linear infinite;
}

@keyframes fileSpin {
    to { transform: rotate(360deg); }
}

.file-chip .file-meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-type {
    color: var(--text-secondary);
    font-size: 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#file-indicator .file-remove {
    color: var(--text-secondary);
    flex-shrink: 0;
}

.input-area { 
    width: 100%; 
    max-width: 850px; 
    background-color: var(--bg-input); 
    border-radius: 20px; 
    border: 1px solid var(--border-color); 
    padding: 10px 16px; 
    display: flex; 
    align-items: flex-end; 
    gap: 10px; 
    box-shadow: 0 4px 16px rgba(0,0,0,0.15); 
    transition: border-color 0.3s, box-shadow 0.3s; 
}

.input-area:focus-within { 
    border-color: var(--accent-color); 
    box-shadow: 0 4px 20px rgba(var(--accent-color-rgb), 0.1); 
}

textarea#user-input { 
    flex: 1; 
    width: 100%; 
    background: transparent; 
    border: none; 
    color: var(--text-primary); 
    outline: none; 
    font-size: var(--chat-font-size, 16px); 
    line-height: 1.5; 
    resize: none; 
    max-height: 150px; 
    padding: 12px 5px; 
    height: 48px; 
}

.action-btn { background: transparent; color: var(--text-secondary); border: none; width: 42px; height: 42px; cursor: pointer; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: 0.2s; }
.action-btn:hover { color: var(--accent-color); background: var(--bg-input); }

/* Botão de Enviar (Moderno) */
.send-btn { 
    background-color: var(--accent-color); 
    color: #fff; 
    border: none; 
    border-radius: 50%; 
    width: 42px; 
    height: 42px; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s, box-shadow 0.2s; 
    margin-bottom: 3px; 
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.send-btn svg { width: 18px; height: 18px; transform: translateX(-1px) translateY(1px); filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3)); }
.send-btn:hover { background-color: var(--accent-hover); transform: scale(1.1) rotate(-5deg); box-shadow: 0 4px 16px rgba(var(--accent-color-rgb), 0.4); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; background-color: #5a6a6e; box-shadow: none; }

.typing-dots span { width: 6px; height: 6px; background: var(--text-secondary); display: inline-block; border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both; margin: 0 3px; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* --- BOTÕES DE SCROLL FLUTUANTES --- */
.scroll-controls { position: absolute; bottom: 100px; right: 30px; display: flex; flex-direction: column; gap: 10px; z-index: 10; pointer-events: none; }

.scroll-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: rgba(30, 30, 30, 0.7);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: all 0.3s ease;
    pointer-events: auto; 
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.scroll-btn:hover {
    background: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(var(--accent-color-rgb), 0.2);
}

.scroll-btn.hidden { opacity: 0; transform: scale(0.8); pointer-events: none; }
[data-theme="light"] .scroll-btn { background: rgba(235, 227, 212, 0.8); }

/* --- ESCUDO JURÍDICO (DISCLAIMER) --- */
.ark-disclaimer {
    font-size: 0.72rem;
    color: var(--text-secondary);
    opacity: 0.7;
    text-align: center;
    margin-top: 10px;
    padding: 0 15px;
    line-height: 1.4;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    letter-spacing: 0.2px;
    max-width: 800px;
}

/* Disclaimer recolhível: só a 1ª frase + "continuar lendo..." por padrão */
.disclaimer-rest { display: none; }
.ark-disclaimer.expanded .disclaimer-rest { display: inline; }
.disclaimer-toggle {
    color: var(--accent-color);
    opacity: 0.6;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    white-space: nowrap;
}
.disclaimer-toggle:hover { opacity: 1; }
