/* ============================================
   Socra Design System — v3
   Monochrome charcoal accent + warm off-white surfaces + Segoe UI
   ============================================ */

:root {
  /* Brand accent — monochrome charcoal (#252422). No teal.
     In light mode the accent is dark; in dark mode it flips to an off-white
     (defined in the [data-theme="dark"] block below). */
  --primary: #252422;
  --primary-hover: #3A3935;
  --primary-10: rgba(37, 36, 34, 0.10);
  --primary-06: rgba(37, 36, 34, 0.06);
  --primary-soft: #F2F0EC;

  /* Ink (text) */
  --ink: #1A1A1A;
  --ink-muted: #6B7280;

  /* Canvas + surfaces (light) — matches Perplexity's actual palette:
     main page = #FAF8F5, sidebar = #F2F0EC */
  --canvas: #FAF8F5;
  --surface-1: #F2F0EC;
  --surface-2: #ECEAE5;
  --surface-3: #E3E0D9;
  /* Borders almost non-existent — barely perceptible against the surfaces */
  --border: rgba(0, 0, 0, 0.025);
  --border-strong: rgba(0, 0, 0, 0.06);

  /* Status */
  --success: #2D8A56;
  --error: #C42B2B;
  --error-light: #FEF2F2;

  /* Legacy aliases kept for back-compat with old class names */
  --navy: var(--ink);
  --navy-light: #2C2C2C;
  --navy-dark: #000000;
  --navy-10: rgba(26, 26, 26, 0.08);
  --navy-06: rgba(26, 26, 26, 0.05);
  --gold: var(--primary);
  --gold-light: var(--primary-hover);
  --gold-dark: #3A3935;
  --gold-10: var(--primary-10);
  --gold-06: var(--primary-06);
  --white: var(--canvas);
  --surface: var(--surface-1);
  --surface-3: var(--surface-3);
  --border-dark: var(--border-strong);
  --text-primary: var(--ink);
  --text-secondary: var(--ink-muted);
  --text-muted: #9CA3AF;

  /* Typography — Segoe UI first (per user request) */
  --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, system-ui, 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', Consolas, 'Liberation Mono', monospace;
  --h1: 42px; --h2: 28px; --h3: 22px; --body: 16px; --body-lg: 18px; --label: 13px;

  /* Layout */
  --nav-h: 64px;
  --sidebar-w: 280px;
  --sidebar-collapsed: 64px;
  --max-w: 1200px;
  --pad: 40px;
  --gutter: 32px;

  /* Radius — from DESIGN.md */
  --r-sm: 6px;
  --r: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-full: 9999px;

  /* Shadows — from DESIGN.md */
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-elevated: 0 4px 16px rgba(0, 0, 0, 0.10);
  --shadow-overlay: 0 20px 60px rgba(0, 0, 0, 0.18);

  /* Motion — from DESIGN.md */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --fast: 100ms var(--ease);
  --norm: 200ms var(--ease);
  --slow: 400ms var(--ease);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  font-size: var(--body);
  color: var(--ink);
  background: var(--canvas);
  min-height: 100vh;
  line-height: 1.7;
}
/* App layout page: prevent body from scrolling — only inner panels scroll */
body:has(.app-layout) { overflow: hidden; height: 100vh; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; font-size: inherit; color: inherit; }
input, textarea { font-family: var(--font); font-size: inherit; color: inherit; outline: none; }
ul, ol { list-style: none; }
img { max-width: 100%; height: auto; display: block; }
::selection { background: var(--primary-10); color: var(--ink); }

/* ============================================
   Buttons
   ============================================ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 24px; font-size: var(--body); font-weight: 500; border-radius: var(--r-md); transition: all var(--norm); white-space: nowrap; }
.btn-primary { background: var(--primary); color: #FFFFFF; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(32, 178, 170, 0.30); }
.btn-gold { background: var(--primary); color: #FFFFFF; font-weight: 600; }
.btn-gold:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(32, 178, 170, 0.35); }
.btn-outline { background: transparent; color: var(--ink); border: 1.5px solid var(--border-strong); }
.btn-outline:hover { background: var(--ink); color: #FFFFFF; border-color: var(--ink); }
.btn-ghost { background: transparent; color: var(--ink-muted); }
.btn-ghost:hover { color: var(--ink); background: var(--surface-2); }
.btn-large { padding: 14px 36px; font-size: var(--body-lg); border-radius: var(--r-md); }
.btn-disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

/* ============================================
   Marketing nav (index / pricing / auth)
   ============================================ */
.nav { position: fixed; top: 0; left: 0; right: 0; height: var(--nav-h); background: var(--canvas); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 var(--pad); z-index: 1000; transition: box-shadow var(--norm); }
.nav.scrolled { box-shadow: var(--shadow-card); }
.nav-logo { display: flex; align-items: center; gap: 8px; }
.nav-logo img { height: 36px; width: 36px; object-fit: contain; }
/* In dark mode, swap to the inverted logo (background baked in matches dark canvas) */
[data-theme="dark"] .nav-logo img { content: url('/assets/inverted-small-logo.png'); }
.nav-links { display: flex; align-items: center; gap: 32px; }
.nav-links a.nav-link { font-size: var(--body); font-weight: 500; color: var(--ink-muted); transition: color var(--fast); position: relative; padding: 4px 0; }
.nav-links a.nav-link::after { content: ''; position: absolute; bottom: -2px; left: 0; width: 0; height: 2px; background: var(--primary); border-radius: 1px; transition: width var(--norm); }
.nav-links a.nav-link:hover { color: var(--ink); text-decoration: none; }
.nav-links a.nav-link:hover::after { width: 100%; }
.nav-links a.nav-link.active { color: var(--ink); }
.nav-links a.nav-link.active::after { width: 100%; }

/* ============================================
   Hero (marketing)
   ============================================ */
.hero { min-height: calc(100vh - var(--nav-h)); display: flex; align-items: center; justify-content: center; padding: 80px var(--pad) 60px; margin-top: var(--nav-h); position: relative; overflow: hidden; }
.hero-bg { position: absolute; inset: 0; background: radial-gradient(ellipse at 20% 50%, var(--primary-06) 0%, transparent 50%), radial-gradient(ellipse at 80% 20%, rgba(26, 26, 26, 0.04) 0%, transparent 50%); pointer-events: none; }
.hero-content { max-width: 800px; text-align: center; position: relative; z-index: 1; animation: fadeUp 0.8s var(--ease); }
.hero-badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 16px; background: var(--primary-10); border: 1px solid rgba(32, 178, 170, 0.25); border-radius: var(--r-full); font-size: var(--label); font-weight: 600; color: var(--primary-hover); letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 28px; animation: fadeUp 0.8s var(--ease) 0.1s both; }
.hero h1 { font-size: var(--h1); font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; color: var(--ink); margin-bottom: 24px; animation: fadeUp 0.8s var(--ease) 0.2s both; }
.hero h1 .accent { color: var(--primary); }
.hero-sub { font-size: var(--body-lg); line-height: 1.7; color: var(--ink-muted); margin-bottom: 44px; max-width: 600px; margin-left: auto; margin-right: auto; animation: fadeUp 0.8s var(--ease) 0.3s both; }
.hero-actions { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; animation: fadeUp 0.8s var(--ease) 0.4s both; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes ProseMirror-cursor-blink { to { visibility: hidden; } }

.hero-float { position: absolute; border-radius: 50%; opacity: 0.10; pointer-events: none; }
.hero-float-1 { width: 300px; height: 300px; background: var(--primary); top: -50px; right: -80px; animation: float 6s ease-in-out infinite; }
.hero-float-2 { width: 200px; height: 200px; background: var(--ink); bottom: 40px; left: -60px; animation: float 8s ease-in-out infinite 1s; }
.hero-float-3 { width: 120px; height: 120px; background: var(--primary); top: 30%; left: 15%; animation: float 7s ease-in-out infinite 2s; }

/* ============================================
   Marketing sections
   ============================================ */
.section { padding: 100px var(--pad); position: relative; }
.section-alt { background: var(--surface-1); }
.section-container { max-width: var(--max-w); margin: 0 auto; }
.section-header { text-align: center; margin-bottom: 60px; }
.section-header h2 { font-size: var(--h2); font-weight: 700; color: var(--ink); margin-bottom: 16px; letter-spacing: -0.01em; }
.section-header p { font-size: var(--body-lg); color: var(--ink-muted); max-width: 560px; margin: 0 auto; line-height: 1.7; }
.section-header .gold-line { width: 48px; height: 3px; background: var(--primary); margin: 20px auto 0; border-radius: 2px; }

.comparison-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gutter); max-width: 920px; margin: 0 auto; }
.comparison-card { padding: 36px; border-radius: var(--r-lg); border: 1.5px solid var(--border); background: var(--canvas); transition: all var(--norm); }
.comparison-card.socratic { border-color: var(--primary); position: relative; background: linear-gradient(135deg, var(--canvas) 0%, var(--primary-06) 100%); }
.comparison-card.socratic::before { content: 'Our Approach'; position: absolute; top: -13px; left: 24px; background: var(--primary); color: #FFFFFF; padding: 3px 14px; border-radius: var(--r-full); font-size: var(--label); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.comparison-card h3 { font-size: 20px; font-weight: 600; color: var(--ink); margin-bottom: 18px; }
.comparison-list { display: flex; flex-direction: column; gap: 14px; }
.comparison-list li { display: flex; align-items: flex-start; gap: 10px; font-size: var(--body); line-height: 1.6; color: var(--ink-muted); }
.comparison-list li .icon { flex-shrink: 0; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; margin-top: 1px; font-weight: 700; }
.comparison-list li .icon.cross { color: var(--error); }
.comparison-list li .icon.check { color: var(--success); }

.features-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; }
.feature-card { padding: 32px; border-radius: var(--r-lg); border: 1.5px solid var(--border); background: var(--canvas); transition: all var(--norm); position: relative; overflow: hidden; }
.feature-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--ink), var(--primary)); opacity: 0; transition: opacity var(--norm); }
.feature-card:hover { border-color: var(--primary); transform: translateY(-4px); box-shadow: var(--shadow-elevated); }
.feature-card:hover::before { opacity: 1; }
.feature-icon { width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; background: var(--primary-10); border-radius: var(--r-md); margin-bottom: 20px; color: var(--primary-hover); font-size: 20px; font-weight: 700; }
.feature-card h3 { font-size: 18px; font-weight: 600; color: var(--ink); margin-bottom: 10px; }
.feature-card p { font-size: var(--body); color: var(--ink-muted); line-height: 1.7; }

