/**
 * Chatbot Widget Styles
 * 
 * @author Tasadores Joyeros
 * @version 1.0.0
 * @license MIT
 */

/* ===== CSS VARIABLES ===== */
:root {
    --chatbot-primary: #007bff;
    --chatbot-secondary: #6c757d;
    --chatbot-success: #28a745;
    --chatbot-danger: #dc3545;
    --chatbot-warning: #ffc107;
    --chatbot-info: #17a2b8;
    --chatbot-light: #f8f9fa;
    --chatbot-dark: #343a40;
    --chatbot-white: #ffffff;
    --chatbot-gray-100: #f8f9fa;
    --chatbot-gray-200: #e9ecef;
    --chatbot-gray-300: #dee2e6;
    --chatbot-gray-400: #ced4da;
    --chatbot-gray-500: #adb5bd;
    --chatbot-gray-600: #6c757d;
    --chatbot-gray-700: #495057;
    --chatbot-gray-800: #343a40;
    --chatbot-gray-900: #212529;
    
    /* Shadows */
    --chatbot-shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --chatbot-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    --chatbot-shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.2);
    --chatbot-shadow-xl: 0 12px 40px rgba(0, 0, 0, 0.25);
    
    /* Border radius */
    --chatbot-border-radius: 12px;
    --chatbot-border-radius-sm: 8px;
    --chatbot-border-radius-lg: 16px;
    --chatbot-border-radius-xl: 20px;
    
    /* Transitions */
    --chatbot-transition: all 0.3s ease;
    --chatbot-transition-fast: all 0.15s ease;
    --chatbot-transition-slow: all 0.5s ease;
    
    /* Typography */
    --chatbot-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --chatbot-font-size-xs: 0.75rem;
    --chatbot-font-size-sm: 0.875rem;
    --chatbot-font-size-base: 1rem;
    --chatbot-font-size-lg: 1.125rem;
    --chatbot-font-size-xl: 1.25rem;
    
    /* Z-index */
    --chatbot-z-index: 9999;
    --chatbot-z-index-overlay: 10000;
    
    /* Dimensions */
    --chatbot-window-width: 380px;
    --chatbot-window-height: 500px;
    --chatbot-toggle-size: 60px;
    --chatbot-avatar-size: 32px;
}

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

.chatbot-widget {
    font-family: var(--chatbot-font-family);
    font-size: var(--chatbot-font-size-base);
    line-height: 1.5;
    color: var(--chatbot-gray-800);
    position: fixed;
    z-index: var(--chatbot-z-index);
    pointer-events: none;
}

.chatbot-widget * {
    pointer-events: auto;
}

/* ===== POSITIONING ===== */
.chatbot-widget.chatbot-bottom-right {
    bottom: 20px;
    right: 20px;
}

.chatbot-widget.chatbot-bottom-left {
    bottom: 20px;
    left: 20px;
}

.chatbot-widget.chatbot-top-right {
    top: 20px;
    right: 20px;
}

.chatbot-widget.chatbot-top-left {
    top: 20px;
    left: 20px;
}

/* ===== TOGGLE BUTTON ===== */
.chatbot-toggle {
    position: relative;
    width: var(--chatbot-toggle-size);
    height: var(--chatbot-toggle-size);
    background: linear-gradient(135deg, var(--chatbot-primary), #0056b3);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--chatbot-shadow-lg);
    transition: var(--chatbot-transition);
    user-select: none;
    border: none;
    outline: none;
}

.chatbot-toggle:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: var(--chatbot-shadow-xl);
}

.chatbot-toggle:active {
    transform: translateY(0) scale(0.98);
}

.chatbot-toggle-icon {
    position: relative;
    width: 24px;
    height: 24px;
    color: var(--chatbot-white);
}

.chatbot-toggle-icon svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: var(--chatbot-transition);
}

.chatbot-toggle-icon .chatbot-icon-close {
    opacity: 0;
    transform: rotate(180deg) scale(0.8);
}

.chatbot-widget.chatbot-open .chatbot-toggle-icon .chatbot-icon-chat {
    opacity: 0;
    transform: rotate(-180deg) scale(0.8);
}

