/* -------- Foxy Chat Bot -------- */

.foxy-chat-launcher {
    position: fixed;
    right: 18px;
    bottom: 30px;
    width: 60px;
    height: auto;
    border: none;
    background: none;
    color: #fff;
    z-index: 20000 !important;
    display: block !important;
    padding: 0;
    margin: 0;
    line-height: 0;
    box-shadow: none;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.foxy-chat-launcher:hover,
.foxy-chat-launcher:focus {
    transform: scale(1.1);
    outline: none;
}

/* Solo la imagen de Foxy a su proporción natural, sin caja ni fondo. */
.foxy-chat-launcher-img {
    width: 100%;
    height: auto;
    object-fit: contain;
    display: block !important;
    background: transparent !important;
    border: none;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    filter: drop-shadow(0 12px 26px rgba(0, 0, 0, 0.5));
}

/* Burbuja de saludo junto al Foxy flotante */
.foxy-chat-bubble {
    position: absolute;
    right: calc(100% + 6px);
    top: 50%;
    transform: translateY(-50%);
    background: #fff;
    color: #0b283f;
    padding: 8px 14px;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Flecha de la burbuja apuntando a Foxy */
.foxy-chat-bubble::after {
    content: '';
    position: absolute;
    right: -7px;
    top: 50%;
    transform: translateY(-50%);
    border-left: 8px solid #fff;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
}

/* Ocultar la burbuja cuando el chat está abierto */
.foxy-chat-launcher[aria-expanded="true"] .foxy-chat-bubble {
    opacity: 0;
}

/* Desaparición progresiva de la burbuja a los 3 segundos */
.foxy-chat-bubble--hide {
    opacity: 0 !important;
    transform: translateY(-50%) scale(0.9);
}

/* Badge de nuevo mensaje */
.foxy-chat-launcher-nudge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: #e53935;
    color: #fff;
    font-size: 10px;
    line-height: 18px;
    font-weight: 700;
    text-align: center;
    display: none;
}

.foxy-chat-launcher-nudge.show {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Puerto de la ventana */
.foxy-chat-window {
    position: fixed;
    right: 18px;
    bottom: 120px;
    width: 360px;
    max-width: calc(100vw - 24px);
    height: 500px;
    max-height: calc(100vh - 170px);
    z-index: 20001 !important;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.foxy-chat-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.foxy-chat-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: #0b283f;
    color: #fff;
}

.foxy-chat-header-img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    padding: 3px;
    flex-shrink: 0;
}

.foxy-chat-header__text {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
}

.foxy-chat-header__text strong {
    display: block;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.3px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.foxy-chat-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.foxy-chat-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ecc71;
    box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.6);
    animation: foxy-pulse 1.8s infinite;
}

@keyframes foxy-pulse {
    0% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.5); }
    70% { box-shadow: 0 0 0 8px rgba(46, 204, 113, 0); }
    100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

/* Botón de cierre en la esquina superior derecha */
.foxy-chat-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.9;
    transition: opacity 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.foxy-chat-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.22);
    transform: scale(1.06);
}

.foxy-chat-close:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.7);
    outline-offset: 2px;
}

/* Botón "Limpiar conversación" en la cabecera */
.foxy-chat-clear {
    position: absolute;
    top: 10px;
    right: 44px;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #fff;
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.9;
    transition: opacity 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.foxy-chat-clear:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.22);
    transform: scale(1.06);
}

.foxy-chat-clear:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.7);
    outline-offset: 2px;
}

/* El texto del header no debe chocar con la X */
.foxy-chat-header {
    padding-right: 44px;
}

/* Body */
.foxy-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f4f6f8;
}

.foxy-chat-body::-webkit-scrollbar {
    width: 6px;
}

.foxy-chat-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 3px;
}

/* Burbujas */
.foxy-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.foxy-msg.user {
    align-self: flex-end;
    background: #0b283f;
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(15, 63, 95, 0.22);
}

