/* ============================================================
   NovaTech RAG Chatbot — Design System & Styles
   ============================================================
   
   Color Palette:
     - Primary: Deep violet (hsl 250°) to teal (hsl 180°)
     - Surface: Dark slate with translucent glassmorphism
     - Text: Warm whites with subtle opacity hierarchy
   
   Design Principles:
     - Glassmorphism on panels for depth and elegance
     - Subtle animated gradient background for visual interest
     - Micro-animations on every interactive element
     - Clean type hierarchy using Inter + JetBrains Mono
   ============================================================ */

/* ─── CSS RESET & VARIABLES ─── */

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

:root {
    /* Colors */
    --bg-primary: #ffffff;
    --bg-surface: #fdfdfd;
    --bg-surface-hover: #f5f5f5;
    --bg-glass: #ffffff;
    --bg-glass-hover: #f7f7f7;
    
    --accent-primary: #000000;
    --accent-primary-dim: rgba(0, 0, 0, 0.05);
    --accent-secondary: #000000;
    --accent-secondary-dim: rgba(0, 0, 0, 0.05);
    --accent-gradient: #000000;
    --accent-gradient-soft: rgba(0, 0, 0, 0.05);
    
    --text-primary: #111111;
    --text-secondary: #555555;
    --text-tertiary: #888888;
    --text-accent: #000000;
    
    --border-subtle: #eaeaea;
    --border-medium: #cccccc;
    --border-accent: #000000;
    
    --success: #000000;
    --warning: #000000;
    --error: #ff4444;
    
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    
    /* Sizing */
    --sidebar-width: 300px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
    
    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* ─── ANIMATED BACKGROUND ─── */

.bg-gradient {
    display: none;
}

.bg-noise {
    display: none;
}

/* ─── APP CONTAINER ─── */

.app-container {
    position: relative;
    z-index: 1;
    display: flex;
    height: 100vh;
    width: 100%;
}

/* ─── SIDEBAR ─── */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    overflow-y: auto;
    transition: transform var(--transition-base);
}

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

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

.logo-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-primary);
    border-radius: var(--radius-md);
    color: white;
    flex-shrink: 0;
}

.logo-icon svg {
    width: 22px;
    height: 22px;
}

.logo-text h1 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.logo-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-secondary);
    background: var(--accent-secondary-dim);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    margin-top: 2px;
}

/* Sidebar sections */
.sidebar-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.section-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-tertiary);
    margin-bottom: 12px;
}

/* Knowledge base items */
.kb-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.kb-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    transition: var(--transition-fast);
}

.kb-item:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-medium);
}

.kb-item.active {
    border-color: var(--border-accent);
    background: var(--accent-primary-dim);
}

.kb-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.kb-name {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-primary);
}

.kb-desc {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 1px;
}

/* Suggestion buttons */
.suggestion-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.suggestion-btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    font-size: 0.8rem;
    font-family: var(--font-sans);
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
}

.suggestion-btn:hover {
    color: var(--text-primary);
    background: var(--bg-glass-hover);
    border-color: var(--border-medium);
    transform: translateX(4px);
}

/* Sidebar footer */
.sidebar-footer {
    margin-top: auto;
    padding: 16px 20px;
    border-top: 1px solid var(--border-subtle);
}

.status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
    color: var(--text-tertiary);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-tertiary);
    flex-shrink: 0;
    transition: background var(--transition-base);
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.4);
}

.status-dot.error {
    background: var(--error);
    box-shadow: 0 0 8px rgba(248, 113, 113, 0.4);
}

/* ─── MAIN CHAT AREA ─── */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

/* Mobile header */
.mobile-header {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
}

.mobile-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.menu-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

/* Messages container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    scroll-behavior: smooth;
}

/* Scrollbar styling */
.messages-container::-webkit-scrollbar {
    width: 6px;
}

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

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

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

