/**
 * AS Norte — Chat widget
 * Etapa 2. Estilos del chatbox flotante.
 *
 * Paleta derivada de la identidad AS Norte:
 *   --asn-azul      #1E3A6E  (corporativo)
 *   --asn-azul-med  #2B5BA8  (acento secundario)
 *   --asn-azul-claro#E6F1FB  (fondos suaves / burbuja asesor)
 *   --asn-verde     #1EB954  (acción / online)
 *   --asn-tinta     #0F2040  (texto fuerte)
 */

.asn-chat {
    --asn-azul: #1E3A6E;
    --asn-azul-med: #2B5BA8;
    --asn-azul-claro: #E6F1FB;
    --asn-verde: #1EB954;
    --asn-tinta: #0F2040;
    --asn-gris: #6B7280;
    --asn-borde: #E5E7EB;
    --asn-radio: 16px;
    --asn-sombra: 0 12px 40px rgba(15, 32, 64, 0.18);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Caja de variables a nivel raíz del widget para que apliquen a hijos */
#asn-chat-root {
    --asn-azul: #1E3A6E;
    --asn-azul-med: #2B5BA8;
    --asn-azul-claro: #E6F1FB;
    --asn-verde: #1EB954;
    --asn-tinta: #0F2040;
    --asn-gris: #6B7280;
    --asn-borde: #E5E7EB;
    --asn-radio: 16px;
    --asn-sombra: 0 12px 40px rgba(15, 32, 64, 0.18);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ─── Botón flotante ─────────────────────────────────────────────── */
.asn-chat-launcher {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--asn-azul);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: var(--asn-sombra);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99998;
    transition: transform 0.18s ease, background 0.18s ease;
}
.asn-chat-launcher:hover {
    transform: translateY(-2px) scale(1.04);
    background: var(--asn-azul-med);
}
.asn-chat-launcher svg { width: 28px; height: 28px; }

/* Puntito verde "online" cuando hay atención */
.asn-chat-launcher .asn-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--asn-verde);
    border: 2.5px solid #fff;
    display: block;
}
.asn-chat-launcher.asn-online .asn-dot { background: var(--asn-verde); }
.asn-chat-launcher.asn-offline .asn-dot { background: #E5484D; }

/* ─── Panel del chat ─────────────────────────────────────────────── */
.asn-chat-panel {
    position: fixed;
    right: 24px;
    bottom: 96px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: var(--asn-radio);
    box-shadow: var(--asn-sombra);
    z-index: 99999;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.asn-chat-panel.asn-open { display: flex; }

/* Header */
.asn-chat-header {
    background: var(--asn-azul);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.asn-chat-header .asn-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.asn-chat-header .asn-h-info { flex: 1; min-width: 0; }
.asn-chat-header .asn-h-title { font-weight: 700; font-size: 15px; line-height: 1.2; }
.asn-chat-header .asn-h-status { font-size: 12px; opacity: 0.85; margin-top: 2px; }
.asn-chat-header .asn-h-status .asn-status-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--asn-verde);
    margin-right: 5px;
    vertical-align: middle;
}
.asn-chat-header .asn-h-status.asn-offline .asn-status-dot { background: #E5484D; }
.asn-chat-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    opacity: 0.85;
    padding: 4px;
    font-size: 20px;
    line-height: 1;
}
.asn-chat-close:hover { opacity: 1; }

/* Cuerpo de mensajes */
.asn-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    background: #F9FAFB;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Burbujas */
.asn-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.asn-msg-bot, .asn-msg-asesor {
    align-self: flex-start;
    background: #fff;
    color: var(--asn-tinta);
    border: 1px solid var(--asn-borde);
    border-bottom-left-radius: 4px;
}
.asn-msg-asesor {
    background: var(--asn-azul-claro);
    border-color: #CFE2F7;
}
.asn-msg-user {
    align-self: flex-end;
    background: var(--asn-azul);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.asn-msg-meta {
    font-size: 10px;
    color: var(--asn-gris);
    margin-top: 3px;
    align-self: flex-start;
}
.asn-msg-user + .asn-msg-meta { align-self: flex-end; }

/* Botones de opción (categorías, etc.) */
.asn-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}
.asn-option-btn {
    background: #fff;
    border: 1.5px solid var(--asn-azul-med);
    color: var(--asn-azul);
    padding: 9px 14px;
    border-radius: 22px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.asn-option-btn:hover {
    background: var(--asn-azul);
    color: #fff;
}
.asn-option-btn .asn-emoji { margin-right: 5px; }

/* Indicador "escribiendo" */
.asn-typing {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--asn-borde);
    border-radius: 14px;
    padding: 12px 14px;
    display: flex;
    gap: 4px;
}
.asn-typing span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #B6BECC;
    animation: asn-bounce 1.2s infinite ease-in-out;
}
.asn-typing span:nth-child(2) { animation-delay: 0.15s; }
.asn-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes asn-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* Indicador de estado "conectando con asesor" (no es una burbuja) */
.asn-chat-estado {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    margin: 4px auto 0;
    font-size: 12.5px;
    color: var(--asn-gris);
    background: var(--asn-azul-claro);
    border-radius: 20px;
    max-width: 90%;
    text-align: center;
}
.asn-chat-estado.asn-visible { display: flex; }
.asn-chat-estado .asn-estado-dots {
    display: inline-flex;
    gap: 3px;
}
.asn-chat-estado .asn-estado-dots span {
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--asn-azul-med);
    animation: asn-bounce 1.2s infinite ease-in-out;
}
.asn-chat-estado .asn-estado-dots span:nth-child(2) { animation-delay: 0.15s; }
.asn-chat-estado .asn-estado-dots span:nth-child(3) { animation-delay: 0.3s; }

