/* =========================
   HUMANIZED CHAT RAG - Frontend Styles
   ========================= */

:root {
    --hcrag-primary: #0066cc;
    --hcrag-primary-dark: #0052a3;
    --hcrag-text: #333333;
    --hcrag-bg: #ffffff;
    --hcrag-user-bg: #0066cc;
    --hcrag-user-text: #ffffff;
    --hcrag-bot-bg: #f0f2f5;
    --hcrag-bot-text: #333333;
    --hcrag-border: #e0e0e0;
    --hcrag-shadow: rgba(0, 0, 0, 0.1);
}

/* Chat Container */
.hcrag-chat-container {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Posições */
.hcrag-chat-container.position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.hcrag-chat-container.position-bottom-left {
    bottom: 20px;
    left: 20px;
}

.hcrag-chat-container.position-top-right {
    top: 20px;
    right: 20px;
}

.hcrag-chat-container.position-top-left {
    top: 20px;
    left: 20px;
}

/* Chat Bubble (Botão flutuante) */
.hcrag-chat-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--hcrag-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--hcrag-shadow);
    transition: all 0.3s ease;
    touch-action: manipulation;
}

.hcrag-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px var(--hcrag-shadow);
}

.hcrag-chat-bubble svg {
    width: 28px;
    height: 28px;
}

.hcrag-chat-bubble.active {
    transform: rotate(180deg);
}

/* Badge de notificação */
.hcrag-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    animation: hcrag-pulse 2s infinite;
}

@keyframes hcrag-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* Chat Window */
.hcrag-chat-window {
    position: absolute;
    bottom: 80px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--hcrag-bg);
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: hcrag-slideUp 0.3s ease;
}

.hcrag-chat-window.active {
    display: flex;
}

@keyframes hcrag-slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Posicionamento da janela */
.position-bottom-right .hcrag-chat-window,
.position-bottom-left .hcrag-chat-window {
    bottom: 80px;
}

.position-top-right .hcrag-chat-window,
.position-top-left .hcrag-chat-window {
    top: 80px;
}

.position-bottom-right .hcrag-chat-window,
.position-top-right .hcrag-chat-window {
    right: 0;
}

.position-bottom-left .hcrag-chat-window,
.position-top-left .hcrag-chat-window {
    left: 0;
}

/* Header */
.hcrag-chat-header {
    background: var(--hcrag-primary);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.hcrag-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hcrag-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.hcrag-chat-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.hcrag-chat-title {
    display: flex;
    flex-direction: column;
}

.hcrag-chat-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.hcrag-chat-title span {
    font-size: 12px;
    opacity: 0.9;
}

.hcrag-chat-close {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.hcrag-chat-close:hover {
    opacity: 1;
}

.hcrag-chat-close svg {
    width: 20px;
    height: 20px;
}

/* Messages Area */
.hcrag-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

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

.hcrag-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.hcrag-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

/* Feedback */
.hcrag-feedback {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px;
    margin: 8px 20px 0 60px;
}
.hcrag-feedback-title {
    font-size: 13px;
    color: #374151;
    margin-bottom: 6px;
}
.hcrag-stars span {
    font-size: 18px;
    cursor: pointer;
    color: #cbd5e0;
    margin-right: 4px;
}
.hcrag-stars span.active {
    color: #fbbf24;
}
.hcrag-feedback-comment textarea {
    width: 100%;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 8px;
    resize: vertical;
}
.hcrag-feedback-comment .hcrag-feedback-send {
    margin-top: 8px;
    background: var(--hcrag-primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
}
.hcrag-feedback-thanks {
    color: #4b5563;
}
/* Message */
.hcrag-message {
    display: flex;
    gap: 10px;
    animation: hcrag-fadeIn 0.3s ease;
}

@keyframes hcrag-fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hcrag-message.user {
    justify-content: flex-end;
}

.hcrag-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--hcrag-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.hcrag-message-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.hcrag-message.user .hcrag-message-avatar {
    background: #4a5568;
    order: 2;
}

.hcrag-message-content {
    max-width: 70%;
}

.hcrag-message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
}

.hcrag-message.bot .hcrag-message-bubble {
    background: var(--hcrag-bot-bg);
    color: var(--hcrag-bot-text);
    border-bottom-left-radius: 4px;
}

.hcrag-message.user .hcrag-message-bubble {
    background: var(--hcrag-user-bg);
    color: var(--hcrag-user-text);
    border-bottom-right-radius: 4px;
}

.hcrag-message-time {
    font-size: 11px;
    color: #718096;
    margin-top: 4px;
    padding: 0 4px;
}

/* Typing indicator */
.hcrag-typing-indicator {
    display: none;
    gap: 10px;
}

.hcrag-typing-indicator.active {
    display: flex;
}

.hcrag-typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--hcrag-bot-bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.hcrag-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #a0aec0;
    animation: hcrag-typing 1.4s infinite;
}

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

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

@keyframes hcrag-typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Input Area */
.hcrag-chat-input-area {
    padding: 16px 20px;
    background: var(--hcrag-bg);
    border-top: 1px solid var(--hcrag-border);
}

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

.hcrag-chat-input {
    flex: 1;
    border: 1px solid var(--hcrag-border);
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 15px;
    resize: none;
    max-height: 100px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.hcrag-chat-input:focus {
    outline: none;
    border-color: var(--hcrag-primary);
}

.hcrag-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--hcrag-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    touch-action: manipulation;
}

.hcrag-chat-send:hover:not(:disabled) {
    background: var(--hcrag-primary-dark);
    transform: scale(1.05);
}

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

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

/* Welcome Message */
.hcrag-welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: #718096;
}