.foxy-msg.bot {
    align-self: flex-start;
    background: #fff;
    color: #22303c;
    border: 1px solid rgba(15, 63, 95, 0.08);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.foxy-msg.bot.error {
    background: #fdecea;
    border-color: #f5c6c2;
    color: #a94442;
}

/* Tarjeta de persona/unidad (foto + nombre + cargo) */
.foxy-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
    text-decoration: none;
    margin-bottom: 6px;
    transition: box-shadow 0.15s ease;
    align-self: flex-start;
    max-width: 82%;
}

.foxy-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.foxy-card-img {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: #eceff1;
}

.foxy-card-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.3;
}

.foxy-card-info strong {
    font-size: 14px;
    color: #0b283f;
}

.foxy-card-info span {
    font-size: 12px;
    color: #6b7785;
}

/* Fuentes / enlaces de "más información" */
.foxy-sources {
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: #f0f4f8;
    border-left: 3px solid #0b283f;
    width: fit-content;
}

.foxy-sources-label {
    font-size: 11px;
    font-weight: 600;
    color: #0b283f;
    margin-bottom: 4px;
}

.foxy-sources-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.foxy-sources-link {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 14px;
    background: #0b283f;
    color: #fff !important;
    font-size: 12px;
    text-decoration: none;
    transition: background 0.15s ease;
}

.foxy-sources-link:hover {
    background: #165c86;
}

/* Cursor de escritura */
.foxy-msg.bot.streaming::after {
    content: '▍';
    opacity: 1;
    animation: foxy-blink 1s steps(2, start) infinite;
}

@keyframes foxy-blink {
    50% { opacity: 0; }
}

/* Indicador "escribiendo" */
.foxy-typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 2px 0;
}

.foxy-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9aa4af;
    animation: foxy-bounce 1.2s infinite ease-in-out;
}

.foxy-typing span:nth-child(2) { animation-delay: 0.15s; }
.foxy-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes foxy-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* Footer */
.foxy-chat-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, 0.07);
}

.foxy-chat-input {
    flex: 1;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 20px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s ease;
    background: #f8f9fa;
}

.foxy-chat-input:focus {
    border-color: #0b283f;
    background: #fff;
}

.foxy-chat-submit {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #0b283f;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.15s ease;
}

.foxy-chat-submit:hover {
    background: #154e73;
    transform: scale(1.05);
}

.foxy-chat-submit:disabled {
    background: #b0b7bf;
    cursor: not-allowed;
    transform: none;
}

/* Botones inline (reintentar / limpiar) */
.foxy-chat-actions {
    display: flex;
    gap: 8px;
    padding: 0 16px 12px;
    background: #f4f6f8;
}

.foxy-chat-action-btn {
    border: 1px solid #0b283f;
    background: transparent;
    color: #0b283f;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.foxy-chat-action-btn:hover {
    background: #0b283f;
    color: #fff;
}

/* Ajustes responsive */
@media (max-width: 640px) {
    .foxy-chat-launcher {
        right: 12px;
        bottom: 30px;
        width: 52px;
        height: auto;
    }
    .foxy-chat-launcher-img {
        width: 100%;
        height: auto;
    }
    .foxy-chat-bubble {
        right: calc(100% + 3px);
        padding: 7px 12px;
        font-size: 12px;
    }
    .foxy-chat-window {
        right: 8px;
        left: 8px;
        top: 8px;
        bottom: 8px;
        width: auto;
        max-width: none;
        max-height: none;
        height: auto;
        border-radius: 14px;
    }
    .foxy-msg {
        max-width: 88%;
    }
}

@media (max-width: 380px) {
    .foxy-chat-window {
        right: 6px;
        left: 6px;
        top: 6px;
        bottom: 6px;
        max-height: none;
        height: auto;
        border-radius: 12px;
    }
    .foxy-chat-header {
        padding: 12px 12px 12px;
        padding-right: 42px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .foxy-chat-dot,
    .foxy-msg.bot.streaming::after,
    .foxy-typing span {
        animation: none !important;
    }
}

/* Coloca el botón "scroll to top" por encima del botón de Foxy. */
.progress-wrap {
    bottom: 126px;
}

@media (max-width: 640px) {
    .progress-wrap {
        bottom: 110px;
        right: 12px;
    }
}
