/**
 * Modern Chat Widget Styles v2.0
 * Estilos para el widget de chat moderno con soporte SSE
 */

/* PREVENIR OVERFLOW HORIZONTAL */
html {
    overflow-x: hidden;
}

/* RESET PARA EVITAR CONFLICTOS */
#modern-chat-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* CONTENEDOR PRINCIPAL */
#modern-chat-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    max-width: calc(100vw - 40px);
    contain: layout style;
}

#modern-chat-widget.position-left {
    left: 20px;
    right: auto;
}

/* BURBUJA DE CHAT */
#modern-chat-widget .chat-bubble {
    width: auto;
    height: 40px;
    background-color: #000000;
    border-radius: 20px;
    display: flex;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    position: relative;
    border: none;
    padding: 0 15px;
    gap: 6px;
    min-width: 90px;
    justify-content: center;
}

#modern-chat-widget .chat-bubble:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
}

#modern-chat-widget .chat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

#modern-chat-widget .chat-bubble svg {
    width: 18px;
    height: 18px;
    fill: white;
    transition: transform 0.3s ease;
    margin-left: 2px;
}

#modern-chat-widget .chat-bubble.active svg {
    transform: rotate(45deg);
}

#modern-chat-widget .status-dot {
    position: absolute;
    bottom: 6px;
    left: 9px;
    width: 7px;
    height: 7px;
    background-color: #2ecc71;
    border-radius: 50%;
    box-shadow: 0 0 4px rgba(46, 204, 113, 0.7);
}

#modern-chat-widget .chat-text {
    color: white;
    font-weight: 500;
    font-size: 14px;
    margin-left: 8px;
    letter-spacing: 0.2px;
    margin-right: 2px;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* BADGE DE NOTIFICACIÓN */
#modern-chat-widget .notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff3838;
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

@keyframes pulseGlow {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 4px 15px rgba(255, 71, 87, 0.5);
    }
    50% { 
        transform: scale(1.2);
        box-shadow: 0 6px 25px rgba(255, 71, 87, 0.8);
    }
}

/* MENSAJE INICIAL */
#modern-chat-widget .initial-message {
    position: absolute;
    bottom: 60px;
    right: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.9) 100%);
    backdrop-filter: blur(20px);
    padding: 18px 44px 18px 22px;
    border-radius: 25px 25px 8px 25px;
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.2);
    min-width: 320px;
    max-width: 420px;
    width: fit-content;
    transform: translateY(15px) scale(0.9);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 14px;
    color: #2d3748;
    line-height: 1.6;
    border: 1px solid rgba(0, 0, 0, 0.1);
    font-weight: 500;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    text-align: left;
}

#modern-chat-widget.position-left .initial-message {
    left: 0;
    right: auto;
    border-radius: 25px 25px 25px 8px;
}

#modern-chat-widget .initial-message.show {
    transform: translateY(0) scale(1);
    opacity: 1;
}

#modern-chat-widget .initial-message::after {
    content: '';
    position: absolute;
    bottom: -12px;
    right: 35px;
    width: 0;
    height: 0;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-top: 12px solid rgba(255, 255, 255, 0.95);
    filter: drop-shadow(0 4px 8px rgba(255, 107, 157, 0.2));
}

#modern-chat-widget.position-left .initial-message::after {
    left: 35px;
    right: auto;
}

#modern-chat-widget .close-initial {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    font-size: 18px;
    color: #000;
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
    line-height: 1;
    font-weight: bold;
}

#modern-chat-widget .close-initial:hover {
    background: rgba(0, 0, 0, 0.2);
    transform: scale(1.1);
}

/* VENTANA DE CHAT */
#modern-chat-widget .chat-window {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 380px;
    height: 550px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.9) 100%);
    backdrop-filter: blur(25px);
    border-radius: 25px 25px 0 0;
    box-shadow: 0 25px 80px rgba(255, 107, 157, 0.4);
    transform: translateY(100%);
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    display: none;
    flex-direction: column;
    border: 1px solid rgba(255, 107, 157, 0.2);
}

#modern-chat-widget.position-left .chat-window {
    left: 0;
    right: auto;
}

#modern-chat-widget .chat-window.open {
    transform: translateY(0);
    display: flex;
}