/* Banner reducido de fuera de horario (al inicio del flujo) */
.asn-chat-banner-offline {
    margin: 10px 12px 4px;
    padding: 9px 12px;
    background: #FFF4E0;
    border: 1px solid #F0D284;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.45;
    color: #7A5C12;
    text-align: center;
}

/* Aviso destacado de fuera de horario */
.asn-chat-aviso-fuera {
    margin: 12px;
    padding: 18px 16px;
    background: linear-gradient(180deg, #FFF8E6 0%, #FFF1CC 100%);
    border: 1px solid #F0D284;
    border-radius: 14px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.asn-chat-aviso-fuera .asn-aviso-icono {
    font-size: 28px;
    margin-bottom: 8px;
}
.asn-chat-aviso-fuera .asn-aviso-texto {
    font-size: 13.5px;
    line-height: 1.55;
    color: #5C4A1A;
    text-align: left;
}
.asn-chat-aviso-fuera .asn-reabrir {
    margin-top: 14px;
    background: var(--asn-azul);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.asn-chat-aviso-fuera .asn-reabrir:hover { background: var(--asn-azul-med); }
.asn-chat-footer {
    border-top: 1px solid var(--asn-borde);
    padding: 12px;
    display: flex;
    gap: 8px;
    background: #fff;
}
.asn-chat-footer input[type="text"],
.asn-chat-footer input[type="email"],
.asn-chat-footer input[type="tel"] {
    flex: 1;
    border: 1.5px solid var(--asn-borde);
    border-radius: 22px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s ease;
}
.asn-chat-footer input:focus { border-color: var(--asn-azul-med); }
.asn-chat-send {
    background: var(--asn-azul);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 42px; height: 42px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease;
}
.asn-chat-send:hover { background: var(--asn-azul-med); }
.asn-chat-send:disabled { background: #C7CDD6; cursor: not-allowed; }
.asn-chat-send svg { width: 18px; height: 18px; }

/* Aviso de chat cerrado */
.asn-chat-cerrado {
    text-align: center;
    padding: 14px;
    font-size: 13px;
    color: var(--asn-gris);
    background: #F3F4F6;
    border-top: 1px solid var(--asn-borde);
}
.asn-chat-cerrado button {
    margin-top: 8px;
    background: var(--asn-azul);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

/* Scrollbar discreto */
.asn-chat-body::-webkit-scrollbar { width: 6px; }
.asn-chat-body::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 3px;
}

/* Responsive: ocupar casi toda la pantalla en mobile */
@media (max-width: 480px) {
    .asn-chat-panel {
        right: 0;
        bottom: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
    }
    .asn-chat-launcher { right: 16px; bottom: 16px; }
}

/* Respetar reduce-motion */
@media (prefers-reduced-motion: reduce) {
    .asn-chat-launcher, .asn-option-btn, .asn-chat-send { transition: none; }
    .asn-typing span { animation: none; }
}
