@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Design Tokens ──────────────────────────────────────────────────────────── */
:root {
    /* Brand */
    --primary:        #6366f1;
    --primary-dark:   #4f46e5;
    --primary-light:  #818cf8;

    /* Status */
    --success: #22c55e;
    --danger:  #ef4444;
    --warning: #f59e0b;
    --error:   #ef4444;
    --accent:  #6366f1;

    /* Backgrounds */
    --bg-base:      #0d0d14;
    --bg-primary:   #0d0d14;
    --bg-surface:   #13131c;
    --bg-secondary: #13131c;
    --bg-elevated:  #1a1a26;
    --bg-tertiary:  #1a1a26;
    --bg-card:      #13131c;
    --bg-hover:     #1f1f2e;

    /* Text */
    --text-primary:   #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted:     #4f6279;

    /* Borders */
    --border:         rgba(255,255,255,0.08);
    --border-light:   rgba(255,255,255,0.12);
    --border-color:   rgba(255,255,255,0.08);

    /* Shadows */
    --shadow:    0 1px 3px rgba(0,0,0,0.35), 0 1px 2px rgba(0,0,0,0.25);
    --shadow-lg: 0 10px 20px rgba(0,0,0,0.4), 0 4px 8px rgba(0,0,0,0.3);
    --glow:      0 0 24px rgba(99,102,241,0.12);

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 0.75rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    padding: var(--spacing-lg);
    -webkit-font-smoothing: antialiased;
}

/* ── App Shell (sidebar-nav layout for non-chat pages) ──────────────────────── */
body.app-body {
    padding: 0;
    overflow: hidden;
    background: var(--bg-base);
}

.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.app-nav {
    width: 220px;
    flex-shrink: 0;
    background: #0a0a10;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.app-nav-logo {
    padding: 1.25rem 1.25rem 1.1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.app-nav-logo-wordmark {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.app-nav-logo-wordmark span { font-size: 1.1rem; }

.app-nav-logo-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
    letter-spacing: 0.02em;
}

.app-nav-links {
    flex: 1;
    overflow-y: auto;
    padding: 0.6rem 0.5rem;
}
.app-nav-links::-webkit-scrollbar { width: 3px; }
.app-nav-links::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.app-nav-section {
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.65rem 0.75rem 0.2rem;
}

.app-nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.48rem 0.75rem;
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.855rem;
    font-weight: 500;
    transition: all 0.12s;
    margin-bottom: 1px;
    border: 1px solid transparent;
}

.app-nav-link:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
}

.app-nav-link.active {
    background: rgba(99,102,241,0.12);
    color: #a5b4fc;
    border-color: rgba(99,102,241,0.2);
}

.app-nav-link-icon {
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    font-size: 0.9rem;
    opacity: 0.8;
}

.app-nav-bottom {
    padding: 0.7rem 0.75rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.app-nav-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.3rem;
}

.app-nav-user-name {
    font-size: 0.78rem;
    color: var(--text-muted);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-nav-logout {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.72rem;
    cursor: pointer;
    font-family: inherit;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    transition: all 0.12s;
    flex-shrink: 0;
}
.app-nav-logout:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-secondary);
}

.app-content {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-base);
    display: flex;
    flex-direction: column;
}
.app-content::-webkit-scrollbar { width: 5px; }
.app-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }

.app-content-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 2.5rem 2rem 3rem;
    width: 100%;
}

.page-header {
    margin-bottom: 2rem;
}

.page-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.page-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ── Auth Pages ─────────────────────────────────────────────────────────────── */
body.auth-body {
    padding: 0;
    background: var(--bg-base);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 1.5rem;
}

.auth-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-lg);
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo-icon {
    font-size: 2rem;
    display: block;
    margin-bottom: 0.75rem;
}

.auth-logo-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.auth-logo-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.auth-heading {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin-bottom: 0.3rem;
}

.auth-subheading {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1.75rem;
}

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.auth-footer a {
    color: var(--primary-light);
    text-decoration: none;
    font-weight: 500;
}
.auth-footer a:hover { text-decoration: underline; }

.auth-error {
    color: var(--danger);
    font-size: 0.835rem;
    text-align: center;
    margin-top: 0.75rem;
    display: none;
}

.auth-success {
    color: var(--success);
    font-size: 0.835rem;
    text-align: center;
    margin-top: 0.75rem;
    display: none;
}

