/* ===================================================
   CHATBOT LATENTE - Widget de Chat (Rediseño moderno)
   =================================================== */

/* Ocultar botón flotante de WhatsApp (reemplazado por el chatbot) */
#whatsapp-float {
    display: none !important;
}

/* ===================================================
   Botón WhatsApp directo (encima del toggle chatbot)
   =================================================== */

#latente-wa-direct {
    position: fixed;
    bottom: 104px;
    right: 28px;
    z-index: 9999;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(145deg, #2fd366 0%, #075e54 100%);
    box-shadow: 0 6px 24px rgba(37, 211, 102, 0.5), 0 2px 8px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    overflow: visible;
    transform-origin: bottom right;
    transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1),
                box-shadow 0.3s ease;
    outline: none;
}

#latente-wa-direct::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    background: rgba(37, 211, 102, 0.25);
    animation: wa-direct-pulse 2.5s ease-in-out infinite;
    pointer-events: none;
}

@keyframes wa-direct-pulse {
    0%, 100% { transform: scale(1);    opacity: 0.6; }
    50%       { transform: scale(1.38); opacity: 0; }
}

#latente-wa-direct svg {
    width: 30px;
    height: 30px;
    fill: #fff;
    display: block;
    flex-shrink: 0;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.2));
}

#latente-wa-direct:hover {
    transform: scale(1.08);
    box-shadow: 0 10px 32px rgba(37,211,102,0.65), 0 4px 12px rgba(0,0,0,0.3);
}

#latente-wa-direct:active {
    transform: scale(0.96);
}

/* Tooltip label */
#latente-wa-direct .wa-direct-label {
    position: absolute;
    right: 72px;
    top: 50%;
    transform: translateY(-50%) translateX(6px);
    background: rgba(15,15,15,0.92);
    backdrop-filter: blur(6px);
    color: #fff;
    font-family: 'Raleway', Arial, sans-serif;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: 0.4px;
    white-space: nowrap;
    padding: 7px 14px;
    border-radius: 30px;
    border: 1px solid rgba(37,211,102,0.35);
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

#latente-wa-direct:hover .wa-direct-label {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* ===================================================
   Botón toggle flotante
   =================================================== */

#latente-chatbot-toggle {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9999;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(145deg, #e4b346 0%, #8a5a14 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(196, 135, 42, 0.55), 0 2px 8px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: bottom right;
    transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1),
                box-shadow 0.3s ease,
                opacity 0.3s ease;
    outline: none;
    overflow: visible;
}

/* Anillo pulsante de fondo */
#latente-chatbot-toggle::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    background: rgba(196, 135, 42, 0.28);
    animation: cb-ring-pulse 2.5s ease-in-out infinite;
    pointer-events: none;
}

#latente-chatbot-toggle.is-open::before {
    animation: none;
    opacity: 0;
}

/* Botón oculto cuando el chat está abierto */
#latente-chatbot-toggle.is-open {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

@keyframes cb-ring-pulse {
    0%, 100% { transform: scale(1);    opacity: 0.6; }
    50%       { transform: scale(1.38); opacity: 0; }
}

#latente-chatbot-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 10px 32px rgba(196,135,42,0.7), 0 4px 12px rgba(0,0,0,0.3);
}

#latente-chatbot-toggle:active {
    transform: scale(0.96);
}

#latente-chatbot-toggle svg {
    width: 30px;
    height: 30px;
    fill: #fff;
    display: block;
    flex-shrink: 0;
    /* Posición absoluta centrada — los dos SVGs se superponen exactamente */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.2));
}

#latente-chatbot-toggle .cb-icon-close {
    display: block;
    opacity: 0;
    transform: translate(-50%, -50%) rotate(-90deg);
    pointer-events: none;
}

#latente-chatbot-toggle.is-open .cb-icon-chat {
    opacity: 0;
    pointer-events: none;
}

#latente-chatbot-toggle.is-open .cb-icon-close {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg);
    pointer-events: auto;
}

/* Badge de notificación */
#latente-chatbot-toggle .cb-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, #ff5f3e, #d94b27);
    border-radius: 50%;
    font-size: 10px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: Arial, sans-serif;
    font-weight: 800;
    animation: cb-badge-pop 2.2s ease-in-out infinite;
    letter-spacing: 0;
}

