/* ═══════════════════════════════════════════════════════════════ */
/* INTELLIGENCE CHAT — Design Premium, Dinâmico e Vivo           */
/* LabNote CDSS — Assistente Clínico                             */
/* Usa CSS custom properties do tema (palettes.css/theme.js)     */
/* ═══════════════════════════════════════════════════════════════ */

/* ─── Variáveis locais (herdam do tema global se disponível) ─── */
:root {
    --chat-accent: var(--color-primary, #10b981);
    --chat-accent-light: var(--color-primary-light, #ecfdf5);
    --chat-accent-glow: rgba(16, 185, 129, 0.15);
    --chat-bg: #ffffff;
    --chat-bg-subtle: #fafbfc;
    --chat-border: #e8ecf1;
    --chat-text: #374151;
    --chat-text-secondary: #6b7280;
    --chat-text-muted: #9ca3af;
}

/* ═══════════════════════════════════════ */
/* CONTAINER PRINCIPAL                    */
/* ═══════════════════════════════════════ */

.intelligence-chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 400px;
    max-height: 100%;
    background: var(--chat-bg);
    border-radius: 16px;
    border: 1px solid var(--chat-border);
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.04),
        0 4px 16px rgba(0, 0, 0, 0.03);
    overflow: hidden;
    position: relative;
}

/* ═══════════════════════════════════════ */
/* HEADER — com indicador de IA "vivo"    */
/* ═══════════════════════════════════════ */

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    background: linear-gradient(135deg, #f8fafb 0%, #f0f4f7 100%);
    border-bottom: 1px solid var(--chat-border);
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

/* Linha animada sutil no fundo do header — "pulso de IA" */
.chat-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--chat-accent) 20%,
        #06b6d4 50%,
        var(--chat-accent) 80%,
        transparent 100%
    );
    opacity: 0.4;
    animation: headerPulse 4s ease-in-out infinite;
    background-size: 200% 100%;
}

@keyframes headerPulse {
    0%, 100% { background-position: -100% 0; opacity: 0.2; }
    50% { background-position: 200% 0; opacity: 0.5; }
}

/* Ícone do bot com glow pulsante */
.chat-ai-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--chat-accent) 0%, #059669 60%, #0d9488 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 2px 8px rgba(16, 185, 129, 0.3),
        0 0 20px var(--chat-accent-glow);
    animation: iconGlow 3s ease-in-out infinite;
    position: relative;
}

@keyframes iconGlow {
    0%, 100% { box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3), 0 0 15px rgba(16, 185, 129, 0.1); }
    50% { box-shadow: 0 2px 12px rgba(16, 185, 129, 0.4), 0 0 25px rgba(16, 185, 129, 0.2); }
}

/* "Streaming" state — ícone mais vivo */
.chat-header.is-streaming .chat-ai-icon {
    animation: iconGlowActive 1.5s ease-in-out infinite;
}

.chat-header.is-streaming::after {
    animation: headerPulseActive 2s ease-in-out infinite;
    opacity: 0.7;
}

@keyframes iconGlowActive {
    0%, 100% { box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4), 0 0 20px rgba(16, 185, 129, 0.2); }
    50% { box-shadow: 0 2px 16px rgba(16, 185, 129, 0.6), 0 0 35px rgba(16, 185, 129, 0.35); }
}

@keyframes headerPulseActive {
    0% { background-position: -100% 0; }
    100% { background-position: 200% 0; }
}

.chat-action-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: white;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chat-action-btn:hover {
    background: var(--chat-accent-light);
    border-color: var(--chat-accent);
    color: var(--chat-accent);
    transform: scale(1.05);
}

/* ═══════════════════════════════════════ */
/* ÁREA DE MENSAGENS                      */
/* ═══════════════════════════════════════ */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    background: var(--chat-bg-subtle);
    /* Background pattern sutil de "circuito" — remete a IA */
    background-image: radial-gradient(circle at 1px 1px, rgba(0,0,0,0.015) 1px, transparent 0);
    background-size: 24px 24px;
}

/* ═══════════════════════════════════════ */
/* EMPTY STATE — com animação de pulso    */
/* ═══════════════════════════════════════ */

.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    flex: 1;
}

.chat-empty-state.hidden { display: none; }

/* Ícone central com pulso de "IA ativa" */
.chat-empty-icon {
    width: 60px;
    height: 60px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--chat-accent-light) 0%, #d1fae5 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
    position: relative;
}

