/**
 * Oráculo Tainacan — Chat da BIA (Bibliotecária de IA)
 *
 * Design claro e limpo, estilo mensageiro moderno. As cores derivam das
 * variáveis injetadas pelas opções de aparência do plugin:
 *   --oraculo-primary  (padrão #1f2f56)
 *   --oraculo-accent   (padrão #b5e0e3)
 */

.oraculo-chat-button,
.oraculo-chat-window {
    --bia-primary: var(--oraculo-primary, #1f2f56);
    --bia-accent: var(--oraculo-accent, #b5e0e3);
    --bia-surface: #ffffff;
    --bia-canvas: #f6f8fa;
    --bia-border: #e6e9ee;
    --bia-text: #1c2733;
    --bia-text-soft: #5c6b7a;
    --bia-radius: 16px;
    --bia-shadow: 0 8px 30px rgba(16, 24, 40, 0.14);
    --bia-online: #2fbf71;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ============================= Botão flutuante ============================ */

.oraculo-chat-button {
    position: fixed;
    z-index: 99999;
    width: 60px;
    height: 60px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--bia-surface);
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(16, 24, 40, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.oraculo-chat-button.bottom-right { bottom: 24px; right: 24px; }
.oraculo-chat-button.bottom-left  { bottom: 24px; left: 24px; }

.oraculo-chat-button:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 8px 24px rgba(16, 24, 40, 0.28);
}

.oraculo-chat-button .chat-icon {
    display: flex;
    border-radius: 50%;
    overflow: hidden;
}

.oraculo-chat-button svg.close-icon {
    display: none;
    width: 24px;
    height: 24px;
    color: var(--bia-primary);
}

.oraculo-chat-button.open .chat-icon { display: none; }
.oraculo-chat-button.open svg.close-icon { display: block; }

/* ============================= Janela do chat ============================= */

.oraculo-chat-window {
    position: fixed;
    z-index: 99998;
    width: 384px;
    height: min(600px, calc(100vh - 120px));
    display: flex;
    flex-direction: column;
    background: var(--bia-canvas);
    border: 1px solid var(--bia-border);
    border-radius: var(--bia-radius);
    box-shadow: var(--bia-shadow);
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px) scale(0.98);
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.oraculo-chat-window.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.oraculo-chat-window.bottom-right { bottom: 96px; right: 24px; }
.oraculo-chat-window.bottom-left  { bottom: 96px; left: 24px; }

@media (max-width: 480px) {
    .oraculo-chat-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 96px);
        bottom: 84px !important;
        right: 8px !important;
        left: 8px !important;
    }
}

/* ================================ Cabeçalho =============================== */

.oraculo-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bia-surface);
    border-bottom: 1px solid var(--bia-border);
    flex-shrink: 0;
}

.oraculo-chat-avatar {
    display: flex;
    flex-shrink: 0;
}

.oraculo-chat-identity {
    flex: 1;
    min-width: 0;
}

.oraculo-chat-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--bia-text);
    line-height: 1.2;
}

.oraculo-chat-subtitle {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--bia-text-soft);
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.2;
}

.oraculo-chat-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--bia-online);
    flex-shrink: 0;
}

.oraculo-chat-new,
.oraculo-chat-close {
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--bia-text-soft);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
    flex-shrink: 0;
}

.oraculo-chat-new:hover,
.oraculo-chat-close:hover {
    background: var(--bia-canvas);
    color: var(--bia-primary);
}

/* ================================ Mensagens =============================== */

.oraculo-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

/* Boas-vindas */
.oraculo-chat-welcome {
    text-align: center;
    padding: 28px 16px 12px;
}

.oraculo-chat-welcome-avatar {
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
}

.oraculo-chat-welcome-name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--bia-text);
    margin-bottom: 6px;
}

.oraculo-chat-welcome-text {
    font-size: 14px;
    line-height: 1.55;
    color: var(--bia-text-soft);
    max-width: 300px;
    margin: 0 auto 18px;
}

.oraculo-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.oraculo-chat-suggestion {
    background: var(--bia-surface);
    border: 1px solid var(--bia-border);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--bia-text);
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.oraculo-chat-suggestion:hover {
    border-color: var(--bia-primary);
    box-shadow: 0 2px 8px rgba(16, 24, 40, 0.08);
    transform: translateY(-1px);
}

