/**
 * CHATBOT.CSS - Gemini/ChatGPT Style Interface
 * Modern, clean design matching Epstein Archive theme
 */

:root {
    --primary-color: #3b82f6;
    --bg-dark: #0a0a0a;
    --bg-darker: #050505;
    --bg-light: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --border-color: #2a2a2a;
    --hover-bg: #252525;
}

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

.chatbot-body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
}

/* ==================== SHARED MENU ==================== */
/* Match the exact styling from menu.css but use fixed positioning for chatbot layout */
#shared-menu-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    background-color: rgba(10, 10, 10, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid #333; /* Use main site border color */
}

/* Ensure the body doesn't have extra padding when menu is shown */
.chatbot-body.shared-view {
    padding-top: 0;
}

/* Ensure main nav in shared menu has proper centering and max-width like other pages */
#shared-menu-container .main-nav {
    max-width: 1200px;
    margin: 0 auto;
}

/* ==================== SIDEBAR ==================== */
.chatbot-sidebar {
    width: 280px;
    background: var(--bg-darker);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 16px;
    flex-shrink: 0;
}

.sidebar-header {
    margin-bottom: 20px;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 16px;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.sidebar-logo:hover {
    background: var(--hover-bg);
}

.logo-icon {
    font-size: 24px;
}

.new-chat-btn {
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    transition: all 0.2s;
    margin-bottom: 20px;
}

.new-chat-btn:hover {
    background: var(--hover-bg);
    border-color: var(--primary-color);
}

.sidebar-info {
    flex: 1;
    padding: 20px 0;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 8px;
}

.info-item svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-footer {
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.sidebar-link {
    display: block;
    padding: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    border-radius: 6px;
    transition: all 0.2s;
}

.sidebar-link:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

/* ==================== MAIN CHAT AREA ==================== */
.chatbot-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
}

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

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

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

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

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

/* ==================== WELCOME SCREEN ==================== */
.welcome-screen {
    max-width: 800px;
    margin: 0 auto;
    padding: 60px 20px;
    text-align: center;
}

.welcome-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.welcome-title {
    font-size: 48px;
    font-weight: 600;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-subtitle {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 40px;
}

.suggestion-chips {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 12px;
    max-width: 700px;
    margin: 0 auto;
}

.chip {
    padding: 16px 20px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
}

.chip:hover {
    background: var(--hover-bg);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

/* ==================== MESSAGES ==================== */
.message {
    max-width: 800px;
    margin: 0 auto 24px;
    padding: 0 20px;
    animation: fadeIn 0.4s ease-out;
}

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

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(-20px);
    }
}

.message-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

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

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

.bot-message .message-avatar {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.message-sender {
    font-weight: 600;
    font-size: 14px;
}

.message-content {
    padding-left: 44px;
    line-height: 1.6;
    font-size: 15px;
}

.message-content p {
    margin-bottom: 12px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.user-message .message-content {
    color: var(--text-primary);
}

.bot-message .message-content {
    color: var(--text-secondary);
}

/* Source Tags */
.message-sources {
    margin-top: 16px;
    padding: 12px;
    background: var(--bg-light);
    border-radius: 8px;
    border-left: 3px solid var(--primary-color);
}

.message-sources strong {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-primary);
}

.source-tag {
    display: inline-block;
    background: var(--hover-bg);
    padding: 4px 10px;
    border-radius: 6px;
    margin: 4px 4px 4px 0;
    font-size: 12px;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.source-link {
    display: inline-block;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid var(--primary-color);
    padding: 6px 12px;
    border-radius: 6px;
    margin: 4px 4px 4px 0;
    font-size: 12px;
    color: var(--primary-color);
    text-decoration: none;
    transition: all 0.2s;
}

.source-link:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: #60a5fa;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.search-stats {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-secondary);
    font-style: italic;
}

/* Error Messages */
.error-message .message-content {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    padding: 12px;
    border-radius: 8px;
    border-left: 3px solid #ef4444;
}

/* Typing Indicator */
.typing-indicator {
    padding-left: 44px;
}

.typing-dots {
    display: inline-flex;
    gap: 6px;
    padding: 12px 16px;
    background: var(--bg-light);
    border-radius: 18px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

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

/* ==================== INPUT AREA ==================== */
.chatbot-input-wrapper {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, var(--bg-dark) 80%, transparent);
    padding: 20px 20px 30px;
}

.chatbot-input-container {
    max-width: 800px;
    margin: 0 auto;
}

.chatbot-input-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 4px 4px 4px 20px;
    transition: border-color 0.2s;
}

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

.chatbot-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 15px;
    resize: none;
    min-height: 24px;
    max-height: 200px;
    padding: 10px 0;
    line-height: 1.5;
}

