.aplhd-widget {
    --hd-aplweb-700: #10766e;
    --hd-aplweb-600: #1B822C;
    --hd-aplweb-500: #40b76c;
    --hd-aplweb-800: #0d403d;
    --hd-aplweb-50: #ecfdf5;
    --hd-aplweb-100: #d1fae5;
    --hd-ink-50: #f8fafc;
    --hd-ink-100: #f1f5f9;
    --hd-ink-200: #e2e8f0;
    --hd-ink-300: #cbd5e1;
    --hd-ink-500: #64748b;
    --hd-ink-700: #334155;
    --hd-ink-900: #0f172a;

    /* Posicionado ACIMA do widget de WhatsApp existente (que ocupa right:24px bottom:24px) */
    position: fixed; bottom: 100px; right: 24px;
    z-index: 9000;
    font-family: 'Manrope', system-ui, sans-serif;
}

/* FAB */
.aplhd-fab {
    width: 60px; height: 60px; border-radius: 50%;
    background: linear-gradient(135deg, var(--hd-aplweb-700), var(--hd-aplweb-500));
    color: white; border: none; cursor: pointer;
    display: grid; place-items: center;
    box-shadow: 0 12px 30px -8px rgba(16, 118, 110, 0.5);
    transition: transform .2s, box-shadow .2s;
    position: relative;
}
.aplhd-fab:hover { transform: scale(1.05); box-shadow: 0 16px 40px -8px rgba(16, 118, 110, 0.6); }
.aplhd-fab::after {
    content: ''; position: absolute; top: 4px; right: 4px;
    width: 12px; height: 12px; background: #ef4444;
    border-radius: 50%; border: 2px solid white;
    animation: aplhd-pulse 2s ease-in-out infinite;
}
@keyframes aplhd-pulse {
    0%,100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}
.aplhd-widget.open .aplhd-fab::after { display: none; }