.chat-empty-icon::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 22px;
    border: 2px solid var(--chat-accent);
    opacity: 0;
    animation: emptyPulse 3s ease-in-out infinite;
}

.chat-empty-icon::after {
    content: '';
    position: absolute;
    inset: -14px;
    border-radius: 28px;
    border: 1.5px solid var(--chat-accent);
    opacity: 0;
    animation: emptyPulse 3s ease-in-out 0.5s infinite;
}

@keyframes emptyPulse {
    0% { opacity: 0; transform: scale(0.95); }
    30% { opacity: 0.3; }
    100% { opacity: 0; transform: scale(1.15); }
}

/* ═══════════════════════════════════════ */
/* BUBBLE USUÁRIO                         */
/* ═══════════════════════════════════════ */

.chat-bubble-user {
    max-width: 85%;
    margin-left: auto;
    padding: 12px 16px;
    background: linear-gradient(135deg, #eff6ff 0%, #e0f0ff 100%);
    border: 1px solid #bfdbfe;
    border-radius: 18px 18px 4px 18px;
    position: relative;
    animation: bubbleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

/* ═══════════════════════════════════════ */
/* BUBBLE IA — com borda accent e glow    */
/* ═══════════════════════════════════════ */

.chat-bubble-ai {
    max-width: 92%;
    margin-right: auto;
    padding: 16px 20px;
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-left: 3px solid var(--chat-accent);
    border-radius: 4px 18px 18px 18px;
    box-shadow:
        0 1px 4px rgba(0, 0, 0, 0.03),
        0 0 0 0 var(--chat-accent-glow);
    position: relative;
    animation: bubbleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition: box-shadow 0.3s ease;
}

/* Glow enquanto está recebendo streaming */
.chat-bubble-ai.is-streaming {
    box-shadow:
        0 1px 4px rgba(0, 0, 0, 0.03),
        0 0 20px var(--chat-accent-glow);
    border-left-color: var(--chat-accent);
    animation: streamGlow 2s ease-in-out infinite;
}

@keyframes streamGlow {
    0%, 100% { box-shadow: 0 1px 4px rgba(0,0,0,0.03), 0 0 15px rgba(16,185,129,0.08); }
    50% { box-shadow: 0 1px 4px rgba(0,0,0,0.03), 0 0 25px rgba(16,185,129,0.15); }
}

/* ─── Markdown content ─── */
.chat-bubble-ai .ai-content {
    line-height: 1.7;
    color: var(--chat-text);
    font-size: 13.5px;
}

.chat-bubble-ai .ai-content h1,
.chat-bubble-ai .ai-content h2,
.chat-bubble-ai .ai-content h3 {
    font-weight: 700;
    margin-top: 14px;
    margin-bottom: 6px;
    color: #1f2937;
}
.chat-bubble-ai .ai-content h2 { font-size: 14px; }
.chat-bubble-ai .ai-content h3 { font-size: 13px; }
.chat-bubble-ai .ai-content p { margin-bottom: 8px; }

.chat-bubble-ai .ai-content ul,
.chat-bubble-ai .ai-content ol {
    padding-left: 20px;
    margin-bottom: 8px;
}
.chat-bubble-ai .ai-content li { margin-bottom: 4px; }

.chat-bubble-ai .ai-content strong {
    font-weight: 600;
    color: #1f2937;
}

.chat-bubble-ai .ai-content code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    color: #0f766e;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.chat-bubble-ai .ai-content blockquote {
    border-left: 3px solid var(--chat-accent);
    padding-left: 12px;
    margin: 10px 0;
    color: #4b5563;
    background: var(--chat-accent-light);
    padding: 8px 12px;
    border-radius: 0 8px 8px 0;
}

/* Referências — pills douradas */
.chat-bubble-ai .ai-content a,
.ref-pill {
    display: inline;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border: 1px solid #fbbf24;
    color: #92400e;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 10.5px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.chat-bubble-ai .ai-content a:hover,
.ref-pill:hover {
    background: linear-gradient(135deg, #fde68a, #fbbf24);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
}

/* ═══════════════════════════════════════ */
/* TYPING INDICATOR — 3 pontos "vivos"    */
/* ═══════════════════════════════════════ */

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 2px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-accent), #06b6d4);
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
    0%, 80%, 100% { opacity: 0.25; transform: scale(0.75) translateY(0); }
    40% { opacity: 1; transform: scale(1) translateY(-4px); }
}

/* ═══════════════════════════════════════ */
/* STEPPER DINÂMICO — pipeline visual     */
/* ═══════════════════════════════════════ */

.chat-stepper {
    padding: 8px 18px;
    background: linear-gradient(180deg, var(--chat-bg-subtle), var(--chat-bg));
    border-top: 1px solid #f0f2f5;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

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

.chat-step {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    transition: all 0.3s ease;
    animation: stepIn 0.3s ease-out;
}

@keyframes stepIn {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}

.chat-step-active {
    background: var(--chat-accent-light);
    border: 1px solid #a7f3d0;
    color: #065f46;
    font-weight: 600;
}

.chat-step-done {
    background: #f0fdf4;
    border: 1px solid #d1fae5;
    color: #6b7280;
    opacity: 0.65;
}

.chat-step-spinner {
    width: 13px;
    height: 13px;
    border: 2px solid #bbf7d0;
    border-top-color: var(--chat-accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ═══════════════════════════════════════ */
/* SUGESTÕES — chips elegantes            */
/* ═══════════════════════════════════════ */

.chat-suggestions {
    padding: 10px 18px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    border-top: 1px solid #f0f2f5;
    background: var(--chat-bg-subtle);
    flex-shrink: 0;
    animation: fadeInUp 0.3s ease-out;
}

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

.chat-suggestion-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 7px 14px;
    background: var(--chat-bg);
    border: 1.5px solid #d1d9e0;
    border-radius: 20px;
    font-size: 12px;
    color: var(--chat-text-secondary);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.3;
    position: relative;
}

/* Ícone de centelha antes do chip */
.chat-suggestion-chip::before {
    content: '✦';
    font-size: 9px;
    color: var(--chat-accent);
    opacity: 0.6;
}

.chat-suggestion-chip:hover {
    background: var(--chat-accent-light);
    border-color: var(--chat-accent);
    color: #065f46;
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.15);
}

.chat-suggestion-chip:hover::before {
    opacity: 1;
}

.chat-suggestion-chip:active {
    transform: translateY(0) scale(0.98);
}

/* ═══════════════════════════════════════ */
/* INPUT AREA — premium com glow          */
/* ═══════════════════════════════════════ */

.chat-input-area {
    padding: 12px 18px 10px;
    background: var(--chat-bg);
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--chat-bg-subtle);
    border: 1.5px solid #e2e8f0;
    border-radius: 16px;
    padding: 6px 8px 6px 16px;
    transition: all 0.3s ease;
}

.chat-input-wrapper:focus-within {
    border-color: var(--chat-accent);
    box-shadow: 0 0 0 3px var(--chat-accent-glow);
    background: var(--chat-bg);
}

.chat-textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--chat-text);
    max-height: 120px;
    padding: 6px 0;
    font-family: inherit;
}