.cta-section { text-align: center; padding: 100px var(--pad); background: var(--ink); color: #FFFFFF; position: relative; overflow: hidden; }
.cta-section::before { content: ''; position: absolute; top: -100px; right: -100px; width: 400px; height: 400px; border-radius: 50%; background: rgba(32, 178, 170, 0.10); pointer-events: none; }
.cta-section::after { content: ''; position: absolute; bottom: -60px; left: -60px; width: 250px; height: 250px; border-radius: 50%; background: rgba(32, 178, 170, 0.06); pointer-events: none; }
.cta-section h2 { color: #FFFFFF; margin-bottom: 16px; position: relative; }
.cta-section p { color: rgba(255, 255, 255, 0.7); margin-bottom: 36px; font-size: var(--body-lg); max-width: 500px; margin-left: auto; margin-right: auto; position: relative; }

.footer { padding: 40px var(--pad); border-top: 1px solid var(--border); text-align: center; color: var(--ink-muted); font-size: var(--label); }

/* ============================================
   Pricing
   ============================================ */
.pricing-section { margin-top: var(--nav-h); padding: 60px var(--pad) 80px; }
.pricing-header { text-align: center; margin-bottom: 56px; }
.pricing-header h1 { font-size: var(--h1); font-weight: 700; color: var(--ink); margin-bottom: 16px; }
.pricing-header p { font-size: var(--body-lg); color: var(--ink-muted); max-width: 520px; margin: 0 auto; }
.pricing-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gutter); max-width: 1020px; margin: 0 auto; }
.pricing-card { padding: 36px; border-radius: var(--r-lg); border: 1.5px solid var(--border); background: var(--canvas); display: flex; flex-direction: column; position: relative; transition: all var(--norm); }
.pricing-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-elevated); }
.pricing-card.current-plan { border-color: var(--ink); }
.pricing-card.current-plan::after { content: 'Current Plan'; position: absolute; top: -13px; left: 24px; background: var(--ink); color: #FFFFFF; padding: 3px 14px; border-radius: var(--r-full); font-size: var(--label); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.pricing-card.featured { border-color: var(--primary); }
.pricing-card.featured::before { content: 'Recommended'; position: absolute; top: -13px; left: 24px; background: var(--primary); color: #FFFFFF; padding: 3px 14px; border-radius: var(--r-full); font-size: var(--label); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.pricing-card.best { border-color: #C9A84C; }
.pricing-card.best::before { content: 'Best'; position: absolute; top: -13px; left: 24px; background: #C9A84C; color: #FFFFFF; padding: 3px 14px; border-radius: var(--r-full); font-size: var(--label); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.pricing-name { font-size: 22px; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.pricing-label { font-style: italic; font-size: var(--label); color: var(--ink-muted); margin-bottom: 22px; text-transform: none; letter-spacing: 0; }
.pricing-price { margin-bottom: 24px; }
.pricing-price .amount { font-size: 38px; font-weight: 700; color: var(--ink); }
.pricing-price .period { font-size: var(--body); color: var(--ink-muted); }
.pricing-price .annual { display: block; font-size: var(--label); color: var(--primary-hover); margin-top: 4px; font-weight: 500; }
.pricing-features { flex: 1; display: flex; flex-direction: column; gap: 12px; margin-bottom: 28px; }
.pricing-features li { display: flex; align-items: flex-start; gap: 10px; font-size: var(--body); color: var(--ink-muted); line-height: 1.6; }
.pricing-features li .check-icon { flex-shrink: 0; color: var(--primary); margin-top: 2px; font-weight: 700; }
.pricing-features li.disabled { color: var(--ink-muted); }
.pricing-features li.disabled .check-icon { color: var(--border-strong); }
.pricing-card .btn { width: 100%; }

/* Per-plan accent colors — match the model selector dot colors:
   Doxa = sky blue (#38BDF8, fixed), Elenchus = green (#2D8A56, fixed), Nous = gold (#C9A84C, fixed).
   This visually ties each pricing card to its corresponding model tier. */
#plan-doxa { border-color: #38BDF8; }
#plan-elenchus { border-color: #2D8A56; }
#plan-nous { border-color: #C9A84C; }
/* Recommended badge inherits the plan's accent color */
#plan-elenchus.featured::before { background: #2D8A56; color: #FFFFFF; }
/* Current Plan badge inherits the plan's accent color */
#plan-doxa.current-plan::after { background: #38BDF8; color: #FFFFFF; }
#plan-elenchus.current-plan::after { background: #2D8A56; color: #FFFFFF; }
#plan-nous.current-plan::after { background: #C9A84C; color: #FFFFFF; }


/* ============================================
   Auth page
   ============================================ */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--surface-1); padding: var(--pad); }
.auth-container { width: 100%; max-width: 440px; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 40px; }
.auth-logo img { width: 200px; height: auto; object-fit: contain; }
.auth-logo-dark { display: none; }
/* In dark mode, swap to the inverted full logo */
[data-theme="dark"] .auth-logo-light { display: none; }
[data-theme="dark"] .auth-logo-dark { display: block; }
.auth-card { background: var(--canvas); border: 1.5px solid var(--border); border-radius: var(--r-lg); padding: 36px; box-shadow: var(--shadow-elevated); }
.auth-tabs { display: flex; border-bottom: 1.5px solid var(--border); margin-bottom: 28px; }
.auth-tab { flex: 1; padding: 12px; text-align: center; font-weight: 600; color: var(--ink-muted); border-bottom: 2px solid transparent; transition: all var(--fast); cursor: pointer; }
.auth-tab.active { color: var(--ink); border-bottom-color: var(--primary); }
.auth-tab:hover { color: var(--ink); }
.auth-form { display: flex; flex-direction: column; gap: 18px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: var(--label); font-weight: 600; color: var(--ink-muted); letter-spacing: 0.04em; text-transform: uppercase; }
.form-input-wrapper { position: relative; }
.form-input { width: 100%; padding: 11px 14px; border: 1.5px solid var(--border); border-radius: var(--r); background: var(--canvas); font-size: var(--body); transition: border-color var(--fast); }
.form-input:focus { border-color: var(--primary); }
.form-input.error { border-color: var(--error); }
.password-toggle { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--ink-muted); cursor: pointer; padding: 4px; display: flex; }
.password-toggle:hover { color: var(--ink); }
.form-error { font-size: var(--label); color: var(--error); }

/* ============================================
   App layout
   ============================================ */
.app-layout { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ── Sidebar (ChatGPT-style, decluttered) ── */
.sidebar { width: var(--sidebar-w); min-width: var(--sidebar-w); height: 100vh; background: var(--surface-1); border-right: 1px solid var(--border); display: flex; flex-direction: column; transition: width var(--norm), min-width var(--norm); overflow: hidden; }
.sidebar.collapsed { width: var(--sidebar-collapsed); min-width: var(--sidebar-collapsed); }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; min-height: 60px; background: var(--surface-1); }
.sidebar-logo-full, .sidebar-logo-small { display: flex; align-items: center; cursor: pointer; }
/* Both the expanded and collapsed sidebar use the small (square) logo.
   Logos are transparent PNGs, so object-fit: contain lets the mark sit
   cleanly on the sidebar surface without cropping. */
.sidebar-logo-full img { width: 32px; height: 32px; transition: transform var(--fast); object-fit: contain; }
.sidebar-logo-full:hover img { transform: scale(1.05); }
.sidebar-logo-small { display: none; }
.sidebar-logo-small img { width: 32px; height: 32px; transition: transform var(--fast); object-fit: contain; }
.sidebar-logo-small:hover img { transform: scale(1.05); }
.sidebar.collapsed .sidebar-logo-full { display: none; }
.sidebar.collapsed .sidebar-logo-small { display: flex; }
/* In dark mode, swap to the inverted logo so the mark's background (#1E1D1B)
   blends with the dark sidebar surface. content: url() replaces the img src
   without touching the markup, keeping the JS logo-click handlers intact. */
[data-theme="dark"] .sidebar-logo-full img,
[data-theme="dark"] .sidebar-logo-small img { content: url('/assets/inverted-small-logo.png'); }
.sidebar-actions { display: flex; align-items: center; gap: 2px; }
.sidebar.collapsed .sidebar-actions { display: none; }
.sidebar-icon-btn { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border-radius: var(--r); color: var(--ink-muted); transition: all var(--fast); }
.sidebar-icon-btn:hover { background: var(--surface-2); color: var(--ink); }
/* sidebar-search removed — replaced by Spotlight popup */

/* New chat button — flat, minimal like ChatGPT.
   Default background matches the sidebar surface (var(--surface-1)) so the
   button blends in. Active + hover states keep their existing colors. */
.new-chat-btn { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin: 6px 12px 4px; border-radius: var(--r); color: var(--ink); font-weight: 500; transition: all var(--fast); width: calc(100% - 24px); border: 1px solid var(--border); background: var(--surface-1); }
.new-chat-btn:hover { background: var(--primary-06); border-color: var(--primary-10); color: var(--primary-hover); }
.new-chat-btn.active { background: var(--primary-10); color: var(--primary-hover); border-color: transparent; }
.sidebar.collapsed .new-chat-btn { justify-content: center; padding: 10px; margin: 6px 8px; width: calc(100% - 16px); }
.sidebar.collapsed .new-chat-btn span { display: none; }

/* Sidebar link button (e.g. Cognitive Portfolio, View Documents) — same shell as .new-chat-btn
   but never has the .active state, and text-decoration: none on hover. */
.sidebar-link-btn { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin: 0 12px 4px; border-radius: var(--r); color: var(--ink); font-weight: 500; transition: all var(--fast); width: calc(100% - 24px); border: 1px solid var(--border); background: var(--surface-1); text-decoration: none; }
.sidebar-link-btn:hover { background: var(--primary-06); border-color: var(--primary-10); color: var(--primary-hover); text-decoration: none; }
.sidebar-link-btn.active { background: var(--primary-10); color: var(--primary-hover); border-color: transparent; text-decoration: none; }
.sidebar.collapsed .sidebar-link-btn { justify-content: center; padding: 10px; margin: 0 8px 4px; width: calc(100% - 16px); }
.sidebar.collapsed .sidebar-link-btn span { display: none; }

.sidebar-divider { height: 1px; background: var(--border); margin: 8px 12px; }

/* Chat history list — cleaner, less dense */
.chat-history { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.chat-history-label { padding: 12px 8px 4px; font-size: 11px; font-weight: 600; color: var(--ink-muted); letter-spacing: 0.06em; text-transform: uppercase; }
.chat-history-empty { padding: 24px 14px; text-align: center; color: var(--ink-muted); font-size: var(--body); line-height: 1.6; flex: 1; display: flex; align-items: center; justify-content: center; }
.chat-item { display: flex; align-items: center; padding: 8px 10px; border-radius: var(--r); cursor: pointer; transition: background var(--fast); gap: 8px; margin-bottom: 1px; position: relative; color: var(--ink); }
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--surface-2); color: var(--ink); font-weight: 500; }
/* Title truncation: always leave a gap with the sidebar edge so the ellipsis
   never visually touches the right border of the sidebar.
   - Not hovered: 8px gap (matches the .chat-history horizontal padding so
     the title's visible end aligns with the sidebar's inner edge).
   - Hovered/active: 28px gap (24px three-dot menu + 4px breathing room)
     so the ellipsis never touches the menu icon. */
.chat-item-title {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 14px;
  padding-right: 8px;
  transition: padding-right var(--fast);
}
.chat-item:hover .chat-item-title,
.chat-item.active .chat-item-title {
  padding-right: 28px; /* 24px menu button + 4px gap */
}
.chat-item-actions { display: none; align-items: center; gap: 2px; flex-shrink: 0; }
.chat-item:hover .chat-item-actions { display: flex; }
.chat-item-menu-btn { width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; border-radius: var(--r-sm); color: var(--ink-muted); transition: all var(--fast); }
.chat-item-menu-btn:hover { background: var(--surface-3); color: var(--ink); }
.chat-item-dropdown { position: absolute; right: 6px; top: 100%; background: var(--canvas); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-elevated); z-index: 1200; min-width: 140px; padding: 4px; display: none; }
.chat-item-dropdown.open { display: block; }
.chat-item-dropdown-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: var(--r-sm); font-size: var(--body); color: var(--ink); transition: background var(--fast); cursor: pointer; width: 100%; text-align: left; }
.chat-item-dropdown-item:hover { background: var(--surface-2); }
.chat-item-dropdown-item.danger { color: var(--error); }
.chat-item-dropdown-item.danger:hover { background: var(--error-light); }
.chat-item-rename-input { flex: 1; border: 1.5px solid var(--primary); border-radius: var(--r-sm); padding: 2px 6px; font-size: var(--body); color: var(--ink); background: var(--canvas); outline: none; min-width: 0; }
.sidebar.collapsed .chat-item-title, .sidebar.collapsed .chat-history-label, .sidebar.collapsed .chat-history-empty { display: none; }
.sidebar.collapsed .chat-item { justify-content: center; padding: 8px; }
.sidebar.collapsed .chat-item-actions { display: none; }

/* Profile section — sits at the bottom of the sidebar, just the profile-info
   row (logout moved into Settings). */
.sidebar-profile { border-top: 1px solid var(--border); padding: 8px 12px; background: var(--surface-1); flex-shrink: 0; }
.profile-info { display: flex; align-items: center; gap: 10px; padding: 6px 8px; cursor: pointer; border-radius: var(--r); transition: background var(--fast); }
.profile-info:hover { background: var(--surface-2); }
.profile-info .profile-avatar { width: 30px; height: 30px; border-radius: var(--r-full); background: var(--primary); color: #FFFFFF; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.profile-info .profile-details { flex: 1; min-width: 0; }
.profile-info .settings-btn { margin-left: auto; flex-shrink: 0; }
.profile-name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.profile-plan { font-size: 12px; color: var(--ink-muted); text-transform: capitalize; }
.sidebar.collapsed .profile-details, .sidebar.collapsed .settings-btn { display: none; }
.sidebar.collapsed .profile-info { justify-content: center; padding: 6px; }

/* Logout button — full width */
.logout-btn { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; padding: 8px 12px; font-size: 13px; font-weight: 500; border-radius: var(--r); color: var(--ink-muted); background: transparent; border: 1px solid var(--border); transition: all var(--fast); }
.logout-btn:hover { background: var(--error); color: #FFFFFF; border-color: var(--error); }
.logout-btn.full-width { width: 100%; }

/* Hide upgrade button in sidebar (moved to chat panel) */
.sidebar .upgrade-btn { display: none; }

/* Sidebar-pinned Upgrade button at the bottom of .chat-history.
   margin-top: auto pushes it to the bottom of the flex column when the chat
   list is short; position: sticky + bottom: 0 keeps it visible at the bottom
   of the scroll viewport when the chat list is long. */
.sidebar-upgrade-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  margin-top: auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-hover);
  background: var(--primary-06);
  border: 1px solid var(--primary-10);
  border-radius: var(--r);
  transition: all var(--fast);
  position: sticky;
  bottom: 0;
  z-index: 2;
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-upgrade-btn:hover {
  background: var(--primary);
  color: #FFFFFF;
  border-color: var(--primary);
}
.sidebar-upgrade-btn svg { flex-shrink: 0; }
.sidebar.collapsed .sidebar-upgrade-btn {
  /* In collapsed sidebar, show only the icon centered */
  justify-content: center;
  padding: 9px;
  margin: 8px 8px 0;
  width: calc(100% - 16px);
}
.sidebar.collapsed .sidebar-upgrade-btn span { display: none; }

/* Lay out chat-history as a flex column so margin-top: auto on the upgrade
   button can push it to the bottom. Preserve original scroll behavior. */
.chat-history { display: flex; flex-direction: column; }


/* ============================================
   Main content / top bar
   ============================================ */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--canvas); }