@keyframes cb-badge-pop {
    0%, 100% { transform: scale(1); }
    30%       { transform: scale(1.25); }
    50%       { transform: scale(1.1); }
}

/* Mini badge WhatsApp */
#latente-chatbot-toggle .cb-wa-mini {
    position: absolute;
    bottom: -4px;
    left: -4px;
    width: 22px;
    height: 22px;
    background: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
    transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.2s ease;
    z-index: 2;
}

#latente-chatbot-toggle .cb-wa-mini svg {
    width: 12px !important;
    height: 12px !important;
    fill: #25d366 !important;
    filter: none !important;
    transition: none !important;
}

#latente-chatbot-toggle.is-open .cb-wa-mini {
    transform: scale(0);
    opacity: 0;
}

/* Tooltip label */
#latente-chatbot-toggle .cb-label {
    position: absolute;
    right: 72px;
    top: 50%;
    transform: translateY(-50%) translateX(6px);
    background: rgba(15,15,15,0.92);
    backdrop-filter: blur(6px);
    color: #f0d898;
    font-family: 'Raleway', Arial, sans-serif;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: 0.4px;
    white-space: nowrap;
    padding: 7px 14px;
    border-radius: 30px;
    border: 1px solid rgba(228,179,84,0.28);
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

#latente-chatbot-toggle:hover .cb-label,
#latente-chatbot-toggle:not(.is-open) .cb-label.cb-label-visible {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

#latente-chatbot-toggle.is-open .cb-label {
    display: none;
}

/* ===================================================
   Ventana del chat
   =================================================== */

#latente-chatbot-window {
    position: fixed;
    bottom: 18px;
    right: 28px;
    z-index: 10000;
    width: 345px;
    max-height: 600px;
    border-radius: 22px;
    overflow: hidden;
    box-shadow:
        0 24px 60px rgba(0,0,0,0.65),
        0 0 0 1px rgba(255,255,255,0.06),
        inset 0 1px 0 rgba(255,255,255,0.07);
    display: flex;
    flex-direction: column;
    background: #111111;
    transform: scale(0.88) translateY(18px);
    transform-origin: bottom right;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1), opacity 0.28s ease;
}

#latente-chatbot-window.is-visible {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* ===================================================
   Header
   =================================================== */

.cb-header {
    background: linear-gradient(135deg, #c4872a 0%, #8a5a14 100%);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

/* Textura sutil en el header */
.cb-header::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.09) 0%, transparent 100%);
    pointer-events: none;
}

.cb-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: rgba(255,255,255,0.18);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.cb-header-avatar svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}

.cb-header-info {
    flex: 1;
    position: relative;
    z-index: 1;
    min-width: 0;
}

