/* =========================================================
   ASISTENTE IA - DISEÑO VISUAL (FUERZA TACNA)
   ========================================================= */

#ft-chat-container {
    position: fixed;
    bottom: 4px;
    right: 4px;
    z-index: 10000; /* Siempre por encima de todo */
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    --ft-guinda: #801039;
    --ft-guinda-2: #b01455;
    --ft-amarillo: #ffc300;
    --ft-cyan: #20dff0;
}

/* --- Botón Flotante --- */
#ft-chat-fab {
    width: 168px;
    height: 168px;
    border-radius: 50%;
    flex-shrink: 0;
    aspect-ratio: 1 / 1;
    box-sizing: border-box;
    padding: 0;
    background: transparent;
    color: #ffc300;      /* Amarillo institucional */
    border: none;
    box-shadow: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.4s ease, filter 0.4s ease;
    position: relative;
    animation: fab-levitate 4s ease-in-out infinite;
}

#ft-chat-fab::before {
    content: '';
    position: absolute;
    inset: 13px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(166, 38, 83, 0.34) 0 38%, rgba(166, 38, 83, 0.16) 52%, rgba(166, 38, 83, 0) 72%);
    filter: blur(2px);
    animation: fab-aura 2.4s ease-in-out infinite;
    z-index: -1;
    pointer-events: none;
}

#ft-chat-fab::after {
    content: '';
    position: absolute;
    inset: 2px;
    border-radius: 50%;
    background:
        radial-gradient(circle at 18% 28%, rgba(174, 45, 92, 0.9) 0 3px, transparent 4px),
        radial-gradient(circle at 78% 22%, rgba(199, 70, 115, 0.85) 0 2px, transparent 3px),
        radial-gradient(circle at 88% 62%, rgba(174, 45, 92, 0.8) 0 3px, transparent 4px),
        radial-gradient(circle at 28% 84%, rgba(213, 87, 130, 0.86) 0 2px, transparent 3px),
        radial-gradient(circle at 50% 8%, rgba(174, 45, 92, 0.72) 0 2px, transparent 3px),
        radial-gradient(circle at 8% 58%, rgba(199, 70, 115, 0.78) 0 2px, transparent 3px);
    filter: drop-shadow(0 0 7px rgba(174, 45, 92, 0.62));
    opacity: 0.9;
    animation: fab-particles 5.6s linear infinite;
    z-index: -1;
    pointer-events: none;
}

#ft-chat-fab:hover {
    transform: scale(1.08) translateY(-6px);
    box-shadow: none;
    filter: brightness(1.05) drop-shadow(0 12px 18px rgba(128,16,57,0.24));
}

.ft-fab-avatar {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: visible;
    display: block;
    filter: drop-shadow(0 12px 20px rgba(128,16,57,0.30));
}

.ft-fab-avatar img,
.ft-fab-avatar video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
    pointer-events: none;
    -webkit-user-drag: none;
}

.ft-fab-avatar img {
    transition: opacity 0.16s ease;
}

.ft-fab-avatar video {
    opacity: 0;
    transition: opacity 0.16s ease;
}

.ft-fab-avatar.is-video-playing img {
    opacity: 0;
}

.ft-fab-avatar.is-video-ready.is-video-playing video {
    opacity: 1;
}

.ft-fab-avatar.is-mp4-fallback video {
    mix-blend-mode: screen;
}

/* --- Ventana Principal del Chat --- */
#ft-chat-window {
    position: absolute;
    bottom: 18px;
    right: 190px;
    width: 410px;
    height: 640px;
    max-height: 80vh;
    background: rgba(255, 255, 255, 0.85); /* Más transparente */
    backdrop-filter: blur(25px); /* Desenfoque tipo iOS mucho más fuerte */
    -webkit-backdrop-filter: blur(25px);
    border-radius: 28px; /* Curvas ultra modernas */
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.5) inset;
    border: 1px solid rgba(255, 255, 255, 0.3); /* Borde blanco sutil en vez de guinda */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    opacity: 0;
    transform: scale(0.6) translateY(30px);
    pointer-events: none;
}

/* Estados de Apertura/Cierre */
.ft-chat-open #ft-chat-window { opacity: 1; transform: scale(1) translateY(0); pointer-events: auto; }
.ft-chat-open #ft-chat-fab { opacity: 1; transform: scale(1) rotate(0) translateY(0); pointer-events: auto; }
.ft-chat-open #ft-chat-fab:hover { transform: scale(1.06) translateY(-5px); }
.ft-chat-closed #ft-chat-fab { opacity: 1; transform: scale(1) rotate(0) translateY(0); pointer-events: auto; }
.ft-chat-closed #ft-chat-fab:hover { transform: scale(1.08) translateY(-6px); }