.chatbot-input:focus {
    outline: none;
}

.chatbot-input::placeholder {
    color: var(--text-secondary);
}

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

.chatbot-send-btn:hover:not(:disabled) {
    background: #2563eb;
    transform: scale(1.05);
}

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

.chatbot-footer-text {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 12px;
}

/* ==================== MOBILE RESPONSIVE ==================== */
@media (max-width: 768px) {
    .chatbot-sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s;
    }

    .chatbot-sidebar.open {
        left: 0;
    }

    .chatbot-main {
        width: 100%;
    }

    .welcome-title {
        font-size: 36px;
    }

    .welcome-subtitle {
        font-size: 16px;
    }

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

    .message {
        padding: 0 12px;
    }

    .chatbot-input-wrapper {
        padding: 12px;
    }

    .chatbot-input-form {
        padding: 4px 4px 4px 16px;
    }
}


/* ==================== CHAT HISTORY ==================== */
.chat-history {
    flex: 1;
    overflow-y: auto;
    margin: 20px 0;
}

.chat-history::-webkit-scrollbar {
    width: 6px;
}

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

.history-loading,
.history-empty,
.history-error {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

.history-item {
    padding: 10px;
    margin-bottom: 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
}

.history-item:hover {
    background: var(--hover-bg);
}

.history-item.active {
    background: var(--hover-bg);
    border-left: 3px solid var(--primary-color);
}

.history-item-content {
    padding-right: 8px;
}

.history-title {
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.history-actions {
    display: none;
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    gap: 4px;
}

.history-item:hover .history-actions {
    display: flex;
}

.history-action-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--bg-dark);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.history-action-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.history-action-btn.delete:hover {
    background: #ef4444;
    color: white;
}

/* Rename Input */
.rename-input {
    background: var(--bg-dark);
    border: 1px solid var(--primary-color);
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 13px;
    width: calc(100% - 60px);
    font-family: 'Inter', sans-serif;
}

.rename-input:focus {
    outline: none;
}

.rename-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    margin-left: 4px;
    transition: all 0.2s;
}

.rename-btn.confirm:hover {
    background: #10b981;
    color: white;
}

.rename-btn.cancel:hover {
    background: #ef4444;
    color: white;
}

/* ==================== MODALS ==================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 9998;
    display: none;
}

.modal-overlay.active {
    display: block;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s;
}

.modal.active {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    pointer-events: all;
}

.modal-content {
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    min-width: 400px;
    max-width: 90vw;
}

.modal-content h3 {
    margin: 0 0 12px 0;
    font-size: 20px;
    color: var(--text-primary);
}

.modal-content p {
    margin: 0 0 20px 0;
    color: var(--text-secondary);
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.btn-secondary,
.btn-danger,
.btn-copy,
.btn-continue-chat {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
}

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

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

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

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

.btn-copy:hover {
    background: #2563eb;
}

/* Share Link */
.share-link-container {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.share-link-input {
    flex: 1;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-family: 'Inter', monospace;
}

.share-link-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Continue Chat Button */
.continue-chat-container {
    text-align: center;
    padding: 40px 20px;
    border-top: 1px solid var(--border-color);
    margin-top: 20px;
}

.btn-continue-chat {
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    color: white;
    padding: 16px 32px;
    font-size: 16px;
}

.btn-continue-chat:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

/* ==================== MOBILE RESPONSIVE ==================== */
@media (max-width: 768px) {
    .modal-content {
        min-width: 300px;
        padding: 20px;
    }
    
    .modal-content h3 {
        font-size: 18px;
    }
    
    .modal-actions {
        flex-direction: column;
    }
    
    .btn-secondary,
    .btn-danger {
        width: 100%;
    }
    
    .share-link-container {
        flex-direction: column;
    }
    
    .history-actions {
        display: flex;
        position: static;
        transform: none;
        margin-top: 8px;
        justify-content: flex-end;
    }
}
