.ahd-widget {
    --ahd-color: #1769ff;
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: min(380px, calc(100vw - 24px));
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.ahd-panel {
    background: #ffffff;
    border-radius: 26px;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
    border: 1px solid rgba(15, 23, 42, 0.06);
    transition: opacity 0.22s ease, transform 0.22s ease, max-height 0.22s ease, margin-bottom 0.22s ease;
    display: flex;
    flex-direction: column;
    max-height: min(500px, calc(100vh - 150px));
    margin-bottom: 16px;
}

.ahd-widget:not(.is-open) .ahd-panel {
    opacity: 0;
    transform: translateY(18px);
    pointer-events: none;
    max-height: 0;
    margin-bottom: 0;
}

.ahd-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px 12px;
    color: #fff;
    background: linear-gradient(135deg, var(--ahd-color) 0%, #0f172a 145%);
}

.ahd-header-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ahd-header-profile img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.48);
    background: rgba(255,255,255,0.15);
}

.ahd-header-profile strong,
.ahd-header-profile span {
    display: block;
}

.ahd-header-profile strong {
    font-size: 16px;
    line-height: 1.2;
}

.ahd-header-profile span {
    font-size: 13px;
    opacity: 0.92;
}

.ahd-minimize {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.16);
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.ahd-panel-body {
    background: linear-gradient(180deg, #f8fbff 0%, #f8fafc 100%);
    padding: 12px 14px;
    min-height: 120px;
    max-height: none;
    overflow-y: auto;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 12px;
}

.ahd-msg-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ahd-msg-wrap-agent {
    align-items: flex-start;
}

.ahd-msg-wrap-user {
    align-items: flex-end;
}

.ahd-msg {
    max-width: 82%;
    border-radius: 18px;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.5;
    color: #0f172a;
}

.ahd-msg-agent {
    background: #fff;
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08);
}

.ahd-msg-user {
    background: rgba(23, 105, 255, 0.11);
}

.ahd-brand-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    font-size: 12px;
    color: #334155;
    background: rgba(255,255,255,0.92);
    padding: 6px 10px;
    border-radius: 999px;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.ahd-brand-link:hover {
    color: var(--ahd-color);
}

.ahd-brand-logo {
    width: 22px;
    height: 22px;
    object-fit: contain;
    display: block;
}

.ahd-brand-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--ahd-color) 0%, #0f172a 155%);
    color: #fff;
    font-weight: 700;
    font-size: 11px;
}

.ahd-brand-copy {
    white-space: nowrap;
}


.ahd-panel-input-wrap {
    background: #fff;
    border-top: 1px solid #e5e7eb;
    padding: 12px 14px 14px;
}

.ahd-attachment-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    background: #f8fafc;
    border: 1px solid #dbe3ef;
    border-radius: 14px;
    padding: 8px 12px;
    font-size: 12px;
    color: #334155;
}


/* Correccion v1.9.2: ocultar la vista previa de adjuntos cuando no hay archivo. */
.ahd-attachment-preview[hidden],
.ahd-attachment-preview.is-hidden {
    display: none !important;
}