.top-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; border-bottom: 1px solid var(--border); min-height: 50px; background: var(--canvas); }
.top-bar-left { display: flex; align-items: center; gap: 12px; }
.top-bar-right { display: flex; align-items: center; gap: 8px; }
.metrics-btn { display: flex; align-items: center; gap: 6px; padding: 6px 14px; border: 1px solid var(--border); border-radius: var(--r-full); font-size: var(--label); font-weight: 500; color: var(--ink-muted); transition: all var(--fast); letter-spacing: 0.02em; }
.metrics-btn:hover { border-color: var(--primary); color: var(--primary-hover); text-decoration: none; }

/* Plan selector dropdown (Socra—Doxa in the top bar) */
.plan-selector { position: relative; }
.plan-selector-btn { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border: none; border-radius: var(--r); background: transparent; color: var(--ink); font-size: 15px; font-weight: 600; cursor: pointer; transition: background var(--fast); }
.plan-selector-btn:hover { background: var(--surface-2); }
.plan-selector-btn svg { color: var(--ink-muted); transition: transform var(--fast); }
.plan-selector-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
.plan-selector-dropdown { position: absolute; top: calc(100% + 4px); left: 0; min-width: 340px; background: var(--canvas); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-elevated); padding: 8px; display: none; z-index: 200; }
.plan-selector-dropdown.open { display: block; }
.plan-option { padding: 14px; border-radius: var(--r-md); margin-bottom: 4px; position: relative; }
.plan-option:last-child { margin-bottom: 0; }
.plan-option:hover { background: var(--surface-2); }
.plan-option.active { background: var(--primary-06); }
.plan-option-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.plan-option-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.plan-option-dot.low { background: #38BDF8; }
.plan-option-dot.med { background: #2D8A56; }
.plan-option-dot.high { background: #C9A84C; }
.plan-option-name { font-size: 15px; font-weight: 600; color: var(--ink); flex: 1; }
.plan-option-tag { font-size: 11px; font-weight: 600; color: var(--primary-hover); background: var(--primary-10); padding: 2px 8px; border-radius: var(--r-full); text-transform: uppercase; letter-spacing: 0.04em; }
.plan-option-lock { color: #C9A84C; flex-shrink: 0; }
.plan-option-desc { font-size: 13px; color: var(--ink-muted); line-height: 1.5; margin-bottom: 0; }
.plan-option.locked .plan-option-desc { margin-bottom: 10px; }
.plan-option-upgrade-btn { display: inline-flex; align-items: center; padding: 6px 16px; font-size: 13px; font-weight: 600; color: #FFFFFF; background: var(--primary); border: none; border-radius: var(--r-full); cursor: pointer; transition: background var(--fast); }
.plan-option-upgrade-btn:hover { background: var(--primary-hover); }

/* ============================================
   Workspace + chat split
   ============================================ */
.workspace-chat-split { flex: 1; display: flex; overflow: hidden; }

/* ============================================
   Documents View (list + single document)
   ============================================ */
.documents-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--canvas); }
.documents-view.hidden { display: none; }
.documents-view-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 32px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.documents-view-header h2 { font-size: 22px; font-weight: 700; color: var(--ink); }
.documents-close-btn { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border-radius: var(--r); color: var(--ink-muted); transition: all var(--fast); }
.documents-close-btn:hover { background: var(--primary-06); color: var(--primary-hover); }
.documents-list { flex: 1; overflow-y: auto; padding: 24px 32px; }
.documents-loading, .documents-empty { text-align: center; padding: 60px 20px; color: var(--ink-muted); font-size: 15px; }
.documents-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.document-card { background: var(--canvas); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 18px 20px; cursor: pointer; transition: all var(--fast); display: flex; flex-direction: column; gap: 8px; }
.document-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow-card); }
.document-card-title { font-size: 16px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.document-card-preview { font-size: 14px; color: var(--ink-muted); line-height: 1.5; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; min-height: 63px; }
.document-card-meta { font-size: 12px; color: var(--ink-muted); display: flex; gap: 8px; align-items: center; }
.document-card-meta svg { width: 13px; height: 13px; }

/* Single document view */
.document-single-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--canvas); }
.document-single-view.hidden { display: none; }
.document-single-header { display: flex; align-items: center; gap: 12px; padding: 16px 24px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.document-back-btn { display: flex; align-items: center; gap: 6px; padding: 6px 12px; font-size: 14px; font-weight: 500; color: var(--ink-muted); border-radius: var(--r); transition: all var(--fast); }
.document-back-btn:hover { background: var(--primary-06); color: var(--primary-hover); }
.document-single-title { flex: 1; font-size: 18px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.document-open-chat-btn { display: flex; align-items: center; gap: 6px; padding: 7px 14px; font-size: 13px; font-weight: 600; color: #FFFFFF; background: var(--primary); border: none; border-radius: var(--r-full); transition: all var(--fast); flex-shrink: 0; }
.document-open-chat-btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
.document-single-content { flex: 1; overflow-y: auto; padding: 32px 40px; font-size: var(--body); line-height: 1.8; color: var(--ink); }
.document-single-content h1 { font-size: 28px; font-weight: 700; margin: 0.8em 0 0.3em; }
.document-single-content h2 { font-size: 22px; font-weight: 600; margin: 0.7em 0 0.3em; }
.document-single-content h3 { font-size: 18px; font-weight: 600; margin: 0.6em 0 0.2em; }
.document-single-content p { margin-bottom: 12px; }
.document-single-content code { font-family: var(--font-mono); background: var(--surface-2); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
.document-single-content pre { background: var(--surface-2); padding: 14px; border-radius: var(--r-md); overflow-x: auto; margin: 12px 0; }
.document-single-content pre code { background: none; padding: 0; }
.document-single-content blockquote { border-left: 3px solid var(--primary); padding: 6px 16px; margin: 12px 0; background: var(--primary-06); border-radius: 0 var(--r) var(--r) 0; color: var(--ink-muted); }
.document-single-content ul, .document-single-content ol { padding-left: 24px; margin-bottom: 12px; }

/* Dark mode for documents views */
[data-theme="dark"] .documents-view { background: var(--canvas); }
[data-theme="dark"] .document-card { background: var(--surface-1); border-color: var(--border); }
[data-theme="dark"] .document-card:hover { border-color: var(--primary); }
[data-theme="dark"] .document-single-view { background: var(--canvas); }
[data-theme="dark"] .document-open-chat-btn { color: #1C1C1C; }

.workspace-panel { width: 58%; min-width: 0; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--canvas); }
.workspace-panel.hidden { display: none; }
.chat-panel { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--canvas); }
.workspace-panel ~ .chat-panel { width: 42%; }
/* When in document-only mode (opened from Documents view), the workspace panel
   takes the full width and the chat panel is hidden. */
.workspace-chat-split.doc-only-mode .workspace-panel { width: 100%; border-right: none; }
.workspace-chat-split.doc-only-mode .chat-panel { display: none; }

.workspace-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--canvas); }
.workspace-title-input { border: none; background: transparent; font-size: var(--body); font-weight: 500; color: var(--ink); max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-title-input:focus { outline: none; overflow: visible; }
.workspace-actions { display: flex; align-items: center; gap: 4px; }
.workspace-action-btn { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; border-radius: var(--r); color: var(--ink-muted); transition: all var(--fast); }
.workspace-action-btn:hover { background: var(--surface-2); color: var(--ink); }

.editor-split { flex: 1; display: flex; overflow: hidden; flex-direction: column; }
.live-editor-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.live-editor { flex: 1; min-height: 200px; overflow: hidden; }
.milkdown-live-editor-wrapper { background: var(--canvas); }
.milkdown-live-editor { overflow: auto; }
.milkdown-live-editor .milkdown {
  min-height: 100%;
  background: var(--canvas);
  color: var(--ink);
  --crepe-color-background: var(--canvas);
  --crepe-color-on-background: var(--ink);
  --crepe-color-surface: var(--surface-2);
  --crepe-color-surface-low: var(--surface-1);
  --crepe-color-on-surface: var(--ink);
  --crepe-color-on-surface-variant: var(--ink-muted);
  --crepe-color-outline: var(--border-strong);
  --crepe-color-primary: var(--primary);
  --crepe-color-secondary: var(--surface-2);
  --crepe-color-hover: var(--primary-06);
  --crepe-color-selected: var(--primary-10);
  --crepe-font-default: var(--font);
  --crepe-font-code: var(--font-mono);
}
.milkdown-live-editor .ProseMirror { min-height: 100%; padding: 24px 32px; outline: none; font-family: var(--font); font-size: 16px; line-height: 1.7; color: var(--ink); background: var(--canvas); }
.milkdown-live-editor .ProseMirror-focused { outline: none; }
.milkdown-live-editor .ProseMirror-selectednode { outline: 2px solid var(--primary-10); }
.milkdown-live-editor .ProseMirror-gapcursor { display: none; pointer-events: none; position: absolute; }
.milkdown-live-editor .ProseMirror-gapcursor::after { content: ''; display: block; position: absolute; top: -2px; width: 20px; border-top: 1px solid var(--ink); animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite; }
.milkdown-live-editor .ProseMirror-hideselection *::selection { background: transparent; }
.milkdown-live-editor .ProseMirror h1 { font-size: 32px; line-height: 1.25; margin: 0.7em 0 0.35em; font-weight: 700; color: var(--ink); }
.milkdown-live-editor .ProseMirror h2 { font-size: 24px; line-height: 1.3; margin: 0.65em 0 0.3em; font-weight: 650; color: var(--ink); }
.milkdown-live-editor .ProseMirror h3 { font-size: 20px; line-height: 1.35; margin: 0.6em 0 0.25em; font-weight: 650; color: var(--ink); }
.milkdown-live-editor .ProseMirror ul, .milkdown-live-editor .ProseMirror ol { padding-left: 28px; margin: 8px 0; }
.milkdown-live-editor .ProseMirror li { margin: 2px 0; padding-left: 4px; }
.milkdown-live-editor .ProseMirror code { font-family: var(--font-mono); background: var(--surface-2); color: var(--ink); border-radius: 4px; padding: 2px 5px; }
.milkdown-live-editor .ProseMirror pre { background: var(--surface-2); border-left: 3px solid var(--border-strong); border-radius: var(--r); padding: 12px 14px; overflow-x: auto; }
.milkdown-live-editor .ProseMirror pre code { padding: 0; background: transparent; }
.milkdown-live-editor .ProseMirror blockquote { border-left: 3px solid var(--primary); background: var(--primary-06); color: var(--ink-muted); padding: 6px 16px; border-radius: 0 var(--r) var(--r) 0; }
.milkdown-live-editor .milkdown-toolbar,
.milkdown-live-editor .milkdown-block-handle,
.milkdown-live-editor .milkdown-slash-menu,
.milkdown-live-editor .milkdown-link-preview,
.milkdown-live-editor .milkdown-link-edit { display: none !important; }
.milkdown-live-editor .milkdown-list-item-block { display: block; padding: 0; }
.milkdown-live-editor .milkdown-list-item-block > .list-item { display: flex; align-items: flex-start; }
.milkdown-live-editor .milkdown-list-item-block > .list-item > .children { min-width: 0; flex: 1; }
.milkdown-live-editor .milkdown-list-item-block li { gap: 10px; }
.milkdown-live-editor .milkdown-list-item-block li .label-wrapper { width: 24px; min-width: 24px; height: 32px; display: flex; align-items: center; justify-content: center; color: var(--ink-muted); }
.milkdown-live-editor .milkdown-list-item-block li .label-wrapper svg { fill: var(--ink-muted); }
.milkdown-live-editor .milkdown-list-item-block li .label-wrapper .label { width: 24px; height: 32px; padding: 4px 0; text-align: right; }
.milkdown-live-editor .milkdown-code-block { display: block; position: relative; margin: 8px 0; padding: 8px 14px 14px; background: var(--surface-2); border-left: 3px solid var(--border-strong); border-radius: var(--r); }
.milkdown-live-editor .milkdown-code-block.selected { outline: 1px solid var(--primary-10); }
.milkdown-live-editor .milkdown-code-block .milkdown-code-block-placeholder { margin: 0; padding: 4px 0; font-family: var(--font-mono); font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.milkdown-live-editor .milkdown-code-block .milkdown-code-block-placeholder code { font-family: inherit; background: transparent; padding: 0; }
.milkdown-live-editor .milkdown-code-block .cm-editor,
.milkdown-live-editor .milkdown-code-block .cm-gutters,
.milkdown-live-editor .milkdown-code-block .cm-scroller { background: var(--surface-2); color: var(--ink); font-family: var(--font-mono); }
.milkdown-live-editor .milkdown-code-block .cm-editor { outline: none !important; }
.milkdown-live-editor .milkdown-code-block .cm-content { font-family: var(--font-mono); font-size: 14px; line-height: 1.55; caret-color: var(--primary); }
.milkdown-live-editor .milkdown-code-block .cm-line { padding: 0 4px; }
.milkdown-live-editor .milkdown-code-block .cm-gutters { border-right: 1px solid var(--border); color: var(--ink-muted); }
.milkdown-live-editor .milkdown-code-block .tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.milkdown-live-editor .milkdown-code-block .tools .language-button,
.milkdown-live-editor .milkdown-code-block .tools .tools-button-group button { opacity: 1; border-radius: 4px; background: var(--surface-1); color: var(--ink-muted); font-family: var(--font); font-size: 12px; }
.milkdown-live-editor .milkdown-code-block .language-picker { position: absolute; z-index: 20; padding-top: 10px; width: max-content; }
.milkdown-live-editor .milkdown-code-block .hidden { display: none !important; }
.milkdown-live-editor span[data-type='math_inline'] { display: inline-block; padding: 0 4px; vertical-align: bottom; color: var(--primary); }
.milkdown-live-editor .milkdown-latex-inline-edit[data-show='false'] { display: none; }
.milkdown-live-editor .milkdown-latex-inline-edit { position: absolute; z-index: 20; background: var(--surface-1); box-shadow: var(--shadow-lg); border: 1px solid var(--border); border-radius: var(--r); padding: 2px 6px 2px 12px; }
.milkdown-live-editor .milkdown-latex-inline-edit .container { display: flex; gap: 6px; align-items: flex-start; }
.milkdown-live-editor .milkdown-latex-inline-edit .container button { width: 24px; height: 24px; cursor: pointer; border-radius: var(--r); }
.milkdown-live-editor .milkdown-latex-inline-edit .container button:hover { background: var(--primary-06); }
.milkdown-live-editor .milkdown-latex-inline-edit .ProseMirror { min-width: 174px; max-width: 294px; padding: 0; font-family: var(--font-mono); }
.socra-question-block { position: relative; display: block; margin: 8px 0; padding: 8px 12px 8px 42px; border-left: 3px solid var(--primary); border-radius: 0 var(--r) var(--r) 0; background: var(--primary-06); color: transparent; font-size: 0; cursor: pointer; }
.socra-question-block::before { content: '?'; position: absolute; left: 12px; top: 9px; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: var(--r-full); background: var(--primary); color: #FFFFFF; font-size: 12px; font-weight: 700; }
.socra-question-block::after { content: attr(data-question); color: var(--ink); font-size: 16px; line-height: 1.6; }
.socra-question-block:hover { background: var(--primary-10); }
/* ============================================
   CodeMirror — Socra Theme with Live Preview (v3)
   ============================================ */
.CodeMirror { height: 100% !important; font-family: var(--font) !important; font-size: 16px !important; line-height: 1.6 !important; color: var(--ink) !important; background: var(--canvas) !important; }
/* Padding on .CodeMirror-lines (the actual content container in CM5). */
.CodeMirror-lines { padding: 24px 32px !important; }
.CodeMirror-line { padding: 0 !important; }
.CodeMirror-cursor { border-left: 2px solid var(--primary) !important; }
.CodeMirror-selected { background: var(--primary-10) !important; }
.CodeMirror-focused .CodeMirror-selected { background: var(--primary-10) !important; }
/* Hidden syntax markers: invisible but in the DOM flow so selection works.
   color: transparent keeps the text taking up space (so selection rectangles
   align correctly) while making it invisible. This is the key difference
   from collapsed:true (which removes text from the DOM and breaks selection)
   and display:none (which also removes from flow). */
.cm-hidden { color: transparent !important; font-size: 0 !important; line-height: 0 !important; letter-spacing: 0 !important; }
/* Markdown syntax highlighting */
/* Header classes include line-height so the cursor height scales with
   the font size. Without this, the cursor stays at the base line-height
   even on large heading lines. */
.cm-header { color: var(--ink) !important; font-weight: 700 !important; }
.cm-header-1 { font-size: 1.75em !important; line-height: 1.3 !important; }
.cm-header-2 { font-size: 1.4em !important; line-height: 1.35 !important; }
.cm-header-3 { font-size: 1.2em !important; line-height: 1.4 !important; }
.cm-header-4 { font-size: 1.1em !important; line-height: 1.45 !important; }
.cm-em { font-style: italic !important; }
.cm-strong { font-weight: 700 !important; }
.cm-link { color: var(--primary-hover) !important; text-decoration: underline !important; }
.cm-url { color: var(--primary-hover) !important; }
.cm-comment { color: var(--ink-muted) !important; }
.cm-quote { color: var(--ink-muted) !important; border-left: 3px solid var(--primary) !important; padding-left: 12px !important; }
.cm-variable-2, .cm-variable-3, .cm-keyword { color: var(--primary-hover) !important; }
.cm-string { color: var(--ink) !important; }
.cm-builtin { color: var(--primary-hover) !important; }
.cm-tag { color: var(--ink-muted) !important; }
.cm-bracket { color: var(--ink-muted) !important; }
.cm-atom { color: var(--primary-hover) !important; }
.cm-number { color: var(--ink) !important; }
.cm-def { color: var(--primary-hover) !important; }
.cm-operator { color: var(--ink) !important; }

/* Question block decoration */
.cm-question-content {
  background: var(--primary-06);
  border-left: 3px solid var(--primary);
  padding: 6px 12px;
  border-radius: 0 var(--r) var(--r) 0;
  color: var(--ink);
}
/* Strikethrough */
.cm-strikethrough { text-decoration: line-through; color: var(--ink-muted); }

/* Code block line styling — applied to text element (not wrapper) to avoid cursor offset */
.cm-code-line { background: var(--surface-2) !important; font-family: var(--font-mono) !important; font-size: 0.9em !important; display: block; padding: 2px 12px !important; line-height: 1.5 !important; }
/* Inline code styling */
.cm-mono { font-family: var(--font-mono) !important; background: var(--surface-2) !important; padding: 2px 6px !important; border-radius: 4px !important; font-size: 0.9em !important; }

/* Dark mode CodeMirror */
[data-theme="dark"] .CodeMirror { background: var(--canvas) !important; color: var(--ink) !important; }
[data-theme="dark"] .CodeMirror-cursor { border-left-color: var(--primary) !important; }
[data-theme="dark"] .CodeMirror-selected { background: var(--primary-10) !important; }
[data-theme="dark"] .cm-header { color: var(--ink) !important; }
[data-theme="dark"] .cm-link { color: var(--primary-hover) !important; }
[data-theme="dark"] .cm-quote { color: var(--ink-muted) !important; }

/* ── Obsidian-style syntax visibility ── */
.md-syntax { font-size: 0; line-height: 0; display: inline; overflow: hidden; vertical-align: middle; user-select: none; pointer-events: none; color: var(--ink-muted); }
.md-syntax.md-active { font-size: inherit; line-height: inherit; user-select: auto; pointer-events: auto; color: var(--ink-muted); opacity: 0.7; }
.md-syntax.md-active:hover { opacity: 1; }

.md-line { min-height: 1.8em; position: relative; }
.md-line.md-empty { min-height: 1.8em; }

/* Headings — monochrome-accented, clear hierarchy */
.md-h1 { font-size: 32px; font-weight: 700; color: var(--ink); line-height: 1.3; letter-spacing: -0.01em; margin: 0.6em 0 0.3em; }
.md-h2 { font-size: 24px; font-weight: 600; color: var(--ink); line-height: 1.35; letter-spacing: -0.005em; margin: 0.6em 0 0.3em; }
.md-h3 { font-size: 20px; font-weight: 600; color: var(--ink); line-height: 1.4; margin: 0.5em 0 0.25em; }
.md-h4 { font-size: 18px; font-weight: 600; color: var(--ink); margin: 0.5em 0 0.25em; }
.md-h5 { font-size: 16px; font-weight: 600; color: var(--ink); text-transform: uppercase; letter-spacing: 0.04em; margin: 0.4em 0 0.2em; }
.md-h6 { font-size: 14px; font-weight: 600; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 0.4em 0 0.2em; }

/* Inline formatting */
.live-editor strong, .md-element strong { font-weight: 600; }
.live-editor em, .md-element em { font-style: italic; }
.live-editor del, .md-element del { text-decoration: line-through; color: var(--ink-muted); }
.live-editor code, .md-element code { font-family: var(--font-mono); background: var(--surface-2); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; color: var(--ink); }
.live-editor a, .md-link { color: var(--primary-hover); text-decoration: underline; text-underline-offset: 2px; }

/* Block elements — charcoal accent on blockquote */
.md-blockquote { border-left: 3px solid var(--primary); padding: 6px 16px; color: var(--ink-muted); background: var(--primary-06); border-radius: 0 var(--r) var(--r) 0; margin: 0; }
.md-list-item, .md-ol-item { display: list-item; margin-left: 20px; padding: 2px 0; }
.md-ol-item { list-style-type: decimal; }
.md-list-item { list-style-type: disc; }
.live-editor hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* Question blocks — use display: inline so cursor can enter text in contentEditable.
   The ::before circle is styled separately and doesn't block cursor navigation. */
.live-editor .question-block { background: var(--primary-06); border-left: 3px solid var(--primary); padding: 6px 12px; border-radius: 0 var(--r) var(--r) 0; cursor: pointer; margin: 4px 0; display: inline; color: var(--ink); }
.live-editor .question-block:hover { background: var(--primary-10); }
.live-editor .question-block::before { content: '?'; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; background: var(--primary); color: #FFFFFF; border-radius: var(--r-full); font-size: 12px; font-weight: 700; margin-right: 6px; vertical-align: middle; }

/* KaTeX — no scrollbars, full height always renders */
.md-katex { display: inline; }
.md-katex-display { display: block; margin: 12px 0; text-align: center; overflow: visible !important; max-height: none !important; height: auto !important; }
.live-editor .katex-display { margin: 12px 0; overflow: visible !important; max-height: none !important; height: auto !important; }
.live-editor .katex { font-size: 1.1em; }

/* Fenced code blocks */
.md-code-fence-line { background: var(--surface-1); border-left: 3px solid var(--border-strong); padding-left: 12px; }
.md-code-fence-line:first-child { border-radius: var(--r-md) var(--r-md) 0 0; padding-top: 6px; }
.md-code-fence-line:last-child { border-radius: 0 0 var(--r-md) var(--r-md); padding-bottom: 6px; }
.md-code-line { background: var(--surface-1); border-left: 3px solid var(--border-strong); padding-left: 12px; }
.md-code-lang { font-family: var(--font-mono); font-size: 0.85em; color: var(--ink-muted); margin-left: 4px; }
.md-code-block-content { font-family: var(--font-mono); font-size: 0.9em; color: var(--ink); display: block; white-space: pre-wrap; word-break: break-all; background: transparent; padding: 0; }
/* Highlighted code block (when cursor is outside the block) — uses hljs syntax colors */
.md-code-highlighted { background: var(--surface-1); border-left: 3px solid var(--border-strong); padding: 8px 12px; margin: 0; }
.md-code-highlighted pre { margin: 0; background: transparent; padding: 0; border: none; overflow-x: auto; }
.md-code-highlighted code { font-family: var(--font-mono); font-size: 0.9em; line-height: 1.6; background: transparent; padding: 0; color: var(--ink); display: block; white-space: pre-wrap; word-break: break-all; }

/* Format bar — flat, minimal */
.format-bar { display: flex; align-items: center; gap: 2px; padding: 6px 14px; border-bottom: 1px solid var(--border); background: var(--surface-1); flex-wrap: wrap; }
.format-btn { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: var(--r-sm); color: var(--ink-muted); font-size: 13px; font-weight: 500; transition: all var(--fast); }
.format-btn:hover { background: var(--surface-2); color: var(--ink); }
.format-divider { width: 1px; height: 18px; background: var(--border); margin: 0 3px; }
.format-select { padding: 3px 8px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--canvas); font-size: var(--label); color: var(--ink-muted); cursor: pointer; }
.format-select:focus { border-color: var(--primary); }

/* ============================================
   Chat messages + welcome screen
   ============================================ */
.chat-messages { flex: 1; overflow-y: auto; padding: 24px 20px; background: var(--canvas); }

/* Welcome screen — redesigned: Socra wordmark + centered compact input */
.welcome-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; text-align: center; padding: 40px 20px; animation: fadeUp 0.4s var(--ease); }
.welcome-icon { display: none; } /* logo block deprecated in favor of wordmark */
.welcome-icon img { width: 56px; height: 56px; border-radius: 12px; }
.welcome-wordmark { display: none; } /* legacy text wordmark — replaced by .welcome-wordmark-img */
/* Text logo (424x100, aspect ratio 4.24:1). Transparent PNG, so object-fit:
   contain lets the wordmark sit cleanly on the canvas. Width-based sizing
   keeps the aspect ratio locked. */
.welcome-wordmark-img {
  width: 260px;
  height: auto;
  aspect-ratio: 424 / 100;
  margin-bottom: 36px;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}
/* In dark mode, swap to the inverted text logo */
[data-theme="dark"] .welcome-wordmark-img { content: url('/assets/inverted-text-logo.png'); }
.welcome-subtitle { display: none; }
.welcome-screen h2 { font-size: 22px; margin-bottom: 8px; color: var(--ink); font-weight: 600; display: none; } /* legacy h2 hidden — replaced by wordmark */
.welcome-screen p { color: var(--ink-muted); max-width: 480px; margin-bottom: 32px; line-height: 1.7; display: none; }
.welcome-presets { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 640px; margin-bottom: 24px; }
.welcome-preset { padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--r-full); font-size: 14px; color: var(--ink-muted); cursor: pointer; transition: all var(--fast); background: var(--canvas); }
.welcome-preset:hover { border-color: var(--primary); color: var(--primary-hover); background: var(--primary-06); }

/* Welcome composer — centered, not full-width */
.welcome-composer { width: 100%; max-width: 640px; margin: 0 auto; }
/* Model row sits BELOW the input bar, aligned to the left edge of the input */
.welcome-model-row { display: flex; justify-content: flex-start; margin-top: 10px; padding-left: 4px; }
/* Welcome composer wrapper: row layout with align-items: flex-end.
   The textarea min-height matches the send button height (32px), so on a
   single line the button sits inline with the text. When the textarea grows
   to multiple lines, flex-end puts the button at the bottom-right and the
   text occupies the full width above it — exactly like ChatGPT. */
.welcome-composer-wrapper { display: flex; align-items: flex-end; gap: 8px; background: var(--canvas); border: 1.5px solid var(--border); border-radius: var(--r-xl); padding: 8px 8px 8px 16px; transition: border-color var(--fast), box-shadow var(--fast); box-shadow: var(--shadow-card); }
.welcome-composer-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-10); }
.welcome-composer-input { flex: 1; resize: none; border: none; background: transparent; font-size: var(--body); line-height: 32px; max-height: 120px; min-height: 32px; padding: 0; color: var(--ink); overflow-y: hidden; box-sizing: border-box; }
.welcome-composer-input::placeholder { color: var(--ink-muted); }
.welcome-composer-btn-row { display: flex; justify-content: flex-end; flex-shrink: 0; }
.welcome-composer-btn { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: var(--r-full); background: var(--primary); color: #FFFFFF; transition: all var(--fast); flex-shrink: 0; }
.welcome-composer-btn:hover { background: var(--primary-hover); transform: scale(1.04); }
.welcome-composer-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

/* Messages */
.message { margin-bottom: 20px; display: flex; flex-direction: column; animation: fadeUp 0.3s var(--ease); }
.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }
.message-bubble { max-width: 80%; padding: 14px 18px; border-radius: var(--r-lg); line-height: 1.65; font-size: var(--body); }
.message.user .message-bubble { background: var(--primary); color: #FFFFFF; border-bottom-right-radius: var(--r-sm); }
.message.assistant .message-bubble { background: var(--surface-1); color: var(--ink); border: 1px solid var(--border); border-bottom-left-radius: var(--r-sm); }
.message-role { font-size: var(--label); font-weight: 600; color: var(--ink-muted); letter-spacing: 0.02em; margin-bottom: 4px; text-transform: uppercase; padding: 0 4px; }
.message.user .message-role { text-align: right; }
.message-bubble p { margin-bottom: 10px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul, .message-bubble ol { padding-left: 20px; margin-bottom: 10px; }
.message-bubble li { margin-bottom: 4px; }
.message-bubble code { font-family: var(--font-mono); font-size: 0.9em; }
.message.user .message-bubble code { background: rgba(255, 255, 255, 0.18); padding: 1px 5px; border-radius: 3px; }
.message.assistant .message-bubble code { background: var(--surface-2); padding: 1px 5px; border-radius: 3px; color: var(--ink); }
/* Code blocks — clean, minimal, with subtle background contrast.
   No border (dividers are nearly invisible anyway). Language label sits
   faintly in the top-right. highlight.js theme provides the syntax colors. */
.message-bubble pre {
  background: var(--surface-2);
  padding: 14px 16px;
  border-radius: var(--r-md);
  overflow-x: auto;
  margin: 12px 0;
  position: relative;
  border: none;
}
.message-bubble pre code { background: none; padding: 0; font-size: 0.875em; line-height: 1.6; color: var(--ink); font-family: var(--font-mono); }

/* Language label for fenced code blocks — faint, top-right */
.message-bubble pre.has-lang-label { padding-top: 30px; }
.message-bubble pre .code-lang-label {
  position: absolute;
  top: 8px;
  right: 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-muted);
  text-transform: lowercase;
  letter-spacing: 0.04em;
  pointer-events: none;
  user-select: none;
  opacity: 0.5;
}

/* highlight.js: let the theme's syntax colors show through.
   Only override background (transparent so our <pre> bg shows) and font. */
.message-bubble pre code.hljs { background: transparent !important; padding: 0 !important; font-family: var(--font-mono); }
.message-bubble pre code.hljs::before, .message-bubble pre code.hljs::after { content: none; }
/* In user messages (charcoal bubble), code text is white for readability */
.message.user .message-bubble pre code.hljs { color: #FFFFFF; }
.message.user .message-bubble pre .code-lang-label { color: rgba(255, 255, 255, 0.6); }
.message-bubble :not(pre) > code { font-family: var(--font-mono); font-size: 0.9em; }
.message.user .message-bubble pre { background: rgba(255, 255, 255, 0.10); border-color: rgba(255, 255, 255, 0.15); }
.message-bubble .katex-display { margin: 12px 0; overflow-x: auto; }

/* Markdown formatting in chat messages */
.message-bubble h1, .message-bubble h2, .message-bubble h3, .message-bubble h4, .message-bubble h5, .message-bubble h6 { margin: 14px 0 8px; font-weight: 600; line-height: 1.3; color: var(--ink); }
.message-bubble h1 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.message-bubble h2 { font-size: 1.3em; border-bottom: 1px solid var(--border); padding-bottom: 5px; }
.message-bubble h3 { font-size: 1.15em; }
.message-bubble h4 { font-size: 1.05em; }
.message-bubble h1:first-child, .message-bubble h2:first-child, .message-bubble h3:first-child { margin-top: 0; }
.message-bubble strong { font-weight: 600; color: var(--ink); }
.message-bubble em { font-style: italic; }
.message.user .message-bubble strong { color: #FFFFFF; }
.message-bubble blockquote { border-left: 3px solid var(--primary); padding: 6px 14px; margin: 10px 0; background: var(--primary-06); border-radius: 0 var(--r-sm) var(--r-sm) 0; color: var(--ink-muted); }
.message-bubble blockquote p { margin-bottom: 4px; }
.message-bubble hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.message.user .message-bubble a { color: #FFFFFF; text-decoration: underline; text-decoration-color: rgba(255, 255, 255, 0.4); text-underline-offset: 2px; }
.message.assistant .message-bubble a { color: var(--primary-hover); text-decoration: underline; text-decoration-color: var(--primary-10); text-underline-offset: 2px; }
.message-bubble a:hover { text-decoration-thickness: 2px; }
.message-bubble table { border-collapse: collapse; margin: 10px 0; font-size: 0.95em; width: 100%; }
.message-bubble th, .message-bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.message-bubble th { background: var(--surface-2); font-weight: 600; }
.message-bubble img { max-width: 100%; border-radius: var(--r-md); margin: 8px 0; }
.message-bubble .katex { font-size: 1.05em; }

/* Copy button */
.msg-copy-btn { display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; border: none; border-radius: var(--r-sm); background: transparent; color: var(--ink-muted); cursor: pointer; transition: all var(--fast); margin-top: 4px; flex-shrink: 0; }
.msg-copy-btn:hover { background: var(--surface-2); color: var(--ink); }
.msg-copy-btn.copied { color: var(--success); }
.msg-copy-btn.hover-reveal { opacity: 0; }
.message.user:hover .msg-copy-btn.hover-reveal { opacity: 1; }
.msg-copy-btn.always-show { opacity: 0.4; }
.msg-copy-btn.always-show:hover { opacity: 1; }
.msg-copy-btn svg { flex-shrink: 0; }

/* AI loading indicator */
.ai-loading { display: flex; align-items: flex-start; margin-bottom: 20px; animation: fadeUp 0.3s var(--ease); }
.ai-loading-bubble { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-lg); border-bottom-left-radius: var(--r-sm); padding: 18px 22px; max-width: 80%; }
.ai-loading-dots { display: flex; align-items: center; gap: 8px; }
.ai-loading-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary-10); }
.ai-loading-dot:nth-child(1) { animation: loadingPulse 1.4s ease-in-out infinite; }
.ai-loading-dot:nth-child(2) { animation: loadingPulse 1.4s ease-in-out infinite 0.2s; }
.ai-loading-dot:nth-child(3) { animation: loadingPulse 1.4s ease-in-out infinite 0.4s; }
@keyframes loadingPulse {
  0%, 60%, 100% { transform: scale(1); opacity: 0.3; background: var(--primary-10); }
  30% { transform: scale(1.3); opacity: 1; background: var(--primary); }
}
.ai-loading-text { font-size: var(--label); color: var(--ink-muted); margin-top: 10px; font-style: italic; }
.ai-loading-text span { animation: pulse 2s ease-in-out infinite; }

/* ============================================
   Composer area (chat mode — full width, bottom)
   ============================================ */
/* When welcome screen is shown, hide the full-width bottom composer (the welcome composer is used instead) */
.chat-panel.welcome-active .composer-area { display: none; }
/* Hide composer-area by default to prevent flicker on page load.
   JS shows it via setWelcomeMode(false) when entering chat mode. */
.composer-area { padding: 14px 20px 18px; border-top: 1px solid var(--border); background: var(--canvas); display: none; }
.chat-panel:not(.welcome-active) .composer-area { display: block; }
.composer-top-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.composer-top-row .spacer { flex: 1; }

/* Upgrade button — moved here, on the right side of the top row */
.upgrade-btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; font-size: 12px; font-weight: 600; border-radius: var(--r-full); color: var(--primary-hover); border: 1px solid var(--primary); background: var(--primary-06); transition: all var(--fast); letter-spacing: 0.02em; margin-left: auto; }
.upgrade-btn:hover { background: var(--primary); color: #FFFFFF; border-color: var(--primary); }
.upgrade-btn svg { flex-shrink: 0; }

/* Model selector — pill style */
.model-selector { position: relative; }
.model-selector-btn { display: flex; align-items: center; gap: 6px; padding: 4px 10px 4px 8px; border: 1px solid var(--border); border-radius: var(--r-full); background: var(--surface-1); color: var(--ink-muted); font-size: 12px; font-weight: 500; cursor: pointer; transition: all var(--fast); letter-spacing: 0.01em; }
.model-selector-btn:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--ink); }
.model-selector-dot { width: 7px; height: 7px; border-radius: 50%; background: #38BDF8; } /* Doxa = sky blue (fixed) */
.model-selector-dot.med { background: #2D8A56; } /* Elenchus = green (fixed) */
.model-selector-dot.high { background: #C9A84C; } /* Nous = gold (fixed) */
.model-selector-dropdown { position: absolute; bottom: calc(100% + 6px); left: 0; min-width: 220px; background: var(--canvas); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-elevated); padding: 6px; display: none; z-index: 100; }
.model-selector-dropdown.open { display: block; }
.model-option { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: none; border-radius: var(--r-sm); background: none; cursor: pointer; transition: background var(--fast); text-align: left; font-size: var(--body); color: var(--ink); }
.model-option:hover { background: var(--surface-2); }
.model-option.active { background: var(--primary-06); color: var(--primary-hover); }
.model-option.locked { color: var(--ink-muted); }
.model-option.locked:hover { color: var(--ink-muted); background: var(--surface-2); }
.model-option-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.model-option-dot.low { background: #38BDF8; } /* Doxa = sky blue (fixed) */
.model-option-dot.med { background: #2D8A56; } /* Elenchus = green (fixed) */
.model-option-dot.high { background: #C9A84C; } /* Nous = gold (fixed) */
.model-option.locked .model-option-dot { opacity: 0.4; }
/* Lock/star icons for Elenchus + Nous = fixed gold */
.model-lock-icon { display: flex; align-items: center; color: #C9A84C; margin-left: auto; flex-shrink: 0; transition: color var(--fast); }
.model-option.locked:hover .model-lock-icon { color: #C9A84C; }
.model-option-info { display: flex; align-items: center; gap: 6px; flex: 1; flex-wrap: wrap; }
.model-tier { font-size: 11px; color: var(--ink-muted); font-weight: 400; }

/* Composer wrapper — default (welcome + workspace-closed): row layout with
   align-items: flex-end. The textarea min-height matches the send button
   height, so on a single line the button sits inline with the text. When the
   textarea grows to multiple lines, flex-end puts the button at the bottom-
   right and the text occupies the full width above it — exactly like ChatGPT.
   When the workspace is open (.workspace-open on chat-panel), switch to
   column layout: textarea on top (full width), action row below with
   Document button (left) + Send button (right). */
.composer-wrapper { display: flex; align-items: flex-end; gap: 8px; background: var(--canvas); border: 1.5px solid var(--border); border-radius: var(--r-xl); padding: 8px 8px 8px 16px; transition: border-color var(--fast), box-shadow var(--fast); }
.composer-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-10); }
.composer-input { flex: 1; resize: none; border: none; background: transparent; font-size: var(--body); line-height: 32px; max-height: 120px; min-height: 32px; padding: 0; color: var(--ink); overflow-y: hidden; box-sizing: border-box; }
.composer-input::placeholder { color: var(--ink-muted); }
.composer-btn { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: var(--r-full); transition: all var(--fast); flex-shrink: 0; }
.composer-btn.send-btn { background: var(--primary); color: #FFFFFF; }
.composer-btn.send-btn:hover { background: var(--primary-hover); transform: scale(1.05); }
.composer-btn.send-btn:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }
/* The action-row (containing the workspace-open send button) is hidden by default.
   The Document button + standalone send button are direct children, always visible. */
.composer-wrapper .composer-action-row { display: none; }

/* Workspace-open layout: column with textarea on top, action row below.
   The action row has Document button (left) + Send button (right).
   Hide the standalone Document + send buttons; show the action row. */
.chat-panel.workspace-open .composer-wrapper { display: flex !important; flex-direction: column !important; align-items: stretch !important; gap: 10px; padding: 12px 12px 8px 16px; }
.chat-panel.workspace-open .composer-input { width: 100%; display: block; flex: none; min-height: 32px; }
/* Hide standalone buttons in workspace-open mode */
.chat-panel.workspace-open .composer-wrapper > .composer-btn.standalone { display: none !important; }
/* Show the action row in workspace-open mode */
.chat-panel.workspace-open .composer-wrapper .composer-action-row { display: flex !important; align-items: center; gap: 8px; }
.chat-panel.workspace-open .composer-wrapper .composer-action-row .spacer { flex: 1; }
.composer-action-row .spacer { flex: 1; }
.composer-btn.attach-btn { color: var(--primary-hover); background: var(--primary-06); border: 1px solid var(--primary-10); font-weight: 600; font-size: 12px; width: auto; padding: 0 12px; gap: 5px; }
.composer-btn.attach-btn span { display: inline; }
.composer-btn.attach-btn:hover { background: var(--primary); color: #FFFFFF; border-color: var(--primary); }

.reopen-workspace-btn { display: flex; align-items: center; gap: 6px; padding: 6px 12px; font-size: var(--label); font-weight: 500; color: var(--primary-hover); background: var(--primary-06); border: 1px solid var(--primary-10); border-radius: var(--r-full); transition: all var(--fast); }
.reopen-workspace-btn:hover { background: var(--primary); color: #FFFFFF; border-color: var(--primary); }

/* ============================================
   Metrics page
   ============================================ */
.metrics-page { margin-top: var(--nav-h); padding: 40px var(--pad) 60px; min-height: calc(100vh - var(--nav-h)); background: var(--surface-1); }
.metrics-container { max-width: 900px; margin: 0 auto; }
.metrics-back { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-muted); font-weight: 500; margin-bottom: 32px; transition: color var(--fast); }
.metrics-back:hover { color: var(--primary-hover); text-decoration: none; }
.metrics-summary { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 32px; }
.metric-card { text-align: center; padding: 20px 12px; background: var(--canvas); border: 1px solid var(--border); border-radius: var(--r-md); }
.metric-value { font-size: 28px; font-weight: 700; color: var(--primary-hover); margin-bottom: 4px; }
.metric-label { font-size: var(--label); color: var(--ink-muted); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.metric-bar { height: 4px; background: var(--surface-2); border-radius: var(--r-full); margin-top: 10px; overflow: hidden; }
.metric-bar-fill { height: 100%; background: linear-gradient(90deg, var(--ink), var(--primary)); border-radius: var(--r-full); transition: width 0.8s var(--ease); }
.metrics-chart-area { background: var(--canvas); border: 1px solid var(--border); border-radius: var(--r-md); padding: 24px; margin-bottom: 24px; }
.metrics-chart-area h3 { font-size: 16px; font-weight: 600; color: var(--ink); margin-bottom: 16px; }
.metrics-chart-container { position: relative; height: 250px; }
.metrics-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.metrics-stat-card { padding: 16px; background: var(--canvas); border: 1px solid var(--border); border-radius: var(--r-md); }
.metrics-stat-label { font-size: var(--label); color: var(--ink-muted); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.metrics-stat-value { font-size: 24px; font-weight: 700; color: var(--ink); margin-top: 4px; }

/* ============================================
   Toasts + dialogs
   ============================================ */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 3000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; background: var(--ink); color: #FFFFFF; border-radius: var(--r-md); font-size: var(--body); box-shadow: var(--shadow-elevated); animation: fadeUp 0.3s var(--ease); max-width: 360px; }
.toast.error { background: var(--error); }

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 1024px) {
  .pricing-grid { grid-template-columns: 1fr; max-width: 400px; }
  .features-grid { grid-template-columns: 1fr; }
  .comparison-grid { grid-template-columns: 1fr; }
  .workspace-chat-split { flex-direction: column; }
  .workspace-panel { width: 100%; height: 50%; border-right: none; border-bottom: 1px solid var(--border); }
  .workspace-panel ~ .chat-panel { width: 100%; }
  .metrics-summary { grid-template-columns: repeat(3, 1fr); }
  .editor-split { flex-direction: column; }
  .live-editor { min-height: 150px; }
}
@media (max-width: 768px) {
  :root { --h1: 32px; --h2: 24px; --pad: 20px; }
  .nav-links { gap: 16px; }
  .hero { padding: 60px var(--pad) 40px; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 1100; transform: translateX(-100%); transition: transform var(--norm); }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar.collapsed { transform: translateX(-100%); }
  .metrics-summary { grid-template-columns: repeat(2, 1fr); }
  .welcome-wordmark { font-size: 36px; }
  .welcome-wordmark-img { width: 180px; }
  .welcome-composer { max-width: 100%; }
  .composer-area { padding: 10px 12px 14px; }
}

/* ============================================
   Scrollbars
   ============================================ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

.hidden { display: none !important; }

/* ============================================
   Confirm dialog
   ============================================ */
.confirm-overlay { position: fixed; inset: 0; background: rgba(26, 26, 26, 0.55); z-index: 2000; display: flex; align-items: center; justify-content: center; animation: fadeIn 0.15s var(--ease); }
.confirm-dialog { background: var(--canvas); border-radius: var(--r-lg); padding: 28px 32px; max-width: 400px; width: 90%; box-shadow: var(--shadow-overlay); }
.confirm-dialog h3 { font-size: 18px; font-weight: 600; color: var(--ink); margin-bottom: 10px; }
.confirm-dialog p { font-size: var(--body); color: var(--ink-muted); line-height: 1.6; margin-bottom: 20px; }
.confirm-dialog-btns { display: flex; gap: 10px; justify-content: flex-end; }
.confirm-dialog-btns .btn { padding: 8px 20px; border-radius: var(--r); font-size: var(--body); font-weight: 500; cursor: pointer; transition: all var(--fast); }
.confirm-dialog-btns .btn-cancel { background: var(--surface-1); color: var(--ink-muted); border: 1px solid var(--border); }
.confirm-dialog-btns .btn-cancel:hover { background: var(--surface-2); }
.confirm-dialog-btns .btn-danger { background: var(--error); color: #FFFFFF; border: none; }
.confirm-dialog-btns .btn-danger:hover { opacity: 0.9; }

/* ============================================
   Settings Panel (centered modal)
   ============================================ */
/* ============================================
   Spotlight Search Popup (Mac Spotlight-style)
   ============================================ */
.spotlight-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(4px); z-index: 2299; opacity: 0; visibility: hidden; transition: opacity var(--norm), visibility var(--norm); }
.spotlight-overlay.open { opacity: 1; visibility: visible; }
.spotlight-popup {
  position: fixed;
  top: 15vh;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  width: 560px;
  max-width: calc(100vw - 32px);
  max-height: 60vh;
  background: var(--canvas);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-overlay);
  z-index: 2300;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--norm), transform var(--norm), visibility var(--norm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.spotlight-popup.open { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
.spotlight-input-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.spotlight-search-icon { color: var(--ink-muted); flex-shrink: 0; }
.spotlight-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--ink);
  outline: none;
  font-family: var(--font);
}
.spotlight-input::placeholder { color: var(--ink-muted); }
.spotlight-kbd {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  flex-shrink: 0;
}
.spotlight-results {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}
.spotlight-empty {
  padding: 24px 18px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 14px;
}
.spotlight-result {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r);
  cursor: pointer;
  transition: background var(--fast);
  color: var(--ink);
}
.spotlight-result:hover, .spotlight-result.selected {
  background: var(--surface-2);
}
.spotlight-result-icon { color: var(--ink-muted); flex-shrink: 0; }
.spotlight-result-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.spotlight-result-meta {
  font-size: 12px;
  color: var(--ink-muted);
  flex-shrink: 0;
}

/* Dark mode for spotlight */
[data-theme="dark"] .spotlight-popup { background: var(--surface-1); box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6); }
[data-theme="dark"] .spotlight-kbd { background: var(--surface-3); border-color: var(--border); }

.settings-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(4px); z-index: 2100; opacity: 0; visibility: hidden; transition: opacity var(--norm), visibility var(--norm); }
.settings-overlay.open { opacity: 1; visibility: visible; }

/* Settings panel — wider, ChatGPT-style with sidebar nav + content */
.settings-panel { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.96); width: 640px; max-width: calc(100vw - 40px); height: 70vh; max-height: calc(100vh - 60px); min-height: 400px; background: var(--canvas); border-radius: var(--r-xl); box-shadow: var(--shadow-overlay); z-index: 2200; opacity: 0; visibility: hidden; transition: all var(--norm); display: flex; flex-direction: column; overflow: hidden; }
.settings-panel.open { opacity: 1; visibility: visible; transform: translate(-50%, -50%) scale(1); }
.settings-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.settings-title { display: flex; align-items: center; gap: 10px; }
.settings-title svg { color: var(--ink-muted); flex-shrink: 0; }
.settings-header h2 { font-size: 18px; font-weight: 600; color: var(--ink); }
.settings-close { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: var(--r); color: var(--ink-muted); transition: all var(--fast); }
.settings-close:hover { background: var(--surface-1); color: var(--ink); }
/* Body: sidebar nav (left) + content (right) */
.settings-body { flex: 1; display: flex; overflow: hidden; }
.settings-nav { width: 180px; flex-shrink: 0; border-right: 1px solid var(--border); padding: 12px 8px; overflow-y: auto; }
.settings-nav-btn { display: block; width: 100%; text-align: left; padding: 9px 12px; border-radius: var(--r); font-size: 14px; font-weight: 500; color: var(--ink-muted); transition: all var(--fast); cursor: pointer; }
.settings-nav-btn:hover { background: var(--surface-1); color: var(--ink); }
.settings-nav-btn.active { background: var(--surface-2); color: var(--ink); }
.settings-content { flex: 1; overflow-y: auto; padding: 20px 24px; }
/* Sections — only the active one is shown */
.settings-section { display: none; }
.settings-section.active { display: block; }
.settings-section h3 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-muted); margin: 0 0 12px; }
.settings-section h3:not(:first-child) { margin-top: 24px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; margin: 0 -14px 4px; border-radius: var(--r-md); }
.settings-row:last-child { margin-bottom: 0; }
.settings-row.clickable { cursor: pointer; transition: background var(--fast); }
.settings-row.clickable:hover { background: var(--surface-1); }
.settings-row.clickable.danger .settings-row-label { color: var(--error); }
.settings-row-info { flex: 1; }
.settings-row-label { display: block; font-size: 15px; font-weight: 500; color: var(--ink); margin-bottom: 2px; }
.settings-row-desc { display: block; font-size: 13px; color: var(--ink-muted); }
.settings-row.clickable svg { color: var(--ink-muted); flex-shrink: 0; }