/* --- Cabecera --- */
.ft-chat-header {
    background: linear-gradient(135deg, #801039, #9a1546);
    color: #ffc300;
    padding: 18px 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ft-chat-title {
    font-family: 'Arial Black Web', "Arial Black", Arial, sans-serif;
    font-size: 14px;
    font-weight: 900;
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ft-chat-title svg { width: 22px; height: 22px; }

#ft-chat-close {
    width: 32px; height: 32px;
    flex-shrink: 0; /* Escudo anti-elipse */
    box-sizing: border-box;
    padding: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2); 
    color: #ffc300; 
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}
#ft-chat-close:hover { 
    background: #ffc300; color: #801039; border-color: #ffc300;
    transform: rotate(90deg) scale(1.15); box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
#ft-chat-close svg { width: 16px; height: 16px; stroke-width: 3px; }

/* --- Rediseño tipo panel Luchito IA --- */
#ft-chat-window {
    background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(255,248,229,0.94));
    border: 2px solid rgba(255, 255, 255, 0.85);
    border-radius: 30px;
    box-shadow: 0 26px 70px rgba(72, 18, 32, 0.30), 0 0 0 2px rgba(255, 195, 0, 0.74), 0 0 0 5px rgba(128, 16, 57, 0.22), 0 0 34px rgba(32, 223, 240, 0.28);
    animation: chat-panel-glow 3.8s ease-in-out infinite;
}

.ft-chat-header {
    min-height: 112px;
    padding: 18px 22px;
    background:
        radial-gradient(circle at 78% 18%, rgba(255, 195, 0, 0.18), transparent 24%),
        linear-gradient(135deg, #770b35 0%, #b01455 58%, #8d103f 100%);
    border-bottom: 2px solid rgba(255, 195, 0, 0.72);
    box-shadow: inset 0 -10px 28px rgba(255, 255, 255, 0.08), 0 8px 18px rgba(128, 16, 57, 0.18);
}

.ft-chat-title {
    gap: 14px;
    letter-spacing: 0;
}

.ft-header-avatar,
.ai-message .ft-avatar {
    color: transparent;
    overflow: hidden;
    background: #fff url('../img/luchito ia.webp') center / contain no-repeat;
}

.ft-header-avatar {
    width: 76px;
    height: 76px;
    border-radius: 999px;
    border: 3px solid var(--ft-amarillo);
    box-shadow: 0 0 0 3px rgba(255,255,255,0.65), 0 0 22px rgba(255, 195, 0, 0.68);
    flex: 0 0 auto;
}

.ft-header-info span {
    display: block;
    color: var(--ft-amarillo);
    font-family: 'Arial Black Web', "Arial Black", Arial, sans-serif;
    font-size: 28px;
    line-height: 1;
    text-shadow: 0 2px 0 rgba(64, 0, 25, 0.5);
}

.ft-header-info small {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 9px;
    color: #fff;
    font-size: 15px;
    line-height: 1;
}

.ft-online-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--ft-cyan);
    box-shadow: 0 0 10px rgba(32, 223, 240, 0.9);
}

#ft-chat-close {
    width: 54px;
    height: 54px;
    color: var(--ft-amarillo);
    background: radial-gradient(circle, rgba(255, 195, 0, 0.16), rgba(128, 16, 57, 0.28));
    border: 2px solid rgba(255, 90, 130, 0.52);
    box-shadow: 0 0 20px rgba(255, 70, 122, 0.45), inset 0 0 14px rgba(255,255,255,0.10);
}

/* --- Cuerpo y Mensajes --- */
.ft-chat-body {
    flex: 1; padding: 20px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px;
    background: rgba(255, 255, 255, 0.4); /* Mucho más limpio */
}
.ft-chat-body::-webkit-scrollbar { width: 6px; }
.ft-chat-body::-webkit-scrollbar-thumb { background: rgba(128, 16, 57, 0.25); border-radius: 10px; }

.ft-message { display: flex; gap: 10px; max-width: 88%; animation: floatUp 0.3s ease-out; }
.ft-message.ai-message { align-self: flex-start; }
.ft-message.user-message { align-self: flex-end; flex-direction: row-reverse; }