/* ── Legacy container (non-app-shell pages) ─────────────────────────────────── */
.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* ── Header (legacy top-nav) ────────────────────────────────────────────────── */
.app-header {
    background: rgba(13,13,20,0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    margin-bottom: var(--spacing-xl);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon { font-size: 1.5rem; }

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}

.nav-link:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.05);
}

.nav-link.active {
    color: var(--text-primary);
    background: rgba(99,102,241,0.15);
    border: 1px solid rgba(99,102,241,0.25);
}

/* ── Dashboard Grid ─────────────────────────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-top: 0;
}

.dashboard-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 2rem 1.5rem;
    text-align: left;
    text-decoration: none;
    color: var(--text-primary);
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.dashboard-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), transparent);
    opacity: 0;
    transition: opacity 0.2s;
}

.dashboard-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-light);
    background: var(--bg-elevated);
}

.dashboard-card:hover::before { opacity: 1; }

.card-icon {
    font-size: 2rem;
    display: block;
}

.dashboard-card h3 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.dashboard-card p {
    color: var(--text-muted);
    font-size: 0.835rem;
    line-height: 1.55;
}

.dashboard-card-arrow {
    margin-top: auto;
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding-top: 0.5rem;
}

/* ── Stats Bar ───────────────────────────────────────────────────────────────── */
.stats-bar {
    display: flex;
    gap: var(--spacing-xl);
    padding: var(--spacing-lg) var(--spacing-xl);
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    margin-bottom: 2rem;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary-light);
    letter-spacing: -0.02em;
}

.status-healthy {
    color: var(--success);
    font-size: 1.8rem;
    animation: pulse 2.5s infinite;
}

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

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
    padding: 0.55rem 1.1rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    text-decoration: none;
}

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

.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 1px 4px rgba(99,102,241,0.35);
}
.btn-primary:hover {
    background: var(--primary-light);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99,102,241,0.45);
    border-color: transparent;
}

.btn-secondary {
    background: rgba(255,255,255,0.07);
    color: var(--text-primary);
    border-color: var(--border);
}
.btn-secondary:hover { background: rgba(255,255,255,0.11); }

.btn-danger {
    background: rgba(239,68,68,0.12);
    color: #fca5a5;
    border-color: rgba(239,68,68,0.25);
}
.btn-danger:hover {
    background: rgba(239,68,68,0.2);
    color: #fecaca;
}

.btn-success {
    background: rgba(34,197,94,0.12);
    color: #86efac;
    border-color: rgba(34,197,94,0.25);
}
.btn-success:hover { background: rgba(34,197,94,0.2); color: #bbf7d0; }

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
}