/* Theme dropdown + accent picker */
.settings-select { padding: 6px 10px; border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--canvas); font-size: 14px; color: var(--ink); font-family: var(--font); cursor: pointer; flex-shrink: 0; }
.settings-select:focus { border-color: var(--primary); outline: none; }

/* Theme cards — 3 image radio cards (System, Light, Dark) */
.theme-cards { display: flex; gap: 12px; margin-bottom: 8px; }
.theme-card { display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; flex: 1; }
.theme-card input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.theme-card-image { width: 100%; aspect-ratio: 16 / 10; border-radius: var(--r-md); border: 2px solid var(--border); transition: border-color var(--fast); background-size: cover; background-position: center; }
.theme-card:hover .theme-card-image { border-color: var(--border-strong); }
.theme-card input[type="radio"]:checked + .theme-card-image { border-color: var(--primary); }
.theme-card-label { font-size: 13px; font-weight: 500; color: var(--ink-muted); transition: color var(--fast); }
.theme-card input[type="radio"]:checked ~ .theme-card-label { color: var(--ink); }
[data-theme="dark"] .theme-card-image { border-color: var(--border); }
/* Theme card images — upload light.png, dark.png, system.png (1920x1080) to /assets/ */
.theme-card-image-system { background-image: url('/assets/system.png'); }
.theme-card-image-light { background-image: url('/assets/light.png'); }
.theme-card-image-dark { background-image: url('/assets/dark.png'); }
.accent-picker { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.accent-color-input { width: 36px; height: 36px; border: 1px solid var(--border-strong); border-radius: var(--r); cursor: pointer; padding: 2px; background: var(--canvas); }
.accent-color-input::-webkit-color-swatch-wrapper { padding: 0; }
.accent-color-input::-webkit-color-swatch { border: none; border-radius: 4px; }
.accent-color-input::-moz-color-swatch { border: none; border-radius: 4px; }
.accent-reset-btn { padding: 6px 12px; font-size: 13px; font-weight: 500; color: var(--ink-muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); cursor: pointer; transition: all var(--fast); }
.accent-reset-btn:hover { background: var(--surface-3); color: var(--ink); }

/* Legacy toggle (kept for back-compat, unused now) */
.settings-toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.settings-toggle input { opacity: 0; width: 0; height: 0; }
.settings-toggle-slider { position: absolute; cursor: pointer; inset: 0; background: var(--border-strong); border-radius: 24px; transition: all var(--norm); }
.settings-toggle-slider::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; bottom: 3px; background: #FFFFFF; border-radius: 50%; transition: all var(--norm); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.settings-toggle input:checked + .settings-toggle-slider { background: var(--primary); }
.settings-toggle input:checked + .settings-toggle-slider::before { transform: translateX(20px); }
.settings-toggle input:focus + .settings-toggle-slider { box-shadow: 0 0 0 3px var(--primary-10); }

.settings-btn { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--r); color: var(--ink-muted); transition: all var(--fast); }
.settings-btn:hover { background: var(--surface-1); color: var(--ink); }