.cb-header-info strong {
    display: block;
    color: #fff;
    font-family: 'Raleway', Arial, sans-serif;
    font-size: 14.5px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cb-header-info span {
    font-size: 11px;
    color: rgba(255,255,255,0.75);
    font-family: Arial, sans-serif;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
    letter-spacing: 0.2px;
}

.cb-online-dot {
    width: 6px;
    height: 6px;
    background: #5ef08a;
    border-radius: 50%;
    box-shadow: 0 0 6px rgba(94, 240, 138, 0.9);
    animation: cb-blink 2.5s ease-in-out infinite;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

@keyframes cb-blink {
    0%, 100% { opacity: 1;   box-shadow: 0 0 8px rgba(94,240,138,0.9); }
    50%       { opacity: 0.5; box-shadow: 0 0 3px rgba(94,240,138,0.4); }
}

/* ===================================================
   Área de mensajes
   =================================================== */

.cb-messages {
    flex: 1;
    min-height: 0;            /* esencial para que flex + overflow funcione */
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 22px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 400px;
    scrollbar-width: thin;
    scrollbar-color: #2a2a2a transparent;
    background:
        radial-gradient(ellipse at top left, rgba(196,135,42,0.05) 0%, transparent 60%),
        #111111;
}

.cb-messages::-webkit-scrollbar       { width: 3px; }
.cb-messages::-webkit-scrollbar-track { background: transparent; }
.cb-messages::-webkit-scrollbar-thumb { background: #282828; border-radius: 4px; }

/* ===================================================
   Burbujas de mensaje
   =================================================== */

.cb-msg-bot,
.cb-msg-user {
    max-width: 82%;
    padding: 11px 15px;
    border-radius: 18px;
    font-size: 13.5px;
    line-height: 1.6;
    font-family: 'SF Pro Text', -apple-system, Arial, sans-serif;
    animation: cb-msg-in 0.3s cubic-bezier(0.34,1.56,0.64,1);
    white-space: pre-line;
}

@keyframes cb-msg-in {
    from { opacity: 0; transform: translateY(10px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)  scale(1); }
}

.cb-msg-bot {
    background: #1e1e1e;
    color: #e2e2e2;
    border-bottom-left-radius: 5px;
    align-self: flex-start;
    border: 1px solid rgba(255,255,255,0.07);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.cb-msg-user {
    background: linear-gradient(135deg, #d49a38 0%, #b07220 100%);
    color: #fff;
    border-bottom-right-radius: 5px;
    align-self: flex-end;
    box-shadow: 0 3px 10px rgba(196,135,42,0.4);
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* ===================================================
   Typing indicator
   =================================================== */

.cb-typing {
    display: flex;
    gap: 5px;
    padding: 11px 15px;
    background: #1e1e1e;
    border-radius: 18px;
    border-bottom-left-radius: 5px;
    align-self: flex-start;
    border: 1px solid rgba(255,255,255,0.07);
    width: fit-content;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.cb-typing span {
    width: 7px;
    height: 7px;
    background: #555;
    border-radius: 50%;
    animation: cb-typing-bounce 1.4s ease-in-out infinite;
}

.cb-typing span:nth-child(1) { animation-delay: 0s; }
.cb-typing span:nth-child(2) { animation-delay: 0.18s; }
.cb-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes cb-typing-bounce {
    0%, 60%, 100% { transform: translateY(0);  background: #444; }
    30%            { transform: translateY(-7px); background: #cfa144; }
}

/* ===================================================
   Quick replies
   =================================================== */

.cb-quick-replies {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-top: 8px;
    align-self: stretch;
    width: 100%;
    animation: cb-msg-in 0.35s cubic-bezier(0.34,1.4,0.64,1);
}

.cb-quick-reply-btn {
    background: rgba(196, 135, 42, 0.08);
    border: 1px solid rgba(196, 135, 42, 0.35);
    color: #d4a44c;
    padding: 13px 16px 13px 18px;
    border-radius: 14px;
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    font-family: 'Raleway', Arial, sans-serif;
    font-weight: 600;
    letter-spacing: 0.25px;
    transition:
        background 0.22s ease,
        color 0.22s ease,
        border-color 0.22s ease,
        transform 0.18s ease,
        box-shadow 0.22s ease;
    outline: none;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Chevron decorativo */
.cb-quick-reply-btn::after {
    content: '›';
    font-size: 18px;
    line-height: 1;
    color: rgba(196,135,42,0.45);
    flex-shrink: 0;
    margin-left: 8px;
    transition: transform 0.18s ease, color 0.18s ease;
}

.cb-quick-reply-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(196,135,42,0.12) 0%, transparent 60%);
    opacity: 0;
    transition: opacity 0.22s ease;
    border-radius: inherit;
}

.cb-quick-reply-btn:hover {
    background: rgba(196, 135, 42, 0.22);
    border-color: rgba(196, 135, 42, 0.7);
    color: #f0c96a;
    transform: translateX(4px);
    box-shadow: 0 3px 12px rgba(196,135,42,0.22);
}

.cb-quick-reply-btn:hover::before {
    opacity: 1;
}

.cb-quick-reply-btn:hover::after {
    transform: translateX(3px);
    color: #f0c96a;
}

.cb-quick-reply-btn:active {
    transform: translateX(2px) scale(0.99);
}

.cb-quick-reply-btn.cb-agent-btn {
    background: rgba(37, 211, 102, 0.08);
    border-color: rgba(37, 211, 102, 0.45);
    color: #25d366;
    font-weight: 700;
}

.cb-quick-reply-btn.cb-agent-btn::before {
    background: linear-gradient(90deg, rgba(37,211,102,0.1) 0%, transparent 60%);
}

.cb-quick-reply-btn.cb-agent-btn:hover {
    background: rgba(37, 211, 102, 0.2);
    border-color: rgba(37, 211, 102, 0.8);
    color: #2eea73;
    box-shadow: 0 3px 12px rgba(37,211,102,0.25);
}

/* Botón disparador de preguntas frecuentes — destacado, centrado */
.cb-quick-reply-btn.cb-faq-trigger-btn {
    background: linear-gradient(135deg, rgba(196,135,42,0.18) 0%, rgba(139,88,14,0.10) 100%);
    border: 1.5px solid rgba(196,135,42,0.55);
    color: #e8c068;
    font-weight: 700;
    letter-spacing: 0.4px;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 2px 12px rgba(196,135,42,0.14);
}

.cb-quick-reply-btn.cb-faq-trigger-btn::after {
    display: none; /* sin chevron lateral */
}

.cb-quick-reply-btn.cb-faq-trigger-btn:hover {
    background: linear-gradient(135deg, rgba(196,135,42,0.35) 0%, rgba(139,88,14,0.22) 100%);
    border-color: rgba(196,135,42,0.85);
    color: #fcd96a;
    box-shadow: 0 4px 18px rgba(196,135,42,0.30);
    transform: translateY(-2px);
}

/* Botón Enviarnos un mensaje — CTA diferenciado, paleta Latente */
.cb-quick-reply-btn.cb-mail-btn {
    background: linear-gradient(135deg, rgba(196,135,42,0.32) 0%, rgba(139,88,14,0.22) 100%);
    border: 1.5px solid rgba(212,165,50,0.65);
    color: #fcd96a;
    box-shadow: 0 2px 10px rgba(196,135,42,0.18), inset 0 1px 0 rgba(255,220,100,0.08);
}

.cb-quick-reply-btn.cb-mail-btn::after {
    color: rgba(252,217,106,0.6);
}

.cb-quick-reply-btn.cb-mail-btn::before {
    background: linear-gradient(90deg, rgba(212,169,58,0.22) 0%, transparent 60%);
}

.cb-quick-reply-btn.cb-mail-btn:hover {
    background: linear-gradient(135deg, rgba(196,135,42,0.5) 0%, rgba(139,88,14,0.38) 100%);
    border-color: rgba(212,169,58,0.9);
    color: #ffe484;
    box-shadow: 0 4px 18px rgba(196,135,42,0.4), inset 0 1px 0 rgba(255,230,120,0.12);
}

/* ===================================================
   Footer
   =================================================== */

.cb-footer {
    padding: 9px 14px;
    border-top: 1px solid rgba(255,255,255,0.05);
    background: rgba(0,0,0,0.25);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.cb-footer-text {
    font-size: 10px;
    color: rgba(255,255,255,0.2);
    font-family: Arial, sans-serif;
    text-align: center;
    letter-spacing: 0.3px;
}

.cb-footer-text a {
    color: rgba(207,161,68,0.5);
    text-decoration: none;
}

/* ===================================================
   Envoltorio de mensaje + timestamp
   =================================================== */

.cb-msg-wrap {
    display: flex;
    flex-direction: column;
}
.cb-msg-wrap-bot  { align-items: flex-start; }
.cb-msg-wrap-user { align-items: flex-end; }

.cb-timestamp {
    font-size: 9px;
    color: rgba(255,255,255,0.22);
    font-family: Arial, sans-serif;
    margin-top: 3px;
    padding: 0 4px;
    user-select: none;
}

/* ===================================================
   Botón cerrar (X) en header
   =================================================== */

.cb-close-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    margin-left: 4px;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
}
.cb-close-btn svg {
    width: 18px;
    height: 18px;
    fill: rgba(255,255,255,0.65);
    display: block;
}
.cb-close-btn:hover {
    background: rgba(255,255,255,0.15);
}
.cb-close-btn:hover svg {
    fill: #fff;
}

/* ===================================================
   Área de input libre
   =================================================== */

.cb-input-area {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 14px;
    border-top: 1px solid rgba(255,255,255,0.06);
    background: rgba(0,0,0,0.2);
    flex-shrink: 0;
}

.cb-input {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.10);
    color: #e2e2e2;
    border-radius: 22px;
    padding: 10px 18px;
    font-size: 13px;
    font-family: Arial, sans-serif;
    outline: none;
    transition: border-color 0.22s, background 0.22s, box-shadow 0.22s;
    min-width: 0;
}
.cb-input::placeholder {
    color: rgba(255,255,255,0.30);
}
.cb-input:focus {
    border-color: rgba(196,135,42,0.55);
    background: rgba(255,255,255,0.09);
    box-shadow: 0 0 0 3px rgba(196,135,42,0.08);
}

.cb-send-btn {
    background: transparent;
    border: none;
    border-radius: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.18s ease, opacity 0.18s ease;
    box-shadow: none;
    padding: 0;
}
.cb-send-btn::after {
    content: '';
    display: block;
    width: 11px;
    height: 11px;
    border-top: 2.5px solid #d4a44c;
    border-right: 2.5px solid #d4a44c;
    transform: rotate(45deg) translateX(-2px);
    flex-shrink: 0;
}
.cb-send-btn svg {
    display: none;
}
.cb-send-btn:hover::after {
    border-color: #f0c96a;
}
.cb-send-btn:hover {
    transform: translateX(3px);
    opacity: 1;
}
.cb-send-btn:active {
    transform: translateX(1px);
}

/* ===================================================
   Flujo de email — input en modo captura de datos
   =================================================== */

/* El input parpadea sutilmente cuando el bot espera un dato */
.cb-input[placeholder="Tu nombre..."],
.cb-input[placeholder="Tu email..."],
.cb-input[placeholder="Tu mensaje..."] {
    border-color: rgba(196,135,42,0.5);
    background: rgba(255,255,255,0.08);
    box-shadow: 0 0 0 3px rgba(196,135,42,0.07);
}

/* Mensaje del bot con aspecto de "paso de formulario" */
.cb-msg-bot.cb-mail-step {
    border-left: 2px solid rgba(196,135,42,0.5);
    padding-left: 13px;
}

/*
   BASELINE (≥ 769px, escritorio estándar):
   Toggle 64px · Ventana 370px · max-height 580px
   — Estos son los valores ya definidos arriba —
*/

/* La ventana nunca supera el alto visible (pantallas cortas) */
#latente-chatbot-window {
    max-height: min(600px, calc(100vh - 36px));
}

/* Desktop grande (≥ 1280px) */
@media (min-width: 1280px) {
    #latente-chatbot-window {
        width: 385px;
        max-height: min(680px, calc(100vh - 36px));
        right: 28px;
        bottom: 18px;
    }

    #latente-chatbot-toggle {
        right: 32px;
        bottom: 28px;
        width: 62px;
        height: 62px;
    }

    #latente-chatbot-toggle svg {
        width: 30px;
        height: 30px;
    }

    #latente-chatbot-toggle .cb-label {
        right: 72px;
    }

    .cb-messages {
        min-height: 260px;
        max-height: min(480px, calc(100vh - 210px));
    }

    .cb-quick-reply-btn {
        padding: 12px 16px;
        font-size: 13px;
    }
}

/* Tablet (481px – 768px) */
@media (max-width: 768px) and (min-width: 481px) {
    #latente-chatbot-window {
        right: 14px;
        bottom: 14px;
        width: calc(100vw - 28px);
        max-width: 380px;
        max-height: min(calc(100vh - 28px), 640px);
        border-radius: 20px;
    }

    #latente-chatbot-toggle {
        right: 16px;
        bottom: 18px;
        width: 54px;
        height: 54px;
    }

    #latente-chatbot-toggle svg {
        width: 24px;
        height: 24px;
    }

    #latente-wa-direct {
        right: 16px;
        bottom: 86px;
        width: 54px;
        height: 54px;
    }

    #latente-wa-direct svg {
        width: 24px;
        height: 24px;
    }

    .cb-messages {
        min-height: 200px;
        max-height: min(420px, calc(100vh - 200px));
    }
}

