/* ═══════════════════════════════════════════════════════════════
   DriveStream AI — Premium Dark Chat UI
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Custom Properties (Design Tokens) ──────────────────── */
:root {
    /* Background layers */
    --bg-deep: #0a0b0f;
    --bg-primary: #0f1117;
    --bg-secondary: #161822;
    --bg-tertiary: #1c1f2e;
    --bg-elevated: #222538;

    /* Accent colors */
    --accent-primary: #6c5ce7;
    --accent-secondary: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.25);
    --accent-cyan: #00cec9;
    --accent-cyan-glow: rgba(0, 206, 201, 0.2);
    --accent-emerald: #00b894;

    /* Text */
    --text-primary: #e8eaed;
    --text-secondary: #9aa0b4;
    --text-tertiary: #6b7280;
    --text-inverse: #0f1117;

    /* Borders */
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-medium: rgba(255, 255, 255, 0.1);
    --border-focus: rgba(108, 92, 231, 0.5);

    /* Glassmorphism */
    --glass-bg: rgba(22, 24, 34, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-blur: blur(20px);

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px var(--accent-glow);

    /* Spacing */
    --sidebar-width: 280px;
    --header-height: 60px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Border radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-deep);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── App Layout ─────────────────────────────────────────────── */
#app {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: transform var(--transition-normal);
    z-index: 100;
}

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

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

.logo-icon {
    font-size: 28px;
    filter: drop-shadow(0 0 12px var(--accent-glow));
    animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { filter: drop-shadow(0 0 8px var(--accent-glow)); }
    50% { filter: drop-shadow(0 0 20px var(--accent-glow)); }
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

.logo-ai {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 800;
}

.logo-subtitle {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 4px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* ── Sidebar Navigation ─────────────────────────────────────── */
.sidebar-nav {
    padding: 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
    width: 100%;
}

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

.nav-btn.active {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-medium);
    box-shadow: var(--shadow-sm);
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

/* ── Sidebar Info ───────────────────────────────────────────── */
.sidebar-info {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.info-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 16px;
}

.info-card h4 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
    margin-bottom: 8px;
}

.info-card p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.class-list h4 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
    margin-bottom: 10px;
    padding-left: 4px;
}

.class-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    padding: 5px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    color: var(--accent-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.chip:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    box-shadow: 0 0 12px var(--accent-glow);
    transform: translateY(-1px);
}

/* ── Sidebar Footer ─────────────────────────────────────────── */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-subtle);
}

.health-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-tertiary);
}

.health-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    transition: background var(--transition-normal);
}

.health-dot.online {
    background: var(--accent-emerald);
    box-shadow: 0 0 8px rgba(0, 184, 148, 0.5);
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 4px rgba(0, 184, 148, 0.3); }
    50% { box-shadow: 0 0 12px rgba(0, 184, 148, 0.6); }
}

.health-dot.error {
    background: #e74c3c;
}

.repo-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.github-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    color: #ffffff;
    background: #111111;
    border: 1px solid #333333;
    border-radius: 6px;
    text-decoration: none;
    transition: background 0.2s, border-color 0.2s, transform 0.1s;
    width: 100%;
}

.github-link svg {
    color: #ffffff;
}

.github-link:hover {
    background: #000000;
    border-color: #666666;
    transform: translateY(-1px);
}

.github-link:active {
    transform: translateY(0);
}

/* ── Main Content ───────────────────────────────────────────── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-deep);
    overflow: hidden;
    min-width: 0;
}

/* ── Header ─────────────────────────────────────────────────── */
.main-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
}

.main-header h1 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.3px;
    color: var(--text-primary);
    flex: 1;
}

.header-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    font-size: 11px;
    color: var(--text-secondary);
}

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-primary);
}

/* ── Messages Area ──────────────────────────────────────────── */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
}

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

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

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

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

/* ── Message Bubbles ────────────────────────────────────────── */
.message {
    display: flex;
    gap: 14px;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
    animation: message-in 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--accent-primary), #8b5cf6);
    box-shadow: 0 0 16px var(--accent-glow);
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-emerald));
    box-shadow: 0 0 16px var(--accent-cyan-glow);
}

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

.message-text {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    line-height: 1.65;
    font-size: 14.5px;
}

.message.user .message-text {
    background: var(--bg-elevated);
    border: 1px solid var(--border-medium);
    color: var(--text-primary);
}

.message.assistant .message-text {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

/* ── Welcome Message ────────────────────────────────────────── */
.welcome-message .message-text h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-message .message-text p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.suggestions {
    margin-top: 8px;
}

.suggestions h4 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-tertiary);
    margin-bottom: 10px;
}

.suggestion {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    margin-bottom: 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 13.5px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.suggestion:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--accent-primary);
    box-shadow: 0 0 12px var(--accent-glow);
    transform: translateX(4px);
}

/* ── Message Content Formatting ─────────────────────────────── */
.message-text h2, .message-text h3, .message-text h4 {
    margin-top: 16px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.message-text h2:first-child, .message-text h3:first-child {
    margin-top: 0;
}

.message-text p {
    margin-bottom: 10px;
}

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

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

.message-text li {
    margin-bottom: 4px;
    color: var(--text-secondary);
}

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

.message-text em {
    color: var(--accent-secondary);
}

.message-text code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: var(--bg-elevated);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--accent-cyan);
    border: 1px solid var(--border-subtle);
}

.message-text pre {
    margin: 12px 0;
    border-radius: var(--radius-md);
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
}

.message-text pre code {
    display: block;
    padding: 14px 18px;
    background: var(--bg-deep);
    color: var(--text-secondary);
    border: none;
    font-size: 13px;
    line-height: 1.55;
}

/* ── Sources ────────────────────────────────────────────────── */
.sources {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
}

.sources-header {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
    margin-bottom: 8px;
}

.source-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    margin: 2px 4px 2px 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--accent-secondary);
    transition: all var(--transition-fast);
}

.source-tag:hover {
    border-color: var(--accent-primary);
}

.source-relevance {
    font-size: 10px;
    color: var(--accent-emerald);
    font-weight: 600;
}

/* ── Typing Indicator ───────────────────────────────────────── */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-secondary);
    animation: typing-bounce 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-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ── Input Area ─────────────────────────────────────────────── */
.input-area {
    padding: 16px 24px 20px;
    background: linear-gradient(to top, var(--bg-primary) 60%, transparent);
    flex-shrink: 0;
}

.input-form {
    max-width: 860px;
    margin: 0 auto;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-lg);
    padding: 10px 10px 10px 18px;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-md);
}

.input-wrapper:focus-within {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow), var(--shadow-md);
}

#user-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    max-height: 150px;
    min-height: 24px;
}

#user-input::placeholder {
    color: var(--text-tertiary);
}

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

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

.send-btn:not(:disabled):hover {
    background: #7c6cf0;
    box-shadow: 0 0 20px var(--accent-glow);
    transform: scale(1.05);
}

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

.input-hint {
    text-align: center;
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 8px;
    letter-spacing: 0.3px;
}

/* ── Error Message ──────────────────────────────────────────── */
.error-text {
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.2);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

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

    .sidebar-toggle {
        display: block;
    }

    .messages {
        padding: 16px;
    }

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

    .header-badge {
        display: none;
    }
}

/* ── Backdrop for mobile sidebar ────────────────────────────── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
    backdrop-filter: blur(4px);
}

.sidebar-backdrop.visible {
    display: block;
    animation: fade-in 0.2s ease;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