/* Responsive: stack the settings nav above the content on narrow screens */
@media (max-width: 600px) {
  .settings-panel { width: calc(100vw - 20px); }
  .settings-body { flex-direction: column; }
  .settings-nav { width: 100%; border-right: none; border-bottom: 1px solid var(--border); display: flex; gap: 4px; padding: 8px; overflow-x: auto; }
  .settings-nav-btn { white-space: nowrap; }
}

/* ============================================
   DARK MODE — Perplexity palette (#161514 canvas, #1E1D1B sidebar)
   ============================================ */
[data-theme="dark"] {
  /* Matches Perplexity's actual dark palette:
     main page = #161514, sidebar = #1E1D1B */
  --canvas: #161514;
  --surface-1: #1E1D1B;
  --surface-2: #282725;
  --surface-3: #333230;
  /* Borders almost non-existent — barely perceptible against the dark surfaces */
  --border: rgba(255, 255, 255, 0.035);
  --border-strong: rgba(255, 255, 255, 0.07);
  --ink: #F9FAFB;
  --ink-muted: #9CA3AF;
  --text-muted: #9CA3AF;

  /* Legacy aliases */
  --white: var(--canvas);
  --surface: var(--surface-1);
  --navy: var(--ink);
  --navy-light: #E5E7EB;
  --navy-dark: #FFFFFF;
  --navy-10: rgba(249, 250, 251, 0.10);
  --navy-06: rgba(249, 250, 251, 0.06);
  --gold-10: var(--primary-10);
  --gold-06: var(--primary-06);

  /* Brand accent in dark mode — off-white tone (#E8E6E1) so the monochrome
     accent stays visible against the near-black surfaces. */
  --primary: #E8E6E1;
  --primary-hover: #FFFFFF;
  --primary-10: rgba(232, 230, 225, 0.10);
  --primary-06: rgba(232, 230, 225, 0.06);
  --primary-soft: #1E1D1B;

  --success: #3FB68B;
  --error: #F85149;
  --error-light: #3D1F1F;
}

