/* ============================================
   Chat Widget - Assistente IA AssemblPro
   Usa as variáveis do tema definidas em style.css
   ============================================ */

.ia-chat-widget {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    z-index: 9998;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ---- Botão flutuante ---- */
.ia-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--gradient-green);
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.ia-chat-toggle:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 12px 20px -4px rgba(0, 212, 170, 0.4);
}

.ia-chat-toggle.has-unread::after {
    content: "";
    position: absolute;
    top: 4px;
    right: 4px;
    width: 12px;
    height: 12px;
    background: var(--accent-red);
    border-radius: 50%;
    border: 2px solid var(--bg-primary);
}

/* ---- Painel ---- */
.ia-chat-panel {
    position: absolute;
    right: 0;
    bottom: 72px;
    width: 360px;
    height: 520px;
    max-height: calc(100vh - 100px);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: iaChatFadeIn 0.2s ease;
}

.ia-chat-panel[hidden] { display: none; }

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

/* ---- Header ---- */
.ia-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.ia-chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}

.ia-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gradient-green);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
}

.ia-chat-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.1;
}

.ia-chat-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.ia-chat-subtitle.online { color: var(--accent-green); }
.ia-chat-subtitle.offline { color: var(--accent-red); }

.ia-chat-header-actions {
    display: flex;
    gap: 0.25rem;
}

.ia-chat-icon-btn {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.ia-chat-icon-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

/* ---- Mensagens ---- */
.ia-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    background: var(--bg-primary);
}

.ia-chat-messages::-webkit-scrollbar { width: 6px; }
.ia-chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.ia-msg {
    max-width: 80%;
    padding: 0.55rem 0.75rem;
    border-radius: 12px;
    font-size: 0.88rem;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.ia-msg-user {
    align-self: flex-end;
    background: var(--gradient-green);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ia-msg-assistant {
    align-self: flex-start;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.ia-msg-system {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-align: center;
    max-width: 100%;
    padding: 0.4rem 0.6rem;
    font-style: italic;
}

.ia-msg-error {
    align-self: flex-start;
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-red);
    border: 1px solid var(--accent-red);
    border-radius: 8px;
    font-size: 0.85rem;
}

.ia-msg-error .ia-retry-btn {
    margin-top: 0.4rem;
    background: var(--accent-red);
    color: #fff;
    border: none;
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
}

.ia-tools-badge {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.68rem;
    color: var(--text-muted);
    font-style: italic;
}

.ia-tools-badge i { margin-right: 0.2rem; }

/* ---- Indicador "digitando" ---- */
.ia-chat-typing {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.4rem 1rem;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.75rem;
}

.ia-chat-typing[hidden] { display: none; }

.ia-chat-typing span {
    width: 6px;
    height: 6px;
    background: var(--accent-green);
    border-radius: 50%;
    animation: iaChatBlink 1.2s infinite ease-in-out;
}
.ia-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.ia-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
.ia-chat-typing em {
    margin-left: 0.35rem;
    font-style: italic;
}

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

/* ---- Form ---- */
.ia-chat-form {
    display: flex;
    gap: 0.4rem;
    padding: 0.65rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.ia-chat-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 0.55rem 0.75rem;
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.15s;
}

.ia-chat-input:focus {
    border-color: var(--accent-green);
}

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

.ia-chat-send {
    width: 40px;
    background: var(--accent-green);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ia-chat-send:hover:not(:disabled) {
    background: var(--accent-green-hover);
}

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

/* ---- Link no erro de config ---- */
.ia-msg-assistant a {
    color: var(--accent-green);
    text-decoration: underline;
}

/* ---- Responsivo ---- */
@media (max-width: 600px) {
    .ia-chat-widget {
        right: 1rem;
        bottom: 1rem;
    }
    .ia-chat-panel {
        width: calc(100vw - 2rem);
        height: 70vh;
        right: 0;
        bottom: 68px;
    }
}
