/**
 * support-chat.css
 * Assistente Virtual Inteligente do AppBox Pro (Lumi)
 * Inspirado no modelo de alta conversão "Posso ajudar?"
 */

/* ==========================================================================
   1. Entrada e Botão Flutuante (Canto Inferior Direito)
   ========================================================================== */
.support-entry {
    position: fixed;
    z-index: 100001;
    right: max(24px, env(safe-area-inset-right));
    bottom: max(24px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    user-select: none;
    -webkit-user-select: none;
}

/* Balãozinho de Dica ("👋 Tem alguma dúvida? Fale comigo!") */
.support-hint {
    position: relative;
    padding: 11px 16px;
    background: #ffffff;
    color: #2b2e42;
    font-weight: 700;
    font-size: 12px;
    border: 1px solid #efecf8;
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 12px 32px rgba(29, 21, 93, 0.16), 0 4px 12px rgba(0, 0, 0, 0.08);
    animation: supportHintAppear 0.5s 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.support-hint span {
    font-size: 14px;
}

.support-hint[hidden] {
    display: none !important;
}

@keyframes supportHintAppear {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Botão Launcher ("Posso ajudar?") */
.support-launcher {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 7px 20px 7px 7px;
    background: linear-gradient(135deg, #6956ec 0%, #5543d6 100%);
    border: 1px solid #7f6ff8;
    border-radius: 999px;
    color: #ffffff;
    box-shadow: 0 14px 36px rgba(83, 68, 209, 0.42), 0 4px 14px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    outline: none;
    transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), 
                box-shadow 0.22s ease, 
                background 0.22s ease;
    -webkit-tap-highlight-color: transparent;
}

.support-launcher:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 18px 44px rgba(83, 68, 209, 0.52), 0 6px 18px rgba(0, 0, 0, 0.18);
}

.support-launcher:active {
    transform: translateY(0) scale(0.98);
}

.support-launcher .launcher-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.support-launcher .launcher-icon svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    display: block;
}

.support-launcher strong {
    font-size: 13.5px;
    font-weight: 750;
    letter-spacing: -0.01em;
    color: #ffffff;
    white-space: nowrap;
}

/* Bolinha de status online (ping pulsante verde) */
.support-launcher .ping {
    position: relative;
    width: 9px;
    height: 9px;
    background: #9cf5b9;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(156, 245, 185, 0.25);
    flex-shrink: 0;
}

.support-launcher .ping::after {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 1.5px solid #9cf5b9;
    animation: supportPingAnim 1.8s infinite ease-out;
}

@keyframes supportPingAnim {
    0% { transform: scale(0.9); opacity: 0.9; }
    70% { transform: scale(2.2); opacity: 0; }
    100% { transform: scale(2.2); opacity: 0; }
}

/* Estado Aberto do Launcher */
.support-launcher[data-open="true"] {
    padding: 8px;
    border-radius: 50%;
    background: #4736bf;
}

.support-launcher[data-open="true"] .launcher-icon {
    width: 42px;
    height: 42px;
}

.support-launcher[data-open="true"] strong,
.support-launcher[data-open="true"] .ping {
    display: none;
}

/* ==========================================================================
   2. Painel Modal do Chat (Support Panel)
   ========================================================================== */
.support-panel {
    position: fixed;
    z-index: 100000;
    right: max(24px, env(safe-area-inset-right));
    bottom: calc(max(24px, env(safe-area-inset-bottom)) + 76px);
    width: min(418px, calc(100vw - 32px));
    height: min(650px, calc(100dvh - 110px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 24px;
    background: #ffffff;
    border: 1px solid #efecfa;
    box-shadow: 0 25px 90px rgba(34, 25, 105, 0.24), 0 8px 26px rgba(0, 0, 0, 0.12);
    transform-origin: bottom right;
    animation: supportPanelIn 0.26s cubic-bezier(0.16, 1, 0.3, 1) both;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.support-panel[hidden] {
    display: none !important;
}

@keyframes supportPanelIn {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Cabeçalho do Chat */
.support-head {
    flex: 0 0 auto;
    position: relative;
    overflow: hidden;
    padding: 20px 20px 16px;
    color: #ffffff;
    background: linear-gradient(120deg, #7464f2 0%, #5547d0 100%);
}

.support-head::before {
    content: "";
    position: absolute;
    width: 240px;
    height: 240px;
    right: -130px;
    top: -180px;
    border: 34px solid rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    pointer-events: none;
}

.support-head::after {
    content: "";
    position: absolute;
    width: 90px;
    height: 90px;
    right: 70px;
    bottom: -80px;
    border: 20px solid rgba(255, 255, 255, 0.06);
    border-radius: 50%;
    pointer-events: none;
}

.head-row {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    z-index: 1;
}

.assistant-avatar {
    position: relative;
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    border: 1.5px solid rgba(255, 255, 255, 0.28);
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.2);
    display: grid;
    place-items: center;
    color: #ffffff;
}

.assistant-avatar .sparkle {
    width: 24px;
    height: 24px;
}

.assistant-avatar::after {
    content: "";
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    border: 2.5px solid #6253de;
    border-radius: 50%;
    background: #9cf5b9;
}

.assistant-details {
    flex: 1;
    min-width: 0;
}

.assistant-details strong {
    font-size: 15.5px;
    letter-spacing: -0.02em;
    color: #ffffff;
    display: block;
    line-height: 1.25;
}

.assistant-details .assistant-badge {
    font-size: 11px;
    font-weight: 600;
    opacity: 0.9;
    letter-spacing: 0;
    margin-left: 2px;
}

.assistant-details p {
    font-size: 11px;
    opacity: 0.88;
    margin: 4px 0 0;
    display: flex;
    align-items: center;
    gap: 6px;
    color: #e9e6ff;
}

.assistant-details p::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #b8ffce;
    flex-shrink: 0;
}

.head-buttons {
    display: flex;
    gap: 4px;
    position: relative;
    z-index: 1;
}

.head-icon-btn {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    background: transparent;
    color: #ffffff;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.18s ease;
    outline: none;
}

.head-icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.head-icon-btn:active {
    transform: scale(0.92);
}

.head-caption {
    position: relative;
    z-index: 1;
    margin: 14px 0 0;
    font-size: 12px;
    color: #eeeaff;
    line-height: 1.5;
}

/* ==========================================================================
   3. Corpo do Chat e Rolagem de Mensagens
   ========================================================================== */
.chat-main {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #fafafe;
}

.chat-scroller {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 20px 16px 12px;
    scrollbar-width: thin;
    scrollbar-color: #d8d8eb transparent;
}

.chat-scroller::-webkit-scrollbar {
    width: 5px;
}

.chat-scroller::-webkit-scrollbar-thumb {
    background: #d8d8eb;
    border-radius: 10px;
}

.chat-date {
    margin: 0 0 18px;
    text-align: center;
    font-size: 10px;
    color: #a4a5b6;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* Mensagens */
.message {
    display: flex;
    align-items: flex-end;
    gap: 9px;
    margin-bottom: 16px;
    animation: messageInAnim 0.24s ease both;
}

.message.mine {
    justify-content: flex-end;
}

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

.message-avatar {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: #e9e6ff;
    color: #7463e9;
}

.message-content {
    max-width: 86%;
    min-width: 0;
}

.message-bubble {
    background: #ffffff;
    padding: 12px 15px;
    font-size: 12.8px;
    line-height: 1.62;
    color: #3f4358;
    box-shadow: 0 2px 10px rgba(36, 37, 71, 0.05);
    border: 1px solid #f0eff7;
    border-radius: 16px 16px 16px 4px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.message-bubble strong {
    color: #1a1c2e;
    font-weight: 700;
}

.mine .message-bubble {
    background: #6956ec;
    border-color: #6956ec;
    color: #ffffff;
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 6px 18px rgba(105, 86, 236, 0.22);
}

.mine .message-bubble strong {
    color: #ffffff;
}

.message-time {
    font-size: 9.5px;
    color: #a8aab8;
    margin: 5px 3px 0;
}

.mine .message-time {
    text-align: right;
}

/* Indicador de Digitação (Typing Dots) */
.typing .message-bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    height: 38px;
    padding: 0 14px;
}

.typing .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9f96da;
    animation: typingBounceAnim 1.2s infinite ease-in-out;
}

.typing .dot:nth-child(2) { animation-delay: 0.16s; }
.typing .dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes typingBounceAnim {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* ==========================================================================
   4. Sugestões de Perguntas (Chips Interativos)
   ========================================================================== */
.topic-title {
    padding: 4px 0 10px;
    font-size: 10px;
    color: #9da0b2;
    font-weight: 800;
    letter-spacing: 0.7px;
    text-transform: uppercase;
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-bottom: 16px;
}

.suggestion {
    max-width: 100%;
    background: #ffffff;
    border: 1px solid #e5e1f8;
    border-radius: 12px;
    color: #6353d6;
    font-size: 11.5px;
    line-height: 1.35;
    font-weight: 650;
    text-align: left;
    padding: 9px 12px;
    cursor: pointer;
    transition: background 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.suggestion:hover {
    background: #f0edff;
    border-color: #cfc6ff;
    transform: translateY(-1px);
}

.suggestion:active {
    transform: translateY(0);
}

/* ==========================================================================
   5. Área de Digitação (Composer)
   ========================================================================== */
.composer-area {
    flex: 0 0 auto;
    background: #ffffff;
    padding: 10px 14px 12px;
    border-top: 1px solid #f0eff5;
}

.composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f7f7fb;
    border: 1px solid #eae9f1;
    border-radius: 16px;
    padding: 6px 6px 6px 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.composer:focus-within {
    border-color: #b7a9ff;
    box-shadow: 0 0 0 3px #f1efff;
}

.composer textarea {
    flex: 1;
    resize: none;
    min-height: 33px;
    max-height: 96px;
    border: none;
    outline: none;
    padding: 7px 0 5px;
    background: transparent;
    color: #2b2e42;
    font-family: inherit;
    font-size: 12.5px;
    line-height: 20px;
    overflow-y: auto;
}

.composer textarea::placeholder {
    color: #a4a6b8;
}

.send-btn {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    border: none;
    color: #ffffff;
    background: #6956ec;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
    outline: none;
}

.send-btn:hover:not(:disabled) {
    background: #5543d6;
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.chat-footnote {
    text-align: center;
    padding-top: 9px;
    font-size: 10px;
    color: #a2a4b4;
}

.chat-footnote .diamond {
    color: #8a7af5;
}

/* ==========================================================================
   6. Toast de Notificação
   ========================================================================== */
.toast {
    position: fixed;
    z-index: 100001;
    bottom: 110px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 18px;
    background: #25263a;
    color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.25);
    font-size: 12px;
    font-weight: 600;
    animation: toastAppear 0.25s both;
    pointer-events: none;
    white-space: nowrap;
}

.toast[hidden] {
    display: none !important;
}

@keyframes toastAppear {
    from {
        opacity: 0;
        transform: translate(-50%, 8px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

/* ==========================================================================
   7. Responsividade Mobile
   ========================================================================== */
@media (max-width: 768px) {
    .support-entry {
        right: max(14px, env(safe-area-inset-right));
        bottom: calc(max(14px, env(safe-area-inset-bottom)) + 64px); /* Acima da barra sticky do mobile */
    }

    .support-launcher {
        padding-right: 15px;
        gap: 9px;
    }

    .support-launcher .launcher-icon {
        width: 42px;
        height: 42px;
    }

    .support-launcher strong {
        font-size: 12.5px;
    }

    .support-hint {
        font-size: 11px;
        padding: 9px 13px;
    }

    .support-panel {
        right: 10px;
        left: 10px;
        width: auto;
        bottom: calc(max(12px, env(safe-area-inset-bottom)) + 64px);
        height: min(650px, calc(100dvh - 90px));
        border-radius: 20px;
    }

    .message-content {
        max-width: 90%;
    }
}

@media (max-height: 650px) and (min-width: 501px) {
    .support-panel {
        height: calc(100dvh - 110px);
    }
    .support-head {
        padding-top: 14px;
        padding-bottom: 12px;
    }
    .head-caption {
        margin-top: 8px;
    }
}

/* Respeito a prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .support-hint,
    .support-panel,
    .message,
    .support-launcher .ping::after,
    .typing .dot {
        animation: none !important;
        transition: none !important;
    }
}