.chatbot-widget.chatbot-open .chatbot-toggle-icon .chatbot-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Notification Badge */
.chatbot-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--chatbot-danger);
    color: var(--chatbot-white);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--chatbot-font-size-xs);
    font-weight: 600;
    animation: chatbot-pulse 2s infinite;
}

@keyframes chatbot-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* ===== CHAT WINDOW ===== */
.chatbot-window {
    position: absolute;
    width: var(--chatbot-window-width);
    height: var(--chatbot-window-height);
    background: var(--chatbot-white);
    border-radius: var(--chatbot-border-radius);
    box-shadow: var(--chatbot-shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: var(--chatbot-transition);
    transform-origin: bottom right;
}

.chatbot-widget.chatbot-bottom-right .chatbot-window {
    bottom: 80px;
    right: 0;
}

.chatbot-widget.chatbot-bottom-left .chatbot-window {
    bottom: 80px;
    left: 0;
    transform-origin: bottom left;
}

.chatbot-widget.chatbot-top-right .chatbot-window {
    top: 80px;
    right: 0;
    transform-origin: top right;
}

.chatbot-widget.chatbot-top-left .chatbot-window {
    top: 80px;
    left: 0;
    transform-origin: top left;
}

/* Window states */
.chatbot-window {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none;
}

.chatbot-widget.chatbot-open .chatbot-window {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

/* ===== HEADER ===== */
.chatbot-header {
    background: linear-gradient(135deg, var(--chatbot-primary), #0056b3);
    color: var(--chatbot-white);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--chatbot-border-radius) var(--chatbot-border-radius) 0 0;
}

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

.chatbot-avatar {
    width: var(--chatbot-avatar-size);
    height: var(--chatbot-avatar-size);
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--chatbot-white);
}

.chatbot-avatar svg {
    width: 18px;
    height: 18px;
}

.chatbot-header-text h4 {
    font-size: var(--chatbot-font-size-base);
    font-weight: 600;
    margin: 0;
    line-height: 1.2;
}

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

.chatbot-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--chatbot-success);
    border-radius: 50%;
    animation: chatbot-online-pulse 2s infinite;
}

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

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

.chatbot-minimize,
.chatbot-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: var(--chatbot-border-radius-sm);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--chatbot-transition);
    color: var(--chatbot-white);
}

.chatbot-minimize:hover,
.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.chatbot-minimize svg,
.chatbot-close svg {
    width: 16px;
    height: 16px;
}

/* ===== MESSAGES AREA ===== */
.chatbot-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--chatbot-gray-100);
}

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

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

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

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--chatbot-gray-500);
}

/* ===== MESSAGE BUBBLES ===== */
.chatbot-message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: chatbot-message-slide-in 0.3s ease;
}

@keyframes chatbot-message-slide-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbot-message-bot {
    align-self: flex-start;
}

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

.chatbot-message-avatar {
    width: var(--chatbot-avatar-size);
    height: var(--chatbot-avatar-size);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 4px;
}

.chatbot-message-bot .chatbot-message-avatar {
    background: var(--chatbot-primary);
    color: var(--chatbot-white);
}

.chatbot-message-user .chatbot-message-avatar {
    background: var(--chatbot-gray-400);
    color: var(--chatbot-white);
}

.chatbot-message-avatar svg {
    width: 18px;
    height: 18px;
}

.chatbot-message-content {
    flex: 1;
    min-width: 0;
}

.chatbot-message-bubble {
    padding: 12px 16px;
    border-radius: var(--chatbot-border-radius);
    word-wrap: break-word;
    line-height: 1.4;
}

.chatbot-message-bot .chatbot-message-bubble {
    background: var(--chatbot-white);
    color: var(--chatbot-gray-800);
    border: 1px solid var(--chatbot-gray-200);
    border-bottom-left-radius: 4px;
}

.chatbot-message-user .chatbot-message-bubble {
    background: var(--chatbot-primary);
    color: var(--chatbot-white);
    border-bottom-right-radius: 4px;
}

