/**
 * OpenSistemas ChatBot Module - CSS Styles
 * DinIA - Asistente Virtual para HiperDino/Dinosol
 * 
 * Features:
 * - Responsive design
 * - Smooth animations
 * - Accessible colors
 * - Mobile-first approach
 * 
 * @category    OpenSistemas
 * @package     OpenSistemas_ChatBot
 * @author      OpenSistemas
 * @copyright   Copyright (c) 2024 OpenSistemas
 */

/* ========================================
   CSS VARIABLES - Personalización fácil
   ======================================== */
:root {
    /* Colores principales - MODIFICAR AQUÍ PARA PERSONALIZAR */
    --chatbot-primary: #4CAF50;        /* Verde DinoSol - Color principal */
    --chatbot-primary-dark: #45a049;   /* Verde oscuro - Hover */
    --chatbot-secondary: #2196F3;      /* Azul - Color secundario */
    --chatbot-text: #333333;           /* Negro - Texto principal */
    --chatbot-text-light: #666666;     /* Gris - Texto secundario */
    --chatbot-bg: #FFFFFF;             /* Blanco - Fondo */
    --chatbot-bg-light: #F5F5F5;       /* Gris claro - Fondo alternativo */
    --chatbot-border: #E0E0E0;         /* Gris - Bordes */
    --chatbot-shadow: rgba(0,0,0,0.1); /* Sombra */
    --chatbot-user-msg: #E3F2FD;       /* Azul claro - Mensaje usuario */
    --chatbot-bot-msg: #F1F8E9;        /* Verde claro - Mensaje bot */
    
    /* Dimensiones - Facebook Style */
    --chatbot-width: 400px;
    --chatbot-height: 600px;
    --chatbot-border-radius: 12px;
    --chatbot-spacing: 16px;
    
    /* Animaciones */
    --chatbot-transition: all 0.3s ease;
}

/* ========================================
   RESET & BASE
   ======================================== */
.chatbot-wrapper * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ========================================
   NOTIFICATION
   ======================================== */
.chatbot-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 24px;
    background-color: var(--chatbot-primary);
    color: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--chatbot-shadow);
    font-size: 14px;
    font-weight: 500;
    z-index: 10001;
    animation: slideInRight 0.3s ease;
}

.chatbot-notification.error {
    background-color: #f44336;
}

.chatbot-notification.success {
    background-color: #4CAF50;
}

.chatbot-notification.info {
    background-color: #2196F3;
}

@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ========================================
   FLOATING BUTTON - Facebook Style
   ======================================== */
.chatbot-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--chatbot-primary);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px var(--chatbot-shadow);
    transition: var(--chatbot-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
}

.chatbot-toggle:hover {
    background-color: var(--chatbot-primary-dark);
    transform: scale(1.1);
}

.chatbot-toggle:active {
    transform: scale(0.95);
}

.chatbot-toggle.chatbot-open {
    opacity: 0;
    visibility: hidden;
    transform: scale(0);
}

.chatbot-toggle svg {
    width: 28px;
    height: 28px;
}

/* ========================================
   CHAT CONTAINER - Facebook Style (Pegado al Borde)
   ======================================== */
.chatbot-container {
    position: fixed;
    bottom: 0;
    right: 0;
    width: var(--chatbot-width);
    height: var(--chatbot-height);
    background-color: var(--chatbot-bg);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -2px 16px var(--chatbot-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: var(--chatbot-transition);
    z-index: 9999;
}

.chatbot-container.chatbot-hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(100%);
}

/* ========================================
   HEADER - Facebook Style (Pegado)
   ======================================== */
.chatbot-header {
    background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-dark) 100%);
    color: white;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-radius: 12px 12px 0 0;
}

.chatbot-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-icon-img {
    width: 40px;
    height: 40px;
    background-color: white;
    border-radius: 8px;
    padding: 4px;
    object-fit: contain;
}

/* Mantener estilos legacy del SVG para compatibilidad */
.chatbot-icon {
    width: 40px;
    height: 40px;
    background-color: rgba(255,255,255,0.2);
    border-radius: 50%;
    padding: 8px;
}

.chatbot-title h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.chatbot-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chatbot-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background-color: #4CAF50;
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chatbot-actions {
    display: flex;
    gap: 8px;
}

.chatbot-action-btn {
    background-color: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--chatbot-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.chatbot-action-btn:hover {
    background-color: rgba(255,255,255,0.3);
}

.chatbot-action-btn:active {
    transform: scale(0.95);
}

/* Cart Badge */
.chatbot-cart-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background-color: #ff4444;
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: bold;
    min-width: 18px;
    height: 18px;
    text-align: center;
    line-height: 14px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    animation: badgePulse 2s ease-in-out infinite;
}

@keyframes badgePulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* ========================================
   TOOLBAR - Minimalista (Solo Iconos Desktop)
   ======================================== */
.chatbot-toolbar {
    display: flex;
    gap: 8px;
    padding: 0;
    background-color: var(--chatbot-bg);
    border-top: 1px solid var(--chatbot-border);
    border-bottom: 1px solid var(--chatbot-border);
    justify-content: center;
    align-items: center;
    min-height: 30px;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background-color: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--chatbot-transition);
    font-size: 12px;
    color: var(--chatbot-text-light);
}

.toolbar-btn:hover {
    background-color: var(--chatbot-bg-light);
    color: var(--chatbot-primary);
    border: none;
}