/* Móvil (≤ 480px) — sheet nativo a pantalla completa */
@media (max-width: 480px) {
    #latente-chatbot-window {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        max-width: 100%;
        /* 88dvh: levemente más bajo que antes (92dvh), el input queda
           más cerca del teclado y el sheet no ocupa casi toda la pantalla */
        max-height: 88dvh;
        height: auto;
        border-radius: 18px 18px 0 0;
        transform-origin: bottom center;
        display: flex;
        flex-direction: column;
        transition: transform 0.32s cubic-bezier(0.34,1.4,0.64,1),
                    opacity 0.25s ease;
    }

    #latente-chatbot-toggle {
        right: 16px;
        bottom: 44px;
        width: 52px;
        height: 52px;
    }

    #latente-chatbot-toggle svg {
        width: 24px;
        height: 24px;
    }

    #latente-chatbot-toggle .cb-label {
        display: none;
    }

    #latente-wa-direct {
        right: 16px;
        bottom: 110px;
        width: 52px;
        height: 52px;
    }

    #latente-wa-direct svg {
        width: 24px;
        height: 24px;
    }

    #latente-wa-direct .wa-direct-label {
        display: none;
    }

    /* Header más bajo: avatar pequeño, menos padding */
    .cb-header {
        padding: 8px 12px;
        flex-shrink: 0;
        gap: 10px;
    }

    .cb-header-avatar {
        width: 28px;
        height: 28px;
        border-radius: 7px;
    }

    .cb-header-avatar svg {
        width: 14px;
        height: 14px;
    }

    .cb-header-info strong {
        font-size: 12.5px;
    }

    .cb-header-info span {
        font-size: 10px;
        margin-top: 1px;
    }

    .cb-close-btn {
        width: 30px;
        height: 30px;
        padding: 4px;
    }

    .cb-close-btn svg {
        width: 15px;
        height: 15px;
    }

    /* Área de mensajes: flex:1 + min-height:0 la expande hasta llenar */
    .cb-messages {
        flex: 1;
        min-height: 0;
        max-height: none;
        padding: 10px 11px 8px;
        gap: 7px;
    }

    /* Burbujas más compactas — más mensajes visibles sin scroll */
    .cb-msg-bot,
    .cb-msg-user {
        max-width: 86%;
        font-size: 13px;
        padding: 8px 12px;
        line-height: 1.5;
        border-radius: 15px;
    }

    .cb-msg-bot  { border-bottom-left-radius:  4px; }
    .cb-msg-user { border-bottom-right-radius: 4px; }

    .cb-timestamp {
        font-size: 8.5px;
        margin-top: 2px;
    }

    /* Quick replies: botones menos altos, sigue siendo fácil tocarlos */
    .cb-quick-replies {
        gap: 6px;
        margin-top: 5px;
    }

    .cb-quick-reply-btn {
        padding: 9px 12px;
        font-size: 12.5px;
        border-radius: 11px;
        min-height: 40px;  /* área táctil mínima cómoda */
    }

    .cb-quick-reply-btn::after {
        font-size: 16px;
        margin-left: 6px;
    }

    /* Input ligeramente más compacto */
    .cb-input-area {
        flex-shrink: 0;
        padding: 8px 12px;
        gap: 8px;
        padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
    }

    .cb-input {
        font-size: 16px; /* evita zoom automático en iOS */
        padding: 9px 14px;
    }

    .cb-send-btn {
        width: 32px;
        height: 32px;
    }

    .cb-send-btn::after {
        width: 9px;
        height: 9px;
    }

    /* Footer oculto en móvil — gana espacio para mensajes */
    .cb-footer {
        display: none;
    }
}

/* Móvil muy pequeño (≤ 360px) */
@media (max-width: 360px) {
    #latente-chatbot-window {
        border-radius: 14px 14px 0 0;
    }

    .cb-messages {
        padding: 8px 10px 6px;
    }

    .cb-msg-bot,
    .cb-msg-user {
        max-width: 92%;
        font-size: 12.5px;
        padding: 7px 11px;
    }

    .cb-quick-reply-btn {
        padding: 8px 11px;
        font-size: 12px;
        min-height: 38px;
    }

    .cb-input-area {
        padding: 7px 10px;
        padding-bottom: max(7px, env(safe-area-inset-bottom, 7px));
    }

    .cb-input {
        padding: 8px 12px;
    }
}

/* Landscape móvil (pantalla baja) */
@media (max-height: 500px) {
    #latente-chatbot-window {
        max-height: calc(100dvh - 16px);
        bottom: 0;
        border-radius: 12px 12px 0 0;
    }

    #latente-chatbot-toggle {
        bottom: 12px;
    }

    .cb-messages {
        min-height: 0;
        max-height: none;
    }

    .cb-footer {
        display: none;
    }
}
