/* Chatbot do site: painel ancorado junto da bolha, sem bloquear a pagina. */

.ae-chat-launcher {
    position: fixed;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    z-index: 1030; /* abaixo do backdrop (1040) e da modal (1050) do Bootstrap */
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, var(--ae-accent, #3498db), var(--ae-primary, #2c3e50));
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.ae-chat-launcher:hover,
.ae-chat-launcher:focus-visible {
    transform: scale(1.06);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.34);
    outline: none;
}

.ae-chat-launcher:focus-visible {
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--ae-accent, #3498db);
}

.ae-chat-panel {
    position: fixed;
    right: 20px;
    bottom: calc(90px + env(safe-area-inset-bottom, 0px));
    z-index: 1031;
    width: min(440px, calc(100vw - 40px));
    height: min(600px, calc(100vh - 110px - env(safe-area-inset-bottom, 0px)));
    height: min(600px, calc(100dvh - 110px - env(safe-area-inset-bottom, 0px)));
    border: 0;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform-origin: bottom right;
    animation: ae-chat-open 0.18s ease-out;
}

.ae-chat-panel[hidden] {
    display: none;
}

@keyframes ae-chat-open {
    from { opacity: 0; transform: translateY(12px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.ae-chat-header {
    display: flex;
    flex-shrink: 0;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 14px 12px;
    color: #fff;
    background: linear-gradient(135deg, var(--ae-primary, #2c3e50), var(--ae-primary-light, #34495e));
    border-bottom: 0;
}

.ae-chat-heading small {
    display: block;
    opacity: 0.85;
}

.ae-chat-header .ae-chat-title {
    margin-bottom: 0;
    font-weight: 600;
    font-size: 1rem;
}

.ae-chat-header-actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 4px;
}

.ae-chat-header .close,
.ae-chat-header .ae-chat-reset {
    color: #fff;
    opacity: 0.9;
    text-shadow: none;
}

.ae-chat-header .ae-chat-reset {
    white-space: nowrap;
    padding: 0.25rem 0.4rem !important; /* idem: o .btn do autoexpo.css leva !important */
}

.ae-chat-header .close {
    margin: 0 0 0 4px;
    padding: 0 6px;
}

.ae-chat-header .close:hover,
.ae-chat-header .ae-chat-reset:hover {
    color: #fff;
    opacity: 1;
}

.ae-chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--ae-bg-light, #f8f9fa);
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
}

.ae-chat-msg {
    flex-shrink: 0;
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.ae-chat-msg p {
    margin: 0 0 0.5em;
}

.ae-chat-msg p:last-child,
.ae-chat-msg ul:last-child,
.ae-chat-msg ol:last-child {
    margin-bottom: 0;
}

.ae-chat-msg ul,
.ae-chat-msg ol {
    padding-left: 1.2em;
    margin: 0 0 0.5em;
}

.ae-chat-msg-user {
    align-self: flex-end;
    color: #fff;
    background: var(--ae-accent, #3498db);
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.ae-chat-msg-assistant {
    align-self: flex-start;
    color: var(--ae-text-dark, #2c3e50);
    background: #fff;
    border: 1px solid #e3e7eb;
    border-bottom-left-radius: 4px;
}

.ae-chat-msg-assistant a {
    color: var(--ae-accent-dark, #2980b9);
    font-weight: 600;
}

.ae-chat-msg-notice {
    align-self: center;
    max-width: 95%;
    font-size: 0.9em;
    color: #8a5a00;
    background: #fff4e0;
    border: 1px solid #f5d9a8;
}

.ae-chat-msg img.ae-chat-img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 6px 0;
}

.ae-chat-table-wrap {
    overflow-x: auto;
    margin: 0 0 0.5em;
}

.ae-chat-table-wrap table {
    border-collapse: collapse;
    font-size: 0.9em;
    width: 100%;
}

.ae-chat-table-wrap th,
.ae-chat-table-wrap td {
    border: 1px solid #e3e7eb;
    padding: 4px 6px;
    vertical-align: top;
}

.ae-chat-table-wrap th {
    background: var(--ae-primary-soft, #e8eef3);
}

.ae-chat-thinking {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ae-text-muted, #6c757d);
}

.ae-chat-dots {
    display: inline-flex;
    gap: 3px;
}

.ae-chat-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: ae-chat-bounce 1.2s infinite ease-in-out;
}

.ae-chat-dots span:nth-child(2) { animation-delay: 0.15s; }
.ae-chat-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ae-chat-bounce {
    0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

.ae-chat-suggestions {
    display: flex;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px 0;
    background: #fff;
}

.ae-chat-suggestions[hidden] {
    display: none;
}

.ae-chat-form[hidden],
.ae-chat-auth[hidden],
.ae-chat-reset[hidden] {
    display: none;
}

.ae-chat-auth {
    flex-shrink: 0;
    padding: 16px;
    text-align: center;
    background: #fff;
    border-top: 1px solid #eef0f2;
}

.ae-chat-chip {
    border: 1px solid var(--ae-accent, #3498db);
    color: var(--ae-accent-dark, #2980b9);
    background: #fff;
    border-radius: 16px;
    padding: 4px 12px;
    font-size: 0.9em;
    cursor: pointer;
}

.ae-chat-chip:hover,
.ae-chat-chip:focus-visible {
    background: var(--ae-primary-soft, #e8eef3);
}

.ae-chat-form {
    display: flex;
    flex-shrink: 0;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px 6px;
    background: #fff;
    border-top: 1px solid #eef0f2;
    margin: 0;
}

.ae-chat-input {
    resize: none;
    max-height: 140px;
    overflow-y: hidden; /* o JS so liga o scroll quando o texto passa da altura maxima */
    border-radius: 12px;
}

.ae-chat-send {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    color: #fff;
    background: var(--ae-accent, #3498db);
    display: flex;
    align-items: center;
    justify-content: center;
    /* !important: o autoexpo.css impoe ".btn { padding: .55rem 1.4rem !important }", que num botao
       de 38px deixava 0px para o icone. */
    padding: 0 !important;
}

.ae-chat-send svg {
    flex: 0 0 18px;
}

.ae-chat-send:hover,
.ae-chat-send:focus {
    color: #fff;
    background: var(--ae-accent-dark, #2980b9);
}

.ae-chat-send:disabled {
    opacity: 0.55;
}

.ae-chat-disclaimer {
    flex-shrink: 0;
    font-size: 0.75em;
    color: var(--ae-text-muted, #6c757d);
    text-align: center;
    padding: 0 16px 10px;
    background: #fff;
}

/* Telemovel: janela em ecra inteiro. */
@media (max-width: 575.98px) {
    html.ae-chat-mobile-open,
    html.ae-chat-mobile-open body {
        overflow: hidden;
    }

    .ae-chat-launcher {
        right: 14px;
        bottom: calc(14px + env(safe-area-inset-bottom, 0px));
        width: 54px;
        height: 54px;
    }

    .ae-chat-panel {
        inset: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
            env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .ae-chat-panel,
    .ae-chat-dots span {
        animation: none;
    }
}

@media print {
    .ae-chat-launcher,
    .ae-chat-panel {
        display: none;
    }
}