/* ===== LINKS IN MESSAGES ===== */
.chatbot-message-bubble a,
.chatbot-message-bubble .chatbot-link {
    color: #0066cc;
    text-decoration: underline;
    cursor: pointer;
    word-break: break-word;
    transition: color 0.2s ease;
}

.chatbot-message-bubble a:hover,
.chatbot-message-bubble .chatbot-link:hover {
    color: #004499;
    text-decoration: underline;
}

.chatbot-message-bubble a:visited,
.chatbot-message-bubble .chatbot-link:visited {
    color: #551a8b;
}

/* Links in user messages (white background) */
.chatbot-message-user .chatbot-message-bubble a,
.chatbot-message-user .chatbot-message-bubble .chatbot-link {
    color: #ffffff;
    text-decoration: underline;
}

.chatbot-message-user .chatbot-message-bubble a:hover,
.chatbot-message-user .chatbot-message-bubble .chatbot-link:hover {
    color: #e0e0e0;
}

.chatbot-message-time {
    margin-top: 4px;
    font-size: var(--chatbot-font-size-xs);
    color: var(--chatbot-gray-500);
}

.chatbot-message-user .chatbot-message-time {
    text-align: right;
}

/* ===== QUICK ACTIONS ===== */
.chatbot-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.chatbot-quick-action {
    background: var(--chatbot-white);
    border: 1px solid var(--chatbot-gray-300);
    border-radius: var(--chatbot-border-radius-lg);
    padding: 8px 12px;
    font-size: var(--chatbot-font-size-sm);
    color: var(--chatbot-gray-700);
    cursor: pointer;
    transition: var(--chatbot-transition);
    display: flex;
    align-items: center;
    gap: 6px;
}

.chatbot-quick-action:hover {
    background: var(--chatbot-primary);
    color: var(--chatbot-white);
    border-color: var(--chatbot-primary);
    transform: translateY(-1px);
}

.chatbot-quick-action svg {
    width: 14px;
    height: 14px;
}

/* ===== TYPING INDICATOR ===== */
.chatbot-typing {
    padding: 0 20px;
}

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

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

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

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

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

/* ===== INPUT AREA ===== */
.chatbot-input-area {
    background: var(--chatbot-white);
    border-top: 1px solid var(--chatbot-gray-200);
    padding: 16px 20px;
}

.chatbot-input-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chatbot-input {
    flex: 1;
    border: 1px solid var(--chatbot-gray-300);
    border-radius: var(--chatbot-border-radius-lg);
    padding: 12px 16px;
    font-size: var(--chatbot-font-size-base);
    font-family: var(--chatbot-font-family);
    resize: none;
    outline: none;
    transition: var(--chatbot-transition);
    max-height: 120px;
    min-height: 44px;
}

.chatbot-input:focus {
    border-color: var(--chatbot-primary);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.chatbot-input::placeholder {
    color: var(--chatbot-gray-500);
}

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

.chatbot-send:hover:not(:disabled) {
    background: #0056b3;
    transform: scale(1.05);
}

.chatbot-send:disabled {
    background: var(--chatbot-gray-400);
    cursor: not-allowed;
    transform: none;
}

.chatbot-send svg {
    width: 18px;
    height: 18px;
}

.chatbot-input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-size: var(--chatbot-font-size-xs);
    color: var(--chatbot-gray-500);
}

.chatbot-char-count {
    opacity: 0.7;
}

.chatbot-powered-by {
    opacity: 0.7;
}

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

/* ===== OFFLINE STATE ===== */
.chatbot-offline {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--chatbot-white);
    border-radius: var(--chatbot-border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.chatbot-offline-content {
    text-align: center;
    padding: 40px 20px;
}

.chatbot-offline-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
    color: var(--chatbot-gray-400);
}

.chatbot-offline-icon svg {
    width: 100%;
    height: 100%;
}

.chatbot-offline h4 {
    font-size: var(--chatbot-font-size-lg);
    color: var(--chatbot-gray-800);
    margin-bottom: 8px;
}

.chatbot-offline p {
    color: var(--chatbot-gray-600);
    margin-bottom: 20px;
    line-height: 1.5;
}

