/* ============================================
   Variables y Reset
   ============================================ */
:root {
    /* Colores principales */
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    --secondary-color: #8b5cf6;
    
    /* Colores de fondo */
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --bg-hover: #f5f5f5;
    
    /* Colores de texto */
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    
    /* Colores de mensaje */
    --user-message-bg: #6366f1;
    --user-message-text: #ffffff;
    --bot-message-bg: #f3f4f6;
    --bot-message-text: #111827;
    
    /* Bordes y sombras */
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    
    /* Espaciado */
    --sidebar-width: 280px;
    --header-height: 72px;
    --input-height: auto;
    
    /* Animaciones */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;
    
    /* Otros */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --status-online: #10b981;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    display: flex;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-normal);
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    fill: var(--primary-color);
}

.logo-text {
    font-size: 20px;
    font-weight: 400;
    color: var(--text-primary);
}

.logo-text strong {
    font-weight: 700;
    color: var(--primary-color);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.new-chat-btn {
    width: 100%;
    padding: 12px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.new-chat-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.new-chat-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.conversations-section {
    margin-top: 24px;
}

.section-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
    margin-bottom: 12px;
    padding: 0 8px;
}

.conversations-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.conversation-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--text-secondary);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.conversation-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.conversation-item.active {
    background: var(--primary-light);
    color: var(--primary-color);
    font-weight: 500;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.user-details {
    min-width: 0;
    flex: 1;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-id {
    font-size: 11px;
    color: var(--text-tertiary);
    font-family: 'Courier New', monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.settings-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.settings-btn:hover {
    background: var(--bg-tertiary);
}

.settings-btn svg {
    width: 20px;
    height: 20px;
    fill: var(--text-secondary);
}

/* ============================================
   Chat Main Area
   ============================================ */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.chat-header {
    height: var(--header-height);
    padding: 20px 32px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-primary);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.bot-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: var(--shadow-md);
}

.chat-title h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--status-online);
    animation: pulse 2s ease-in-out infinite;
}

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

.chat-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.config-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    cursor: help;
    transition: all var(--transition-fast);
}

.config-status.configured {
    background: rgba(16, 185, 129, 0.1);
    color: var(--status-online);
}

.config-status.not-configured {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    animation: pulse-warning 2s ease-in-out infinite;
}

.config-status .status-indicator {
    font-size: 14px;
}

@keyframes pulse-warning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    color: var(--text-secondary);
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* ============================================
   Chat Messages
   ============================================ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

.welcome-screen {
    max-width: 700px;
    margin: 0 auto;
    text-align: center;
    padding: 60px 20px;
}

.welcome-icon {
    font-size: 64px;
    margin-bottom: 24px;
    animation: wave 1s ease-in-out;
}

@keyframes wave {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(20deg); }
    75% { transform: rotate(-20deg); }
}

.welcome-screen h2 {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.welcome-screen p {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 40px;
}

.suggestion-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-top: 32px;
}

.suggestion-card {
    padding: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-normal);
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.suggestion-card:hover {
    background: var(--bg-primary);
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.suggestion-icon {
    font-size: 32px;
}

.suggestion-text {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.message {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    animation: fadeIn 0.3s ease;
}

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

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.message.bot .message-avatar {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
}

.message.user .message-avatar {
    background: var(--primary-light);
}

.message-content {
    max-width: 70%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message.user .message-content {
    align-items: flex-end;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.bot .message-bubble {
    background: var(--bot-message-bg);
    color: var(--bot-message-text);
    border-bottom-left-radius: 4px;
}

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

.message-time {
    font-size: 12px;
    color: var(--text-tertiary);
    padding: 0 4px;
}

.typing-indicator {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    animation: fadeIn 0.3s ease;
}

.typing-dots {
    background: var(--bot-message-bg);
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 6px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: typing 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.error-message {
    background: #fee;
    border: 1px solid #fcc;
    color: #c33;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 14px;
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

/* ============================================
   Chat Input
   ============================================ */
.chat-input-container {
    padding: 20px 32px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.chat-input-wrapper {
    max-width: 900px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    transition: all var(--transition-fast);
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary-color);
    background: var(--bg-primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.chat-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 15px;
    font-family: inherit;
    color: var(--text-primary);
    resize: none;
    max-height: 200px;
    line-height: 1.5;
}

.chat-input::placeholder {
    color: var(--text-tertiary);
}

.input-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.attach-btn {
    width: 36px;
    height: 36px;
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--primary-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.send-btn svg {
    width: 20px;
    height: 20px;
    fill: white;
}

.input-footer {
    max-width: 900px;
    margin: 12px auto 0;
    text-align: center;
}

.input-hint {
    font-size: 12px;
    color: var(--text-tertiary);
}

.input-hint kbd {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
}

/* ============================================
   Modal
   ============================================ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-content {
    position: relative;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
    animation: slideUp 0.3s ease;
}

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

.modal-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-tertiary);
}

.modal-close svg {
    width: 20px;
    height: 20px;
    fill: var(--text-secondary);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.settings-group {
    margin-bottom: 24px;
}

.settings-group:last-child {
    margin-bottom: 0;
}

.settings-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.settings-group input[type="text"],
.settings-group input[type="password"],
.settings-group input[type="number"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-secondary);
    transition: all var(--transition-fast);
}

.settings-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.settings-group input[readonly] {
    background: var(--bg-tertiary);
    cursor: not-allowed;
}

.settings-group small {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 400 !important;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.btn-secondary {
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-top: 8px;
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-tertiary);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.btn-primary {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary-color);
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 100;
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .chat-messages {
        padding: 20px 16px;
    }

    .chat-input-container {
        padding: 16px;
    }

    .message-content {
        max-width: 85%;
    }

    .welcome-screen {
        padding: 40px 16px;
    }

    .welcome-screen h2 {
        font-size: 24px;
    }

    .suggestion-cards {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Dark Mode Support (opcional)
   ============================================ */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1f2937;
        --bg-secondary: #111827;
        --bg-tertiary: #374151;
        --bg-hover: #4b5563;
        
        --text-primary: #f9fafb;
        --text-secondary: #d1d5db;
        --text-tertiary: #9ca3af;
        
        --border-color: #374151;
        
        --bot-message-bg: #374151;
        --bot-message-text: #f9fafb;
    }
}
