/* ============================================================
   Santhira Medical Coding — Design System
   Modern medical SaaS inspired by Linear/Notion/Vercel
   ============================================================ */

/* --- Custom Properties --- */
:root {
    /* Primary palette */
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --primary-50: rgba(79, 70, 229, 0.08);
    --primary-100: rgba(79, 70, 229, 0.15);

    /* Medical accent */
    --accent: #0d9488;
    --accent-hover: #0f766e;
    --accent-light: #f0fdfa;

    /* Sidebar */
    --sidebar-bg: #1e1b4b;
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    --sidebar-active: rgba(255, 255, 255, 0.12);
    --sidebar-text: rgba(255, 255, 255, 0.7);
    --sidebar-text-active: #ffffff;
    --sidebar-width: 260px;

    /* Neutrals */
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --text: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;

    /* Semantic */
    --success: #10b981;
    --success-light: #ecfdf5;
    --error: #ef4444;
    --error-light: #fef2f2;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --info: #3b82f6;
    --info-light: #eff6ff;

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

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 10px 10px -5px rgba(0, 0, 0, 0.03);

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Z-index layers */
    --z-sidebar: 40;
    --z-overlay: 45;
    --z-header: 30;
    --z-toast: 100;
    --z-modal: 50;
}

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

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

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

::selection {
    background: var(--primary);
    color: #fff;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

a {
    color: var(--primary);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

img { max-width: 100%; }
.hidden { display: none !important; }

/* --- Layout System --- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: var(--z-sidebar);
    transition: transform var(--transition-slow);
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-lg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sidebar-brand-icon svg {
    color: #fff;
    width: 20px;
    height: 20px;
}

.sidebar-brand-text {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.01em;
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-md) 0;
}

.sidebar-section-title {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.35);
    padding: var(--space-md) var(--space-lg) var(--space-xs);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.6rem var(--space-lg);
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
    margin: 1px 0;
}
.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
    text-decoration: none;
}
.sidebar-link.active {
    background: var(--sidebar-active);
    color: var(--sidebar-text-active);
    border-left-color: var(--primary);
}
.sidebar-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}
.sidebar-link.active svg,
.sidebar-link:hover svg {
    opacity: 1;
}

.sidebar-footer {
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-tenant {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.05);
    margin-bottom: var(--space-sm);
}
.sidebar-tenant-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}
.sidebar-tenant-name {
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-logout {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    color: var(--sidebar-text);
    cursor: pointer;
    border: none;
    background: none;
    font-size: 0.85rem;
    font-family: var(--font);
    width: 100%;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.sidebar-logout:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}
.sidebar-logout svg {
    width: 16px;
    height: 16px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-overlay);
    backdrop-filter: blur(2px);
}

/* Main content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.main-header {
    position: sticky;
    top: 0;
    z-index: var(--z-header);
    background: rgba(248, 250, 252, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 0 var(--space-xl);
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    padding: var(--space-sm);
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
}
.mobile-menu-btn:hover {
    background: var(--bg-hover);
}
.mobile-menu-btn svg {
    width: 22px;
    height: 22px;
}

.page-content {
    flex: 1;
    padding: var(--space-xl);
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
}

/* --- Card System --- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-base);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-glass {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.card-flat {
    box-shadow: none;
}
.card-flat:hover {
    box-shadow: none;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: 0.55rem 1.1rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-fast);
    line-height: 1.4;
    white-space: nowrap;
}
.btn:hover {
    text-decoration: none;
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--border);
}

.btn-danger {
    background: var(--error);
    color: #fff;
}
.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.35);
}

.btn-accent {
    background: var(--accent);
    color: #fff;
}
.btn-accent:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 2px 8px rgba(13, 148, 136, 0.35);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text);
}

.btn-icon {
    padding: 0.5rem;
    border-radius: var(--radius-md);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}
.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}
.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* --- Forms --- */
input, textarea, select {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg-card);
    transition: all var(--transition-fast);
    line-height: 1.5;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-50);
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
}

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

.input-with-icon {
    position: relative;
}
.input-with-icon input {
    padding-left: 2.5rem;
}
.input-with-icon .input-icon {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}
.input-with-icon .input-icon svg {
    width: 16px;
    height: 16px;
}

/* --- Login Page --- */
.login-page {
    min-height: 100vh;
    display: flex;
    background: var(--bg);
}