/* ── Form Controls ───────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }

.form-group label,
.form-control-label {
    display: block;
    margin-bottom: 0.4rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
}

.form-control,
.search-input,
.textarea {
    width: 100%;
    padding: 0.6rem 0.875rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus,
.search-input:focus,
.textarea:focus {
    outline: none;
    border-color: rgba(99,102,241,0.5);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.08);
}

.form-control::placeholder,
.search-input::placeholder {
    color: var(--text-muted);
}

.input-small {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    transition: border-color 0.15s;
}
.input-small:focus { outline: none; border-color: rgba(99,102,241,0.5); }

/* ── Modals ───────────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal {
    width: 100%;
    max-width: 500px;
    animation: modalPop 0.25s ease-out;
}

@keyframes modalPop {
    from { transform: scale(0.94) translateY(-8px); opacity: 0; }
    to   { transform: scale(1) translateY(0);       opacity: 1; }
}

.modal h2 {
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: 1.25rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* ── Loading ──────────────────────────────────────────────────────────────────── */
.loading-spinner {
    width: 36px;
    height: 36px;
    border: 2px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 0.9s linear infinite;
    margin: 1rem auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast Notifications ─────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: var(--spacing-lg);
    right: var(--spacing-lg);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1.25rem;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    min-width: 280px;
    max-width: 380px;
    animation: toastSlide 0.25s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.875rem;
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes toastSlide {
    from { transform: translateX(120%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

/* ── Search Results ──────────────────────────────────────────────────────────── */
.results-container {
    margin-top: 1.5rem;
}

/* ── Search Options ──────────────────────────────────────────────────────────── */
.search-options {
    display: flex;
    gap: 1rem;
    margin-top: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.search-options .option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.search-box {
    display: flex;
    gap: 0.75rem;
}

.search-section h2 { margin-bottom: 1rem; }
.add-section h2    { margin-bottom: 1rem; }

/* ── Section Title ───────────────────────────────────────────────────────────── */
.section-title {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

/* ── Main content padding for legacy pages ───────────────────────────────────── */
.main { margin-top: 1rem; }

/* ── Dark mode class (used on login/register) ────────────────────────────────── */
body.dark-mode {
    background: var(--bg-base);
    color: var(--text-primary);
}

/* ── App-container alias ─────────────────────────────────────────────────────── */
.app-container { max-width: 1200px; margin: 0 auto; }

/* ── Main content alias ─────────────────────────────────────────────────────── */
.main-content { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }

/* ════════════════════════════════════════════════════════════════════════════════
   CHAT PAGES (Claude-style layout)
   ════════════════════════════════════════════════════════════════════════════════ */

body.chat-body {
    padding: 0 !important;
    overflow: hidden;
    background: #141420;
}

.chat-app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Chat Sidebar */
.chat-sidebar {
    width: 260px;
    flex-shrink: 0;
    background: #0e0e16;
    border-right: 1px solid rgba(255,255,255,0.07);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-logo {
    padding: 1.1rem 1rem 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
}

.sidebar-logo-icon { font-size: 1.2rem; }

.sidebar-logo-text {
    font-size: 0.88rem;
    font-weight: 600;
    color: rgba(255,255,255,0.88);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    letter-spacing: -0.01em;
}

.sidebar-hub-link {
    color: rgba(255,255,255,0.3);
    text-decoration: none;
    font-size: 0.72rem;
    font-weight: 400;
    margin-left: 0.4rem;
    transition: color 0.15s;
}
.sidebar-hub-link:hover { color: rgba(255,255,255,0.6); }

.sidebar-selectors {
    padding: 0.6rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}

.sidebar-select-label {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.28);
    margin-bottom: 0.15rem;
}

.sidebar-select {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 6px;
    color: rgba(255,255,255,0.65);
    font-size: 0.78rem;
    font-family: inherit;
    padding: 0.35rem 0.5rem;
    cursor: pointer;
    transition: border-color 0.15s;
}
.sidebar-select:focus { outline: none; border-color: rgba(255,255,255,0.2); }

.sidebar-new-btn {
    margin: 0.6rem 0.75rem;
    padding: 0.5rem 1rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 7px;
    color: rgba(255,255,255,0.75);
    font-family: inherit;
    font-size: 0.845rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}
.sidebar-new-btn:hover {
    background: rgba(255,255,255,0.09);
    border-color: rgba(255,255,255,0.15);
    color: white;
}

.sidebar-conversations {
    flex: 1;
    overflow-y: auto;
    padding: 0.25rem 0.5rem;
}
.sidebar-conversations::-webkit-scrollbar { width: 3px; }
.sidebar-conversations::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.09); border-radius: 3px; }

.sidebar-section-label {
    padding: 0.55rem 0.5rem 0.2rem;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.25);
}

.conv-item {
    padding: 0.48rem 0.6rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 1px;
}
.conv-item:hover { background: rgba(255,255,255,0.06); }
.conv-item.active { background: rgba(255,255,255,0.09); }

.conv-title {
    font-size: 0.82rem;
    color: rgba(255,255,255,0.65);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}
.conv-item.active .conv-title { color: rgba(255,255,255,0.92); }

.conv-delete {
    opacity: 0;
    background: none;
    border: none;
    color: rgba(255,255,255,0.3);
    cursor: pointer;
    padding: 2px 3px;
    border-radius: 3px;
    flex-shrink: 0;
    transition: all 0.1s;
    display: flex;
    align-items: center;
}
.conv-item:hover .conv-delete { opacity: 1; }
.conv-delete:hover { background: rgba(239,68,68,0.15); color: #fca5a5; }

.sidebar-bottom {
    padding: 0.65rem 0.75rem;
    border-top: 1px solid rgba(255,255,255,0.07);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}
.sidebar-user {
    font-size: 0.77rem;
    color: rgba(255,255,255,0.35);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}
.sidebar-logout {
    background: none;
    border: none;
    color: rgba(255,255,255,0.28);
    font-size: 0.73rem;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: inherit;
    transition: all 0.1s;
    flex-shrink: 0;
}
.sidebar-logout:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.6); }

.sidebar-hub-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.35);
    font-size: 0.73rem;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: inherit;
    transition: all 0.1s;
    flex-shrink: 0;
    text-decoration: none;
    font-weight: 500;
}
.sidebar-hub-btn:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.65); }