.ahd-panel-footer:empty {
    display: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

.ahd-attachment-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ahd-attachment-clear {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    color: #64748b;
}

.ahd-attach-btn {
    display:inline-flex;
    align-items:center;
    justify-content:center;
    width:44px;
    height:44px;
    border:none;
    background:transparent;
    cursor:pointer;
    flex:0 0 44px;
    padding:0;
}

.ahd-attachment-input {
    display: none;
}

.ahd-attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    font-size: 12px;
    color: #0f172a;
    background: rgba(255,255,255,0.92);
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.ahd-panel-input {
    display: flex;
    gap: 8px;
    padding: 14px;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    align-items: center;
}

.ahd-panel-input input {
    flex: 1;
    border: 1px solid #dbe3ef;
    border-radius: 999px;
    padding: 12px 14px;
    font-size: 14px;
    outline: none;
    min-width: 0;
}

.ahd-panel-input input:focus {
    border-color: var(--ahd-color);
    box-shadow: 0 0 0 3px rgba(23, 105, 255, 0.14);
}

.ahd-panel-input button {
    border: none;
    border-radius: 999px;
    padding: 12px 16px;
    color: #fff;
    background: var(--ahd-color);
    font-weight: 600;
    cursor: pointer;
}

.ahd-dock {
    position: relative;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    min-height: 92px;
}

.ahd-teaser-group {
    position: absolute;
    right: 6px;
    bottom: calc(100% + 12px);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    width: max-content;
    max-width: 290px;
    transition: opacity 0.28s ease, transform 0.28s ease;
}

.ahd-teaser-group.is-hidden {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
    pointer-events: none;
}

.ahd-greeting {
    position: relative;
    width: auto;
    max-width: 290px;
    margin: 0;
    background: #ffffff !important;
    padding: 14px 16px;
    border-radius: 18px;
    box-shadow: 0 16px 34px rgba(15, 23, 42, 0.18);
    border: 1px solid rgba(15, 23, 42, 0.08) !important;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.45;
    color: #0f172a !important;
    text-align: left;
    cursor: pointer;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ahd-greeting::after {
    content: '';
    position: absolute;
    right: 18px;
    bottom: -7px;
    width: 14px;
    height: 14px;
    background: #ffffff;
    border-right: 1px solid rgba(15, 23, 42, 0.08);
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    transform: rotate(45deg);
}

.ahd-greeting:focus,
.ahd-fab:focus {
    outline: none;
}

.ahd-fab {
    position: relative;
    width: 90px;
    height: 90px;
    padding: 4px !important;
    border-radius: 50% !important;
    border: none !important;
    outline: none !important;
    background: #ffffff !important;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.24) !important;
    cursor: pointer;
    flex: 0 0 auto;
    overflow: hidden !important;
    -webkit-appearance: none;
    appearance: none;
    display: flex;
    align-items: center;
    justify-content: center;
    clip-path: circle(50% at 50% 50%);
}

.ahd-fab::before {
    content: none !important;
}

.ahd-fab img {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    margin: 0;
    object-fit: cover;
    border-radius: 50% !important;
    display: block;
    background: #ffffff;
    clip-path: circle(50% at 50% 50%);
}

.ahd-status {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 2;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: #14c768;
}

@media (max-width: 680px) {
    .ahd-widget {
        right: 12px;
        bottom: 12px;
        width: calc(100vw - 24px);
    }

    .ahd-teaser-group {
        right: 0;
        bottom: calc(100% + 10px);
        max-width: min(260px, calc(100vw - 30px));
    }

    .ahd-greeting {
        max-width: min(260px, calc(100vw - 30px));
        font-size: 13px;
        padding: 12px 14px;
        -webkit-line-clamp: 2;
    }

    .ahd-fab {
        width: 78px;
        height: 78px;
    }

    .ahd-brand-copy {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

.ahd-widget .ahd-fab,
.ahd-widget button.ahd-fab,
.ahd-widget .ahd-fab:hover,
.ahd-widget .ahd-fab:active,
.ahd-widget .ahd-fab:focus {
    background: #ffffff !important;
    border: none !important;
    border-radius: 50% !important;
    outline: none !important;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.24) !important;
}

.ahd-widget .ahd-greeting,
.ahd-widget button.ahd-greeting,
.ahd-widget .ahd-greeting:hover,
.ahd-widget .ahd-greeting:active,
.ahd-widget .ahd-greeting:focus {
    background: #ffffff !important;
    color: #0f172a !important;
}


.ahd-panel-footer {
    display: flex;
    justify-content: flex-start;
    padding-top: 8px;
}

.ahd-panel-footer .ahd-brand-link {
    margin: 0;
    width: auto;
    max-width: 100%;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    box-shadow: none;
}

.ahd-panel-footer .ahd-brand-copy {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ahd-attach-btn {
    color: #64748b;
    transition: background .2s ease, color .2s ease, border-color .2s ease;
}

.ahd-attach-btn:hover {
    opacity:.9;
}

.ahd-attach-btn img {
    width:36px;
    height:36px;
    display:block;
}

.ahd-panel-input {
    align-items: center;
}

.ahd-panel-input input#ahd-user-input {
    flex: 1 1 auto;
    min-width: 0;
}

.ahd-panel-input input.ahd-attachment-input {
    display: none !important;
}

.ahd-msg-meta{font-size:12px;color:#64748b;font-weight:600;padding:0 4px}.ahd-msg-wrap-user .ahd-msg-meta{text-align:right}.ahd-lead-form-card{background:#fff;border:1px solid #cfe0ff;border-radius:18px;padding:16px;box-shadow:0 10px 22px rgba(15,23,42,.08);display:grid;gap:10px;max-width:92%}.ahd-lead-title{font-size:16px;font-weight:800;color:#0f172a}.ahd-lead-intro{font-size:14px;line-height:1.45;color:#334155}.ahd-lead-form-card input{width:100%;border:1px solid #cbd5e1;border-radius:12px;padding:12px 14px;font-size:14px}.ahd-lead-submit{border:none;border-radius:14px;padding:12px 16px;color:#fff;background:var(--ahd-color);font-weight:700;cursor:pointer;justify-self:start}.ahd-form-error{font-size:12px;color:#b91c1c;min-height:16px}.ahd-attach-btn img{width:24px;height:24px;display:block}.ahd-panel-footer{padding-top:8px}.ahd-panel-footer .ahd-brand-link{box-shadow:none;background:#f8fafc}

@media (max-height: 820px) {
    .ahd-panel {
        max-height: calc(100vh - 92px);
    }

    .ahd-panel-body {
        min-height: 140px;
    }
}

@media (max-height: 680px) {
    .ahd-panel {
        max-height: calc(100vh - 64px);
    }

    .ahd-panel-header {
        padding: 14px 16px 12px;
    }

    .ahd-header-profile img {
        width: 50px;
        height: 50px;
    }

    .ahd-header-profile strong {
        font-size: 16px;
    }

    .ahd-panel-body {
        padding: 12px;
        min-height: 120px;
    }

    .ahd-panel-input-wrap,
    .ahd-panel-input {
        padding: 10px 12px 12px;
    }
}

.ahd-whatsapp-row{display:flex;gap:8px;align-items:center}.ahd-whatsapp-prefix{width:112px;border:1px solid #cbd5e1;border-radius:12px;padding:12px 10px;font-size:14px;background:#fff}.ahd-whatsapp-row input[type="tel"]{flex:1}.ahd-form-note{font-size:12px;color:#64748b;margin-top:-4px}


/* Window height fix */
.ahd-panel {margin-bottom: 12px;}
@media (max-height: 920px) {
  .ahd-panel { max-height: calc(100vh - 150px); }
}
@media (max-height: 780px) {
  .ahd-panel { max-height: calc(100vh - 120px); }
}
@media (max-height: 680px) {
  .ahd-panel { max-height: calc(100vh - 96px); }
  .ahd-panel-body { min-height: 100px; }
}

/* Email verification step */
.ahd-code-request{border:1px solid var(--ahd-color);border-radius:14px;padding:12px 16px;color:var(--ahd-color);background:#fff;font-weight:700;cursor:pointer;justify-self:start}
.ahd-code-request:hover{background:#eef5ff}
.ahd-code-box{display:grid;gap:8px}
.ahd-code-box[hidden]{display:none!important}
.ahd-form-info{min-height:16px}
.ahd-lead-form-card button:disabled{opacity:.7;cursor:not-allowed}


/* =========================================================
   v1.9.6 - Respetar saltos de línea en respuestas del chat
   ========================================================= */

.ahd-msg,
.ahd-msg-agent,
.ahd-msg-user,
#ahd-chat-messages .ahd-msg {
    white-space: pre-line !important;
    word-break: normal !important;
    overflow-wrap: anywhere !important;
}

.ahd-msg-agent {
    line-height: 1.55 !important;
}

.ahd-msg-agent a,
.ahd-msg-user a {
    word-break: break-word !important;
}


/* =========================================================
   v1.9.7 - Enlaces clicables en el chat
   ========================================================= */

.ahd-chat-link {
    color: #0f46d9 !important;
    font-weight: 800 !important;
    text-decoration: underline !important;
    text-underline-offset: 3px !important;
    word-break: break-word !important;
}

.ahd-msg-agent .ahd-chat-link {
    display: inline-block;
    margin-top: 2px;
}

.ahd-chat-link:hover {
    color: #7c3aed !important;
}



/* =========================================================
   v1.9.8 - Mensajes de voz solo Premium
   ========================================================= */

.ahd-voice-btn {
    width: 42px !important;
    height: 42px !important;
    border-radius: 999px !important;
    border: 1px solid rgba(37, 99, 235, .18) !important;
    background: #ffffff !important;
    color: #1769ff !important;
    display: inline-grid !important;
    place-items: center !important;
    font-size: 18px !important;
    font-weight: 900 !important;
    cursor: pointer !important;
    box-shadow: 0 8px 18px rgba(15, 23, 42, .06) !important;
    transition: transform .16s ease, background .16s ease, color .16s ease, box-shadow .16s ease;
}

.ahd-voice-btn:hover {
    transform: translateY(-1px);
    background: #eff6ff !important;
}

.ahd-voice-btn.is-recording {
    background: #ef4444 !important;
    color: #ffffff !important;
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 8px rgba(239, 68, 68, .14), 0 12px 22px rgba(239, 68, 68, .22) !important;
    animation: ahdVoicePulse 1s infinite;
}

.ahd-voice-btn:disabled {
    opacity: .5 !important;
    cursor: not-allowed !important;
    transform: none !important;
}

@keyframes ahdVoicePulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .28), 0 12px 22px rgba(239, 68, 68, .22); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0), 0 12px 22px rgba(239, 68, 68, .22); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0), 0 12px 22px rgba(239, 68, 68, .22); }
}


/* =========================================================
   v1.9.9 - Icono de micrófono SVG visible
   Corrige navegadores donde el emoji 🎤 se veía como coma/punto.
   ========================================================= */

.ahd-voice-btn {
    position: relative !important;
    flex: 0 0 42px !important;
    width: 42px !important;
    min-width: 42px !important;
    max-width: 42px !important;
    height: 42px !important;
    min-height: 42px !important;
    padding: 0 !important;
    border-radius: 999px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
    font-size: 0 !important;
    overflow: hidden !important;
}

.ahd-voice-btn[hidden] {
    display: none !important;
}

.ahd-voice-btn .ahd-voice-icon {
    width: 21px !important;
    height: 21px !important;
    display: block !important;
    fill: none !important;
    stroke: currentColor !important;
    stroke-width: 2.2 !important;
    stroke-linecap: round !important;
    stroke-linejoin: round !important;
    pointer-events: none !important;
}

.ahd-voice-btn .ahd-voice-icon-stop {
    display: none !important;
    fill: currentColor !important;
    stroke: none !important;
}

.ahd-voice-btn.is-recording .ahd-voice-icon-mic {
    display: none !important;
}

.ahd-voice-btn.is-recording .ahd-voice-icon-stop {
    display: block !important;
}

.ahd-widget-footer,
.ahd-input-row,
.ahd-compose,
.ahd-chat-form {
    gap: 8px !important;
}


/* =========================================================
   v1.10.0 - Indicador "escribiendo" del agente
   ========================================================= */

.ahd-typing-wrap {
    opacity: 1;
}

.ahd-typing-bubble {
    width: auto !important;
    min-width: 58px !important;
    max-width: 86px !important;
    min-height: 34px !important;
    padding: 11px 14px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 5px !important;
    background: linear-gradient(135deg, #2563eb, #3b82f6) !important;
    border-radius: 10px 16px 16px 16px !important;
    box-shadow: 0 10px 20px rgba(37, 99, 235, .22) !important;
    white-space: normal !important;
}

.ahd-typing-bubble span {
    width: 7px !important;
    height: 7px !important;
    display: block !important;
    border-radius: 999px !important;
    background: #ffffff !important;
    opacity: .45;
    animation: ahdTypingDot 1.1s infinite ease-in-out;
}

.ahd-typing-bubble span:nth-child(2) {
    animation-delay: .16s;
}

.ahd-typing-bubble span:nth-child(3) {
    animation-delay: .32s;
}

@keyframes ahdTypingDot {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: .45;
    }

    40% {
        transform: translateY(-4px);
        opacity: 1;
    }
}


/* =========================================================
   v1.10.1 - Indicador de escritura más natural
   ========================================================= */

.ahd-typing-bubble span {
    animation-duration: 1.45s !important;
}

.ahd-typing-bubble span:nth-child(2) {
    animation-delay: .22s !important;
}

.ahd-typing-bubble span:nth-child(3) {
    animation-delay: .44s !important;
}
