/* Assistente de Ajuda — companheiro flutuante (addon 'assistente')
   Cores/fonte via CSS vars injectadas no elemento raiz (--apipp-hw-*)
   a partir dos tokens da Identidade Visual. */

.apipp-help {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 99990;
    font-family: var(--apipp-hw-font, sans-serif);
    font-size: 14px;
    line-height: 1.45;
    color: var(--apipp-hw-text, #2c3e50);
}

/* ── Avatar flutuante ─────────────────────────────────────── */
.apipp-help-fab-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.apipp-help-label {
    margin-right: 10px;
    padding: 6px 12px;
    background: #fff;
    border: 1px solid var(--apipp-hw-soft-border, #ccebf2);
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--apipp-hw-text, #2c3e50);
    white-space: nowrap;
    pointer-events: none; /* decorativa — o click é no avatar */
}

.apipp-help-fab {
    display: block;
    width: 56px;
    height: 56px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--apipp-hw-primary, #1FA3C2);
    color: #fff;
    cursor: pointer;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .28);
    transition: transform .15s ease, box-shadow .15s ease;
}
.apipp-help-fab:hover { transform: scale(1.05); box-shadow: 0 4px 14px rgba(0, 0, 0, .32); }
.apipp-help-fab:focus-visible { outline: 2px solid var(--apipp-hw-primary-dark, #1989A3); outline-offset: 2px; }
.apipp-help-fab img { width: 100%; height: 100%; object-fit: cover; display: block; }
.apipp-help-initials { font-size: 19px; font-weight: 700; letter-spacing: .5px; }

/* Selo "?" — identifica o avatar como botão de ajuda */
.apipp-help-fab-badge {
    position: absolute;
    right: -3px;
    bottom: -3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--apipp-hw-primary-dark, #1989A3);
    border: 2px solid #fff;
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
    pointer-events: none;
}

/* ── Painel ───────────────────────────────────────────────── */
.apipp-help-panel {
    position: absolute;
    right: 68px;
    top: 50%;
    width: min(330px, calc(100vw - 88px));
    max-height: min(76vh, 600px);
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--apipp-hw-soft-border, #ccebf2);
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .22);
    padding: 16px;
    opacity: 0;
    transform: translateY(-50%) translateX(10px);
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
}
.apipp-help.apipp-help-opened .apipp-help-panel {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
    pointer-events: auto;
}
.apipp-help.apipp-help-opened .apipp-help-fab { transform: scale(.92); }

.apipp-help-head { display: flex; align-items: center; gap: 10px; }
.apipp-help-avatar { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.apipp-help-head > div { flex: 1; min-width: 0; }
.apipp-help-head strong { display: block; font-size: 15px; }
.apipp-help-sub { display: block; font-size: 12px; color: var(--apipp-hw-muted, #7f8c8d); }
.apipp-help-close {
    border: none; background: none; font-size: 22px; line-height: 1;
    color: var(--apipp-hw-muted, #7f8c8d); cursor: pointer; padding: 4px 8px;
}
.apipp-help-close:hover { color: var(--apipp-hw-text, #2c3e50); }

.apipp-help-tagline {
    margin: 10px 0 12px;
    font-size: 13px;
    color: var(--apipp-hw-muted, #7f8c8d);
    font-style: italic;
}

/* ── WhatsApp ─────────────────────────────────────────────── */
.apipp-help-wa {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 14px;
    border-radius: 8px;
    background: #25D366;
    color: #fff !important;
    font-weight: 600;
    font-size: 14px;
    text-decoration: none !important;
    transition: background .15s ease;
}
.apipp-help-wa:hover { background: #1ebe5b; }
.apipp-help-norobots { margin: 6px 2px 0; font-size: 11.5px; color: var(--apipp-hw-muted, #7f8c8d); text-align: center; }

/* ── Bloco destino ────────────────────────────────────────── */
.apipp-help-dest {
    margin-top: 14px;
    padding: 10px 12px;
    background: var(--apipp-hw-soft-bg, #e9f8fb);
    border: 1px solid var(--apipp-hw-soft-border, #ccebf2);
    border-radius: 8px;
    font-size: 13px;
}
.apipp-help-dest p { margin: 4px 0 8px; color: var(--apipp-hw-muted, #7f8c8d); }
.apipp-help-dest-links { display: flex; gap: 8px; flex-wrap: wrap; }
.apipp-help-dest-links a {
    display: inline-block;
    padding: 6px 12px;
    border: 1px solid var(--apipp-hw-soft-border, #ccebf2);
    border-radius: 6px;
    background: #fff;
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
    color: var(--apipp-hw-text, #2c3e50);
}
.apipp-help-dest-links a:hover { border-color: var(--apipp-hw-primary, #1FA3C2); }

/* ── FAQs ─────────────────────────────────────────────────── */
.apipp-help-faqs { margin-top: 14px; border-top: 1px solid var(--apipp-hw-soft-border, #ccebf2); }
.apipp-help-faq { border-bottom: 1px solid var(--apipp-hw-soft-border, #ccebf2); }
.apipp-help-faq-q {
    display: block;
    width: 100%;
    padding: 10px 4px;
    border: none;
    background: none;
    text-align: left;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--apipp-hw-text, #2c3e50);
    cursor: pointer;
}
.apipp-help-faq-q::after {
    content: '▾';
    float: right;
    color: var(--apipp-hw-muted, #7f8c8d);
    transition: transform .15s ease;
}
.apipp-help-faq.apipp-faq-open .apipp-help-faq-q::after { transform: rotate(180deg); }
.apipp-help-faq-a { padding: 0 4px 12px; font-size: 13px; color: var(--apipp-hw-muted, #7f8c8d); }
.apipp-help-faq-a p { margin: 0 0 6px; }
.apipp-help-faq-a a { color: var(--apipp-hw-primary, #1FA3C2); font-weight: 600; }

/* ── Assistente IA ────────────────────────────────────────── */
.apipp-help-ai { margin-top: 14px; }
.apipp-help-ai-toggle {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--apipp-hw-soft-border, #ccebf2);
    border-radius: 8px;
    background: var(--apipp-hw-field-bg, #f4f6f9);
    color: var(--apipp-hw-text, #2c3e50);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
}
.apipp-help-ai-toggle:hover { border-color: var(--apipp-hw-primary, #1FA3C2); }
.apipp-help-ai-box { margin-top: 10px; }
.apipp-help-ai-intro { margin: 0 0 10px; font-size: 12px; color: var(--apipp-hw-muted, #7f8c8d); }
.apipp-help-ai-log {
    max-height: 220px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}
.apipp-help-msg {
    max-width: 88%;
    padding: 8px 11px;
    border-radius: 10px;
    font-size: 13px;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.apipp-help-msg-user { align-self: flex-end; background: var(--apipp-hw-primary, #1FA3C2); color: #fff; }
.apipp-help-msg-bot { align-self: flex-start; background: var(--apipp-hw-field-bg, #f4f6f9); }
.apipp-help-msg-bot a { color: var(--apipp-hw-primary, #1FA3C2); }
.apipp-help-msg-typing { align-self: flex-start; color: var(--apipp-hw-muted, #7f8c8d); font-style: italic; }
.apipp-help-handoff {
    align-self: flex-start;
    padding: 8px 12px;
    border-radius: 8px;
    background: #25D366;
    color: #fff !important;
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none !important;
}
.apipp-help-guidelink {
    align-self: flex-start;
    padding: 7px 12px;
    border-radius: 8px;
    background: var(--apipp-hw-soft-bg, #e9f8fb);
    border: 1px solid var(--apipp-hw-primary, #1FA3C2);
    color: var(--apipp-hw-primary-dark, #1989A3) !important;
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none !important;
}
.apipp-help-guidelink:hover { background: var(--apipp-hw-soft-border, #ccebf2); }
.apipp-help-ai-form { display: flex; gap: 6px; }
.apipp-help-ai-form input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid var(--apipp-hw-soft-border, #ccebf2);
    border-radius: 8px;
    background: var(--apipp-hw-field-bg, #f4f6f9);
    font-size: 13.5px;
}
.apipp-help-ai-form button {
    padding: 9px 14px;
    border: none;
    border-radius: 8px;
    background: var(--apipp-hw-primary, #1FA3C2);
    color: #fff;
    cursor: pointer;
}
.apipp-help-ai-form button:disabled { opacity: .5; cursor: default; }

/* ── Confiança + dismiss ──────────────────────────────────── */
.apipp-help-trust {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px solid var(--apipp-hw-soft-border, #ccebf2);
    font-size: 12px;
}
.apipp-help-trust a { color: var(--apipp-hw-muted, #7f8c8d); text-decoration: none; }
.apipp-help-trust a:hover { color: var(--apipp-hw-primary, #1FA3C2); }
.apipp-help-rnavt { margin-left: auto; color: var(--apipp-hw-muted, #7f8c8d); font-size: 11px; }

.apipp-help-dismiss {
    display: block;
    margin: 10px auto 0;
    border: none;
    background: none;
    font-size: 11px;
    color: var(--apipp-hw-muted, #7f8c8d);
    text-decoration: underline;
    cursor: pointer;
}

/* Estado escondido (dismiss ou triggers-only) */
.apipp-help.apipp-help-hidden { display: none; }

/* ── Ecrãs médios: avatar mais pequeno, etiqueta esconde ── */
@media (max-width: 900px) {
    .apipp-help-label { display: none; }
    .apipp-help-fab { width: 48px; height: 48px; }
    .apipp-help-fab-badge { width: 18px; height: 18px; font-size: 11px; line-height: 14px; }
}

/* ── Mobile: avatar mantém-se a meio; painel vira bottom-sheet ── */
@media (max-width: 640px) {
    .apipp-help { right: 14px; }
    .apipp-help-panel {
        position: fixed;
        top: auto;
        right: 0;
        left: 0;
        bottom: 0;
        width: auto;
        max-width: none;
        max-height: 78vh;
        border-radius: 16px 16px 0 0;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
        transform: translateY(10px);
    }
    .apipp-help.apipp-help-opened .apipp-help-panel {
        transform: translateY(0);
    }
}
