/* Chatbot Container */
#chatbot-container {
    display: flex;
    flex-direction: column;
    border: 1px solid #e1e5e9;
    border-radius: 16px;
    background: #ffffff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    max-width: 800px;
    margin: 20px auto;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

/* Estados del contenedor */
#chatbot-container.chatbot-collapsed {
    height: auto !important;
}

#chatbot-container.chatbot-floating {
    position: fixed;
    bottom: 20px;
    right: 20px;
    max-width: 380px;
    z-index: 9999;
    margin: 0;
}

/* Header Expandido */
.chatbot-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.chatbot-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    transition: left 0.5s;
}

.chatbot-header:hover::before {
    left: 100%;
}

.chatbot-header-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.chatbot-title-section {
    flex: 1;
}

.chatbot-header h3 {
    margin: 0 0 8px 0;
    font-size: 20px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.chatbot-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.15);
    padding: 4px 10px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

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

.chatbot-header-subtitle {
    margin-top: 8px;
}

.subtitle-text {
    font-size: 13px;
    opacity: 0.9;
    font-weight: 400;
}

/* Botón Toggle */
.chatbot-toggle-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    font-size: 12px;
    flex-shrink: 0;
}

.chatbot-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.1);
}

.toggle-icon {
    transition: transform 0.3s ease;
    font-weight: bold;
}

/* Cuerpo del Chatbot */
.chatbot-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    transition: all 0.3s ease;
}

/* Messages Container */
.chatbot-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background: linear-gradient(145deg, #f8f9fa 0%, #e9ecef 100%);
    min-height: 300px;
    max-height: 400px;
}

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

.chatbot-messages::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.05);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.3);
}

/* Messages */
.chatbot-message {
    margin-bottom: 20px;
    display: flex;
    gap: 12px;
    animation: slideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideIn {
    from { 
        opacity: 0; 
        transform: translateY(20px) scale(0.95); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0) scale(1); 
    }
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.chatbot-user-message .message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.chatbot-bot-message .message-avatar {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.message-bubble {
    max-width: 75%;
    position: relative;
}

.message-content {
    padding: 14px 18px;
    border-radius: 20px;
    word-wrap: break-word;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.chatbot-user-message .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 8px;
}

.chatbot-bot-message .message-content {
    background: white;
    color: #2d3748;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 8px;
}

.chatbot-bot-message.error .message-content {
    background: linear-gradient(135deg, #fed7d7 0%, #feb2b2 100%);
    border-color: #fc8181;
    color: #c53030;
}

.message-time {
    font-size: 11px;
    color: #a0aec0;
    margin-top: 6px;
    text-align: right;
    opacity: 0.8;
}

.chatbot-bot-message .message-time {
    text-align: left;
}

.message-metadata {
    margin-top: 6px;
    color: #718096;
    font-size: 11px;
    background: rgba(0,0,0,0.03);
    padding: 4px 8px;
    border-radius: 8px;
    display: inline-block;
}

/* Typing Indicator */
.chatbot-typing {
    padding: 0 24px 16px;
    background: linear-gradient(145deg, #f8f9fa 0%, #e9ecef 100%);
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #718096;
    font-size: 13px;
    padding: 8px 16px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    max-width: fit-content;
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #a0aec0;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

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

@keyframes typing {
    0%, 80%, 100% { 
        transform: scale(0.8); 
        opacity: 0.5; 
    }
    40% { 
        transform: scale(1.2); 
        opacity: 1; 
    }
}

/* Input Container */
.chatbot-input-container {
    background: white;
    border-top: 1px solid #e2e8f0;
    padding: 20px 24px;
}

.chatbot-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: #f7fafc;
    border: 2px solid #e2e8f0;
    border-radius: 28px;
    padding: 6px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.chatbot-input-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.1), transparent);
    transition: left 0.5s;
}

.chatbot-input-wrapper.focused {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
    background: white;
}

.chatbot-input-wrapper.focused::before {
    left: 100%;
}

#chatbot-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 18px;
    font-size: 14px;
    resize: none;
    outline: none;
    font-family: inherit;
    color: #2d3748;
    line-height: 1.5;
}

#chatbot-input::placeholder {
    color: #a0aec0;
    transition: color 0.2s ease;
}

#chatbot-input:focus::placeholder {
    color: #cbd5e0;
}

#chatbot-send {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    position: relative;
    overflow: hidden;
}

#chatbot-send::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transition: all 0.3s ease;
    transform: translate(-50%, -50%);
}

#chatbot-send:hover:not(:disabled) {
    transform: scale(1.1) rotate(15deg);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

#chatbot-send:hover:not(:disabled)::before {
    width: 100%;
    height: 100%;
}

#chatbot-send:active:not(:disabled) {
    transform: scale(0.95);
}

#chatbot-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.send-icon {
    font-size: 16px;
    font-weight: bold;
    z-index: 1;
    position: relative;
}

/* Estados del contenedor colapsado */
.chatbot-collapsed .chatbot-body {
    display: none;
}