.ft-avatar {
    width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 16px;
    flex-shrink: 0; box-shadow: 0 4px 10px rgba(0,0,0,0.1); background: #fff;
}
.user-message .ft-avatar { background: #801039; color: #ffc300; font-size: 14px; font-weight: bold; }

/* Burbujas estilo moderno */
.ft-bubble { padding: 12px 18px; font-size: 14px; line-height: 1.45; box-shadow: 0 4px 15px rgba(0,0,0,0.04); }
.ai-message .ft-bubble { background: #ffffff; color: #333; border: 1px solid rgba(0, 0, 0, 0.04); border-radius: 20px 20px 20px 4px; }
.user-message .ft-bubble { background: linear-gradient(135deg, #801039, #a31448); color: #fff; border-radius: 20px 20px 4px 20px; box-shadow: 0 4px 15px rgba(128,16,57,0.15); }

/* --- Input y Footer --- */
.ft-chat-footer {
    padding: 12px 16px; background: rgba(255, 255, 255, 0.6);
    border-top: 1px solid rgba(255, 255, 255, 0.6);
}

.ft-input-wrapper {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 30px;
    padding: 4px 4px 4px 16px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.03);
    border: 1px solid rgba(255, 255, 255, 0.5);
    transition: all 0.3s;
}
.ft-input-wrapper:focus-within {
    background: rgba(255,255,255,0.9);
    box-shadow: 0 0 0 2px rgba(128, 16, 57, 0.2);
}

#ft-chat-input {
    flex: 1; padding: 8px 0; 
    border: none; background: transparent;
    outline: none; font-size: 14px; color: #222; font-family: inherit;
}

#ft-chat-send {
    width: 38px; height: 38px; 
    flex-shrink: 0; /* Escudo anti-elipse */
    box-sizing: border-box; padding: 0; aspect-ratio: 1/1;
    border-radius: 50%; 
    background: linear-gradient(135deg, #ffc300, #f39c12); color: #801039; border: none;
    cursor: pointer; display: flex; align-items: center; justify-content: center; 
    box-shadow: 0 4px 12px rgba(255, 195, 0, 0.3);
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}
#ft-chat-send:hover { transform: scale(1.15); box-shadow: 0 8px 18px rgba(255, 195, 0, 0.5); filter: brightness(1.05); }
#ft-chat-send svg { width: 20px; height: 20px; transform: translateX(1px); } /* Centrado óptico de la flecha */

.ft-chat-body {
    padding: 20px 18px 16px;
    gap: 13px;
    background:
        linear-gradient(90deg, transparent 0 83%, rgba(255, 195, 0, 0.10) 83% 84%, transparent 84%),
        radial-gradient(circle at 95% 18%, rgba(32, 223, 240, 0.10), transparent 24%),
        rgba(255, 249, 235, 0.60);
}

.ft-message {
    max-width: 94%;
    gap: 12px;
}

.ft-avatar {
    width: 44px;
    height: 44px;
    border: 2px solid rgba(128, 16, 57, 0.12);
    box-shadow: 0 8px 18px rgba(128, 16, 57, 0.12);
}

.user-message .ft-avatar {
    background: #801039;
    color: #ffc300;
}

.ft-bubble {
    padding: 14px 18px;
    font-size: 15px;
    line-height: 1.42;
}

.ai-message .ft-bubble {
    background: #ffffff;
    color: #2e2c35;
    border: 1px solid rgba(128, 16, 57, 0.13);
    border-radius: 22px 22px 22px 6px;
    box-shadow: 0 16px 34px rgba(61, 34, 45, 0.10);
}

.ai-message .ft-bubble strong {
    color: var(--ft-guinda);
}

.ft-action-btn {
    min-height: 42px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid rgba(128, 16, 57, 0.24);
    background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(255,247,226,0.92));
    color: var(--ft-guinda);
    font-size: 13px;
    font-weight: 800;
    line-height: 1.05;
    box-shadow: 0 7px 16px rgba(128, 16, 57, 0.10);
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.ft-action-btn:hover {
    transform: translateY(-2px);
    border-color: rgba(128, 16, 57, 0.42);
    box-shadow: 0 10px 22px rgba(128, 16, 57, 0.16);
}

.ft-chat-footer {
    padding: 14px 18px 18px;
    background: linear-gradient(180deg, rgba(255,255,255,0.58), rgba(255,248,226,0.82));
    border-top: 1px solid rgba(128, 16, 57, 0.08);
}

.ft-input-wrapper {
    min-height: 54px;
    padding: 5px 6px 5px 18px;
    background: rgba(255, 255, 255, 0.86);
    border: 2px solid rgba(176, 20, 85, 0.28);
    box-shadow: 0 10px 25px rgba(128, 16, 57, 0.10), 0 0 16px rgba(32, 223, 240, 0.18);
}

#ft-chat-input {
    font-size: 15px;
}

#ft-chat-send {
    width: 46px;
    height: 46px;
    background: radial-gradient(circle at 30% 25%, #d82a70, #801039 62%, #5d0828);
    color: var(--ft-amarillo);
    box-shadow: 0 9px 22px rgba(128, 16, 57, 0.28), 0 0 0 2px rgba(255,195,0,0.18);
}

/* --- Animaciones --- */
@keyframes floatUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes typingBounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes fab-aura {
    0%, 100% { transform: scale(0.96); opacity: 0.72; }
    50% { transform: scale(1.12); opacity: 1; }
}
@keyframes fab-particles {
    0% { transform: rotate(0deg) scale(0.96); opacity: 0.68; }
    50% { transform: rotate(180deg) scale(1.08); opacity: 1; }
    100% { transform: rotate(360deg) scale(0.96); opacity: 0.68; }
}
@keyframes chat-panel-glow {
    0%, 100% { box-shadow: 0 26px 70px rgba(72, 18, 32, 0.30), 0 0 0 2px rgba(255, 195, 0, 0.72), 0 0 0 5px rgba(128, 16, 57, 0.20), 0 0 24px rgba(32, 223, 240, 0.22); }
    50% { box-shadow: 0 30px 78px rgba(72, 18, 32, 0.34), 0 0 0 2px rgba(255, 195, 0, 0.88), 0 0 0 5px rgba(128, 16, 57, 0.28), 0 0 42px rgba(32, 223, 240, 0.34); }
}
@keyframes fab-levitate { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

@media (max-width: 760px) {
    #ft-chat-window {
        right: 8px;
        bottom: 154px;
        width: calc(100vw - 18px);
        height: min(560px, calc(100vh - 178px));
        max-height: none;
    }

    .ft-header-info span {
        font-size: 23px;
    }

    .ft-header-avatar {
        width: 64px;
        height: 64px;
    }
}

/* --- Móviles --- */
/* --- Ajustes compactos del panel abierto --- */
#ft-chat-window {
    right: 110px;
    bottom: 22px;
    width: 360px;
    height: 560px;
    max-height: min(76vh, 560px);
}