.chat-textarea::placeholder { color: var(--chat-text-muted); }
.chat-textarea:disabled { opacity: 0.4; }

.chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, var(--chat-accent) 0%, #059669 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    flex-shrink: 0;
    font-size: 13px;
    box-shadow: 0 2px 10px rgba(16, 185, 129, 0.35);
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.45);
}

.chat-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    box-shadow: none;
    background: #9ca3af;
}

/* ═══════════════════════════════════════ */
/* SCROLLBAR                              */
/* ═══════════════════════════════════════ */

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ═══════════════════════════════════════ */
/* ANIMAÇÕES GLOBAIS                      */
/* ═══════════════════════════════════════ */

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

.animate-fade-in {
    animation: fadeInUp 0.25s ease-out;
}

/* ═══════════════════════════════════════ */
/* DARK MODE — Compatível com theme.js    */
/* ═══════════════════════════════════════ */

.dark .intelligence-chat-container,
html[data-theme="dark"] .intelligence-chat-container {
    --chat-bg: #1e293b;
    --chat-bg-subtle: #0f172a;
    --chat-border: #334155;
    --chat-text: #e2e8f0;
    --chat-text-secondary: #94a3b8;
    --chat-text-muted: #4b5563;
    --chat-accent-glow: rgba(16, 185, 129, 0.2);

    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.dark .chat-header,
html[data-theme="dark"] .chat-header {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-color: #334155;
}

.dark .chat-header h3,
html[data-theme="dark"] .chat-header h3 { color: #f1f5f9; }

.dark .chat-messages,
html[data-theme="dark"] .chat-messages {
    background-image: radial-gradient(circle at 1px 1px, rgba(255,255,255,0.02) 1px, transparent 0);
}

.dark .chat-bubble-user,
html[data-theme="dark"] .chat-bubble-user {
    background: linear-gradient(135deg, #1e3a5f 0%, rgba(30, 64, 175, 0.15) 100%);
    border-color: rgba(59, 130, 246, 0.3);
}
.dark .chat-bubble-user p,
html[data-theme="dark"] .chat-bubble-user p { color: #e2e8f0; }

.dark .chat-bubble-ai,
html[data-theme="dark"] .chat-bubble-ai {
    background: #1e293b;
    border-color: #334155;
    border-left-color: var(--chat-accent);
}

.dark .chat-bubble-ai .ai-content,
html[data-theme="dark"] .chat-bubble-ai .ai-content { color: #e2e8f0; }

.dark .chat-bubble-ai .ai-content strong,
html[data-theme="dark"] .chat-bubble-ai .ai-content strong { color: #f1f5f9; }

.dark .chat-bubble-ai .ai-content code,
html[data-theme="dark"] .chat-bubble-ai .ai-content code {
    background: #334155;
    color: #6ee7b7;
}

.dark .chat-bubble-ai .ai-content blockquote,
html[data-theme="dark"] .chat-bubble-ai .ai-content blockquote {
    background: rgba(16, 185, 129, 0.08);
    color: #94a3b8;
}

.dark .chat-suggestion-chip,
html[data-theme="dark"] .chat-suggestion-chip {
    background: #1e293b;
    border-color: #475569;
    color: #94a3b8;
}

.dark .chat-suggestion-chip:hover,
html[data-theme="dark"] .chat-suggestion-chip:hover {
    background: #064e3b;
    border-color: #065f46;
    color: #6ee7b7;
}

.dark .chat-action-btn,
html[data-theme="dark"] .chat-action-btn {
    background: #1e293b;
    border-color: #475569;
    color: #94a3b8;
}

.dark .chat-action-btn:hover,
html[data-theme="dark"] .chat-action-btn:hover {
    background: #334155;
    color: #f1f5f9;
}

.dark .chat-stepper,
html[data-theme="dark"] .chat-stepper {
    background: linear-gradient(180deg, #0f172a, #1e293b);
    border-color: #334155;
}

.dark .chat-step-active,
html[data-theme="dark"] .chat-step-active {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
    color: #6ee7b7;
}

.dark .chat-input-area,
html[data-theme="dark"] .chat-input-area {
    border-color: #334155;
}

.dark .ref-pill,
html[data-theme="dark"] .ref-pill,
.dark .chat-bubble-ai .ai-content a,
html[data-theme="dark"] .chat-bubble-ai .ai-content a {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.15), rgba(251, 191, 36, 0.25));
    border-color: rgba(251, 191, 36, 0.4);
    color: #fbbf24;
}

.dark .typing-indicator span,
html[data-theme="dark"] .typing-indicator span {
    background: linear-gradient(135deg, #6ee7b7, #22d3ee);
}

/* ═══════════════════════════════════════ */
/* PALETTE-AWARE — Responde ao sistema    */
/* de paletas customizadas do LabNote     */
/* ═══════════════════════════════════════ */

/* Se o usuário mudou a cor primária via palette-picker */
[data-palette] .chat-send-btn {
    background: linear-gradient(135deg, var(--color-primary, #10b981) 0%, var(--color-primary-dark, #059669) 100%);
}

[data-palette] .chat-bubble-ai {
    border-left-color: var(--color-primary, #10b981);
}

[data-palette] .chat-suggestion-chip:hover {
    border-color: var(--color-primary, #10b981);
}

[data-palette] .chat-input-wrapper:focus-within {
    border-color: var(--color-primary, #10b981);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb, 16, 185, 129), 0.1);
}

/* ═══════════════════════════════════════ */
/* REFERÊNCIAS PUBMED — Painel flutuante  */
/* ═══════════════════════════════════════ */

.chat-references {
    padding: 10px 18px 8px;
    border-top: 1px solid #f0f2f5;
    background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 50%, #f0fdfa 100%);
    flex-shrink: 0;
    animation: fadeInUp 0.3s ease-out;
    max-height: 220px;
    overflow: hidden;
}

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

.chat-refs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(16, 185, 129, 0.15);
}

.chat-refs-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 160px;
    overflow-y: auto;
    padding-right: 4px;
}

.chat-ref-item {
    display: block;
    padding: 8px 10px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

.chat-ref-item:hover {
    border-color: var(--chat-accent);
    background: #f0fdf4;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.1);
    transform: translateX(2px);
}

.chat-ref-badge {
    display: inline-block;
    padding: 1px 6px;
    background: linear-gradient(135deg, #dbeafe, #eff6ff);
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    font-size: 8px;
    font-weight: 600;
    color: #1d4ed8;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Refs inline dentro da bubble */
.chat-inline-refs {
    animation: fadeInUp 0.2s ease-out;
}
.chat-inline-refs.hidden { display: none; }

.chat-inline-refs a {
    display: block !important;
    background: none !important;
    border: none !important;
    padding: 2px 0 !important;
    border-radius: 0 !important;
    font-weight: 400 !important;
    white-space: normal !important;
}

.chat-inline-refs a:hover {
    transform: none !important;
    box-shadow: none !important;
}

/* Truncate multi-line */
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Dark mode refs */
.dark .chat-references,
html[data-theme="dark"] .chat-references {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.05) 0%, rgba(6, 182, 212, 0.05) 100%);
    border-color: #334155;
}

.dark .chat-ref-item,
html[data-theme="dark"] .chat-ref-item {
    background: #1e293b;
    border-color: #334155;
}

.dark .chat-ref-item:hover,
html[data-theme="dark"] .chat-ref-item:hover {
    background: #0f2518;
    border-color: rgba(16, 185, 129, 0.4);
}

.dark .chat-ref-item p,
html[data-theme="dark"] .chat-ref-item p {
    color: #e2e8f0;
}

.dark .chat-ref-badge,
html[data-theme="dark"] .chat-ref-badge {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.3);
    color: #60a5fa;
}

.dark .chat-refs-header,
html[data-theme="dark"] .chat-refs-header {
    border-color: rgba(16, 185, 129, 0.2);
}

.dark .chat-refs-header span,
html[data-theme="dark"] .chat-refs-header span {
    color: #e2e8f0;
}

/* ═══════════════════════════════════════ */
/* PROACTIVE NUDGE — Cards de IA detectou */
/* ═══════════════════════════════════════ */

.nudge-wrapper { margin-bottom: 12px; }
.nudge-wrapper.hidden { display: none; }

.nudge-container {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 50%, #fff7ed 100%);
    border: 1px solid #fde68a;
    border-radius: 14px;
    padding: 10px 14px;
    box-shadow: 0 2px 12px rgba(245, 158, 11, 0.08);
}

.nudge-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.nudge-pulse {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #f59e0b;
    animation: nudgePulse 2s ease-in-out infinite;
}

@keyframes nudgePulse {
    0%, 100% { opacity: 0.4; transform: scale(0.9); }
    50% { opacity: 1; transform: scale(1.2); }
}

.nudge-cards {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nudge-card {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: 1.5px solid;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    text-align: left;
    outline: none;
}

.nudge-card:hover {
    transform: translateX(3px);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.06);
}

.nudge-card:active {
    transform: translateX(1px) scale(0.98);
}

.nudge-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nudge-arrow {
    flex-shrink: 0;
    opacity: 0;
    transform: translateX(-4px);
    transition: all 0.2s ease;
}

.nudge-card:hover .nudge-arrow {
    opacity: 1;
    transform: translateX(0);
}

/* Dark mode nudges */
.dark .nudge-container,
html[data-theme="dark"] .nudge-container {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.08) 0%, rgba(217, 119, 6, 0.06) 100%);
    border-color: rgba(245, 158, 11, 0.25);
}

.dark .nudge-card,
html[data-theme="dark"] .nudge-card {
    background: rgba(30, 41, 59, 0.8) !important;
}

.dark .nudge-card p:first-child,
html[data-theme="dark"] .nudge-card p:first-child {
    color: #f1f5f9;
}

.dark .nudge-icon,
html[data-theme="dark"] .nudge-icon {
    background: rgba(255, 255, 255, 0.1);
}

/* ═══════════════════════════════════════ */
/* RESPONSIVO                             */
/* ═══════════════════════════════════════ */

@media (max-width: 768px) {
    .intelligence-chat-container {
        border-radius: 12px;
        min-height: 300px;
        max-height: calc(100vh - 140px);
    }

    .chat-messages { padding: 14px 12px; gap: 12px; }

    .chat-bubble-user,
    .chat-bubble-ai { max-width: 95%; }

    .chat-bubble-ai { padding: 12px 14px; }

    .chat-suggestion-chip { font-size: 11px; padding: 5px 10px; }

    .chat-header { padding: 10px 14px; }
    .chat-input-area { padding: 8px 12px; }

    .nudge-container { padding: 8px 10px; }
    .nudge-card { padding: 6px 10px; }
}

/* ═══════════════════════════════════════ */
/* PRINT                                  */
/* ═══════════════════════════════════════ */

@media print { .intelligence-chat-container, .chat-drawer, .fab-chat { display: none; } }


/* ═══════════════════════════════════════════════════════════════ */
/* CHAT DRAWER — Painel deslizante acessível de qualquer aba     */
/* ═══════════════════════════════════════════════════════════════ */

/* Backdrop (escurece fundo quando drawer aberto) */
.chat-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(2px);
    z-index: 9990;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.chat-drawer-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Drawer principal */
.chat-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    height: 100vh;
    height: 100dvh;
    z-index: 9995;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.12);
    background: var(--chat-bg, #fff);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

/* O container do chat dentro do drawer deve preencher tudo */
.chat-drawer .intelligence-chat-container {
    border-radius: 0;
    border: none;
    box-shadow: none;
    max-height: 100vh;
    max-height: 100dvh;
    height: 100%;
    min-height: unset;
}

/* Header do chat no drawer — com botão de fechar */
.chat-drawer .chat-header {
    padding: 14px 18px;
    border-radius: 0;
}

/* Mensagens no drawer — ocupa espaço restante */
.chat-drawer .chat-messages {
    flex: 1;
    max-height: none;
}


/* ═══════════════════════════════════════ */
/* FAB — Botão Flutuante do Chat         */
/* ═══════════════════════════════════════ */

.fab-chat {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    z-index: 9989;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: #fff;
    background: linear-gradient(135deg, #10b981, #059669);
    box-shadow:
        0 4px 14px rgba(16, 185, 129, 0.4),
        0 2px 6px rgba(0, 0, 0, 0.15);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: fabPulseIn 0.5s ease-out;
}

.fab-chat:hover {
    transform: scale(1.08);
    box-shadow:
        0 6px 20px rgba(16, 185, 129, 0.5),
        0 3px 8px rgba(0, 0, 0, 0.2);
}

.fab-chat:active {
    transform: scale(0.95);
}

/* FAB ativo (drawer aberto) */
.fab-chat.active {
    background: linear-gradient(135deg, #475569, #334155);
    box-shadow:
        0 4px 14px rgba(71, 85, 105, 0.4),
        0 2px 6px rgba(0, 0, 0, 0.15);
}

/* Badge de notificação no FAB */
.fab-chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
}

.fab-chat-badge.hidden {
    display: none;
}

/* Esconde FAB no plano Essential */
html.plan-essential .fab-chat,
html.plan-clinical .fab-chat {
    display: none;
}

@keyframes fabPulseIn {
    0% { opacity: 0; transform: scale(0.5); }
    60% { transform: scale(1.1); }
    100% { opacity: 1; transform: scale(1); }
}

/* ═══════════════════════════════════════ */
/* FAB de feedback — ajusta posição       */
/* quando chat FAB está visível           */
/* ═══════════════════════════════════════ */

html.plan-intelligence .fab-feedback {
    bottom: 90px;
}


/* ═══════════════════════════════════════ */
/* RESPONSIVIDADE DO DRAWER              */
/* ═══════════════════════════════════════ */

/* Telas médias (tablets) */
@media (max-width: 768px) {
    .chat-drawer {
        width: 100%;
    }

    .fab-chat {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
        font-size: 20px;
    }

    html.plan-intelligence .fab-feedback {
        bottom: 76px;
    }
}

/* Telas grandes — drawer mais largo */
@media (min-width: 1440px) {
    .chat-drawer {
        width: 480px;
    }
}

/* Telas muito grandes */
@media (min-width: 1920px) {
    .chat-drawer {
        width: 520px;
    }
}


/* ═══════════════════════════════════════ */
/* DARK MODE — Drawer + FAB              */
/* ═══════════════════════════════════════ */

html.dark .chat-drawer {
    background: var(--chat-bg, #1a1a2e);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
}

html.dark .chat-drawer-backdrop {
    background: rgba(0, 0, 0, 0.5);
}

html.dark .fab-chat {
    background: linear-gradient(135deg, #059669, #047857);
    box-shadow:
        0 4px 14px rgba(5, 150, 105, 0.3),
        0 2px 6px rgba(0, 0, 0, 0.3);
}

html.dark .fab-chat.active {
    background: linear-gradient(135deg, #374151, #1f2937);
}

html.dark .fab-chat-badge {
    border-color: #1a1a2e;
}