.chatbot-collapsed .chatbot-header {
    border-radius: 16px;
    cursor: pointer;
}

.chatbot-collapsed .chatbot-header:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(102, 126, 234, 0.2);
}

/* Tema oscuro */
.chatbot-theme-dark {
    background: #1a202c;
    border-color: #2d3748;
}

.chatbot-theme-dark .chatbot-header {
    background: linear-gradient(135deg, #2d3748 0%, #4a5568 100%);
}

.chatbot-theme-dark .chatbot-messages {
    background: linear-gradient(145deg, #2d3748 0%, #1a202c 100%);
}

.chatbot-theme-dark .chatbot-bot-message .message-content {
    background: #4a5568;
    color: #e2e8f0;
    border-color: #4a5568;
}

.chatbot-theme-dark .chatbot-input-container {
    background: #1a202c;
    border-color: #2d3748;
}

.chatbot-theme-dark .chatbot-input-wrapper {
    background: #2d3748;
    border-color: #4a5568;
}

.chatbot-theme-dark .chatbot-input-wrapper.focused {
    border-color: #667eea;
    background: #4a5568;
}

.chatbot-theme-dark #chatbot-input {
    color: #e2e8f0;
}

.chatbot-theme-dark #chatbot-input::placeholder {
    color: #a0aec0;
}

.chatbot-theme-dark .message-time {
    color: #a0aec0;
}

.chatbot-theme-dark .message-metadata {
    color: #a0aec0;
    background: rgba(255,255,255,0.05);
}

.chatbot-theme-dark .chatbot-typing {
    background: linear-gradient(145deg, #2d3748 0%, #1a202c 100%);
    color: #a0aec0;
}

.chatbot-theme-dark .typing-indicator {
    background: #4a5568;
    color: #a0aec0;
}

/* Responsive Design */
@media (max-width: 768px) {
    #chatbot-container {
        margin: 10px;
        border-radius: 12px;
        max-width: calc(100vw - 20px);
    }
    
    .chatbot-floating {
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .chatbot-header {
        padding: 16px;
    }
    
    .chatbot-header h3 {
        font-size: 18px;
    }
    
    .chatbot-messages {
        padding: 16px;
        min-height: 250px;
        max-height: 300px;
    }
    
    .message-content {
        padding: 12px 16px;
        max-width: 85%;
    }
    
    .chatbot-input-container {
        padding: 16px;
    }
    
    #chatbot-input {
        font-size: 16px; /* Previene zoom en iOS */
        padding: 10px 16px;
    }
    
    #chatbot-send {
        width: 40px;
        height: 40px;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .chatbot-header h3 {
        font-size: 16px;
    }
    
    .chatbot-status {
        font-size: 11px;
        padding: 3px 8px;
    }
    
    .subtitle-text {
        font-size: 12px;
    }
    
    .message-content {
        font-size: 14px;
        padding: 10px 14px;
    }
    
    .chatbot-messages {
        padding: 12px;
    }
    
    .chatbot-input-container {
        padding: 12px;
    }
    
    .chatbot-toggle-btn {
        width: 28px;
        height: 28px;
        font-size: 11px;
    }
}

/* Animaciones adicionales */
.message-content:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.chatbot-message:hover .message-time {
    opacity: 1;
}

.message-time {
    transition: opacity 0.2s ease;
}

/* Indicador de carga en el botón */
#chatbot-send:disabled .send-icon {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Efectos de hover para el header colapsado */
.chatbot-collapsed .chatbot-header-content {
    transition: transform 0.2s ease;
}

.chatbot-collapsed .chatbot-header:hover .chatbot-header-content {
    transform: scale(1.02);
}

/* Pulse effect para el botón toggle */
.chatbot-toggle-btn {
    position: relative;
}

.chatbot-toggle-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 0;
    }
}

/* Gradiente animado para el fondo cuando está expandido */
.chatbot-messages {
    background-attachment: fixed;
    position: relative;
}

.chatbot-messages::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, 
        rgba(102, 126, 234, 0.02) 0%, 
        rgba(118, 75, 162, 0.02) 25%, 
        rgba(102, 126, 234, 0.02) 50%, 
        rgba(118, 75, 162, 0.02) 75%, 
        rgba(102, 126, 234, 0.02) 100%);
    background-size: 400% 400%;
    animation: gradientShift 8s ease infinite;
    pointer-events: none;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Mejoras para accesibilidad */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .chatbot-messages::before {
        animation: none;
    }
    
    .status-dot {
        animation: none;
    }
    
    .typing-dots span {
        animation: none;
    }
}

/* Estados de focus para accesibilidad */
.chatbot-toggle-btn:focus {
    outline: 2px solid rgba(255,255,255,0.5);
    outline-offset: 2px;
}

#chatbot-send:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

#chatbot-input:focus {
    /* Ya manejado por .chatbot-input-wrapper.focused */
}

/* Efectos de entrada para el contenedor */
#chatbot-container {
    animation: containerFadeIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes containerFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}