/* ================================================================
   MY SCANNER ID - CHAT WIDGET
   Widget de chat flotante para la página web
   ================================================================ */

/* ===== VARIABLES CSS ===== */
:root {
    --chat-primary: #667eea;
    --chat-secondary: #764ba2;
    --chat-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --chat-success: #10b981;
    --chat-warning: #ffc107;
    --chat-error: #ef4444;
    --chat-dark: #1f2937;
    --chat-gray: #6b7280;
    --chat-light-gray: #f3f4f6;
    --chat-white: #ffffff;
    --chat-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    --chat-shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.1);
    --chat-border-radius: 12px;
    --chat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== BOX SIZING GLOBAL PARA EL CHAT ===== */
.chat-widget-container,
.chat-widget-container * {
    box-sizing: border-box;
}

/* ===== BOTÓN FLOTANTE (CERRADO) ===== */
.chat-widget-button {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 64px;
    height: 64px;
    background: var(--chat-gradient);
    border-radius: 50%;
    border: none;
    box-shadow: var(--chat-shadow);
    cursor: pointer;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
    animation: pulse-chat 2s infinite;
}

.chat-widget-button:hover {
    transform: scale(1.1);
    box-shadow: 0 15px 40px rgba(102, 126, 234, 0.4);
}

.chat-widget-button:active {
    transform: scale(0.95);
}

/* Ícono del chat */
.chat-widget-button .chat-icon {
    width: 32px;
    height: 32px;
    color: var(--chat-white);
    transition: var(--chat-transition);
}

.chat-widget-button.active .chat-icon-open {
    display: none;
}

.chat-widget-button.active .chat-icon-close {
    display: block;
}

.chat-icon-close {
    display: none;
}

/* Badge de notificación */
.chat-widget-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--chat-error);
    color: var(--chat-white);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.5);
    animation: bounce-chat 1s infinite;
}

/* Animaciones */
@keyframes pulse-chat {
    0%, 100% {
        box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
    }
    50% {
        box-shadow: 0 15px 40px rgba(102, 126, 234, 0.5);
    }
}

@keyframes bounce-chat {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

/* ===== VENTANA DE CHAT (ABIERTO) ===== */
.chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 30px;
    width: 400px;
    height: 700px;
    max-height: calc(100vh - 40px);
    background: var(--chat-white);
    border-radius: var(--chat-border-radius);
    box-shadow: var(--chat-shadow);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    transition: var(--chat-transition);
    animation: slideInUp 0.3s ease-out;
}

.chat-widget-container.active {
    display: flex;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== HEADER DEL CHAT ===== */
.chat-widget-header {
    background: var(--chat-gradient);
    color: var(--chat-white);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-widget-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-widget-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.chat-widget-header-text h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-widget-header-text p {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
}

.chat-widget-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.chat-widget-status-dot {
    width: 8px;
    height: 8px;
    background: var(--chat-success);
    border-radius: 50%;
    animation: pulse-dot 2s infinite;
}

.chat-widget-status-dot.offline {
    background: var(--chat-gray);
    animation: none;
}

@keyframes pulse-dot {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.2);
    }
}

.chat-widget-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: var(--chat-white);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
}

.chat-widget-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* ===== CUERPO DEL CHAT (MENSAJES) ===== */
.chat-widget-body {
    flex: 1;
    overflow-y: scroll !important;
    overflow-x: hidden;
    padding: 14px;
    background: var(--chat-light-gray);
    min-height: 0;
    max-height: 100%;
    scrollbar-width: thin;
    scrollbar-color: var(--chat-gray) #e5e7eb;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: min-content;
}

/* Scrollbar personalizado */
.chat-widget-body::-webkit-scrollbar {
    width: 8px;
}

.chat-widget-body::-webkit-scrollbar-track {
    background: #e5e7eb;
    border-radius: 10px;
}

.chat-widget-body::-webkit-scrollbar-thumb {
    background: var(--chat-gray);
    border-radius: 10px;
}

.chat-widget-body::-webkit-scrollbar-thumb:hover {
    background: var(--chat-dark);
}

/* ===== MENSAJES ===== */
.chat-message {
    display: flex;
    gap: 12px;
    animation: fadeInMessage 0.3s ease-out;
}