.hcrag-welcome-message h4 {
    margin: 0 0 8px 0;
    color: var(--hcrag-text);
    font-size: 18px;
}

.hcrag-welcome-message p {
    margin: 0;
    font-size: 14px;
}

/* Quick Actions */
.hcrag-quick-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.hcrag-quick-action {
    background: white;
    border: 1px solid var(--hcrag-border);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    touch-action: manipulation;
}

.hcrag-quick-action:hover {
    border-color: var(--hcrag-primary);
    background: #f7fafc;
}

/* Powered by */
.hcrag-powered-by {
    text-align: center;
    padding: 8px;
    font-size: 11px;
    color: #a0aec0;
    background: #f9fafb;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    /* Evitar que o container ocupe a tela inteira e bloqueie cliques */
    .hcrag-chat-container {
        pointer-events: none;
    }

    /* Botão flutuante deve continuar clicável no mobile */
    .hcrag-chat-bubble {
        bottom: 20px;
        right: 20px;
        position: fixed;
        pointer-events: auto;
    }

    /* Janela de chat em tela cheia no mobile, sem bloquear fora quando fechada */
    .hcrag-chat-window {
        position: fixed;
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        bottom: 0 !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        pointer-events: auto;
    }

    .hcrag-chat-input {
        font-size: 16px;
    }

    .hcrag-chat-input-area {
        padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
    }

    .hcrag-powered-by {
        padding-bottom: calc(env(safe-area-inset-bottom));
    }
}

/* Error state */
.hcrag-error-message {
    background: #fee;
    border: 1px solid #fcc;
    color: #c33;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    margin: 10px 0;
}
.hcrag-callout {
    position: absolute;
    max-width: 260px;
    background: #ffffff;
    color: var(--hcrag-text);
    border: 1px solid var(--hcrag-border);
    border-radius: 12px;
    padding: 10px 12px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.12);
    font-size: 13px;
    line-height: 1.5;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}
.hcrag-callout.active { opacity: 1; transform: translateY(0); }
.hcrag-callout.tail-right::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 22px;
    width: 0; height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #ffffff;
    filter: drop-shadow(0 1px 0 rgba(0,0,0,0.08));
}
.hcrag-callout.tail-left::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 22px;
    width: 0; height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #ffffff;
    filter: drop-shadow(0 1px 0 rgba(0,0,0,0.08));
}