[data-theme="dark"] body { background: var(--canvas); color: var(--ink); }
[data-theme="dark"] ::selection { background: var(--primary-10); color: var(--ink); }

/* Buttons in dark mode */
[data-theme="dark"] .btn-primary { background: var(--primary); color: #1C1C1C; }
[data-theme="dark"] .btn-primary:hover { background: var(--primary-hover); color: #1C1C1C; box-shadow: 0 4px 12px rgba(45, 212, 191, 0.30); }
[data-theme="dark"] .btn-gold { background: var(--primary); color: #1C1C1C; }
[data-theme="dark"] .btn-gold:hover { background: var(--primary-hover); color: #1C1C1C; }
[data-theme="dark"] .btn-outline { border-color: var(--border-strong); color: var(--ink); }
[data-theme="dark"] .btn-outline:hover { background: var(--ink); color: var(--canvas); border-color: var(--ink); }
[data-theme="dark"] .btn-ghost:hover { color: var(--ink); background: var(--surface-2); }

/* Nav */
[data-theme="dark"] .nav { background: var(--canvas); border-color: var(--border); }
[data-theme="dark"] .nav.scrolled { box-shadow: 0 1px 0 var(--border); }
[data-theme="dark"] .nav-link { color: var(--ink-muted); }
[data-theme="dark"] .nav-link:hover, [data-theme="dark"] .nav-link.active { color: var(--ink); }

/* Hero / sections */
[data-theme="dark"] .hero { background: var(--surface-1); }
[data-theme="dark"] .hero-badge { background: var(--primary-10); color: var(--primary-hover); border-color: rgba(45, 212, 191, 0.25); }
[data-theme="dark"] .hero h1 { color: var(--ink); }
[data-theme="dark"] .hero h1 .accent { color: var(--primary); }
[data-theme="dark"] .hero-sub { color: var(--ink-muted); }
[data-theme="dark"] .section { background: var(--canvas); }
[data-theme="dark"] .section-alt { background: var(--surface-1); }
[data-theme="dark"] .section-header h2 { color: var(--ink); }
[data-theme="dark"] .section-header p { color: var(--ink-muted); }
[data-theme="dark"] .gold-line { background: var(--primary); }
[data-theme="dark"] .comparison-card { background: var(--surface-1); border-color: var(--border); }
[data-theme="dark"] .comparison-card h3 { color: var(--ink); }
[data-theme="dark"] .comparison-card.socratic { border-color: var(--primary); background: linear-gradient(135deg, var(--surface-1) 0%, var(--primary-06) 100%); }
[data-theme="dark"] .comparison-list li { color: var(--ink-muted); }
[data-theme="dark"] .comparison-list .icon.check { color: var(--success); }
[data-theme="dark"] .feature-card { background: var(--surface-1); border-color: var(--border); }
[data-theme="dark"] .feature-card h3 { color: var(--ink); }
[data-theme="dark"] .feature-card p { color: var(--ink-muted); }
[data-theme="dark"] .feature-icon { background: var(--primary-10); color: var(--primary-hover); }
[data-theme="dark"] .cta-section { background: #000000; }
[data-theme="dark"] .cta-section h2 { color: #FFFFFF; }
[data-theme="dark"] .cta-section p { color: rgba(255, 255, 255, 0.7); }
[data-theme="dark"] .footer { background: var(--surface-1); border-color: var(--border); }
[data-theme="dark"] .footer p { color: var(--ink-muted); }

/* Pricing */
[data-theme="dark"] .pricing-section { background: var(--canvas); min-height: 100vh; }
[data-theme="dark"] .pricing-header h1 { color: var(--ink); }
[data-theme="dark"] .pricing-header p { color: var(--ink-muted); }
[data-theme="dark"] .pricing-card { background: var(--surface-1); border-color: var(--border); }
[data-theme="dark"] .pricing-name { color: var(--ink); }
[data-theme="dark"] .pricing-label { color: var(--ink-muted); }
[data-theme="dark"] .pricing-price .amount { color: var(--ink); }
[data-theme="dark"] .pricing-price .period { color: var(--ink-muted); }
[data-theme="dark"] .pricing-price .annual { color: var(--primary-hover); }
[data-theme="dark"] .pricing-features li { color: var(--ink-muted); }
[data-theme="dark"] .pricing-features .check-icon { color: var(--primary); }
[data-theme="dark"] .pricing-card.featured { border-color: #2D8A56; background: var(--surface-2); }
[data-theme="dark"] .pricing-card.best { border-color: #C9A84C; background: var(--surface-2); }
[data-theme="dark"] .pricing-card.current-plan { border-color: var(--ink); }
/* Dark-mode per-plan accent colors (same fixed colors as light mode) */
[data-theme="dark"] #plan-doxa { border-color: #38BDF8; }
[data-theme="dark"] #plan-elenchus { border-color: #2D8A56; }
[data-theme="dark"] #plan-nous { border-color: #C9A84C; }
[data-theme="dark"] #plan-elenchus.featured::before { background: #2D8A56; color: #1C1C1C; }
[data-theme="dark"] #plan-doxa.current-plan::after { background: #38BDF8; color: #1C1C1C; }
[data-theme="dark"] #plan-elenchus.current-plan::after { background: #2D8A56; color: #1C1C1C; }
[data-theme="dark"] #plan-nous.current-plan::after { background: #C9A84C; color: #1C1C1C; }

/* Auth */
[data-theme="dark"] .auth-page { background: var(--surface-1); }
[data-theme="dark"] .auth-card { background: var(--canvas); border-color: var(--border); }
[data-theme="dark"] .auth-tabs { border-color: var(--border); }
[data-theme="dark"] .auth-tab { color: var(--ink-muted); }
[data-theme="dark"] .auth-tab.active { color: var(--ink); border-color: var(--primary); }
[data-theme="dark"] .form-group label { color: var(--ink-muted); }
[data-theme="dark"] .form-input { background: var(--surface-1); border-color: var(--border); color: var(--ink); }
[data-theme="dark"] .form-input:focus { border-color: var(--primary); }
[data-theme="dark"] .form-error { color: var(--error); }
[data-theme="dark"] .password-toggle { color: var(--ink-muted); }
[data-theme="dark"] .password-toggle:hover { color: var(--ink); }

/* Sidebar in dark mode */
[data-theme="dark"] .sidebar { background: var(--surface-1); border-color: var(--border); }
/* sidebar-search dark-mode rules removed — element no longer exists */
/* Dark mode: New Chat + sidebar-link buttons keep the #1E1D1B default background.
   Only override hover/active states. */
[data-theme="dark"] .new-chat-btn:hover { background: var(--primary-06); border-color: var(--primary-10); color: var(--primary-hover); }
[data-theme="dark"] .new-chat-btn.active { background: var(--primary-10); color: var(--primary-hover); border-color: transparent; }
[data-theme="dark"] .sidebar-link-btn { color: var(--ink); }
[data-theme="dark"] .sidebar-link-btn:hover { background: var(--primary-06); border-color: var(--primary-10); color: var(--primary-hover); }
[data-theme="dark"] .sidebar-link-btn.active { background: var(--primary-10); color: var(--primary-hover); border-color: transparent; }
[data-theme="dark"] .chat-item { color: var(--ink-muted); }
[data-theme="dark"] .chat-item:hover { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .chat-item.active { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .chat-item-dropdown { background: var(--surface-2); border-color: var(--border); box-shadow: var(--shadow-overlay); }
[data-theme="dark"] .chat-item-dropdown-item { color: var(--ink-muted); }
[data-theme="dark"] .chat-item-dropdown-item:hover { background: var(--surface-3); color: var(--ink); }
[data-theme="dark"] .chat-item-dropdown-item.danger:hover { background: var(--error-light); color: var(--error); }
[data-theme="dark"] .sidebar-divider { background: var(--border); }
[data-theme="dark"] .sidebar-profile { border-color: var(--border); background: var(--surface-1); }
[data-theme="dark"] .profile-avatar { background: var(--primary); color: #1C1C1C; }
[data-theme="dark"] .profile-name { color: var(--ink); }
[data-theme="dark"] .profile-plan { color: var(--ink-muted); }
[data-theme="dark"] .logout-btn { color: var(--ink-muted); background: transparent; border-color: var(--border); }
[data-theme="dark"] .logout-btn:hover { background: var(--error); color: #FFFFFF; border-color: var(--error); }
/* Dark-mode sidebar-upgrade-btn: hover text is dark on the off-white accent */
[data-theme="dark"] .sidebar-upgrade-btn { color: var(--primary-hover); background: var(--primary-06); border-color: var(--primary-10); }
[data-theme="dark"] .sidebar-upgrade-btn:hover { background: var(--primary); color: #1C1C1C; border-color: var(--primary); }
[data-theme="dark"] .sidebar-icon-btn:hover { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .settings-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Main content in dark mode */
[data-theme="dark"] .main-content { background: var(--canvas); }
[data-theme="dark"] .top-bar { background: var(--canvas); border-color: var(--border); }
[data-theme="dark"] .metrics-btn { color: var(--ink-muted); border-color: var(--border); }
[data-theme="dark"] .metrics-btn:hover { border-color: var(--primary); color: var(--primary-hover); }
[data-theme="dark"] .workspace-panel { background: var(--canvas); border-color: var(--border); }
[data-theme="dark"] .workspace-header { background: var(--canvas); border-color: var(--border); }
[data-theme="dark"] .workspace-title-input { color: var(--ink); }
[data-theme="dark"] .workspace-action-btn:hover { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .format-bar { background: var(--surface-1); border-color: var(--border); }
[data-theme="dark"] .format-btn { color: var(--ink-muted); }
[data-theme="dark"] .format-btn:hover { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .format-select { background: var(--surface-1); color: var(--ink); border-color: var(--border); }
[data-theme="dark"] .live-editor { background: var(--canvas); color: var(--ink); caret-color: var(--primary); }
[data-theme="dark"] .live-editor:focus { outline-color: var(--primary); }

/* Markdown editor in dark mode */
[data-theme="dark"] .md-h1, [data-theme="dark"] .md-h2, [data-theme="dark"] .md-h3,
[data-theme="dark"] .md-h4, [data-theme="dark"] .md-h5, [data-theme="dark"] .md-h6 { color: var(--ink); }
[data-theme="dark"] .live-editor code, [data-theme="dark"] .md-element code,
[data-theme="dark"] .md-code-block-content { color: var(--ink); background: transparent; }
[data-theme="dark"] .md-blockquote { background: var(--primary-06); color: var(--ink-muted); border-left-color: var(--primary); }
[data-theme="dark"] .md-code-fence-line, [data-theme="dark"] .md-code-line { background: var(--surface-1); border-left-color: var(--border-strong); }
[data-theme="dark"] .live-editor .question-block { background: var(--primary-06); border-left-color: var(--primary); color: var(--ink); }
[data-theme="dark"] .live-editor .question-block::before { background: var(--primary); color: #1C1C1C; }
[data-theme="dark"] .live-editor a, [data-theme="dark"] .md-link { color: var(--primary-hover); }

/* Chat messages in dark mode */
[data-theme="dark"] .chat-messages { background: var(--canvas); }
[data-theme="dark"] .welcome-screen { background: var(--canvas); }
[data-theme="dark"] .welcome-wordmark { color: var(--ink); }
[data-theme="dark"] .welcome-subtitle { color: var(--ink-muted); }
[data-theme="dark"] .welcome-preset { background: var(--surface-1); color: var(--ink-muted); border-color: var(--border); }
[data-theme="dark"] .welcome-preset:hover { border-color: var(--primary); color: var(--primary-hover); background: var(--primary-06); }
[data-theme="dark"] .welcome-composer-wrapper { background: var(--surface-1); border-color: var(--border); }
[data-theme="dark"] .welcome-composer-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-10); }
[data-theme="dark"] .welcome-composer-input { color: var(--ink); }
[data-theme="dark"] .welcome-composer-input::placeholder { color: var(--ink-muted); }
[data-theme="dark"] .welcome-composer-btn { background: var(--primary); color: #1C1C1C; }
[data-theme="dark"] .welcome-composer-btn:hover { background: var(--primary-hover); }

[data-theme="dark"] .message { color: var(--ink); }
[data-theme="dark"] .message-role { color: var(--ink-muted); }
[data-theme="dark"] .message.user .message-bubble { background: var(--primary); color: #1C1C1C; }
[data-theme="dark"] .message.assistant .message-bubble { background: var(--surface-1); border-color: var(--border); color: var(--ink); }
[data-theme="dark"] .message.user .message-bubble code { background: rgba(28, 28, 28, 0.18); color: #1C1C1C; }
/* In dark mode, user message bubble is off-white, so code blocks need dark text */
[data-theme="dark"] .message.user .message-bubble pre code.hljs { color: #1C1C1C; }
[data-theme="dark"] .message.user .message-bubble pre .code-lang-label { color: rgba(28, 28, 28, 0.6); }
[data-theme="dark"] .message.user .message-bubble pre { background: rgba(28, 28, 28, 0.08); border-color: rgba(28, 28, 28, 0.12); }
[data-theme="dark"] .message.assistant .message-bubble code { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .message-bubble pre { background: var(--surface-1); border-color: var(--border); }
[data-theme="dark"] .message-bubble pre code { color: var(--ink); }
[data-theme="dark"] .message-bubble blockquote { background: var(--primary-06); border-color: var(--primary); color: var(--ink-muted); }
[data-theme="dark"] .message-bubble h1, [data-theme="dark"] .message-bubble h2,
[data-theme="dark"] .message-bubble h3, [data-theme="dark"] .message-bubble h4,
[data-theme="dark"] .message-bubble h5, [data-theme="dark"] .message-bubble h6 { color: var(--ink); }
[data-theme="dark"] .message-bubble strong { color: var(--ink); }
[data-theme="dark"] .message.user .message-bubble strong { color: #1C1C1C; }
[data-theme="dark"] .message.assistant .message-bubble a { color: var(--primary-hover); }
[data-theme="dark"] .message.user .message-bubble a { color: #1C1C1C; }
[data-theme="dark"] .msg-copy-btn { color: var(--ink-muted); }
[data-theme="dark"] .msg-copy-btn:hover { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .ai-loading-bubble { background: var(--surface-1); border-color: var(--border); }
[data-theme="dark"] .ai-loading-text span { color: var(--ink-muted); }

/* Composer area dark mode */
[data-theme="dark"] .composer-area { background: var(--canvas); border-color: var(--border); }
[data-theme="dark"] .composer-wrapper { background: var(--surface-1); border-color: var(--border); }
[data-theme="dark"] .composer-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-10); }
[data-theme="dark"] .composer-input { color: var(--ink); }
[data-theme="dark"] .composer-input::placeholder { color: var(--ink-muted); }
[data-theme="dark"] .composer-btn.send-btn { background: var(--primary); color: #1C1C1C; }
[data-theme="dark"] .composer-btn.send-btn:hover { background: var(--primary-hover); }
[data-theme="dark"] .composer-btn.attach-btn { color: var(--primary-hover); background: var(--primary-06); border-color: var(--primary-10); }
[data-theme="dark"] .composer-btn.attach-btn:hover { background: var(--primary); color: #1C1C1C; border-color: var(--primary); }
[data-theme="dark"] .upgrade-btn { color: var(--primary-hover); border-color: var(--primary); background: var(--primary-06); }
[data-theme="dark"] .upgrade-btn:hover { background: var(--primary); color: #1C1C1C; border-color: var(--primary); }
[data-theme="dark"] .reopen-workspace-btn { color: var(--primary-hover); background: var(--primary-06); border-color: var(--primary-10); }
[data-theme="dark"] .reopen-workspace-btn:hover { background: var(--primary); color: #1C1C1C; border-color: var(--primary); }

/* Model selector dark mode */
[data-theme="dark"] .model-selector-btn { background: var(--surface-1); color: var(--ink-muted); border-color: var(--border); }
[data-theme="dark"] .model-selector-btn:hover { background: var(--surface-2); color: var(--ink); border-color: var(--border-strong); }
[data-theme="dark"] .model-selector-dropdown { background: var(--surface-2); border-color: var(--border); box-shadow: var(--shadow-overlay); }
[data-theme="dark"] .model-option { color: var(--ink-muted); }
[data-theme="dark"] .model-option:hover { background: var(--surface-3); color: var(--ink); }
[data-theme="dark"] .model-option.active { background: var(--primary-10); color: var(--primary-hover); }
[data-theme="dark"] .model-option.active strong { color: var(--primary-hover); }
[data-theme="dark"] .model-tier { color: var(--ink-muted); }
[data-theme="dark"] .model-lock-icon { color: var(--primary); }

/* Metrics page dark mode */
[data-theme="dark"] .metrics-page { background: var(--canvas); min-height: 100vh; }
[data-theme="dark"] .metric-card { background: var(--surface-1); border-color: var(--border); }
[data-theme="dark"] .metric-value { color: var(--primary-hover); }
[data-theme="dark"] .metric-label { color: var(--ink-muted); }
[data-theme="dark"] .metric-bar { background: var(--surface-2); }
[data-theme="dark"] .metric-bar-fill { background: linear-gradient(90deg, var(--ink), var(--primary)); }
[data-theme="dark"] .metrics-chart-area { background: var(--surface-1); border-color: var(--border); }
[data-theme="dark"] .metrics-chart-area h3 { color: var(--ink); }
[data-theme="dark"] .metrics-stat-card { background: var(--surface-1); border-color: var(--border); }
[data-theme="dark"] .metrics-stat-label { color: var(--ink-muted); }
[data-theme="dark"] .metrics-stat-value { color: var(--ink); }
[data-theme="dark"] .metrics-back { color: var(--ink-muted); }
[data-theme="dark"] .metrics-back:hover { color: var(--primary-hover); }
[data-theme="dark"] .metrics-loading { color: var(--ink-muted); }
[data-theme="dark"] .metrics-empty h3 { color: var(--ink); }
[data-theme="dark"] .metrics-empty p { color: var(--ink-muted); }

/* Toasts + dialogs dark mode */
[data-theme="dark"] .toast { background: var(--surface-2); color: var(--ink); box-shadow: var(--shadow-elevated); }
[data-theme="dark"] .toast.error { background: var(--error); color: #FFFFFF; }
[data-theme="dark"] .confirm-overlay { background: rgba(0, 0, 0, 0.75); }
[data-theme="dark"] .confirm-dialog { background: var(--surface-1); box-shadow: var(--shadow-overlay); }
[data-theme="dark"] .confirm-dialog h3 { color: var(--ink); }
[data-theme="dark"] .confirm-dialog p { color: var(--ink-muted); }
[data-theme="dark"] .confirm-dialog-btns .btn-cancel { background: var(--surface-2); color: var(--ink-muted); border-color: var(--border); }
[data-theme="dark"] .confirm-dialog-btns .btn-cancel:hover { background: var(--surface-3); }

/* Settings panel dark mode */
[data-theme="dark"] .settings-panel { background: var(--surface-1); box-shadow: var(--shadow-overlay); }
[data-theme="dark"] .settings-header { border-color: var(--border); }
[data-theme="dark"] .settings-header h2 { color: var(--ink); }
[data-theme="dark"] .settings-close:hover { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .settings-nav { border-color: var(--border); }
[data-theme="dark"] .settings-nav-btn { color: var(--ink-muted); }
[data-theme="dark"] .settings-nav-btn:hover { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .settings-nav-btn.active { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .settings-select { background: var(--surface-2); border-color: var(--border); color: var(--ink); }
[data-theme="dark"] .accent-color-input { background: var(--surface-2); border-color: var(--border); }
[data-theme="dark"] .accent-reset-btn { background: var(--surface-3); border-color: var(--border); color: var(--ink-muted); }
[data-theme="dark"] .accent-reset-btn:hover { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .settings-section h3 { color: var(--ink-muted); }
[data-theme="dark"] .settings-row.clickable:hover { background: var(--surface-2); }
[data-theme="dark"] .settings-row-label { color: var(--ink); }
[data-theme="dark"] .settings-row-desc { color: var(--ink-muted); }
[data-theme="dark"] .settings-toggle-slider { background: var(--surface-3); }
[data-theme="dark"] .settings-toggle input:checked + .settings-toggle-slider { background: var(--primary); }

/* General dark-mode adjustments */
[data-theme="dark"] a { color: var(--primary-hover); }
[data-theme="dark"] a:hover { color: var(--primary); }
[data-theme="dark"] h1, [data-theme="dark"] h2, [data-theme="dark"] h3,
[data-theme="dark"] h4, [data-theme="dark"] h5, [data-theme="dark"] h6 { color: var(--ink); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* ============================================
   CodeMirror 6 Live Preview Editor
   ============================================ */
.cm-live-editor-wrapper { background: var(--canvas); }
.cm-live-editor { flex: 1; min-height: 200px; overflow: hidden; background: var(--canvas); }
.cm-live-editor .cm-editor { height: 100%; font-family: var(--font); font-size: 16px; background: var(--canvas); color: var(--ink); }
.cm-live-editor .cm-scroller { overflow: auto; }
.cm-live-editor .cm-content { min-height: 100%; }
.cm-live-editor .cm-line { min-height: 1.7em; }
.cm-live-editor .cm-cursor { border-left-color: var(--primary); border-left-width: 2px; }
.cm-live-editor .cm-selectionBackground { background: var(--primary-10) !important; }
.cm-live-heading-line { font-weight: 700; color: var(--ink); }
.cm-live-h1 { font-size: 32px; line-height: 1.25; }
.cm-live-h2 { font-size: 24px; line-height: 1.3; }
.cm-live-h3 { font-size: 20px; line-height: 1.35; }
.cm-live-h4 { font-size: 18px; line-height: 1.4; }
.cm-live-h5, .cm-live-h6 { font-size: 16px; line-height: 1.45; }
.cm-live-bold { font-weight: 700; }
.cm-live-italic { font-style: italic; }
.cm-live-inline-code { font-family: var(--font-mono); background: var(--surface-2); border-radius: 4px; padding: 2px 5px; font-size: 0.9em; }
.cm-live-list-marker { display: inline-block; min-width: 1.35em; color: var(--ink); }
.cm-live-question-block { width: 100%; display: flex; align-items: flex-start; gap: 10px; text-align: left; margin: 6px 0; padding: 8px 12px; border-left: 3px solid var(--primary); border-radius: 0 var(--r) var(--r) 0; background: var(--primary-06); color: var(--ink); cursor: pointer; font: inherit; line-height: 1.6; }
.cm-live-question-block:hover { background: var(--primary-10); }
.cm-live-question-icon { display: inline-flex; align-items: center; justify-content: center; width: 20px; min-width: 20px; height: 20px; margin-top: 3px; border-radius: var(--r-full); background: var(--primary); color: #FFFFFF; font-size: 12px; font-weight: 700; }
.cm-live-latex-inline { display: inline-block; vertical-align: middle; }
.cm-live-latex-block { display: block; margin: 12px 0; overflow-x: auto; text-align: center; }
.cm-live-latex-block .katex-display { margin: 0; }
.cm-live-code-block { position: relative; margin: 10px 0; padding: 12px 14px; border-left: 3px solid var(--border-strong); border-radius: var(--r); background: var(--surface-2); overflow-x: auto; }
.cm-live-code-block pre { margin: 0; padding: 0; background: transparent; }
.cm-live-code-block code { font-family: var(--font-mono); font-size: 14px; line-height: 1.55; background: transparent; padding: 0; white-space: pre; }
.cm-live-code-lang { position: absolute; top: 8px; right: 12px; font-family: var(--font); font-size: 12px; color: var(--ink-muted); }
.cm-live-code-lang + pre { padding-top: 18px; }
[data-theme="dark"] .cm-live-editor .cm-editor { background: var(--canvas); color: var(--ink); }
[data-theme="dark"] .cm-live-question-icon { color: #1C1C1C; }