@keyframes fadeInMessage {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mensaje del bot/agente */
.chat-message.bot,
.chat-message.agent {
    flex-direction: row;
}

/* Mensaje del usuario */
.chat-message.visitor {
    flex-direction: row-reverse;
}

.chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 18px;
}

.chat-message.bot .chat-message-avatar {
    background: var(--chat-gradient);
    color: var(--chat-white);
}

.chat-message.agent .chat-message-avatar {
    background: var(--chat-success);
    color: var(--chat-white);
}

.chat-message.visitor .chat-message-avatar {
    background: var(--chat-dark);
    color: var(--chat-white);
}

.chat-message-content {
    max-width: 75%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-message-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-message.bot .chat-message-bubble,
.chat-message.agent .chat-message-bubble {
    background: var(--chat-white);
    color: var(--chat-dark);
    border-bottom-left-radius: 4px;
    box-shadow: var(--chat-shadow-sm);
}

.chat-message.visitor .chat-message-bubble {
    background: var(--chat-gradient);
    color: var(--chat-white);
    border-bottom-right-radius: 4px;
}

.chat-message-sender {
    font-size: 11px;
    font-weight: 600;
    color: var(--chat-gray);
    padding: 0 4px;
}

.chat-message-time {
    font-size: 11px;
    color: var(--chat-gray);
    padding: 0 4px;
}

.chat-message.visitor .chat-message-time {
    text-align: right;
}

/* ===== ESTILOS ADICIONALES DE MENSAJES ===== */
.chat-message-text {
    padding: 9px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap;
    background: var(--chat-white);
    box-shadow: var(--chat-shadow-sm);
}

.chat-message-visitor .chat-message-text {
    background: var(--chat-gradient);
    color: var(--chat-white);
}

.chat-message-agent .chat-message-text,
.chat-message-bot .chat-message-text {
    background: var(--chat-white);
    color: var(--chat-dark);
}

.chat-welcome-message {
    text-align: center;
    padding: 12px;
    background: var(--chat-white);
    border-radius: 12px;
    box-shadow: var(--chat-shadow-sm);
}

.chat-welcome-icon {
    font-size: 36px;
    margin-bottom: 6px;
}

.chat-welcome-message h3 {
    margin: 0 0 4px 0;
    color: var(--chat-dark);
    font-size: 16px;
}

.chat-welcome-message p {
    margin: 0;
    color: var(--chat-gray);
    font-size: 12px;
}

.chat-system-message {
    text-align: center;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    font-size: 12px;
    color: var(--chat-gray);
    margin: 8px 0;
}

/* ===== INDICADOR DE ESCRITURA ===== */
.chat-typing-indicator {
    display: flex;
    gap: 12px;
    align-items: center;
    display: none;
}

.chat-typing-indicator.active {
    display: flex;
}

.chat-typing-indicator .chat-message-avatar {
    width: 36px;
    height: 36px;
    background: var(--chat-gradient);
}

.chat-typing-dots {
    background: var(--chat-white);
    padding: 12px 16px;
    border-radius: 12px;
    display: flex;
    gap: 4px;
}

.chat-typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--chat-gray);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite;
}

.chat-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* ===== OPCIONES RÁPIDAS (QUICK REPLIES) ===== */
.chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 4px;
}

.chat-quick-reply-btn {
    background: var(--chat-white);
    border: 2px solid var(--chat-primary);
    color: var(--chat-primary);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--chat-transition);
}

.chat-quick-reply-btn:hover {
    background: var(--chat-primary);
    color: var(--chat-white);
    transform: translateY(-2px);
    box-shadow: var(--chat-shadow-sm);
}

/* ===== FORMULARIO DE CONTACTO EN EL CHAT ===== */
.chat-contact-form {
    background: var(--chat-white);
    padding: 10px;
    border-radius: 12px;
    box-shadow: var(--chat-shadow-sm);
    width: 100%;
}

.chat-contact-form h4 {
    margin: 0 0 8px 0;
    font-size: 13px;
    color: var(--chat-dark);
}

.chat-contact-form input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    transition: var(--chat-transition);
    margin-bottom: 7px;
    box-sizing: border-box;
}

.chat-contact-form input:focus {
    outline: none;
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-form-group {
    margin-bottom: 12px;
}

.chat-form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--chat-gray);
    margin-bottom: 6px;
}

.chat-form-group input,
.chat-form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: var(--chat-transition);
}