.ft-chat-open #ft-chat-fab {
    transform: translate(-22px, -6px) scale(1.02);
    z-index: 2;
}

.ft-chat-open #ft-chat-fab:hover {
    transform: translate(-22px, -10px) scale(1.05);
}

.ft-chat-header {
    min-height: 76px;
    padding: 12px 16px;
}

.ft-chat-title {
    gap: 10px;
}

.ft-header-avatar {
    width: 52px;
    height: 52px;
    border-width: 2px;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.72), 0 0 16px rgba(255, 195, 0, 0.55);
}

.ft-header-info span {
    font-size: 22px;
}

.ft-header-info small {
    margin-top: 6px;
    font-size: 13px;
}

#ft-chat-close {
    width: 40px;
    height: 40px;
}

.ft-chat-body {
    padding: 14px 14px 12px;
    gap: 10px;
}

.ft-message {
    max-width: 100%;
    gap: 8px;
}

.ft-avatar {
    width: 30px;
    height: 30px;
    border-width: 1px;
}

.ft-bubble {
    padding: 12px 14px;
    font-size: 14px;
}

.ai-message .ft-bubble {
    max-width: calc(100% - 38px);
    border-radius: 18px 18px 18px 5px;
}

.ft-action-btn {
    min-height: 36px;
    padding: 7px 11px;
    font-size: 12.5px;
}

.ft-chat-footer {
    padding: 11px 14px 14px;
}

.ft-input-wrapper {
    min-height: 48px;
    padding: 4px 5px 4px 14px;
}

#ft-chat-send {
    width: 40px;
    height: 40px;
}

@media (max-width: 480px) {
    #ft-chat-container { bottom: 0.8rem; right: 0.6rem; }
    #ft-chat-fab { width: 104px; height: 104px; }
    #ft-chat-fab::before { inset: 11px; opacity: 0.72; }
    #ft-chat-fab::after { inset: 8px; opacity: 0.72; }
    #ft-chat-window { width: calc(100vw - 18px); height: calc(100vh - 142px); max-height: 560px; bottom: 118px; right: 5px; }
    .ft-chat-open #ft-chat-fab { transform: translate(-4px, -2px) scale(0.9); }
    .ft-chat-body { padding: 15px 12px; }
}

@media (min-width: 481px) and (max-width: 760px) {
    #ft-chat-container { bottom: 0.9rem; right: 0.75rem; }
    #ft-chat-fab { width: 118px; height: 118px; }
    #ft-chat-fab::before { inset: 12px; opacity: 0.74; }
    #ft-chat-fab::after { inset: 8px; opacity: 0.74; }

    #ft-chat-window {
        right: 8px;
        bottom: 128px;
        width: calc(100vw - 18px);
        height: min(560px, calc(100vh - 152px));
        max-height: none;
    }

    .ft-chat-open #ft-chat-fab {
        transform: translate(-6px, -3px) scale(0.92);
    }
}
