/* ─────────────────────────────────────────────────────────────
 * Chat drawer flutuante — FAB + painel slide-in pela direita.
 * ───────────────────────────────────────────────────────────── */

/* ── FAB ── */
.chat-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--c-primary, #3e5c67), #5a8a99);
    color: #fff;
    border: none;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35),
                0 0 0 1px rgba(255, 255, 255, 0.08) inset;
    cursor: pointer;
    z-index: 1500;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.chat-fab:hover {
    transform: translateY(-1px) scale(1.03);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45),
                0 0 0 1px rgba(255, 255, 255, 0.12) inset;
}

.chat-fab:focus-visible {
    outline: 2px solid #e9c46a;
    outline-offset: 2px;
}

/* Esconde o FAB enquanto o drawer estiver aberto. */
.chat-open .chat-fab {
    transform: scale(0);
    pointer-events: none;
}

/* ── Overlay + Drawer wrapper ── */
.chat-root {
    /* container do overlay e do painel; sem layout proprio. */
}

.chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 1400;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.chat-open .chat-overlay {
    opacity: 1;
    pointer-events: auto;
}

.chat-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 420px;
    max-width: 100vw;
    background: var(--c-card, #162330);
    border-left: 1px solid var(--c-border, #243444);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.45);
    z-index: 1450;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.chat-open .chat-drawer {
    transform: translateX(0);
}

@media (max-width: 640px) {
    .chat-drawer {
        width: 100vw;
    }
}

/* ── Header ── */
.chat-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--c-border, #243444);
    background: linear-gradient(180deg,
                                rgba(90, 138, 153, 0.05),
                                transparent);
    flex-shrink: 0;
}

.chat-drawer-title {
    display: flex;
    align-items: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--c-text, #f0f4f8);
    letter-spacing: -0.005em;
    font-family: Geist, Inter, system-ui, sans-serif;
}

.chat-drawer-close,
.chat-drawer-icon-btn {
    background: transparent;
    border: none;
    color: var(--c-text-muted, #8fa3b1);
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 15px;
    transition: background 0.15s ease, color 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.chat-drawer-close:hover,
.chat-drawer-icon-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--c-text, #f0f4f8);
}

.chat-drawer-icon-btn:focus-visible {
    outline: 2px solid #5a8a99;
    outline-offset: 1px;
}

.chat-drawer-actions {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

/* ── Modo maximizado (fullscreen) ── */
.chat-maximized .chat-drawer {
    width: 100vw;
    max-width: 100vw;
}

.chat-maximized .chat-overlay {
    /* No fullscreen o overlay nao precisa ficar visivel — o drawer cobre
       a viewport inteira. Manter clicavel atrapalharia (clicar fora fecha). */
    opacity: 0;
    pointer-events: none;
}

/* No fullscreen, mensagens e chart ficam mais respiradas. */
.chat-maximized .chat-messages {
    padding: 24px max(24px, calc((100vw - 880px) / 2));
}

.chat-maximized .chat-msg-bubble {
    max-width: 70ch;
    font-size: 14.5px;
}

.chat-maximized .chat-msg-chart {
    max-width: 880px;
    width: 100%;
}

.chat-maximized .chat-input-row {
    padding: 14px max(24px, calc((100vw - 880px) / 2));
}

/* ── Lista de mensagens ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(143, 163, 177, 0.2);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(143, 163, 177, 0.35);
}

/* ── Empty state ── */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--c-text-muted, #8fa3b1);
    padding: 32px 16px;
}

.chat-empty-title {
    font-size: 14px;
    font-weight: 500;
    margin-top: 12px;
    color: var(--c-text, #f0f4f8);
}

.chat-empty-hint {
    font-size: 12px;
    margin-top: 6px;
    opacity: 0.7;
    font-style: italic;
}

/* ── Mensagens ── */
.chat-msg {
    display: flex;
    max-width: 100%;
}

.chat-msg-user {
    justify-content: flex-end;
}

.chat-msg-assistant {
    justify-content: flex-start;
    flex-direction: column;
    align-items: flex-start;
}

.chat-msg-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    font-family: Inter, system-ui, sans-serif;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.chat-msg-user .chat-msg-bubble {
    background: linear-gradient(135deg, #3e5c67, #4e7484);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg-assistant .chat-msg-bubble {
    background: var(--c-surface, #1e3040);
    color: var(--c-text, #f0f4f8);
    border: 1px solid var(--c-border, #243444);
    border-bottom-left-radius: 4px;
}

.chat-msg-error-bubble {
    background: rgba(224, 96, 96, 0.12) !important;
    border-color: rgba(224, 96, 96, 0.35) !important;
    color: #f3c2c2 !important;
}

.chat-msg-chart {
    margin-top: 8px;
    width: 100%;
    max-width: 100%;
    background: var(--c-surface, #162330);
    border: 1px solid var(--c-border, #243444);
    border-radius: 10px;
    padding: 8px;
}

/* ── Thinking dots ── */
.chat-thinking-dots {
    display: inline-flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--c-surface, #1e3040);
    border: 1px solid var(--c-border, #243444);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

.chat-thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--c-text-muted, #8fa3b1);
    animation: chat-dot-pulse 1.2s ease-in-out infinite;
}

.chat-thinking-dots span:nth-child(2) {
    animation-delay: 0.18s;
}

.chat-thinking-dots span:nth-child(3) {
    animation-delay: 0.36s;
}

@keyframes chat-dot-pulse {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.85);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ── Input row ── */
.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--c-border, #243444);
    background: var(--c-card, #162330);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    background: var(--c-surface, #0f1419);
    border: 1px solid var(--c-border, #243444);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--c-text, #f0f4f8);
    font-family: Inter, system-ui, sans-serif;
    font-size: 13.5px;
    line-height: 1.4;
    resize: none;
    min-height: 38px;
    max-height: 140px;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.chat-input:focus {
    outline: none;
    border-color: #5a8a99;
    background: var(--c-surface, #1e3040);
}

.chat-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-send-btn {
    background: linear-gradient(135deg, #3e5c67, #5a8a99);
    color: #fff;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.chat-send-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(90, 138, 153, 0.35);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Chip de download de arquivo (PDF/XLSX exportados pelo agente) ── */
.chat-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 8px 12px;
    background: rgba(90, 138, 153, 0.12);
    border: 1px solid rgba(90, 138, 153, 0.32);
    border-radius: 10px;
    color: var(--c-text, #f0f4f8);
    text-decoration: none;
    font-family: Inter, system-ui, sans-serif;
    font-size: 12.5px;
    line-height: 1.2;
    max-width: 100%;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.12s ease,
                border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-file-chip:hover {
    background: rgba(90, 138, 153, 0.22);
    border-color: rgba(90, 138, 153, 0.55);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
    text-decoration: none;
    color: var(--c-text, #f0f4f8);
}

.chat-file-chip:focus-visible {
    outline: 2px solid #e9c46a;
    outline-offset: 2px;
}

.chat-file-chip-icon {
    font-size: 18px;
    flex-shrink: 0;
}

/* Variacoes por tipo de arquivo — colore o icone seguindo a paleta usual. */
.chat-file-chip-icon.bi-filetype-pdf {
    color: #e57373;
}

.chat-file-chip-icon.bi-file-earmark-excel {
    color: #66c08a;
}

.chat-file-chip-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}

.chat-file-chip-size {
    color: var(--c-text-muted, #8fa3b1);
    font-size: 11.5px;
    flex-shrink: 0;
}

.chat-file-chip-size:empty {
    display: none;
}

.chat-file-chip-action {
    margin-left: 2px;
    font-size: 13px;
    color: var(--c-text-muted, #8fa3b1);
    flex-shrink: 0;
}

.chat-file-chip:hover .chat-file-chip-action {
    color: var(--c-text, #f0f4f8);
}

/* Em fullscreen o chip pode mostrar o filename completo. */
.chat-maximized .chat-file-chip-name {
    max-width: 480px;
}