.chat-form-group input:focus,
.chat-form-group textarea:focus {
    outline: none;
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.chat-form-submit {
    width: 100%;
    background: var(--chat-gradient);
    color: var(--chat-white);
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--chat-transition);
}

.chat-form-submit:hover {
    transform: translateY(-2px);
    box-shadow: var(--chat-shadow-sm);
}

.chat-form-submit:active {
    transform: translateY(0);
}

/* ===== FOOTER DEL CHAT (INPUT) ===== */
.chat-widget-footer {
    background: var(--chat-white);
    padding: 10px 14px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
    max-height: 380px;
    overflow-y: auto;
    overflow-x: hidden;
}

.chat-widget-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    max-height: 80px;
    transition: var(--chat-transition);
}

.chat-widget-input:focus {
    outline: none;
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-widget-send-btn {
    width: 44px;
    height: 44px;
    background: var(--chat-gradient);
    border: none;
    border-radius: 50%;
    color: var(--chat-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--chat-transition);
}

.chat-widget-send-btn:hover {
    transform: scale(1.1);
}

.chat-widget-send-btn:active {
    transform: scale(0.95);
}

.chat-widget-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ===== ESTILOS ADICIONALES PARA ELEMENTOS DEL JAVASCRIPT ===== */
.chat-input-area {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    width: 100%;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    max-height: 80px;
    transition: var(--chat-transition);
}

.chat-input:focus {
    outline: none;
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    background: var(--chat-gradient);
    border: none;
    border-radius: 50%;
    color: var(--chat-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--chat-transition);
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.1);
}

.chat-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-btn-submit {
    width: 100%;
    background: var(--chat-gradient);
    color: var(--chat-white);
    border: none;
    padding: 9px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--chat-transition);
    margin-top: 6px;
}

.chat-btn-submit:hover {
    transform: translateY(-2px);
    box-shadow: var(--chat-shadow-sm);
}

.chat-btn-submit:active {
    transform: translateY(0);
}

.chat-widget-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-widget-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.chat-widget-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: var(--chat-white);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
}

.chat-widget-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.chat-status-dot {
    width: 8px;
    height: 8px;
    background: var(--chat-gray);
    border-radius: 50%;
}

.chat-status-dot.chat-status-online {
    background: var(--chat-success);
    animation: pulse-dot 2s infinite;
}

.chat-status-dot.chat-status-away {
    background: var(--chat-warning);
}

.chat-status-dot.chat-status-offline {
    background: var(--chat-gray);
}

/* ===== RESPONSIVE (MÓVIL) ===== */
@media (max-width: 768px) {
    .chat-widget-container {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }

    .chat-widget-button {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
    }

    .chat-widget-button .chat-icon {
        width: 28px;
        height: 28px;
    }

    .chat-message-content {
        max-width: 85%;
    }
}

/* ===== ESTADOS ESPECIALES ===== */
.chat-widget-container.minimized {
    height: 80px;
    overflow: hidden;
}

.chat-widget-container.minimized .chat-widget-body,
.chat-widget-container.minimized .chat-widget-footer {
    display: none;
}

/* Mensaje de error */
.chat-error-message {
    background: #fef2f2;
    border-left: 4px solid var(--chat-error);
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    color: #b91c1c;
    margin: 8px 0;
}

/* Mensaje de éxito */
.chat-success-message {
    background: #f0fdf4;
    border-left: 4px solid var(--chat-success);
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    color: #15803d;
    margin: 8px 0;
}

/* Overlay (fondo oscuro en móvil) */
.chat-widget-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9997;
    display: none;
}

.chat-widget-overlay.active {
    display: block;
}

@media (min-width: 769px) {
    .chat-widget-overlay {
        display: none !important;
    }
}

/* ===== ACCESIBILIDAD ===== */
.chat-widget-button:focus,
.chat-widget-close-btn:focus,
.chat-widget-send-btn:focus,
.chat-quick-reply-btn:focus {
    outline: 2px solid var(--chat-primary);
    outline-offset: 2px;
}

/* Reducir animaciones para usuarios que prefieren menos movimiento */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== MODO OSCURO (OPCIONAL - PARA FUTURO) ===== */
@media (prefers-color-scheme: dark) {
    /* Se puede implementar tema oscuro aquí si se desea */
}