.login-left {
    flex: 1;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 40%, #4f46e5 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: var(--space-2xl) 4rem;
    position: relative;
    overflow: hidden;
}
.login-left::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 80%;
    height: 150%;
    background: radial-gradient(circle, rgba(79, 70, 229, 0.3), transparent 70%);
    pointer-events: none;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-2xl);
    position: relative;
}
.login-brand-icon {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
}
.login-brand-icon svg {
    color: #fff;
    width: 24px;
    height: 24px;
}
.login-brand-name {
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
}

.login-tagline {
    font-size: 2.2rem;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
    letter-spacing: -0.03em;
    margin-bottom: var(--space-md);
    position: relative;
}
.login-subtitle {
    font-size: 1.05rem;
    color: rgba(255, 255, 255, 0.65);
    line-height: 1.6;
    margin-bottom: var(--space-2xl);
    max-width: 480px;
    position: relative;
}

.login-features {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    position: relative;
}

.feature-card {
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    transition: all var(--transition-base);
}
.feature-card:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateY(-2px);
}
.feature-card-icon {
    width: 36px;
    height: 36px;
    background: rgba(79, 70, 229, 0.3);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-sm);
}
.feature-card-icon svg {
    width: 18px;
    height: 18px;
    color: #c7d2fe;
}
.feature-card h3 {
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: var(--space-xs);
}
.feature-card p {
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.85rem;
    line-height: 1.5;
}

.login-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
}

.login-form-container {
    width: 100%;
    max-width: 420px;
}

.login-form-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--space-xs);
    letter-spacing: -0.02em;
}
.login-form-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: var(--space-xl);
}

.auth-tabs {
    display: flex;
    background: var(--bg-hover);
    border-radius: var(--radius-md);
    padding: 3px;
    margin-bottom: var(--space-xl);
}
.auth-tab {
    flex: 1;
    padding: 0.55rem;
    text-align: center;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    border: none;
    background: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font);
}
.auth-tab.active {
    background: var(--bg-card);
    color: var(--text);
    box-shadow: var(--shadow-xs);
}

.login-form .form-group {
    margin-bottom: var(--space-md);
}
.login-form .btn-primary {
    width: 100%;
    padding: 0.7rem;
    font-size: 0.95rem;
    margin-top: var(--space-sm);
}

/* Tenant section in login */
.tenant-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: var(--space-sm);
}
.tenant-card:hover {
    border-color: var(--primary);
    background: var(--primary-50);
}
.tenant-card-info {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}
.tenant-card-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}
.tenant-card-name {
    font-weight: 600;
    font-size: 0.95rem;
}
.tenant-card-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.tenant-card-arrow {
    color: var(--text-muted);
}
.tenant-card-arrow svg {
    width: 16px;
    height: 16px;
}

.tenant-divider {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin: var(--space-lg) 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}
.tenant-divider::before,
.tenant-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* --- Notebook Grid --- */
.notebook-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-md);
}

.notebook-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}
.notebook-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.notebook-card-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space-xs);
}
.notebook-card-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: var(--space-md);
    line-height: 1.5;
}
.notebook-card-meta {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    font-size: 0.78rem;
    color: var(--text-muted);
}
.notebook-card-meta svg {
    width: 13px;
    height: 13px;
}
.notebook-card-meta span {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.notebook-card-actions {
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    display: flex;
    gap: var(--space-xs);
    opacity: 0;
    transition: opacity var(--transition-fast);
}
.notebook-card:hover .notebook-card-actions {
    opacity: 1;
}

.empty-state {
    text-align: center;
    padding: var(--space-2xl) var(--space-xl);
    color: var(--text-muted);
}
.empty-state-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto var(--space-md);
    background: var(--bg-hover);
    border-radius: var(--radius-xl);
    display: flex;
    align-items: center;
    justify-content: center;
}
.empty-state-icon svg {
    width: 28px;
    height: 28px;
    color: var(--text-muted);
}
.empty-state h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}
.empty-state p {
    font-size: 0.85rem;
    margin-bottom: var(--space-md);
}

/* --- Upload Zone --- */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    text-align: center;
    transition: all var(--transition-base);
    cursor: pointer;
}
.upload-zone:hover {
    border-color: var(--primary);
    background: var(--primary-50);
}
.upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-100);
    box-shadow: 0 0 0 4px var(--primary-50);
}
.upload-zone-icon {
    margin-bottom: var(--space-sm);
    color: var(--text-muted);
}
.upload-zone-icon svg {
    width: 36px;
    height: 36px;
}
.upload-zone-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.upload-zone-text strong {
    color: var(--primary);
}
.upload-zone-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: var(--space-xs);
}