/* Chat Main */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #141420;
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1.5rem 1rem;
    scroll-behavior: smooth;
}
.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.09); border-radius: 4px; }

.messages-inner {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
}

/* Welcome */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 5rem 2rem 2rem;
    text-align: center;
    gap: 0.75rem;
}
.chat-welcome-icon { font-size: 2.25rem; margin-bottom: 0.25rem; }
.chat-welcome h2 {
    font-size: 1.4rem;
    font-weight: 600;
    color: rgba(255,255,255,0.88);
    letter-spacing: -0.02em;
    margin: 0;
}
.chat-welcome p {
    color: rgba(255,255,255,0.35);
    font-size: 0.875rem;
    max-width: 380px;
    line-height: 1.6;
    margin: 0;
}
.chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.75rem;
    width: 100%;
    max-width: 400px;
}
.chat-suggestion {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 9px;
    padding: 0.6rem 1rem;
    color: rgba(255,255,255,0.55);
    font-size: 0.845rem;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    font-family: inherit;
    line-height: 1.45;
}
.chat-suggestion:hover {
    background: rgba(255,255,255,0.07);
    border-color: rgba(255,255,255,0.14);
    color: rgba(255,255,255,0.82);
}

/* Messages */
.msg {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
}
.msg.user-msg { flex-direction: row-reverse; }

.msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    flex-shrink: 0;
    margin-top: 2px;
}
.msg.ai-msg .msg-avatar {
    background: rgba(99,102,241,0.12);
    border: 1px solid rgba(99,102,241,0.22);
}
.msg.user-msg .msg-avatar {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.09);
}

.msg-body { flex: 1; min-width: 0; }
.msg.user-msg .msg-body { display: flex; justify-content: flex-end; }

.msg-bubble {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 18px 18px 4px 18px;
    padding: 0.6rem 1rem;
    font-size: 0.92rem;
    line-height: 1.55;
    color: rgba(255,255,255,0.88);
    max-width: 85%;
    word-break: break-word;
    white-space: pre-wrap;
}

.msg-text {
    font-size: 0.94rem;
    line-height: 1.75;
    color: rgba(255,255,255,0.85);
    word-break: break-word;
}
.msg-text p { margin: 0 0 0.75rem; }
.msg-text p:last-child { margin-bottom: 0; }
.msg-text strong { color: rgba(255,255,255,0.96); font-weight: 600; }
.msg-text em { font-style: italic; color: rgba(255,255,255,0.7); }
.msg-text code {
    background: rgba(255,255,255,0.09);
    border: 1px solid rgba(255,255,255,0.11);
    border-radius: 4px;
    padding: 0.12em 0.36em;
    font-size: 0.855em;
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
    color: #e5c07b;
}
.msg-text pre {
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 8px;
    padding: 1rem;
    overflow-x: auto;
    margin: 0.75rem 0;
}
.msg-text pre code { background: none; border: none; padding: 0; color: #abb2bf; font-size: 0.84rem; }
.msg-text h1, .msg-text h2, .msg-text h3 {
    color: rgba(255,255,255,0.94);
    font-weight: 600;
    margin: 1rem 0 0.3rem;
    line-height: 1.3;
    letter-spacing: -0.01em;
}
.msg-text h1 { font-size: 1.18rem; }
.msg-text h2 { font-size: 1.04rem; }
.msg-text h3 { font-size: 0.965rem; }
.msg-text ul, .msg-text ol { padding-left: 1.4rem; margin: 0.4rem 0 0.75rem; }
.msg-text li { margin-bottom: 0.25rem; }
.msg-text blockquote {
    border-left: 3px solid rgba(99,102,241,0.45);
    margin: 0.5rem 0;
    padding: 0.2rem 0 0.2rem 0.85rem;
    color: rgba(255,255,255,0.48);
    font-style: italic;
}
.msg-text hr { border: none; border-top: 1px solid rgba(255,255,255,0.09); margin: 1rem 0; }
.msg-text a { color: #818cf8; text-decoration: underline; }

/* Typing dots */
.typing-dots {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0.4rem 0;
}
.typing-dots span {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: rgba(255,255,255,0.28);
    animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.typing-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.28; }
    30%            { transform: translateY(-5px); opacity: 0.9; }
}

/* Input area */
.input-area {
    padding: 0.75rem 1.5rem 1.25rem;
    background: #141420;
    flex-shrink: 0;
}
.input-wrapper {
    max-width: 720px;
    margin: 0 auto;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.11);
    border-radius: 13px;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.6rem 0.7rem;
    transition: border-color 0.2s;
}
.input-wrapper:focus-within { border-color: rgba(255,255,255,0.22); }

