/* ============================================
   Zyko - Chat Widget Styles
   Segue design system do site (variaveis CSS)
   ============================================ */

/* Botao flutuante */
.qrc-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-light, #4361ee);
    color: var(--white, #fff);
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-lg, 0 10px 15px -3px rgba(0,0,0,0.1));
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
}

.qrc-chat-btn:hover {
    transform: scale(1.08);
    background: var(--primary, #2d3a8c);
}

.qrc-chat-btn svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

.qrc-chat-btn .qrc-close-icon {
    display: none;
}

.qrc-chat-btn.active .qrc-chat-icon {
    display: none;
}

.qrc-chat-btn.active .qrc-close-icon {
    display: block;
}

/* Painel do chat */
.qrc-chat-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 380px;
    max-height: 520px;
    background: var(--white, #fff);
    border-radius: var(--radius-lg, 16px);
    box-shadow: var(--shadow-xl, 0 25px 50px -12px rgba(0,0,0,0.25));
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.08);
    transition: width 0.3s ease, max-height 0.3s ease, bottom 0.3s ease;
}

.qrc-chat-panel.open {
    display: flex;
    animation: qrc-slide-up 0.25s ease-out;
}

@keyframes qrc-slide-up {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.qrc-chat-header {
    background: var(--primary, #2d3a8c);
    color: var(--white, #fff);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.qrc-chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.qrc-chat-header-avatar svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.qrc-chat-header-info {
    flex: 1;
}

.qrc-chat-header-title {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.qrc-chat-header-subtitle {
    font-size: 11px;
    opacity: 0.8;
    margin: 0;
}

/* Botao expandir/recolher */
.qrc-expand-btn {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: var(--white, #fff);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
    padding: 0;
}

.qrc-expand-btn:hover {
    background: rgba(255,255,255,0.3);
}

.qrc-expand-btn .qrc-collapse-icon {
    display: none;
}

.qrc-chat-panel.expanded .qrc-expand-btn .qrc-expand-icon {
    display: none;
}

.qrc-chat-panel.expanded .qrc-expand-btn .qrc-collapse-icon {
    display: block;
}

/* Botao nova conversa */
.qrc-new-chat-btn {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: var(--white, #fff);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
    padding: 0;
}

.qrc-new-chat-btn:hover {
    background: rgba(255,255,255,0.3);
}

/* Toggle cliente */
.qrc-client-toggle {
    padding: 8px 16px;
    background: var(--light, #f1f5f9);
    border-bottom: 1px solid rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.qrc-client-toggle label {
    font-size: 12px;
    color: var(--gray, #64748b);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
}

.qrc-client-toggle input[type="checkbox"] {
    accent-color: var(--primary-light, #4361ee);
}

/* Campo API Key */
.qrc-apikey-field {
    padding: 0 16px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s, padding 0.2s;
    background: var(--light, #f1f5f9);
}

.qrc-apikey-field.show {
    max-height: 60px;
    padding: 0 16px 8px;
}

.qrc-apikey-field input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: var(--radius, 8px);
    font-size: 12px;
    font-family: monospace;
    background: var(--white, #fff);
    outline: none;
}

.qrc-apikey-field input:focus {
    border-color: var(--primary-light, #4361ee);
}

/* Area de mensagens */
.qrc-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 200px;
    max-height: 300px;
}

/* Mensagem */
.qrc-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
}

.qrc-msg-user {
    align-self: flex-end;
    background: var(--primary-light, #4361ee);
    color: var(--white, #fff);
    border-bottom-right-radius: 4px;
}

.qrc-msg-bot {
    align-self: flex-start;
    background: var(--light, #f1f5f9);
    color: var(--dark, #0f172a);
    border-bottom-left-radius: 4px;
}

.qrc-msg-bot p {
    color: inherit;
    margin: 0 0 8px 0;
}

.qrc-msg-bot p:last-child {
    margin-bottom: 0;
}

.qrc-msg-bot strong {
    font-weight: 600;
}

.qrc-msg-bot code {
    background: rgba(0,0,0,0.06);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 12px;
    font-family: monospace;
}

.qrc-msg-bot pre {
    background: var(--dark, #0f172a);
    color: var(--light, #f1f5f9);
    padding: 8px 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 6px 0;
    font-size: 12px;
}

.qrc-msg-bot pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.qrc-msg-bot ul, .qrc-msg-bot ol {
    padding-left: 18px;
    margin: 4px 0;
}

.qrc-msg-bot li {
    margin: 2px 0;
}

.qrc-msg-error {
    align-self: center;
    background: #fef2f2;
    color: var(--danger, #ef4444);
    font-size: 12px;
    text-align: center;
    border-radius: 8px;
}

/* Indicador de digitacao */
.qrc-typing {
    display: none;
    align-self: flex-start;
    padding: 10px 14px;
    background: var(--light, #f1f5f9);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

.qrc-typing.show {
    display: flex;
    gap: 4px;
    align-items: center;
}

.qrc-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--gray-light, #94a3b8);
    animation: qrc-bounce 1.2s infinite;
}

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

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

@keyframes qrc-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Input area */
.qrc-chat-input {
    padding: 12px 16px;
    border-top: 1px solid rgba(0,0,0,0.08);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: var(--white, #fff);
}

.qrc-chat-input textarea {
    flex: 1;
    resize: none;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: var(--radius, 8px);
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    line-height: 1.4;
    max-height: 80px;
    outline: none;
    background: var(--light, #f1f5f9);
}

.qrc-chat-input textarea:focus {
    border-color: var(--primary-light, #4361ee);
    background: var(--white, #fff);
}

.qrc-chat-input button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-light, #4361ee);
    color: var(--white, #fff);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.qrc-chat-input button:hover {
    background: var(--primary, #2d3a8c);
}

.qrc-chat-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.qrc-chat-input button svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Powered by */
.qrc-chat-footer {
    text-align: center;
    padding: 4px 0 8px;
    font-size: 10px;
    color: var(--gray-light, #94a3b8);
    flex-shrink: 0;
}

/* Modo expandido (para programadores / codigo) */
.qrc-chat-panel.expanded {
    width: 700px;
    max-height: 80vh;
    bottom: 24px;
    transition: width 0.3s ease, max-height 0.3s ease;
}

.qrc-chat-panel.expanded .qrc-chat-messages {
    max-height: none;
    min-height: 400px;
    flex: 1;
}

.qrc-chat-panel.expanded .qrc-msg {
    max-width: 90%;
    font-size: 14px;
}

.qrc-chat-panel.expanded .qrc-msg-bot pre {
    font-size: 13px;
    max-height: 400px;
    overflow-y: auto;
}

.qrc-chat-panel.expanded .qrc-chat-input textarea {
    font-size: 14px;
    max-height: 120px;
}

/* Responsivo mobile */
@media (max-width: 480px) {
    .qrc-chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: var(--radius-lg, 16px) var(--radius-lg, 16px) 0 0;
    }

    .qrc-chat-panel.expanded {
        width: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        bottom: 0;
        border-radius: 0;
    }

    .qrc-chat-messages {
        max-height: calc(100vh - 260px);
        max-height: calc(100dvh - 260px);
    }

    .qrc-chat-panel.expanded .qrc-chat-messages {
        max-height: calc(100vh - 220px);
        max-height: calc(100dvh - 220px);
    }

    .qrc-chat-btn {
        bottom: 16px;
        right: 16px;
    }
}

/* RTL support (Hebrew) */
[dir="rtl"] .qrc-chat-btn {
    right: auto;
    left: 24px;
}

[dir="rtl"] .qrc-chat-panel {
    right: auto;
    left: 24px;
}

[dir="rtl"] .qrc-msg-user {
    border-bottom-right-radius: 12px;
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .qrc-msg-bot {
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 4px;
}

@media (max-width: 480px) {
    [dir="rtl"] .qrc-chat-panel {
        left: 0;
    }

    [dir="rtl"] .qrc-chat-btn {
        left: 16px;
    }
}
