/* =============================================
   Chat IA Widget - PixJB Brasil
   ============================================= */

/* --- Toggle Button --- */
.chat-widget-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00c853, #00897b);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 200, 83, 0.4);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.chat-widget-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 200, 83, 0.5);
}

.chat-widget-toggle svg {
    width: 28px;
    height: 28px;
    fill: #fff;
}

.chat-widget-toggle .chat-close-icon {
    display: none;
}

.chat-widget-toggle.active .chat-open-icon {
    display: none;
}

.chat-widget-toggle.active .chat-close-icon {
    display: block;
}

/* --- Notification Badge --- */
.chat-widget-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #f44336;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid #1a1a2e;
}

.chat-widget-badge.visible {
    display: flex;
}

/* --- Chat Window --- */
.chat-widget-window {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 370px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #1a1a2e;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    z-index: 99998;
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
    animation: chatSlideUp 0.3s ease;
}

.chat-widget-window.open {
    display: flex;
}

@keyframes chatSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Header --- */
.chat-widget-header {
    background: linear-gradient(135deg, #00c853, #00897b);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chat-widget-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-widget-header-avatar svg {
    width: 22px;
    height: 22px;
    fill: #fff;
}

.chat-widget-header-info {
    flex: 1;
}

.chat-widget-header-title {
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.chat-widget-header-subtitle {
    color: rgba(255, 255, 255, 0.75);
    font-size: 12px;
    margin: 0;
}

.chat-widget-header-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    transition: background 0.2s;
}

.chat-widget-header-close:hover {
    background: rgba(255, 255, 255, 0.15);
}

.chat-widget-header-close svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}

/* --- Messages Container --- */
.chat-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.chat-widget-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-widget-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-widget-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

/* --- Message Bubbles --- */
.chat-msg {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: chatMsgIn 0.25s ease;
}

@keyframes chatMsgIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-msg.assistant .chat-msg-bubble {
    background: #262640;
    color: #e0e0e0;
    border-bottom-left-radius: 4px;
}

.chat-msg.user .chat-msg-bubble {
    background: linear-gradient(135deg, #00c853, #00897b);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg-time {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.35);
    margin-top: 4px;
    align-self: flex-end;
    flex-shrink: 0;
}

/* --- Typing Indicator --- */
.chat-typing {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 0 16px 8px;
}

.chat-typing.visible {
    display: flex;
}

.chat-typing-dots {
    display: flex;
    gap: 4px;
}

.chat-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    animation: chatTypingBounce 1.4s infinite ease-in-out;
}

.chat-typing-dots span:nth-child(2) {
    animation-delay: 0.16s;
}

.chat-typing-dots span:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes chatTypingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.3;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.chat-typing-text {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
}

/* --- Input Area --- */
.chat-widget-input {
    padding: 12px 16px;
    background: #141428;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
}

.chat-widget-input textarea {
    flex: 1;
    background: #1e1e38;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 10px 14px;
    color: #e0e0e0;
    font-size: 13.5px;
    resize: none;
    max-height: 80px;
    min-height: 40px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.chat-widget-input textarea:focus {
    border-color: #00c853;
}

.chat-widget-input textarea::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.chat-widget-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00c853, #00897b);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s, opacity 0.2s;
}

.chat-widget-send:hover {
    transform: scale(1.08);
}

.chat-widget-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.chat-widget-send svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* --- Powered By --- */
.chat-widget-powered {
    text-align: center;
    padding: 6px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.2);
    background: #141428;
}

/* --- Mic Button (Speech-to-Text) --- */
.chat-widget-mic {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #1e1e38;
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.chat-widget-mic svg {
    width: 20px;
    height: 20px;
    fill: rgba(255, 255, 255, 0.5);
    transition: fill 0.3s;
}

.chat-widget-mic:hover {
    background: #262640;
    border-color: rgba(255, 255, 255, 0.2);
}

.chat-widget-mic:hover svg {
    fill: rgba(255, 255, 255, 0.8);
}

.chat-widget-mic.recording {
    background: rgba(244, 67, 54, 0.15);
    border-color: #f44336;
    animation: micPulse 1.2s ease-in-out infinite;
}

.chat-widget-mic.recording svg {
    fill: #f44336;
}

@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.3); }
    50% { box-shadow: 0 0 0 8px rgba(244, 67, 54, 0); }
}

/* --- Audio Button on Messages (Text-to-Speech) --- */
.chat-msg-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 100%;
}

.chat-msg-audio-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: rgba(255, 255, 255, 0.35);
    font-size: 10px;
    transition: all 0.2s;
    align-self: flex-start;
}

.chat-msg-audio-btn svg {
    fill: rgba(255, 255, 255, 0.35);
    transition: fill 0.2s;
}

.chat-msg-audio-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.7);
}

.chat-msg-audio-btn:hover svg {
    fill: rgba(255, 255, 255, 0.7);
}

.chat-msg-audio-btn.speaking {
    background: rgba(0, 200, 83, 0.12);
    color: #00c853;
}

.chat-msg-audio-btn.speaking svg {
    fill: #00c853;
    animation: speakingPulse 1s ease-in-out infinite;
}

@keyframes speakingPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* --- Responsive --- */
@media (max-width: 480px) {
    .chat-widget-window {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
    }

    .chat-widget-toggle {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }
}

/* --- Markdown in messages --- */
.chat-msg-bubble strong,
.chat-msg-bubble b {
    font-weight: 700;
    color: #fff;
}

.chat-msg-bubble em,
.chat-msg-bubble i {
    font-style: italic;
}

.chat-msg-bubble code {
    background: rgba(255, 255, 255, 0.08);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
}

.chat-msg-bubble ul,
.chat-msg-bubble ol {
    margin: 4px 0;
    padding-left: 18px;
}

.chat-msg-bubble li {
    margin-bottom: 2px;
}