/* HEADER DEL CHAT */
#modern-chat-widget .chat-header {
    background: linear-gradient(135deg, var(--chat-headerPrimary, var(--chat-primary-color, #000000)) 0%, var(--chat-headerSecondary, var(--chat-secondary-color, #333333)) 100%);
    padding: 25px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}

#modern-chat-widget .header-content {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
    position: relative;
    z-index: 1;
    justify-content: space-between;
}

#modern-chat-widget .header-title {
    flex: 0.7; /* Reducir esto da más espacio al logo */
}

#modern-chat-widget .header-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    /* Ajusta estos valores para mover el logo */
    margin-left: 0px;  /* Valores positivos lo mueven a la derecha, negativos a la izquierda */
    margin-right: 0px;  /* Valores positivos lo mueven a la izquierda, negativos a la derecha */
}

#modern-chat-widget .header-image {
    height: 38px;
    max-width: 100px;
    opacity: 0.95;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    object-fit: contain;
    position: relative;
    /* Ajusta estos valores para un control más preciso de la posición */
    left: 0px;  /* Valores positivos mueven a la derecha, negativos a la izquierda */
    margin-right: 20px; /* Espacio a la derecha del logo */
}

#modern-chat-widget .chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.2) 0%, transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 40% 60%, rgba(255, 255, 255, 0.1) 0%, transparent 30%),
        linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.05) 50%, transparent 70%),
        url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="elegantPattern" x="0" y="0" width="25" height="25" patternUnits="userSpaceOnUse"><circle cx="12.5" cy="12.5" r="1" fill="rgba(255,255,255,0.1)"/><path d="M8,8 Q12.5,4 17,8 Q12.5,12 8,8" fill="rgba(255,255,255,0.08)"/></pattern></defs><rect width="100" height="100" fill="url(%23elegantPattern)"/></svg>');
    opacity: 0.8;
    animation: headerFlow 15s ease-in-out infinite;
    z-index: 0;
}

@keyframes headerFlow {
    0%, 100% { 
        transform: translateX(0) scale(1);
        opacity: 0.8;
    }
    33% { 
        transform: translateX(-10px) scale(1.02);
        opacity: 0.9;
    }
    66% { 
        transform: translateX(10px) scale(0.98);
        opacity: 0.7;
    }
}

#modern-chat-widget .chat-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    position: relative;
    z-index: 1;
}

#modern-chat-widget .chat-header .status {
    font-size: 13px;
    opacity: 0.9;
    font-weight: 500;
    position: relative;
    z-index: 1;
}

#modern-chat-widget .close-chat {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    position: relative;
    z-index: 1;
}

#modern-chat-widget .close-chat:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* MENSAJES */
#modern-chat-widget .chat-messages {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    background: linear-gradient(145deg, #fafafa 0%, #f5f5f5 100%);
    position: relative;
}

#modern-chat-widget .chat-messages::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60"><circle cx="30" cy="30" r="2" fill="rgba(255,107,157,0.05)"/></svg>') repeat;
    pointer-events: none;
}

#modern-chat-widget .message {
    max-width: 82%;
    padding: 14px 18px;
    border-radius: 22px;
    font-size: 14px;
    line-height: 1.5;
    animation: messageSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 1;
    font-weight: 500;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(25px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

#modern-chat-widget .message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--chat-primary-color, #ff6b9d) 0%, var(--chat-secondary-color, #c44569) 100%);
    color: white;
    border-bottom-right-radius: 8px;
    box-shadow: 0 8px 25px rgba(255, 107, 157, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#modern-chat-widget .message.bot {
    align-self: flex-start;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0.8) 100%);
    color: #2d3748;
    border: 1px solid rgba(255, 107, 157, 0.15);
    border-bottom-left-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

/* INDICADOR DE ESCRITURA */
#modern-chat-widget .typing-indicator {
    align-self: flex-start;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0.8) 100%);
    border: 1px solid rgba(255, 107, 157, 0.15);
    border-radius: 22px;
    padding: 16px;
    display: none;
    backdrop-filter: blur(10px);
}

#modern-chat-widget .typing-dots {
    display: flex;
    gap: 4px;
}

#modern-chat-widget .typing-dots span {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: typingDots 1.4s infinite ease-in-out;
}

#modern-chat-widget .typing-dots span:nth-child(1) { animation-delay: -0.32s; }
#modern-chat-widget .typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingDots {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* INPUT DE CHAT */
#modern-chat-widget .chat-input {
    padding: 25px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.9) 100%);
    border-top: 1px solid rgba(255, 107, 157, 0.2);
    display: flex;
    gap: 15px;
    align-items: flex-end;
    backdrop-filter: blur(15px);
}