.chatbot-retry {
    background: var(--chatbot-primary);
    color: var(--chatbot-white);
    border: none;
    border-radius: var(--chatbot-border-radius);
    padding: 12px 24px;
    font-size: var(--chatbot-font-size-base);
    cursor: pointer;
    transition: var(--chatbot-transition);
}

.chatbot-retry:hover {
    background: #0056b3;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    :root {
        --chatbot-window-width: 100vw;
        --chatbot-window-height: 100vh;
        --chatbot-toggle-size: 56px;
    }
    
    .chatbot-widget {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
    }
    
    .chatbot-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        border-radius: 0 !important;
        transform-origin: center !important;
    }
    
    .chatbot-toggle {
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: var(--chatbot-z-index);
    }
    
    .chatbot-header {
        border-radius: 0;
        padding: 20px;
    }
    
    .chatbot-messages {
        padding: 16px;
    }
    
    .chatbot-input-area {
        padding: 16px 20px 20px;
    }
}

@media (max-width: 480px) {
    :root {
        --chatbot-toggle-size: 52px;
    }
    
    .chatbot-toggle {
        bottom: 16px;
        right: 16px;
    }
    
    .chatbot-header {
        padding: 16px;
    }
    
    .chatbot-messages {
        padding: 12px;
        gap: 12px;
    }
    
    .chatbot-message {
        max-width: 90%;
    }
    
    .chatbot-input-area {
        padding: 12px 16px 16px;
    }
}

/* ===== THEME VARIATIONS ===== */

/* Dark Theme */
.chatbot-widget.chatbot-dark {
    --chatbot-white: #2c3e50;
    --chatbot-gray-100: #34495e;
    --chatbot-gray-200: #3d566e;
    --chatbot-gray-300: #46647d;
    --chatbot-gray-800: #ecf0f1;
    --chatbot-gray-700: #bdc3c7;
    --chatbot-gray-600: #95a5a6;
    --chatbot-gray-500: #7f8c8d;
}

.chatbot-widget.chatbot-dark .chatbot-message-bot .chatbot-message-bubble {
    background: #34495e;
    color: #ecf0f1;
    border-color: #3d566e;
}

.chatbot-widget.chatbot-dark .chatbot-input {
    background: #34495e;
    color: #ecf0f1;
    border-color: #3d566e;
}

.chatbot-widget.chatbot-dark .chatbot-input::placeholder {
    color: #7f8c8d;
}

/* Minimal Theme */
.chatbot-widget.chatbot-minimal {
    --chatbot-border-radius: 4px;
    --chatbot-border-radius-sm: 2px;
    --chatbot-border-radius-lg: 6px;
    --chatbot-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --chatbot-shadow-lg: 0 4px 15px rgba(0, 0, 0, 0.15);
}

.chatbot-widget.chatbot-minimal .chatbot-toggle {
    border-radius: var(--chatbot-border-radius);
}

.chatbot-widget.chatbot-minimal .chatbot-message-bubble {
    border-radius: var(--chatbot-border-radius);
}

/* Classic Theme */
.chatbot-widget.chatbot-classic {
    --chatbot-primary: #0066cc;
    --chatbot-border-radius: 6px;
    --chatbot-border-radius-sm: 4px;
    --chatbot-border-radius-lg: 8px;
}

/* ===== ANIMATIONS ===== */
@keyframes chatbot-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes chatbot-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes chatbot-scale-in {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Reduce animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .chatbot-widget * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== ACCESSIBILITY ===== */
.chatbot-widget [role="button"] {
    cursor: pointer;
}

.chatbot-widget button:focus,
.chatbot-widget input:focus {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 2px;
}

.chatbot-widget button:focus:not(:focus-visible) {
    outline: none;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .chatbot-widget {
        --chatbot-gray-300: #000000;
        --chatbot-gray-200: #000000;
    }
    
    .chatbot-message-bot .chatbot-message-bubble {
        border: 2px solid currentColor;
    }
    
    .chatbot-input {
        border: 2px solid currentColor;
    }
}

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