/**
 * Pitrulino Widget CSS - Widget Flutuante da IA dos Colégios Pitruca
 * Suporte a Desktop e Mobile, Dark Mode, Áudio e Animações Fluidas
 */

:root {
    --pw-primary: #27ae60;
    --pw-primary-dark: #1e824c;
    --pw-primary-light: #e8f8f0;
    --pw-accent: #3498db;
    --pw-dark: #0f172a;
    --pw-card-bg: #ffffff;
    --pw-text: #1e293b;
    --pw-text-muted: #64748b;
    --pw-border: rgba(0, 0, 0, 0.08);
    --pw-radius: 18px;
    --pw-shadow: 0 16px 40px rgba(0, 0, 0, 0.16);
}

/* Modo Escuro para o Widget */
[data-bs-theme="dark"] #pitrulino-widget-drawer,
.pitruca-dark #pitrulino-widget-drawer {
    --pw-card-bg: #1e293b;
    --pw-text: #f8fafc;
    --pw-text-muted: #94a3b8;
    --pw-border: rgba(255, 255, 255, 0.1);
    --pw-primary-light: rgba(39, 174, 96, 0.15);
    --pw-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   1. BOTÃO FLUTUANTE (FAB)
   ========================================================================== */
#pitrulino-fab-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

#pitrulino-fab-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    border: 3px solid #ffffff;
    box-shadow: 0 8px 25px rgba(39, 174, 96, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    outline: none;
    padding: 0;
}

#pitrulino-fab-btn:hover {
    transform: scale(1.08) translateY(-3px);
    box-shadow: 0 12px 30px rgba(39, 174, 96, 0.55);
}

#pitrulino-fab-btn img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    transition: transform 0.3s ease;
}

#pitrulino-fab-btn .fab-close-icon {
    display: none;
    font-size: 24px;
    color: #ffffff;
}

#pitrulino-fab-container.is-open #pitrulino-fab-btn {
    background: #e74c3c;
    border-color: #ffffff;
    box-shadow: 0 8px 25px rgba(231, 76, 60, 0.4);
}

#pitrulino-fab-container.is-open #pitrulino-fab-btn img {
    display: none;
}

#pitrulino-fab-container.is-open #pitrulino-fab-btn .fab-close-icon {
    display: block;
}

/* Indicador de Status Online Pulsante */
.pitrulino-online-pulse {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 15px;
    height: 15px;
    background-color: #2ecc71;
    border: 2.5px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 0 0 rgba(46, 204, 113, 0.5);
    animation: pitrulino-pulse 2s infinite;
}

@keyframes pitrulino-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(46, 204, 113, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(46, 204, 113, 0);
    }
}

/* Balãozinho de Saudação Inicial (Tooltip) */
.pitrulino-fab-tooltip {
    position: absolute;
    right: 76px;
    top: 12px;
    background: #0f172a;
    color: #ffffff;
    padding: 8px 14px;
    border-radius: 12px;
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    pointer-events: none;
    opacity: 1;
    transform: translateX(0);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.pitrulino-fab-tooltip::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 6px 0 6px 6px;
    border-style: solid;
    border-color: transparent transparent transparent #0f172a;
}

.pitrulino-fab-tooltip.hide {
    opacity: 0;
    transform: translateX(10px);
}

/* ==========================================================================
   2. JANELA DO CHAT (DRAWER / POPUP)
   ========================================================================== */
#pitrulino-widget-drawer {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 390px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 120px);
    background: var(--pw-card-bg);
    border: 1px solid var(--pw-border);
    border-radius: var(--pw-radius);
    box-shadow: var(--pw-shadow);
    display: flex;
    flex-direction: column;
    z-index: 10001;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.92) translateY(20px);
    transform-origin: bottom right;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

#pitrulino-widget-drawer.is-active {
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateY(0);
}

/* Cabeçalho */
.pw-header {
    background: linear-gradient(135deg, #1e3a8a, #0f172a);
    color: #ffffff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.pw-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pw-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #ffffff;
    padding: 3px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.pw-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.pw-header-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.pw-header-status {
    font-size: 0.73rem;
    color: #4ade80;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.pw-header-status-dot {
    width: 7px;
    height: 7px;
    background-color: #4ade80;
    border-radius: 50%;
    display: inline-block;
}

.pw-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pw-header-btn {
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #ffffff;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background-color 0.2s, transform 0.2s;
    text-decoration: none;
}

.pw-header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    color: #ffffff;
    transform: scale(1.05);
}

/* Área de Mensagens */
.pw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: inherit;
    scroll-behavior: smooth;
}