#modern-chat-widget .input-container {
    flex: 1;
    position: relative;
}

#modern-chat-widget .chat-input input {
    width: 100%;
    border: 2px solid rgba(255, 107, 157, 0.3);
    border-radius: 30px;
    padding: 14px 22px;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    color: #2d3748;
    font-weight: 500;
}

#modern-chat-widget .chat-input input:focus {
    border-color: var(--chat-primary-color, #ff6b9d);
    box-shadow: 0 0 0 4px rgba(255, 107, 157, 0.1);
    background: rgba(255, 255, 255, 0.95);
}

#modern-chat-widget .chat-input input::placeholder {
    color: rgba(45, 55, 72, 0.6);
    font-weight: 400;
}

#modern-chat-widget .send-button {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--chat-primary-color, #ff6b9d) 0%, var(--chat-secondary-color, #c44569) 100%);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    box-shadow: 0 8px 25px rgba(255, 107, 157, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.3);
}

#modern-chat-widget .send-button:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 35px rgba(255, 107, 157, 0.6);
}

#modern-chat-widget .send-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

#modern-chat-widget .send-button svg {
    width: 22px;
    height: 22px;
}

/* ESTADO DE CONEXIÓN */
#modern-chat-widget .connection-status {
    padding: 8px 16px;
    background: #e8f5e8;
    color: #2d5016;
    font-size: 12px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 107, 157, 0.2);
    position: relative;
}

#modern-chat-widget .connection-status.disconnected {
    background: #ffeaea;
    color: #721c24;
}

#modern-chat-widget .connection-status::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    margin-right: 6px;
    vertical-align: middle;
}

#modern-chat-widget .connection-status.disconnected::before {
    background: #ef4444;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

/* RESPONSIVE */
@media (max-width: 480px) {
    #modern-chat-widget {
        bottom: 10px;
        right: 10px;
        left: 10px;
        width: auto;
        max-width: calc(100vw - 20px);
    }

    #modern-chat-widget.position-left {
        left: 10px;
        right: 10px;
    }

    #modern-chat-widget .chat-bubble {
        width: 60px;
        height: 60px;
        position: fixed;
        right: 15px;
        bottom: 15px;
        left: auto;
        box-shadow: 0 10px 30px rgba(255, 107, 157, 0.5);
    }

    #modern-chat-widget.position-left .chat-bubble {
        left: 15px;
        right: auto;
    }

    #modern-chat-widget .chat-window {
        width: 100vw;
        height: 80vh;
        max-height: 650px;
        right: 0;
        left: 0;
        bottom: 0;
        border-radius: 25px 25px 0 0;
        position: fixed;
        z-index: 999999;
    }

    #modern-chat-widget .initial-message {
        right: 10px;
        left: auto;
        max-width: calc(100vw - 85px);
        min-width: auto;
        bottom: 80px;
        padding: 14px 36px 14px 18px;
        border-radius: 20px 20px 6px 20px;
        position: fixed;
        z-index: 999998;
        font-size: 14px;
    }

    #modern-chat-widget.position-left .initial-message {
        left: 10px;
        right: auto;
        border-radius: 20px 20px 20px 6px;
    }

    #modern-chat-widget .initial-message::after {
        border-left: 10px solid transparent;
        border-right: 10px solid transparent;
        border-top: 10px solid rgba(255, 255, 255, 0.95);
        right: 30px;
        bottom: -10px;
    }

    #modern-chat-widget.position-left .initial-message::after {
        left: 30px;
        right: auto;
    }

    #modern-chat-widget .close-initial {
        top: 10px;
        right: 10px;
        width: 26px;
        height: 26px;
    }

    /* Ajustes para móvil */
    #modern-chat-widget .chat-messages {
        padding: 20px;
        gap: 15px;
    }

    #modern-chat-widget .chat-input {
        padding: 20px;
        gap: 12px;
    }

    #modern-chat-widget .chat-header {
        padding: 20px;
    }

    #modern-chat-widget .message {
        max-width: 88%;
        font-size: 14px;
        padding: 12px 16px;
    }

    #modern-chat-widget .chat-input input {
        font-size: 16px; /* Previene zoom en iOS */
        padding: 12px 18px;
    }

    #modern-chat-widget .send-button {
        width: 45px;
        height: 45px;
    }

    #modern-chat-widget .send-button svg {
        width: 20px;
        height: 20px;
    }

    #modern-chat-widget .chat-header h3 {
        font-size: 18px;
    }
}

