/**
 * STI Chat - Estilo Metálico Profesional
 * Colores: Azul (#5cc8ff), Verde (#00ff9d), Violeta (#c77dff)
 */

:root {
    --sti-metal-blue: #5cc8ff;
    --sti-metal-blue-dark: #009dff;
    --sti-metal-green: #00ff9d;
    --sti-metal-violet: #c77dff;
    --sti-bg-dark: #0a0e14;
    --sti-bg-card: #0f161e;
    --sti-border: rgba(92,200,255,0.2);
    --sti-text: #e5e7eb;
    --sti-text-muted: #9ca3af;
    --sti-glow-blue: rgba(92,200,255,0.3);
    --sti-glow-green: rgba(0,255,157,0.3);
}

/* ========== Contenedor principal del chat ========== */
#sti-chat-box {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 400px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: linear-gradient(180deg, var(--sti-bg-card) 0%, var(--sti-bg-dark) 100%);
    border: 1px solid var(--sti-border);
    border-radius: 20px;
    box-shadow: 
        0 20px 60px rgba(0,0,0,0.5),
        0 0 40px var(--sti-glow-blue),
        inset 0 1px 0 rgba(255,255,255,0.05);
    display: flex;
    flex-direction: column;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    z-index: 10000;
    animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

#sti-chat-box::before {
    content: '🤖 STI Tecnos 24/7';
    display: block;
    padding: 20px 60px 20px 20px;
    font-family: 'Orbitron', sans-serif;
    font-size: 18px;
    font-weight: 700;
    background: #132333;
    color: var(--sti-metal-blue);
    border-bottom: 1px solid var(--sti-border);
    position: relative;
    z-index: 1;
}

@keyframes slideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ========== Botón cerrar ========== */
#sti-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    background: rgba(239,68,68,0.1);
    border: 2px solid rgba(39, 49, 134, 0.37);
    border-radius: 8px;
    color: #fca5a5;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

#sti-close:hover {
    background: rgba(239,68,68,0.2);
    border-color: rgba(239,68,68,0.5);
    transform: scale(1.1);
}

/* ══════════ Área de mensajes ══════════ */
#sti-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #132333;
    border: 3px solid #b5016c;
    border-radius: 12px 12px 12px 12px;
    box-shadow: inset 0 0 20px rgba(181,1,108,0.2);
}

/* Scrollbar personalizado */
#sti-messages::-webkit-scrollbar {
    width: 6px;
}

#sti-messages::-webkit-scrollbar-track {
    background: rgba(181,1,108,0.1);
    border-radius: 3px;
}

#sti-messages::-webkit-scrollbar-thumb {
    background: #b5016c;
    border-radius: 3px;
    box-shadow: 0 0 10px rgba(181,1,108,0.5);
}

#sti-messages::-webkit-scrollbar-thumb:hover {
    background: #d4018a;
    box-shadow: 0 0 15px rgba(181,1,108,0.8);
}

/* ========== Mensajes individuales ========== */
.sti-msg {
    display: flex;
    gap: 12px;
    animation: messageIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes messageIn {
    from {
        transform: translateY(10px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.sti-msg.bot {
    align-self: flex-start;
}

.sti-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

/* Avatar */
.sti-msg .sti-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    border: 1px solid var(--sti-border);
    box-shadow: 0 0 15px var(--sti-glow-blue);
}

.sti-msg.bot .sti-avatar {
    background: linear-gradient(135deg, var(--sti-metal-blue) 0%, var(--sti-metal-blue-dark) 100%);
}

.sti-msg.user .sti-avatar {
    background: linear-gradient(135deg, var(--sti-metal-violet) 0%, #9333ea 100%);
}

/* Contenido del mensaje */
.sti-msg .sti-bubble {
    max-width: 320px;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    position: relative;
}

.sti-msg.bot .sti-bubble {
    background: var(--sti-bg-card);
    border: 1px solid var(--sti-border);
    color: var(--sti-text);
    box-shadow: 
        0 4px 12px rgba(0,0,0,0.3),
        inset 0 1px 0 rgba(255,255,255,0.05);
}

.sti-msg.user .sti-bubble {
    background: linear-gradient(135deg, var(--sti-metal-blue) 0%, var(--sti-metal-blue-dark) 100%);
    color: #ffffff;
    border: 1px solid rgba(92,200,255,0.8);
    box-shadow: 0 4px 12px var(--sti-glow-blue);
}

/* Markdown formatting dentro de bubbles */
.sti-bubble strong {
    font-weight: 700;
    color: var(--sti-metal-blue);
}

.sti-bubble em {
    font-style: italic;
    color: var(--sti-metal-green);
}

.sti-msg.user .sti-bubble strong,
.sti-msg.user .sti-bubble em {
    color: #ffffff;
}

/* ══════════ Indicador de escritura ══════════ */
.sti-typing {
    display: flex;
    gap: 6px;
    padding: 12px 16px;
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 2px;
}

.sti-typing span {
    color: var(--sti-metal-blue);
    opacity: 0.3;
    animation: letterGlow 1.6s ease-in-out infinite;
    text-shadow: 0 0 10px transparent;
    transition: all 0.3s;
}

.sti-typing span:nth-child(1) { animation-delay: 0s; }
.sti-typing span:nth-child(2) { animation-delay: 0.2s; }
.sti-typing span:nth-child(3) { animation-delay: 0.4s; }
.sti-typing span:nth-child(4) { animation-delay: 0.6s; }
.sti-typing span:nth-child(5) { animation-delay: 0.8s; }
.sti-typing span:nth-child(6) { animation-delay: 1s; }
.sti-typing span:nth-child(7) { animation-delay: 1.2s; }
.sti-typing span:nth-child(8) { animation-delay: 1.4s; }

@keyframes letterGlow {
    0%, 100% {
        opacity: 0.3;
        color: var(--sti-metal-blue);
        text-shadow: 0 0 5px transparent;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        color: var(--sti-metal-green);
        text-shadow: 0 0 20px var(--sti-glow-green);
        transform: scale(1.2);
    }
}

/* ========== Botones de opciones ========== */
.sti-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.sti-btn {
    padding: 10px 16px;
    background: var(--sti-bg-card);
    border: 1px solid var(--sti-border);
    border-radius: 8px;
    color: var(--sti-metal-blue);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.sti-btn:hover {
    background: rgba(92,200,255,0.1);
    border-color: var(--sti-metal-blue);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--sti-glow-blue);
}

.sti-btn:active {
    transform: translateY(0);
}

/* ========== Botón WhatsApp ========== */
.sti-wa-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    border: 1px solid rgba(92,200,255,0.8);
    border-radius: 10px;
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(37,211,102,0.3);
    margin-top: 12px;
}

.sti-wa-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37,211,102,0.5);
}

/* ========== Preview de imágenes ========== */
#sti-image-preview {
    padding: 12px;
    background: rgba(92,200,255,0.05);
    border-top: 1px solid var(--sti-border);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.sti-image-thumb {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--sti-border);
}