.upload-url-row {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}
.upload-url-row input {
    flex: 1;
    margin-bottom: 0;
}

/* --- Source List --- */
.source-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-light);
    transition: background var(--transition-fast);
}
.source-item:last-child {
    border-bottom: none;
}
.source-item:hover {
    background: var(--bg-hover);
}
.source-item-info {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-width: 0;
}
.source-item-name {
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.source-item-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.55rem;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-pdf { background: #fef3c7; color: #92400e; }
.badge-txt { background: #e2e8f0; color: #475569; }
.badge-text { background: #e2e8f0; color: #475569; }
.badge-url { background: #ccfbf1; color: #115e59; }
.badge-md { background: #e0e7ff; color: #3730a3; }

/* --- AI Actions --- */
.ai-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.ai-action-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 0.5rem 0.9rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font);
}
.ai-action-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-50);
}
.ai-action-btn svg {
    width: 15px;
    height: 15px;
}

/* --- Insight Output --- */
.insight-card {
    border-left: 4px solid var(--accent);
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    margin-top: var(--space-md);
}
.insight-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}
.insight-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

/* --- Chat Interface --- */
.chat-layout {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 64px);
}

.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-muted);
}
.chat-welcome-icon {
    width: 64px;
    height: 64px;
    background: var(--primary-light);
    border-radius: var(--radius-xl);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-md);
}
.chat-welcome-icon svg {
    width: 32px;
    height: 32px;
    color: var(--primary);
}
.chat-welcome h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space-xs);
}
.chat-welcome p {
    font-size: 0.9rem;
    max-width: 360px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.msg {
    max-width: 75%;
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius-lg);
    font-size: 0.9rem;
    line-height: 1.6;
    animation: fadeIn var(--transition-base);
}

.msg-user {
    background: var(--primary);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.msg-assistant {
    background: var(--bg-hover);
    color: var(--text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.msg-assistant .markdown-body {
    font-size: 0.9rem;
    line-height: 1.7;
}

.citation-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
    vertical-align: super;
}
.citation-badge:hover {
    background: var(--primary);
    color: #fff;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.85rem 1.1rem;
    background: var(--bg-hover);
    border-radius: var(--radius-lg);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

.chat-input-area {
    position: sticky;
    bottom: 0;
    background: rgba(248, 250, 252, 0.85);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding: var(--space-md) var(--space-lg);
}
.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: var(--space-sm);
    max-width: 800px;
    margin: 0 auto;
}
.chat-textarea {
    flex: 1;
    resize: none;
    min-height: 44px;
    max-height: 160px;
    padding: 0.65rem 0.85rem;
    margin-bottom: 0;
    overflow-y: auto;
}
.chat-send-btn {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}
.chat-send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}
.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.chat-send-btn svg {
    width: 18px;
    height: 18px;
}

/* Citations panel */
.citations-panel {
    border-top: 1px solid var(--border);
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-card);
    max-height: 200px;
    overflow-y: auto;
}
.citations-panel h3 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: var(--space-sm);
    color: var(--text-secondary);
}
.citation-item {
    padding: var(--space-sm);
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-xs);
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}
.citation-item strong {
    color: var(--primary);
}

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    top: var(--space-lg);
    right: var(--space-lg);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    pointer-events: auto;
    animation: toastIn var(--transition-slow) ease;
    max-width: 380px;
    border-left: 4px solid var(--text-muted);
}
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error { border-left-color: var(--error); }
.toast.toast-info { border-left-color: var(--info); }
.toast.toast-warning { border-left-color: var(--warning); }

.toast-icon {
    flex-shrink: 0;
}
.toast-icon svg {
    width: 18px;
    height: 18px;
}
.toast.toast-success .toast-icon { color: var(--success); }
.toast.toast-error .toast-icon { color: var(--error); }
.toast.toast-info .toast-icon { color: var(--info); }
.toast.toast-warning .toast-icon { color: var(--warning); }

.toast-message {
    flex: 1;
    color: var(--text);
}