/* Bolhas */
.oraculo-chat-message {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: bia-slide-in 0.22s ease;
}

@keyframes bia-slide-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    .oraculo-chat-message,
    .oraculo-chat-window { animation: none; transition: none; }
}

.oraculo-chat-message.user {
    margin-left: auto;
    flex-direction: row-reverse;
}

.oraculo-message-avatar {
    display: flex;
    align-items: flex-end;
    flex-shrink: 0;
    padding-bottom: 2px;
}

.oraculo-message-body {
    min-width: 0;
}

.oraculo-message-content {
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.oraculo-chat-message.user .oraculo-message-content {
    background: var(--bia-primary);
    color: #fff;
    border-radius: 16px 16px 4px 16px;
}

.oraculo-chat-message.assistant .oraculo-message-content {
    background: var(--bia-surface);
    color: var(--bia-text);
    border: 1px solid var(--bia-border);
    border-radius: 4px 16px 16px 16px;
}

.oraculo-chat-message.is-error .oraculo-message-content {
    background: #fdf2f2;
    border-color: #f3c2c2;
    color: #8a2a2a;
}

.oraculo-message-content a {
    color: var(--bia-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.oraculo-chat-message.user .oraculo-message-content a {
    color: #fff;
}

/* Fontes do acervo */
.oraculo-message-sources {
    margin-top: 8px;
    padding: 10px 12px;
    background: var(--bia-surface);
    border: 1px solid var(--bia-border);
    border-radius: 12px;
    font-size: 12px;
}

.oraculo-message-sources-title {
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--bia-text-soft);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.04em;
}

.oraculo-message-source {
    display: block;
    color: var(--bia-primary);
    text-decoration: none;
    padding: 3px 0;
    line-height: 1.4;
}

.oraculo-message-source:hover {
    text-decoration: underline;
}

/* Feedback */
.oraculo-message-feedback {
    display: flex;
    gap: 4px;
    margin-top: 6px;
}

.oraculo-message-feedback button {
    background: transparent;
    border: none;
    border-radius: 8px;
    padding: 3px 7px;
    font-size: 13px;
    cursor: pointer;
    opacity: 0.45;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.oraculo-message-feedback button:hover {
    opacity: 1;
    background: var(--bia-surface);
}

.oraculo-message-feedback button.selected {
    opacity: 1;
    background: var(--bia-accent);
}

/* Indicador "BIA está pesquisando…" */
.oraculo-chat-typing-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.oraculo-chat-typing {
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    background: var(--bia-surface);
    border: 1px solid var(--bia-border);
    border-radius: 4px 16px 16px 16px;
}

.oraculo-chat-typing span {
    width: 7px;
    height: 7px;
    background: var(--bia-primary);
    border-radius: 50%;
    animation: bia-bounce 1.3s ease-in-out infinite;
}

.oraculo-chat-typing span:nth-child(2) { animation-delay: 0.18s; }
.oraculo-chat-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes bia-bounce {
    0%, 80%, 100% { transform: scale(0.4); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1; }
}

.oraculo-chat-typing-label {
    font-size: 12px;
    color: var(--bia-text-soft);
}

/* ================================= Input ================================== */

.oraculo-chat-input-container {
    padding: 12px 14px;
    background: var(--bia-surface);
    border-top: 1px solid var(--bia-border);
    flex-shrink: 0;
}

.oraculo-chat-input-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.oraculo-chat-input {
    flex: 1;
    border: 1px solid var(--bia-border);
    border-radius: 20px;
    padding: 10px 16px;
    resize: none;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    color: var(--bia-text);
    background: var(--bia-canvas);
    max-height: 120px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.oraculo-chat-input:focus {
    border-color: var(--bia-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--bia-primary) 15%, transparent);
    background: var(--bia-surface);
}

.oraculo-chat-input::placeholder {
    color: var(--bia-text-soft);
}

.oraculo-chat-send {
    width: 42px;
    height: 42px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--bia-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.oraculo-chat-send svg {
    width: 18px;
    height: 18px;
}

.oraculo-chat-send:hover:not(:disabled) {
    transform: scale(1.06);
}

.oraculo-chat-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