/* Welcome screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    min-height: 60vh;
    animation: fadeIn 0.6s ease;
}

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

.welcome-icon {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-primary);
    border-radius: var(--radius-xl);
    margin-bottom: 20px;
    color: white;
}

.welcome-icon svg {
    width: 36px;
    height: 36px;
}

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

.welcome-screen > p {
    font-size: 0.92rem;
    color: var(--text-secondary);
    max-width: 500px;
    line-height: 1.6;
    margin-bottom: 36px;
}

.welcome-features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    max-width: 680px;
    width: 100%;
}

.feature-card {
    padding: 20px 16px;
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    text-align: center;
    transition: var(--transition-base);
}

.feature-card:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-medium);
    transform: translateY(-4px);
}

.feature-icon {
    font-size: 1.8rem;
    margin-bottom: 10px;
}

.feature-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.feature-desc {
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ─── CHAT MESSAGES ─── */

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.message {
    display: flex;
    gap: 14px;
    animation: messageIn 0.35s ease;
}

@keyframes messageIn {
    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: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.9rem;
    font-weight: 600;
}

.message.assistant .message-avatar {
    background: var(--accent-primary);
    color: white;
}

.message.user .message-avatar {
    background: var(--bg-glass-hover);
    border: 1px solid var(--border-medium);
    color: var(--text-secondary);
}

.message-content {
    max-width: 70%;
    min-width: 0;
}

.message.user .message-content {
    text-align: right;
}

.message-bubble {
    display: inline-block;
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    font-size: 0.88rem;
    line-height: 1.65;
    word-wrap: break-word;
    text-align: left;
}

.message.assistant .message-bubble {
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
}

.message.user .message-bubble {
    background: var(--accent-primary);
    color: white;
    border: none;
}

/* Markdown rendering inside messages */
.message-bubble p {
    margin-bottom: 8px;
}

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

.message-bubble ul, .message-bubble ol {
    padding-left: 20px;
    margin: 8px 0;
}

.message-bubble li {
    margin-bottom: 4px;
    line-height: 1.5;
}

.message-bubble strong {
    font-weight: 600;
    color: var(--text-primary);
}

.message-bubble code {
    font-family: var(--font-mono);
    font-size: 0.82em;
    background: rgba(139, 92, 246, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--text-accent);
}

.message.user .message-bubble code {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.message-bubble pre {
    margin: 10px 0;
    padding: 14px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
}

.message-bubble pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
    font-size: 0.8em;
}

/* Source badges */
.message-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.source-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--accent-secondary);
    background: var(--accent-secondary-dim);
    border: 1px solid rgba(6, 182, 212, 0.2);
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.source-badge::before {
    content: "📄";
    font-size: 0.7rem;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 14px 18px;
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    width: fit-content;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-primary);
    opacity: 1;
}

/* Context expansion */
.context-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    padding: 4px 10px;
    font-size: 0.7rem;
    font-family: var(--font-sans);
    color: var(--text-tertiary);
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: var(--transition-fast);
}

.context-toggle:hover {
    color: var(--text-secondary);
    border-color: var(--border-medium);
}

.context-panel {
    margin-top: 10px;
    padding: 12px 14px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.5;
    display: none;
}

.context-panel.open {
    display: block;
    animation: fadeIn 0.25s ease;
}

.context-chunk {
    padding: 8px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.context-chunk:last-child {
    border-bottom: none;
}

.context-chunk-source {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--accent-secondary);
    margin-bottom: 4px;
}

/* ─── INPUT AREA ─── */

.input-area {
    padding: 16px 24px 20px;
    background: var(--bg-primary);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-lg);
    padding: 10px 14px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-wrapper:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-primary-dim), 0 8px 32px rgba(0, 0, 0, 0.3);
}

.input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    padding: 4px 0;
}

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

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

.send-btn:not(:disabled) {
    opacity: 1;
}

.send-btn:not(:disabled):hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(139, 92, 246, 0.4);
}

.send-btn:not(:disabled):active {
    transform: scale(0.95);
}

.send-btn:disabled {
    cursor: default;
}

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

.input-footer {
    text-align: center;
    margin-top: 10px;
    font-size: 0.68rem;
    color: var(--text-tertiary);
}

/* ─── RESPONSIVE ─── */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 1000;
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }

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

    .mobile-header {
        display: flex;
    }

    .welcome-features {
        grid-template-columns: 1fr;
    }

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

    .messages-container {
        padding: 16px;
    }

    .input-area {
        padding: 12px 16px 16px;
    }
}

@media (max-width: 480px) {
    .welcome-screen h2 {
        font-size: 1.3rem;
    }

    .welcome-screen > p {
        font-size: 0.85rem;
    }
}