.toast-close {
    background: none;
    border: none;
    padding: 2px;
    cursor: pointer;
    color: var(--text-muted);
    flex-shrink: 0;
}
.toast-close:hover {
    color: var(--text);
}
.toast-close svg {
    width: 14px;
    height: 14px;
}

.toast.toast-out {
    animation: toastOut var(--transition-base) ease forwards;
}

/* --- Skeleton Loading --- */
.skeleton {
    background: linear-gradient(90deg, var(--bg-hover) 25%, var(--border-light) 50%, var(--bg-hover) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

.skeleton-card {
    height: 140px;
    border-radius: var(--radius-lg);
}

.skeleton-line {
    height: 14px;
    margin-bottom: var(--space-sm);
    border-radius: var(--radius-sm);
}
.skeleton-line:last-child {
    width: 60%;
}

.skeleton-text {
    height: 10px;
    margin-bottom: 6px;
    border-radius: 3px;
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

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

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

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

@keyframes skeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Utility animations */
.animate-fade-in { animation: fadeIn var(--transition-base); }
.animate-slide-up { animation: slideUp var(--transition-slow); }
.animate-slide-in-left { animation: slideInLeft var(--transition-slow); }
.animate-scale-in { animation: scaleIn var(--transition-base); }

/* --- Spinner --- */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar.open + .sidebar-overlay {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .mobile-menu-btn {
        display: flex;
    }
}

@media (max-width: 768px) {
    /* Login responsive */
    .login-page {
        flex-direction: column;
    }
    .login-left {
        display: none;
    }
    .login-right {
        padding: var(--space-lg);
    }

    .notebook-grid {
        grid-template-columns: 1fr;
    }

    .page-content {
        padding: var(--space-md);
    }

    .main-header {
        padding: 0 var(--space-md);
    }

    .msg {
        max-width: 88%;
    }
}

@media (max-width: 480px) {
    .page-content {
        padding: var(--space-sm);
    }

    .card {
        padding: var(--space-md);
    }

    .login-form-container {
        padding: 0 var(--space-sm);
    }

    .chat-input-area {
        padding: var(--space-sm);
    }

    .toast-container {
        right: var(--space-sm);
        left: var(--space-sm);
    }
    .toast {
        max-width: 100%;
    }
}

/* --- Markdown Styles --- */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.3;
}
.markdown-body h1 { font-size: 1.3em; }
.markdown-body h2 { font-size: 1.15em; }
.markdown-body h3 { font-size: 1.05em; }

.markdown-body p {
    margin-bottom: 0.6em;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 1.5em;
    margin-bottom: 0.6em;
}
.markdown-body li {
    margin-bottom: 0.25em;
}

.markdown-body code {
    background: rgba(0, 0, 0, 0.06);
    padding: 0.15em 0.35em;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85em;
}

.markdown-body pre {
    background: #1e293b;
    color: #e2e8f0;
    border-radius: var(--radius-md);
    padding: var(--space-md);
    overflow-x: auto;
    margin-bottom: 0.8em;
}
.markdown-body pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: 0.85em;
}

.markdown-body blockquote {
    border-left: 3px solid var(--primary);
    padding-left: var(--space-md);
    color: var(--text-secondary);
    margin-bottom: 0.6em;
    font-style: italic;
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0.8em;
    font-size: 0.88em;
}
.markdown-body th,
.markdown-body td {
    border: 1px solid var(--border);
    padding: 0.5em 0.75em;
    text-align: left;
}
.markdown-body th {
    background: var(--bg-hover);
    font-weight: 600;
}

.markdown-body a {
    color: var(--primary);
    text-decoration: underline;
}

.markdown-body strong {
    font-weight: 600;
}

.markdown-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1em 0;
}

/* Session selector */
.session-select {
    width: auto;
    min-width: 160px;
    padding: 0.4rem 0.7rem;
    font-size: 0.82rem;
    margin-bottom: 0;
    background: var(--bg-card);
}

/* Detail panel back button */
.back-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    background: none;
    border: none;
    padding: var(--space-xs) 0;
    margin-bottom: var(--space-md);
    font-family: var(--font);
    transition: color var(--transition-fast);
}
.back-btn:hover {
    color: var(--primary);
}
.back-btn svg {
    width: 16px;
    height: 16px;
}

/* Section spacing */
.section {
    margin-bottom: var(--space-xl);
}
.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: var(--space-md);
}

/* Create form toggle */
.create-form {
    animation: slideUp var(--transition-slow);
}