/* PAINEL */
.aplhd-panel {
    position: absolute; bottom: calc(100% + 14px); right: 0;
    width: 380px; max-width: calc(100vw - 32px);
    max-height: calc(100vh - 140px);
    background: white; border-radius: 18px;
    box-shadow: 0 24px 60px -16px rgba(15, 23, 42, 0.25);
    overflow: hidden;
    opacity: 0; transform: translateY(10px) scale(0.96);
    pointer-events: none;
    transition: opacity .25s, transform .25s;
    display: flex; flex-direction: column;
}
.aplhd-widget.open .aplhd-panel {
    opacity: 1; transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* HEADER do painel */
.aplhd-header {
    background: linear-gradient(135deg, var(--hd-aplweb-700), var(--hd-aplweb-800));
    color: white; padding: 18px 20px;
    display: flex; align-items: center; gap: 10px;
    flex-shrink: 0;
}
.aplhd-back-btn {
    background: rgba(255,255,255,.15); border: none; cursor: pointer;
    width: 30px; height: 30px; border-radius: 8px;
    color: white; display: none; place-items: center;
    transition: background .15s;
    padding: 0;
}
.aplhd-back-btn:hover { background: rgba(255,255,255,.25); }
.aplhd-header.has-back .aplhd-back-btn { display: grid; }
.aplhd-header-text { flex: 1; min-width: 0; }
.aplhd-header h3 {
    font-family: 'Sora', sans-serif; font-weight: 700;
    font-size: 1.05rem; margin: 0;
    line-height: 1.2;
}
.aplhd-header p { margin: 2px 0 0; font-size: 0.8rem; opacity: 0.85; }
.aplhd-close-x {
    background: rgba(255,255,255,.15); border: none; cursor: pointer;
    width: 30px; height: 30px; border-radius: 8px;
    color: white; display: grid; place-items: center;
    padding: 0;
}
.aplhd-close-x:hover { background: rgba(255,255,255,.25); }

/* BODY */
.aplhd-body {
    padding: 20px; overflow-y: auto;
    flex: 1; min-height: 0;
}

.aplhd-step { display: none; }
.aplhd-step.active { display: block; animation: aplhdFade .2s; }
@keyframes aplhdFade {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========== TELA 1: ESCOLHA ========== */
.aplhd-choices { display: flex; flex-direction: column; gap: 10px; }
.aplhd-choice {
    background: white; border: 2px solid var(--hd-ink-200);
    border-radius: 12px; padding: 14px 16px;
    cursor: pointer; transition: all .15s;
    display: flex; align-items: center; gap: 14px;
    text-align: left; font-family: 'Manrope', sans-serif;
    width: 100%;
}
.aplhd-choice:hover {
    border-color: var(--hd-aplweb-500);
    background: var(--hd-aplweb-50);
}
.aplhd-choice-icon {
    width: 40px; height: 40px; border-radius: 10px;
    background: var(--hd-aplweb-50); color: var(--hd-aplweb-700);
    display: grid; place-items: center; flex-shrink: 0;
}
.aplhd-choice.lead .aplhd-choice-icon { background: #fff7ed; color: #c2410c; }
.aplhd-choice-text { flex: 1; min-width: 0; }
.aplhd-choice-titulo {
    font-family: 'Sora', sans-serif; font-weight: 700; font-size: 0.95rem;
    color: var(--hd-ink-900); margin: 0;
}
.aplhd-choice-desc {
    color: var(--hd-ink-500); font-size: 0.82rem; margin: 2px 0 0;
    line-height: 1.4;
}

/* ========== BUSCA DE CLIENTE ========== */
.aplhd-search {
    position: relative; margin-bottom: 10px;
}
.aplhd-search-input {
    width: 100%; padding: 11px 14px 11px 38px;
    border: 1.5px solid var(--hd-ink-200); border-radius: 10px;
    font-family: 'Manrope', sans-serif; font-size: 0.92rem;
    color: var(--hd-ink-900); background: white;
    outline: none; -webkit-appearance: none;
    transition: border-color .15s;
}
.aplhd-search-input:focus { border-color: var(--hd-aplweb-500); }
.aplhd-search-icon {
    position: absolute; left: 12px; top: 50%;
    transform: translateY(-50%); color: var(--hd-ink-500);
    pointer-events: none;
}
.aplhd-search-loading {
    position: absolute; right: 12px; top: 50%;
    transform: translateY(-50%);
    width: 14px; height: 14px;
    border: 2px solid var(--hd-ink-200);
    border-top-color: var(--hd-aplweb-500);
    border-radius: 50%; animation: aplhdSpin 0.8s linear infinite;
    display: none;
}
.aplhd-search-loading.show { display: block; }
@keyframes aplhdSpin { to { transform: translateY(-50%) rotate(360deg); } }

.aplhd-results {
    max-height: 260px; overflow-y: auto;
    margin: 0 -6px;
}
.aplhd-result {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; cursor: pointer;
    border-radius: 8px; transition: background .15s;
    margin: 2px 6px;
}
.aplhd-result:hover { background: var(--hd-aplweb-50); }
.aplhd-result-avatar {
    width: 36px; height: 36px; border-radius: 8px;
    background: linear-gradient(135deg, var(--hd-aplweb-700), var(--hd-aplweb-500));
    color: white;
    display: grid; place-items: center;
    font-family: 'Sora', sans-serif; font-weight: 700; font-size: 0.78rem;
    flex-shrink: 0; overflow: hidden;
}
.aplhd-result-avatar img { width: 100%; height: 100%; object-fit: cover; }
.aplhd-result-info { flex: 1; min-width: 0; }
.aplhd-result-nome {
    font-family: 'Sora', sans-serif; font-weight: 600; font-size: 0.88rem;
    color: var(--hd-ink-900);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.aplhd-result-sub {
    font-size: 0.74rem; color: var(--hd-ink-500);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.aplhd-empty {
    padding: 20px 14px; text-align: center;
    color: var(--hd-ink-500); font-size: 0.86rem;
    line-height: 1.5;
}
.aplhd-empty a { color: var(--hd-aplweb-700); font-weight: 600; text-decoration: none; }
.aplhd-empty a:hover { text-decoration: underline; }

.aplhd-fallback {
    background: var(--hd-ink-50); border-radius: 10px;
    padding: 10px 14px; margin-top: 10px;
    text-align: center; font-size: 0.82rem; color: var(--hd-ink-700);
}
.aplhd-fallback a { color: var(--hd-aplweb-700); font-weight: 600; text-decoration: none; }
.aplhd-fallback a:hover { text-decoration: underline; }

/* ========== CLIENTE PILL ========== */
.aplhd-cliente-pill {
    display: flex; align-items: center; gap: 10px;
    background: var(--hd-aplweb-50); border: 1.5px solid var(--hd-aplweb-100);
    border-radius: 10px; padding: 9px 12px; margin-bottom: 14px;
}
.aplhd-cliente-pill-avatar {
    width: 32px; height: 32px; border-radius: 8px;
    background: linear-gradient(135deg, var(--hd-aplweb-700), var(--hd-aplweb-500));
    color: white; display: grid; place-items: center;
    font-family: 'Sora', sans-serif; font-weight: 700; font-size: 0.74rem;
    flex-shrink: 0; overflow: hidden;
}
.aplhd-cliente-pill-avatar img { width: 100%; height: 100%; object-fit: cover; }
.aplhd-cliente-pill-info { flex: 1; min-width: 0; }
.aplhd-cliente-pill-label {
    font-size: 0.66rem; color: var(--hd-aplweb-700); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.06em;
}
.aplhd-cliente-pill-nome {
    font-family: 'Sora', sans-serif; font-weight: 700; font-size: 0.86rem;
    color: var(--hd-ink-900);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ========== FORMULÁRIO ========== */
.aplhd-field { margin-bottom: 12px; }
.aplhd-field:last-child { margin-bottom: 0; }
.aplhd-field label {
    display: block; font-family: 'Sora', sans-serif; font-weight: 600;
    font-size: 0.78rem; color: var(--hd-ink-700); margin-bottom: 4px;
}
.aplhd-field label .req { color: #ef4444; margin-left: 2px; }
.aplhd-field label .opt { color: var(--hd-ink-500); font-weight: 400; }
.aplhd-field input,
.aplhd-field textarea {
    width: 100%; padding: 9px 12px;
    border: 1.5px solid var(--hd-ink-200); border-radius: 9px;
    font-family: 'Manrope', sans-serif; font-size: 0.9rem;
    color: var(--hd-ink-900); background: white;
    outline: none; -webkit-appearance: none;
    transition: border-color .15s;
}
.aplhd-field input:focus,
.aplhd-field textarea:focus { border-color: var(--hd-aplweb-500); }
.aplhd-field textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
.aplhd-field.has-error input,
.aplhd-field.has-error textarea { border-color: #ef4444; }
.aplhd-field-error { color: #ef4444; font-size: 0.74rem; margin-top: 3px; display: none; }
.aplhd-field.has-error .aplhd-field-error { display: block; }

.aplhd-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Tipos compactos */
.aplhd-tipo-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.aplhd-tipo-card {
    border: 1.5px solid var(--hd-ink-200); border-radius: 9px;
    padding: 8px 6px; cursor: pointer; text-align: center;
    transition: all .15s; background: white;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.aplhd-tipo-card:hover { border-color: var(--hd-aplweb-500); }
.aplhd-tipo-card.selected {
    border-color: var(--hd-aplweb-500); background: var(--hd-aplweb-50);
}
.aplhd-tipo-card svg { color: var(--hd-ink-500); transition: color .15s; }
.aplhd-tipo-card.selected svg { color: var(--hd-aplweb-700); }
.aplhd-tipo-card-titulo {
    font-family: 'Sora', sans-serif; font-weight: 600; font-size: 0.76rem;
    color: var(--hd-ink-900);
}

/* Honeypot */
.aplhd-honeypot { position: absolute; left: -9999px; }

/* Botão */
.aplhd-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--hd-aplweb-700), var(--hd-aplweb-500));
    color: white; border: none; cursor: pointer;
    padding: 12px 18px; border-radius: 10px;
    font-family: 'Sora', sans-serif; font-weight: 700; font-size: 0.94rem;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: all .15s; margin-top: 8px;
}
.aplhd-btn:hover:not(:disabled) { transform: translateY(-1px); }
.aplhd-btn:disabled { background: var(--hd-ink-200); cursor: not-allowed; transform: none; color: var(--hd-ink-500); }

/* Alert */
.aplhd-alert {
    background: #fef2f2; color: #991b1b;
    border-left: 3px solid #ef4444;
    padding: 9px 12px; border-radius: 8px;
    font-size: 0.82rem; margin-bottom: 12px; display: none;
}
.aplhd-alert.show { display: block; }

/* Sucesso */
.aplhd-success { text-align: center; padding: 12px 8px; }
.aplhd-success-icon {
    width: 56px; height: 56px; margin: 0 auto 12px;
    background: linear-gradient(135deg, var(--hd-aplweb-500), #6ee7b7);
    border-radius: 50%; display: grid; place-items: center; color: white;
}
.aplhd-success h4 {
    font-family: 'Sora', sans-serif; font-weight: 700;
    margin: 0 0 6px; color: var(--hd-ink-900); font-size: 1.05rem;
}
.aplhd-success p { margin: 0 0 14px; color: var(--hd-ink-500); font-size: 0.86rem; line-height: 1.5; }
.aplhd-success-ref {
    display: inline-block;
    background: var(--hd-aplweb-50); color: var(--hd-aplweb-700);
    padding: 6px 14px; border-radius: 999px;
    font-family: ui-monospace, monospace; font-weight: 700;
    font-size: 0.88rem; margin-bottom: 12px;
}
.aplhd-success-actions { display: flex; flex-direction: column; gap: 8px; }
.aplhd-success-actions a {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 14px; border-radius: 9px; text-decoration: none;
    font-family: 'Sora', sans-serif; font-weight: 600; font-size: 0.86rem;
}
.aplhd-success-actions .primary { background: var(--hd-aplweb-700); color: white; }
.aplhd-success-actions .primary:hover { background: var(--hd-aplweb-800); }
.aplhd-success-actions .secondary {
    background: var(--hd-ink-100); color: var(--hd-ink-700);
    border: none; cursor: pointer; font-family: 'Sora', sans-serif;
}

/* Mobile */
@media (max-width: 480px) {
    .aplhd-widget { bottom: 92px; right: 16px; }
    .aplhd-panel {
        width: calc(100vw - 32px); max-width: 380px;
        max-height: calc(100vh - 170px);
    }
}
/* =========================================================
   ANEXOS — bloco compacto pro widget
   ========================================================= */
.aplhd-attach-field { margin-top: 12px; }

.aplhd-attach-zone {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border: 1.5px dashed var(--hd-ink-300);
    border-radius: 10px;
    background: var(--hd-ink-50);
    transition: all 0.15s;
}
.aplhd-attach-zone.dragover {
    border-color: var(--hd-aplweb-500);
    background: var(--hd-aplweb-50);
}

.aplhd-attach-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px;
    background: white; color: var(--hd-aplweb-700);
    border: 1px solid var(--hd-ink-200);
    border-radius: 7px; cursor: pointer;
    font-family: 'Sora', sans-serif; font-weight: 600;
    font-size: 0.78rem;
    transition: all 0.15s;
}
.aplhd-attach-btn:hover {
    border-color: var(--hd-aplweb-500);
    background: var(--hd-aplweb-50);
}

.aplhd-attach-hint {
    color: var(--hd-ink-500); font-size: 0.78rem;
    flex: 1; min-width: 0;
}

.aplhd-attach-list { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.aplhd-attach-list:empty { display: none; }

.aplhd-attach-row {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px; background: white;
    border: 1px solid var(--hd-ink-200); border-radius: 7px;
    font-size: 0.78rem;
}
.aplhd-attach-row .ic {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px;
    background: var(--hd-aplweb-50); color: var(--hd-aplweb-700);
    border-radius: 5px;
    font-family: ui-monospace, monospace; font-weight: 700;
    font-size: 0.66rem; flex-shrink: 0;
}
.aplhd-attach-row .nm {
    flex: 1; min-width: 0;
    color: var(--hd-ink-700);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.aplhd-attach-row .sz {
    color: var(--hd-ink-500); font-size: 0.72rem; flex-shrink: 0;
}
.aplhd-attach-row.error {
    background: #fef2f2; border-color: #fecaca;
}
.aplhd-attach-row.error .nm { color: #991b1b; }
.aplhd-attach-row.error .ic { background: #fee2e2; color: #b91c1c; }

.aplhd-attach-row .rm {
    width: 22px; height: 22px;
    border-radius: 5px; border: none;
    background: var(--hd-ink-100); color: var(--hd-ink-500);
    cursor: pointer;
    font-size: 1rem; line-height: 1;
    flex-shrink: 0;
    transition: all 0.15s;
}
.aplhd-attach-row .rm:hover { background: #ef4444; color: white; }