.chat-textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: rgba(255,255,255,0.9);
    font-family: inherit;
    font-size: 0.93rem;
    line-height: 1.55;
    resize: none;
    min-height: 26px;
    max-height: 200px;
    overflow-y: auto;
    padding: 0;
}
.chat-textarea::placeholder { color: rgba(255,255,255,0.2); }
.chat-textarea::-webkit-scrollbar { width: 3px; }
.chat-textarea::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.09); border-radius: 2px; }

.chat-send-btn {
    width: 30px; height: 30px;
    border-radius: 7px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.3);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
    align-self: flex-end;
}
.chat-send-btn.ready {
    background: rgba(255,255,255,0.88);
    border-color: rgba(255,255,255,0.88);
    color: #141420;
}
.chat-send-btn.ready:hover { background: white; }
.chat-send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.input-footer {
    max-width: 720px;
    margin: 0.35rem auto 0;
    text-align: center;
    font-size: 0.69rem;
    color: rgba(255,255,255,0.15);
}

/* Chat input alias (used in profile.html) */
.chat-input {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.6rem 0.875rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    height: 2.5rem;
    transition: border-color 0.15s;
}
.chat-input:focus { outline: none; border-color: rgba(99,102,241,0.5); }

/* ── Chat History Panel (collapsible, between app-nav and chat area) ───────── */
.chat-history-panel {
    width: 240px;
    flex-shrink: 0;
    background: #0e0e16;
    border-right: 1px solid rgba(255,255,255,0.07);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.2s ease, opacity 0.2s ease;
}

.chat-history-panel.collapsed {
    width: 0;
    border-right: none;
    opacity: 0;
    pointer-events: none;
}

/* ── Chat Content Area (main chat region) ─────────────────────────────────── */
.chat-content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #141420;
}

/* ── Chat Header (toggle + mode tabs) ─────────────────────────────────────── */
.chat-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
    background: #141420;
}

.chat-history-toggle {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 6px;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    padding: 0.35rem 0.45rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}
.chat-history-toggle:hover {
    background: rgba(255,255,255,0.09);
    color: rgba(255,255,255,0.8);
}

/* ── Mode Tabs ────────────────────────────────────────────────────────────── */
.chat-mode-tabs {
    display: flex;
    gap: 0;
    background: rgba(255,255,255,0.04);
    border-radius: 8px;
    padding: 3px;
    border: 1px solid rgba(255,255,255,0.07);
}

.chat-mode-tab {
    background: none;
    border: none;
    border-radius: 6px;
    color: rgba(255,255,255,0.4);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.35rem 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.chat-mode-tab:hover {
    color: rgba(255,255,255,0.65);
}
.chat-mode-tab.active {
    background: rgba(99,102,241,0.18);
    color: #a5b4fc;
    border: 1px solid rgba(99,102,241,0.25);
}

/* ── Chat Status Bar ──────────────────────────────────────────────────────── */
.chat-status-bar {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.3);
    padding: 0 0.5rem;
    white-space: nowrap;
    margin-left: auto;
}
.chat-status-bar:empty { display: none; }

/* ── Source Documents in Messages ──────────────────────────────────────────── */
.msg-sources {
    margin-top: 0.75rem;
    font-size: 0.78rem;
    color: rgba(255,255,255,0.45);
}

.msg-sources-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,0.45);
    font-size: 0.78rem;
    font-family: inherit;
    padding: 0;
    transition: color 0.15s;
}
.msg-sources-toggle:hover { color: rgba(255,255,255,0.7); }

.msg-sources-list {
    display: none;
    margin-top: 0.5rem;
    flex-direction: column;
    gap: 0.3rem;
}

.msg-source-item {
    background: rgba(255,255,255,0.06);
    border-radius: 4px;
    padding: 0.3rem 0.6rem;
    font-size: 0.76rem;
    color: rgba(255,255,255,0.5);
}

/* ════════════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .chat-sidebar { display: none; }
    .chat-history-panel { display: none; }
    .app-nav { display: none; }
    .messages-area { padding: 1rem 0.75rem 0.75rem; }
    .input-area { padding: 0.5rem 0.75rem 1rem; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .stats-bar { flex-wrap: wrap; gap: 1rem; }
}