.sti-image-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sti-image-thumb button {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(239,68,68,0.9);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========== Área de input ========== */
.sti-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px;
    background: #132333;
    border-top: 1px solid var(--sti-border);
}

/* ========== Botón de adjuntar archivos ========== */
/* Por defecto: ROJO (deshabilitado) - Mayor especificidad para evitar sobrescritura */
#sti-attach-btn:not(.sti-clip-enabled) {
    width: 36px !important;
    height: 36px !important;
    border-radius: 8px !important;
    font-size: 22px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.3s !important;
    /* Por defecto: ROJO (deshabilitado) */
    background: rgba(239,68,68,0.05) !important;
    border: 2px solid #ef4444 !important;
    color: #ef4444 !important;
    cursor: not-allowed !important;
    opacity: 0.6 !important;
    box-shadow: 0 0 20px rgba(239,68,68,0.6), inset 0 0 10px rgba(239,68,68,0.3) !important;
}

/* Estado deshabilitado (rojo) - cuando tiene la clase explícitamente */
#sti-attach-btn.sti-clip-disabled {
    background: rgba(239,68,68,0.05) !important;
    border: 2px solid #ef4444 !important;
    color: #ef4444 !important;
    cursor: not-allowed !important;
    opacity: 0.6 !important;
    box-shadow: 0 0 20px rgba(239,68,68,0.6), inset 0 0 10px rgba(239,68,68,0.3) !important;
}

#sti-attach-btn.sti-clip-disabled:hover {
    background: rgba(239,68,68,0.1);
    transform: none;
}

/* Estado habilitado (verde) - SOLO cuando tiene la clase sti-clip-enabled explícitamente */
#sti-attach-btn.sti-clip-enabled {
    background: rgba(0,255,157,0.05) !important;
    border: 2px solid var(--sti-metal-green) !important;
    color: var(--sti-metal-green) !important;
    cursor: pointer !important;
    opacity: 1 !important;
    box-shadow: 0 0 25px var(--sti-glow-green), inset 0 0 15px rgba(0,255,157,0.2) !important;
}

#sti-attach-btn.sti-clip-enabled:hover {
    background: rgba(0,255,157,0.15) !important;
    border-color: var(--sti-metal-green) !important;
    box-shadow: 0 0 35px var(--sti-glow-green), inset 0 0 20px rgba(0,255,157,0.3) !important;
    transform: scale(1.1) !important;
}

#sti-attach-btn.sti-clip-enabled:active {
    transform: scale(0.95);
}

#sti-text {
    flex: 1;
    padding: 10px 14px;
    background: #132333;
    border: 1px solid var(--sti-border);
    border-radius: 10px;
    color: #ffffff !important;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
}

#sti-text:focus {
    border-color: var(--sti-metal-blue);
    box-shadow: 0 0 0 3px rgba(92,200,255,0.1);
}

#sti-text::placeholder {
    color: var(--sti-text-muted);
}

#sti-send {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--sti-metal-blue) 0%, var(--sti-metal-blue-dark) 100%);
    border: 1px solid rgba(92,200,255,0.8);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 4px 12px var(--sti-glow-blue);
}

#sti-send:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--sti-glow-blue);
}

#sti-send:active {
    transform: translateY(0);
}

#sti-send svg {
    width: 20px;
    height: 20px;
    fill: white;
}

#sti-send::before {
    content: '➤';
    font-size: 20px;
    color: white;
    line-height: 1;
}

/* ========== Responsive ========== */
@media (max-width: 480px) {
    #sti-chat-box {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        right: 10px;
        bottom: 10px;
        border-radius: 16px;
    }
    
    .sti-msg .sti-bubble {
        max-width: calc(100vw - 120px);
    }
}

/* ========== Animaciones adicionales ========== */
@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 20px var(--sti-glow-blue);
    }
    50% {
        box-shadow: 0 0 30px var(--sti-glow-green);
    }
}

/* Estado de carga */
.sti-loading {
    opacity: 0.6;
    pointer-events: none;
}