/* Tablet responsive */
@media (min-width: 481px) and (max-width: 768px) {
    #modern-chat-widget .chat-window {
        width: 400px;
        height: 580px;
    }

    #modern-chat-widget .initial-message {
        max-width: 360px;
    }
}

/* Prevenir overflow en todos los dispositivos */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
    }

    #modern-chat-widget {
        contain: layout style;
    }
}

/* EFECTOS ESPECIALES PARA TEMA ELEGANTE */
#modern-chat-widget.theme-elegant .chat-bubble::after {
    content: '';
    position: absolute;
    top: -5px;
    right: -5px;
    font-size: 12px;
    animation: heartBeat 2s ease-in-out infinite;
    opacity: 0.8;
}

@keyframes heartBeat {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

#modern-chat-widget.theme-elegant .message.bot::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 8px;
    font-size: 14px;
    opacity: 0.7;
    z-index: 1;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0.7) 100%);
    backdrop-filter: blur(5px);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(255, 107, 157, 0.3);
    border: 1px solid rgba(255, 107, 157, 0.2);
    animation: floatKiss 3s ease-in-out infinite;
}

@keyframes floatKiss {
    0%, 100% { 
        transform: translateY(0) scale(1);
        opacity: 0.7;
    }
    50% { 
        transform: translateY(-2px) scale(1.05);
        opacity: 0.9;
    }
}

/* ANIMACIONES ADICIONALES */
@keyframes sparkle {
    0%, 100% { opacity: 0; transform: scale(0); }
    50% { opacity: 1; transform: scale(1); }
}

#modern-chat-widget.theme-elegant::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 20% 80%, rgba(255, 107, 157, 0.05) 0%, transparent 50%),
                radial-gradient(circle at 80% 20%, rgba(196, 69, 105, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

/* TEMAS PREDEFINIDOS */
/* Tema Elegante Rosa (por defecto) */
#modern-chat-widget.theme-elegant {
    --chat-primary-color: #ff6b9d;
    --chat-secondary-color: #c44569;
    --chat-accent-color: #ff4757;
}

/* Tema Seductor Púrpura */
#modern-chat-widget.theme-seductive {
    --chat-primary-color: #a55eea;
    --chat-secondary-color: #8b5cf6;
    --chat-accent-color: #ff6b9d;
}

/* Tema Lujoso Dorado */
#modern-chat-widget.theme-luxury {
    --chat-primary-color: #f39c12;
    --chat-secondary-color: #e67e22;
    --chat-accent-color: #e74c3c;
}

/* Tema Nocturno */
#modern-chat-widget.theme-night {
    --chat-primary-color: #2c3e50;
    --chat-secondary-color: #34495e;
    --chat-accent-color: #ff6b9d;
}

/* Tema Azul Empresarial */
#modern-chat-widget.theme-blue {
    --chat-primary-color: #2563eb;
    --chat-secondary-color: #1d4ed8;
    --chat-accent-color: #dc2626;
}

/* Tema Verde */
#modern-chat-widget.theme-green {
    --chat-primary-color: #059669;
    --chat-secondary-color: #047857;
    --chat-accent-color: #f59e0b;
}

/* Estilos para Markdown y HTML en mensajes */
#modern-chat-widget .message a {
    color: #0088cc;
    text-decoration: underline;
}

#modern-chat-widget .message.user a {
    color: #ffffff;
}

#modern-chat-widget .message ul, 
#modern-chat-widget .message ol {
    padding-left: 20px;
    margin: 5px 0;
}

#modern-chat-widget .message li {
    margin-bottom: 3px;
}

#modern-chat-widget .message p {
    margin: 0 0 8px 0;
}

#modern-chat-widget .message p:last-child {
    margin-bottom: 0;
}

#modern-chat-widget .message strong, 
#modern-chat-widget .message b {
    font-weight: 700;
}

#modern-chat-widget .message em, 
#modern-chat-widget .message i {
    font-style: italic;
}

#modern-chat-widget .message code {
    font-family: monospace;
    background-color: rgba(0,0,0,0.05);
    padding: 2px 4px;
    border-radius: 3px;
}

/* Tema Púrpura */
#modern-chat-widget.theme-purple {
    --chat-primary-color: #7c3aed;
    --chat-secondary-color: #6d28d9;
    --chat-accent-color: #ef4444;
}

/* Tema Oscuro */
#modern-chat-widget.theme-dark {
    --chat-primary-color: #374151;
    --chat-secondary-color: #1f2937;
    --chat-accent-color: #f59e0b;
}