.pw-message {
    display: flex;
    gap: 10px;
    max-width: 88%;
}

.pw-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.pw-message.assistant {
    align-self: flex-start;
}

.pw-avatar-mini {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #ffffff;
    border: 1px solid var(--pw-border);
    padding: 2px;
}

.pw-avatar-mini img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.pw-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.87rem;
    line-height: 1.5;
    position: relative;
    word-break: break-word;
}

.pw-message.user .pw-bubble {
    background: linear-gradient(135deg, #27ae60, #219653);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.pw-message.assistant .pw-bubble {
    background: var(--pw-primary-light);
    color: var(--pw-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--pw-border);
}

/* Botão de Áudio (Text-to-Speech) na Bolha */
.pw-tts-btn {
    background: transparent;
    border: none;
    color: var(--pw-primary);
    cursor: pointer;
    font-size: 0.82rem;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    transition: background 0.2s, color 0.2s;
}

.pw-tts-btn:hover {
    background: rgba(39, 174, 96, 0.15);
}

.pw-tts-btn.is-speaking {
    color: #e74c3c;
    animation: pw-pulse-speak 1s infinite alternate;
}

@keyframes pw-pulse-speak {
    from { opacity: 0.6; }
    to { opacity: 1; }
}

/* Sugestões Rápidas (Chips) */
.pw-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.pw-chip {
    background: rgba(39, 174, 96, 0.1);
    color: var(--pw-primary-dark);
    border: 1px solid rgba(39, 174, 96, 0.25);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.77rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

[data-bs-theme="dark"] .pw-chip,
.pitruca-dark .pw-chip {
    color: #4ade80;
    background: rgba(39, 174, 96, 0.18);
    border-color: rgba(39, 174, 96, 0.35);
}

.pw-chip:hover {
    background: var(--pw-primary);
    color: #ffffff;
    transform: translateY(-1px);
}

/* Rodapé / Input de Envio */
.pw-footer {
    padding: 10px 14px;
    border-top: 1px solid var(--pw-border);
    background: var(--pw-card-bg);
}

.pw-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--pw-border);
    border-radius: 24px;
    padding: 4px 8px 4px 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

[data-bs-theme="dark"] .pw-input-group,
.pitruca-dark .pw-input-group {
    background: rgba(255, 255, 255, 0.05);
}

.pw-input-group:focus-within {
    border-color: var(--pw-primary);
    box-shadow: 0 0 0 3px rgba(39, 174, 96, 0.15);
}

.pw-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--pw-text);
    font-size: 0.88rem;
    outline: none;
    padding: 6px 0;
}

.pw-input::placeholder {
    color: var(--pw-text-muted);
}

/* Botão de Microfone (Speech-to-Text) */
.pw-mic-btn {
    background: transparent;
    border: none;
    color: var(--pw-text-muted);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.pw-mic-btn:hover {
    color: var(--pw-primary);
    background: rgba(39, 174, 96, 0.1);
}

.pw-mic-btn.is-recording {
    color: #ffffff;
    background: #e74c3c !important;
    animation: pw-mic-pulse 1.2s infinite;
}

@keyframes pw-mic-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.6); }
    50% { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(231, 76, 60, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

/* Botão Enviar */
.pw-send-btn {
    background: var(--pw-primary);
    border: none;
    color: #ffffff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.85rem;
    transition: transform 0.2s, background-color 0.2s;
}

.pw-send-btn:hover {
    background: var(--pw-primary-dark);
    transform: scale(1.05);
}

.pw-send-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    transform: none;
}

/* Loading indicador da IA */
.pw-typing {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    align-items: center;
}

.pw-typing-dot {
    width: 6px;
    height: 6px;
    background: var(--pw-primary);
    border-radius: 50%;
    animation: pw-blink 1.4s infinite both;
}

.pw-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.pw-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes pw-blink {
    0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1.1); }
}

/* Ajuste Responsivo para Dispositivos Móveis */
@media (max-width: 576px) {
    #pitrulino-fab-container {
        bottom: 16px;
        right: 16px;
    }
    #pitrulino-fab-btn {
        width: 56px;
        height: 56px;
    }
    #pitrulino-fab-btn img {
        width: 38px;
        height: 38px;
    }
    .pitrulino-fab-tooltip {
        display: none !important;
    }
    #pitrulino-widget-drawer {
        bottom: 80px;
        right: 12px;
        left: 12px;
        width: auto;
        height: calc(100vh - 100px);
        max-height: 540px;
    }
}