.toolbar-btn svg {
    width: 18px;
    height: 18px;
}

.toolbar-btn span {
    display: none;
}

/* ========================================
   MESSAGES AREA - Facebook Style
   ======================================== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background-color: var(--chatbot-bg-light);
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--chatbot-border);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* ========================================
   MESSAGES
   ======================================== */
.chatbot-message {
    display: flex;
    gap: 12px;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbot-message.user-message {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--chatbot-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.user-message .message-avatar {
    background-color: var(--chatbot-secondary);
}

.message-content {
    max-width: 75%;
    background-color: var(--chatbot-bot-msg);
    padding: 12px 16px;
    border-radius: 12px;
    position: relative;
}

.user-message .message-content {
    background-color: var(--chatbot-user-msg);
    text-align: right;
}

.message-content p {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--chatbot-text);
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message-time {
    font-size: 11px;
    color: var(--chatbot-text-light);
    margin-top: 4px;
    display: block;
}

/* ========================================
   TYPING INDICATOR
   ======================================== */
.typing-indicator {
    animation: none;
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background-color: var(--chatbot-primary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* ========================================
   INPUT FORM - Facebook Style
   ======================================== */
.chatbot-input-container {
    padding: 16px;
    background-color: var(--chatbot-bg);
    border-top: 1px solid var(--chatbot-border);
}

.chatbot-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chatbot-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--chatbot-border);
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
    transition: var(--chatbot-transition);
    outline: none;
}

.chatbot-input:focus {
    border-color: var(--chatbot-primary);
}

.chatbot-input:disabled {
    background-color: var(--chatbot-bg-light);
    cursor: not-allowed;
}

.chatbot-voice-btn,
.chatbot-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    transition: var(--chatbot-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatbot-voice-btn {
    background-color: var(--chatbot-bg-light);
    color: var(--chatbot-text);
}

.chatbot-voice-btn:hover {
    background-color: var(--chatbot-border);
}

.chatbot-voice-btn.listening {
    background-color: #4CAF50;
    color: white;
    animation: pulse 1s infinite;
}

.chatbot-send-btn {
    background-color: var(--chatbot-primary);
    color: white;
}

.chatbot-send-btn:hover {
    background-color: var(--chatbot-primary-dark);
}

.chatbot-send-btn:active,
.chatbot-voice-btn:active {
    transform: scale(0.95);
}

.chatbot-send-btn:disabled {
    background-color: var(--chatbot-border);
    cursor: not-allowed;
}

/* ========================================
   FOOTER
   ======================================== */
.chatbot-footer {
    padding: 8px var(--chatbot-spacing);
    background-color: var(--chatbot-bg-light);
    text-align: center;
    font-size: 11px;
    color: var(--chatbot-text-light);
    border-top: 1px solid var(--chatbot-border);
}

.chatbot-footer strong {
    color: var(--chatbot-primary);
}

/* ========================================
   RESPONSIVE - TABLET
   ======================================== */
@media (max-width: 768px) {
    .chatbot-container {
        width: calc(100vw - 48px);
        max-width: 400px;
        height: 550px;
        right: 24px;
        bottom: 90px;
    }
    
    .toolbar-btn span {
        display: inline;
    }
}

/* ========================================
   RESPONSIVE - MOBILE (Facebook Style Pegado)
   ======================================== */
@media (max-width: 768px) {
    .chatbot-container {
        width: 100%;
        height: 70vh;
        max-height: 600px;
        right: 0;
        bottom: 0;
        border-radius: 0;
    }
    
    .chatbot-header {
        padding: 12px;
        border-radius: 0;
    }
    
    .chatbot-title h3 {
        font-size: 15px;
    }
    
    .chatbot-icon-img {
        width: 36px;
        height: 36px;
    }
    
    .chatbot-action-btn {
        width: 32px;
        height: 32px;
    }
    
    .chatbot-messages {
        padding: 12px;
    }
    
    .chatbot-input-container {
        padding: 12px;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .message-content p {
        font-size: 13px;
    }
    
    .chatbot-input {
        font-size: 16px;
        padding: 10px 14px;
    }
    
    .chatbot-voice-btn,
    .chatbot-send-btn {
        width: 40px;
        height: 40px;
    }
    
    /* Mostrar texto en botones toolbar en móvil */
    .toolbar-btn {
        flex: 1;
        padding: 8px 12px;
        background-color: white;
        border: 1px solid var(--chatbot-border);
    }
    
    .toolbar-btn span {
        display: inline;
        font-size: 11px;
    }
    
    .toolbar-btn svg {
        width: 14px;
        height: 14px;
    }
    
    .chatbot-toolbar {
        padding: 8px;
        gap: 6px;
    }
}

/* ========================================
   RESPONSIVE - EXTRA SMALL
   ======================================== */
@media (max-width: 480px) {
    .chatbot-container {
        width: 100%;
        right: 0;
        height: 80vh;
    }
    
    .chatbot-toggle {
        width: 56px;
        height: 56px;
        right: 16px;
        bottom: 16px;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible for keyboard navigation */
.chatbot-toggle:focus-visible,
.chatbot-action-btn:focus-visible,
.toolbar-btn:focus-visible,
.chatbot-voice-btn:focus-visible,
.chatbot-send-btn:focus-visible {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 2px;
}

.chatbot-input:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
}

/* Print styles */
@media print {
    .chatbot-wrapper {
        display: none !important;
    }
}