/* ============================================================
   styles.css — Onboarding AI Assistant
   Design system: indigo primary, clean & production-ready
   ============================================================ */

/* ─── Google Fonts — must be first ──────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ─── CSS Custom Properties ──────────────────────────────── */
:root {
  /* Brand Colors */
  --color-primary:        #4f46e5;
  --color-primary-dark:   #4338ca;
  --color-primary-deeper: #3730a3;
  --color-primary-light:  #e0e7ff;
  --color-primary-bg:     #eef2ff;
  --color-primary-glow:   rgba(79, 70, 229, 0.15);

  /* Semantic Colors */
  --color-success:        #10b981;
  --color-success-light:  #34d399;
  --color-success-bg:     #d1fae5;
  --color-warning:        #f59e0b;
  --color-warning-bg:     #fef3c7;
  --color-danger:         #ef4444;
  --color-danger-bg:      #fee2e2;
  --color-info:           #3b82f6;
  --color-info-bg:        #dbeafe;

  /* Neutrals */
  --color-gray-50:        #f9fafb;
  --color-gray-100:       #f3f4f6;
  --color-gray-200:       #e5e7eb;
  --color-gray-300:       #d1d5db;
  --color-gray-400:       #9ca3af;
  --color-gray-500:       #6b7280;
  --color-gray-600:       #4b5563;
  --color-gray-700:       #374151;
  --color-gray-800:       #1f2937;
  --color-gray-900:       #111827;

  /* Surfaces */
  --surface-page:         #f5f7fb;
  --surface-card:         #ffffff;
  --surface-sidebar:      #1a1740;
  --surface-sidebar-2:    #201d4e;
  --surface-sidebar-hover: rgba(255,255,255,0.07);
  --surface-sidebar-active: rgba(255,255,255,0.13);

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

  --text-xs:   0.8125rem;
  --text-sm:   0.9375rem;
  --text-base: 1.0625rem;
  --text-lg:   1.1875rem;
  --text-xl:   1.375rem;
  --text-2xl:  1.625rem;
  --text-3xl:  2rem;

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Borders */
  --radius-sm:   0.375rem;
  --radius-md:   0.5rem;
  --radius-lg:   0.75rem;
  --radius-xl:   1rem;
  --radius-2xl:  1.25rem;
  --radius-full: 9999px;

  --border-color: #e8ecf0;

  /* Shadows */
  --shadow-xs:  0 1px 2px 0 rgb(0 0 0 / 0.04);
  --shadow-sm:  0 1px 3px 0 rgb(0 0 0 / 0.07), 0 1px 2px -1px rgb(0 0 0 / 0.05);
  --shadow-md:  0 4px 8px -2px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.06);
  --shadow-lg:  0 12px 20px -4px rgb(0 0 0 / 0.1), 0 4px 8px -4px rgb(0 0 0 / 0.06);
  --shadow-xl:  0 24px 40px -8px rgb(0 0 0 / 0.12), 0 8px 16px -6px rgb(0 0 0 / 0.06);
  --shadow-card: 0 2px 8px 0 rgb(0 0 0 / 0.06), 0 0 0 1px rgb(0 0 0 / 0.04);

  /* Layout */
  --sidebar-width:       272px;
  --header-height:       56px;
  --chat-header-height:  60px;

  /* Transitions */
  --transition-fast:   140ms ease;
  --transition-base:   220ms ease;
  --transition-slow:   320ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 380ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ─── Dark Mode ─────────────────────────────────────────── */
[data-theme="dark"] {
  /* Brand Colors — brighter for dark backgrounds */
  --color-primary:        #818cf8;
  --color-primary-dark:   #6366f1;
  --color-primary-deeper: #4f46e5;
  --color-primary-light:  rgba(99,102,241,0.2);
  --color-primary-bg:     rgba(99,102,241,0.1);
  --color-primary-glow:   rgba(129,140,248,0.2);

  /* Semantic Colors */
  --color-success:        #34d399;
  --color-success-light:  #6ee7b7;
  --color-success-bg:     rgba(16,185,129,0.15);
  --color-warning:        #fbbf24;
  --color-warning-bg:     rgba(245,158,11,0.15);
  --color-danger:         #f87171;
  --color-danger-bg:      rgba(239,68,68,0.15);
  --color-info:           #60a5fa;
  --color-info-bg:        rgba(59,130,246,0.15);

  /* Neutrals — inverted */
  --color-gray-50:        #1a1d23;
  --color-gray-100:       #1f2329;
  --color-gray-200:       #2a2f38;
  --color-gray-300:       #3a4049;
  --color-gray-400:       #6b7280;
  --color-gray-500:       #9ca3af;
  --color-gray-600:       #d1d5db;
  --color-gray-700:       #e5e7eb;
  --color-gray-800:       #f3f4f6;
  --color-gray-900:       #f9fafb;

  /* Surfaces */
  --surface-page:         #0f1117;
  --surface-card:         #181b22;
  --surface-sidebar:      #12141a;
  --surface-sidebar-2:    #181b22;
  --surface-sidebar-hover: rgba(255,255,255,0.06);
  --surface-sidebar-active: rgba(99,102,241,0.12);

  /* Borders */
  --border-color: #2a2f38;

  /* Shadows — subtler on dark */
  --shadow-xs:   0 1px 2px 0 rgb(0 0 0 / 0.2);
  --shadow-sm:   0 1px 3px 0 rgb(0 0 0 / 0.25), 0 1px 2px -1px rgb(0 0 0 / 0.2);
  --shadow-md:   0 4px 8px -2px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
  --shadow-lg:   0 12px 20px -4px rgb(0 0 0 / 0.35), 0 4px 8px -4px rgb(0 0 0 / 0.2);
  --shadow-xl:   0 24px 40px -8px rgb(0 0 0 / 0.4), 0 8px 16px -6px rgb(0 0 0 / 0.2);
  --shadow-card: 0 2px 8px 0 rgb(0 0 0 / 0.2), 0 0 0 1px rgb(0 0 0 / 0.15);
}

/* Dark mode — login/welcome screen overrides */
[data-theme="dark"] #login-screen,
[data-theme="dark"] #welcome-screen {
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(99,102,241,0.25) 0%, transparent 70%),
    linear-gradient(160deg, #080a10 0%, #0f1117 40%, #151825 100%);
}

[data-theme="dark"] #login-screen::before,
[data-theme="dark"] #welcome-screen::before {
  background-image:
    linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
}

[data-theme="dark"] .login-card,
[data-theme="dark"] .welcome-card {
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255,255,255,0.04);
}

[data-theme="dark"] .login-logo {
  background: linear-gradient(135deg, rgba(99,102,241,0.2) 0%, rgba(79,70,229,0.15) 100%);
  box-shadow: 0 4px 12px rgba(99,102,241,0.15);
}

[data-theme="dark"] .login-logo svg {
  color: #818cf8;
}

[data-theme="dark"] .login-error {
  background: rgba(239,68,68,0.1);
  border-color: rgba(248,113,113,0.3);
  color: #fca5a5;
}

[data-theme="dark"] .login-error::before {
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f87171' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E") center/contain no-repeat;
}

[data-theme="dark"] .form-input:focus {
  background: #1a1d25;
}

/* Dark mode — welcome screen */
[data-theme="dark"] .welcome-avatar {
  background: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);
  border-color: #2a2f38;
  box-shadow: 0 4px 16px rgba(99,102,241,0.25);
}

[data-theme="dark"] .welcome-avatar::after {
  background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(79,70,229,0.08));
}

[data-theme="dark"] .welcome-step {
  background: rgba(255,255,255,0.03);
  border-color: var(--border-color);
}

[data-theme="dark"] .welcome-step-icon {
  background: rgba(99,102,241,0.15);
  color: #818cf8;
}

/* Dark mode — app header */
[data-theme="dark"] .app-header {
  background: #13151b;
  border-bottom-color: var(--border-color);
}

[data-theme="dark"] .app-header-logo-icon {
  background: linear-gradient(135deg, rgba(99,102,241,0.2) 0%, rgba(79,70,229,0.15) 100%);
}

[data-theme="dark"] .app-header-logo-icon svg {
  stroke: #818cf8;
}

[data-theme="dark"] .app-header-avatar {
  background: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);
  box-shadow: 0 1px 4px rgba(99,102,241,0.2);
}

[data-theme="dark"] .app-header-user:hover {
  background: rgba(255,255,255,0.05);
}

/* Dark mode — sidebar */
[data-theme="dark"] #sidebar {
  background: #0c0e13;
}

[data-theme="dark"] #sidebar::before {
  background: radial-gradient(ellipse 100% 60% at 50% 0%, rgba(99,102,241,0.15) 0%, transparent 100%);
}

[data-theme="dark"] .sidebar-header {
  border-bottom-color: rgba(255,255,255,0.05);
}

/* Dark mode — chat area */
[data-theme="dark"] .chat-header {
  background: #13151b;
  border-bottom-color: var(--border-color);
}

[data-theme="dark"] .chat-header-icon {
  background: rgba(99,102,241,0.1);
  border-color: rgba(99,102,241,0.2);
  color: #818cf8;
}

[data-theme="dark"] .status-badge-pending {
  background: rgba(255,255,255,0.05);
  color: var(--color-gray-500);
  border-color: var(--border-color);
}

[data-theme="dark"] .status-badge-in_progress {
  background: rgba(96,165,250,0.12);
  color: #60a5fa;
  border-color: rgba(96,165,250,0.25);
}

[data-theme="dark"] .status-badge-completed {
  background: rgba(52,211,153,0.12);
  color: #34d399;
  border-color: rgba(52,211,153,0.25);
}

/* Dark mode — messages */
[data-theme="dark"] .message-user .message-bubble {
  background: #4f46e5;
  box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}

[data-theme="dark"] .message-assistant .message-bubble {
  background: #1a1d25;
  border-color: var(--border-color);
}

[data-theme="dark"] .message-streaming .message-bubble {
  border-color: rgba(99,102,241,0.25);
  background: #1a1d25;
}

[data-theme="dark"] .message-user .message-time {
  color: rgba(129,140,248,0.5);
}

/* Dark mode — markdown in messages */
[data-theme="dark"] .message-assistant .message-bubble code {
  background: rgba(99,102,241,0.12);
  color: #a5b4fc;
  border-color: rgba(99,102,241,0.2);
}

[data-theme="dark"] .message-assistant .message-bubble pre {
  background: #0c0e13;
  border-color: rgba(255,255,255,0.06);
}

[data-theme="dark"] .message-assistant .message-bubble pre code {
  color: #c7d2fe;
}

[data-theme="dark"] .message-assistant .message-bubble blockquote {
  border-left-color: rgba(129,140,248,0.3);
  color: var(--color-gray-500);
}

[data-theme="dark"] .message-assistant .message-bubble hr {
  border-top-color: var(--border-color);
}

[data-theme="dark"] .message-assistant .message-bubble a {
  color: #818cf8;
  text-decoration-color: rgba(129,140,248,0.35);
}

/* Dark mode — chat input */
[data-theme="dark"] .chat-input-area {
  background: #13151b;
  border-top-color: var(--border-color);
}

[data-theme="dark"] #chat-form {
  background: #1a1d25;
  border-color: var(--border-color);
}

[data-theme="dark"] #chat-form:focus-within {
  background: #1e2129;
}

[data-theme="dark"] #send-btn {
  background: #6366f1;
  box-shadow: 0 1px 4px rgba(99,102,241,0.3);
}

[data-theme="dark"] #send-btn:hover:not(:disabled) {
  background: #818cf8;
}

[data-theme="dark"] #send-btn:disabled {
  background: #2a2f38;
  color: #4b5563;
}

[data-theme="dark"] #send-btn.streaming {
  background: #2a2f38;
  color: #4b5563;
}

/* Dark mode — empty state */
[data-theme="dark"] .empty-state-icon {
  background: rgba(255,255,255,0.04);
  border-color: var(--border-color);
}

[data-theme="dark"] .empty-state-hint {
  background: rgba(99,102,241,0.08);
  border-color: rgba(99,102,241,0.2);
  color: #a5b4fc;
}

/* Dark mode — error in chat */
[data-theme="dark"] .message-error {
  background: rgba(239,68,68,0.1);
  border-color: rgba(248,113,113,0.25);
  color: #fca5a5;
}

/* Dark mode — tool indicator */
[data-theme="dark"] .tool-indicator {
  background: rgba(255,255,255,0.04);
  border-color: var(--border-color);
  color: var(--color-gray-500);
}

/* Dark mode — skeleton */
[data-theme="dark"] .skeleton-bubble {
  background: linear-gradient(90deg, #1a1d25 25%, #2a2f38 50%, #1a1d25 75%);
  background-size: 200% 100%;
}

[data-theme="dark"] .skeleton-message.skeleton-user .skeleton-bubble {
  background: linear-gradient(90deg, rgba(99,102,241,0.1) 25%, rgba(99,102,241,0.2) 50%, rgba(99,102,241,0.1) 75%);
  background-size: 200% 100%;
}

/* Dark mode — scrollbars */
[data-theme="dark"] #chat-messages {
  scrollbar-color: #2a2f38 transparent;
}

[data-theme="dark"] #chat-messages::-webkit-scrollbar-thumb {
  background: #2a2f38;
}

/* ─── Theme toggle — floating button ────────────────────── */
.theme-toggle-float {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(30,27,75,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #c7d2fe;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25), 0 0 0 1px rgba(255,255,255,0.05);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.theme-toggle-float:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0,0,0,0.35), 0 0 0 1px rgba(255,255,255,0.1);
  background: rgba(30,27,75,0.95);
}

.theme-toggle-float:active {
  transform: scale(0.95);
}

.theme-toggle-float .icon-sun,
.theme-toggle-float .icon-moon {
  position: absolute;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.theme-toggle-float .icon-sun {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.theme-toggle-float .icon-moon {
  opacity: 1;
  transform: rotate(0) scale(1);
}

[data-theme="dark"] .theme-toggle-float {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.1);
  color: #fbbf24;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.05);
}

[data-theme="dark"] .theme-toggle-float:hover {
  background: rgba(255,255,255,0.14);
}

[data-theme="dark"] .theme-toggle-float .icon-sun {
  opacity: 1;
  transform: rotate(0) scale(1);
}

[data-theme="dark"] .theme-toggle-float .icon-moon {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

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

html {
  font-size: 16px;
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--color-gray-800);
  background: var(--surface-page);
  line-height: 1.5;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Accessibility — Focus styles ──────────────────────── */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ─── Screen transitions ─────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen-fade-in {
  animation: screen-in 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.screen-fade-out {
  animation: screen-out 0.25s ease forwards;
  pointer-events: none;
}

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

@keyframes screen-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(-8px) scale(0.98); }
}

/* ─── Login Screen ───────────────────────────────────────── */
#login-screen {
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(99,102,241,0.35) 0%, transparent 70%),
    linear-gradient(160deg, #0f0e25 0%, #1a1740 40%, #2d2b6b 100%);
}

/* Subtle grid pattern overlay */
#login-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

.login-card {
  background: var(--surface-card);
  border-radius: var(--radius-2xl);
  padding: var(--space-10) var(--space-8);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255,255,255,0.06);
  margin: var(--space-4);
  position: relative;
  z-index: 1;
  animation: card-rise 0.5s cubic-bezier(0.34, 1.2, 0.64, 1) forwards;
}

@keyframes card-rise {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--color-primary-light) 0%, #c7d2fe 100%);
  border-radius: var(--radius-xl);
  margin: 0 auto var(--space-6);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

.login-logo svg {
  color: var(--color-primary);
}

.login-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-gray-900);
  text-align: center;
  margin-bottom: var(--space-2);
  letter-spacing: -0.02em;
}

.login-subtitle {
  font-size: var(--text-sm);
  color: var(--color-gray-500);
  text-align: center;
  margin-bottom: var(--space-8);
}

/* ─── Form elements ──────────────────────────────────────── */
.form-group {
  margin-bottom: var(--space-5);
}

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-gray-700);
  margin-bottom: var(--space-2);
}

.form-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-family: var(--font-sans);
  color: var(--color-gray-900);
  background: var(--surface-card);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.form-input::placeholder {
  color: var(--color-gray-400);
}

.form-input:hover {
  border-color: var(--color-gray-300);
}

.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
  background: #fafbff;
}

.form-input:disabled {
  background: var(--color-gray-50);
  color: var(--color-gray-400);
  cursor: not-allowed;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--color-gray-400);
  margin-top: var(--space-2);
  line-height: 1.5;
}

.login-error {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: #b91c1c;
  background: #fff5f5;
  border: 1px solid #fca5a5;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.login-error::before {
  content: '';
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23dc2626' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E") center/contain no-repeat;
  margin-top: 1px;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60%  { transform: translateX(-4px); }
  40%, 80%  { transform: translateX(4px); }
}

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background-color var(--transition-fast), transform var(--transition-fast),
    box-shadow var(--transition-fast), opacity var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(255,255,255,0.08), transparent);
  pointer-events: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  width: 100%;
  padding: var(--space-4) var(--space-5);
  background: var(--color-primary);
  color: #fff;
  font-size: var(--text-base);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 3px rgba(79,70,229,0.3), 0 4px 12px rgba(79,70,229,0.2);
  letter-spacing: 0.01em;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
  box-shadow: 0 2px 6px rgba(79,70,229,0.35), 0 6px 16px rgba(79,70,229,0.25);
  transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 1px 3px rgba(79,70,229,0.3);
}

.btn-primary.loading {
  color: transparent;
  pointer-events: none;
}

.btn-primary.loading::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
}

.btn-welcome {
  background: var(--color-primary);
  color: #fff;
  font-size: var(--text-base);
  padding: var(--space-4) var(--space-10);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 8px rgba(79,70,229,0.3), 0 8px 20px rgba(79,70,229,0.2);
  letter-spacing: 0.01em;
}

.btn-welcome:hover:not(:disabled) {
  background: var(--color-primary-dark);
  box-shadow: 0 4px 12px rgba(79,70,229,0.35), 0 10px 24px rgba(79,70,229,0.25);
  transform: translateY(-2px);
}

.btn-welcome:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

/* ─── Welcome Screen ─────────────────────────────────────── */
#welcome-screen {
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(99,102,241,0.35) 0%, transparent 70%),
    linear-gradient(160deg, #0f0e25 0%, #1a1740 40%, #2d2b6b 100%);
}

#welcome-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

.welcome-card {
  background: var(--surface-card);
  border-radius: var(--radius-2xl);
  padding: var(--space-10) var(--space-10);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255,255,255,0.06);
  margin: var(--space-4);
  text-align: center;
  position: relative;
  z-index: 1;
  animation: card-rise 0.5s cubic-bezier(0.34, 1.2, 0.64, 1) forwards;
}

.welcome-avatar {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-5);
  font-size: var(--text-2xl);
  font-weight: 700;
  color: #fff;
  box-shadow: 0 4px 16px rgba(79,70,229,0.35);
  border: 3px solid white;
  position: relative;
}

.welcome-avatar::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, rgba(99,102,241,0.3), rgba(79,70,229,0.1));
  z-index: -1;
}

.welcome-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-gray-900);
  margin-bottom: var(--space-1);
  letter-spacing: -0.02em;
}

.welcome-name-highlight {
  color: var(--color-primary);
}

.welcome-email {
  font-size: var(--text-sm);
  color: var(--color-gray-400);
  margin-bottom: var(--space-6);
}

.welcome-progress-info {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-primary-dark);
  background: var(--color-primary-bg);
  border: 1px solid var(--color-primary-light);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-4);
  margin-bottom: var(--space-6);
}

.welcome-progress-info::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.welcome-desc {
  font-size: var(--text-sm);
  color: var(--color-gray-500);
  margin-bottom: var(--space-8);
  line-height: 1.7;
  max-width: 380px;
  margin-left: auto;
  margin-right: auto;
}

/* Progress steps on welcome */
.welcome-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-8);
}

.welcome-step {
  background: var(--color-gray-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-3);
  text-align: center;
}

.welcome-step-icon {
  width: 36px;
  height: 36px;
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-2);
}

.welcome-step-label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-gray-600);
  line-height: 1.4;
}

/* ─── App Screen (main layout) ───────────────────────────── */
#app-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#app-screen.app-enter {
  animation: app-enter 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes app-enter {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ─── App Header ──────────────────────────────────────────── */
.app-header {
  height: var(--header-height);
  background: var(--surface-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-3);
  flex-shrink: 0;
  z-index: 20;
  box-shadow: var(--shadow-xs);
}

.app-header-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--color-gray-900);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.app-header-logo-icon {
  width: 30px;
  height: 30px;
  background: linear-gradient(135deg, var(--color-primary-light) 0%, #c7d2fe 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.app-header-divider {
  width: 1px;
  height: 20px;
  background: var(--border-color);
  display: none;
}

.app-header-spacer {
  flex: 1;
}

.app-header-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-gray-700);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}

.app-header-user:hover {
  background: var(--color-gray-50);
}

.app-header-avatar {
  width: 30px;
  height: 30px;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: #fff;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(79,70,229,0.25);
}

/* App body: sidebar + chat */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ─── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  background: var(--surface-sidebar);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: transform var(--transition-slow);
  position: relative;
}

/* Subtle inner glow at top */
#sidebar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 120px;
  background: radial-gradient(ellipse 100% 60% at 50% 0%, rgba(99,102,241,0.25) 0%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}

.sidebar-header {
  padding: var(--space-5) var(--space-4) var(--space-4);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.sidebar-title {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.35);
  margin-bottom: var(--space-4);
}

/* Progress bar in sidebar */
.progress-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.progress-label {
  font-size: var(--text-xs);
  color: rgba(255,255,255,0.55);
}

.progress-pct {
  font-size: var(--text-xs);
  font-weight: 700;
  color: rgba(255,255,255,0.85);
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 5px;
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #818cf8, #6366f1);
  border-radius: var(--radius-full);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 0;
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 40px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2));
  border-radius: var(--radius-full);
}

.progress-fill.complete {
  background: linear-gradient(90deg, #34d399, #10b981);
}

/* Topic list */
.sidebar-topics {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) 0 var(--space-4);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.12) transparent;
  position: relative;
  z-index: 1;
}

.sidebar-topics::-webkit-scrollbar {
  width: 3px;
}

.sidebar-topics::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-topics::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: var(--radius-full);
}

#topic-list {
  list-style: none;
  padding: 0 var(--space-3);
}

.topic-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
  position: relative;
  margin-bottom: 2px;
  border: 1px solid transparent;
}

.topic-item:hover {
  background: var(--surface-sidebar-hover);
}

.topic-item:active {
  transform: scale(0.99);
}

.topic-item.active {
  background: var(--surface-sidebar-active);
  border-color: rgba(99,102,241,0.3);
}

.topic-item.active::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 25%;
  height: 50%;
  width: 3px;
  background: #818cf8;
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
}

/* Status indicator dot (replaces order number for completed) */
.topic-order {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  background: rgba(255,255,255,0.08);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.topic-item.active .topic-order {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.25);
}

.topic-item.status-completed .topic-order {
  background: rgba(16,185,129,0.2);
  color: #6ee7b7;
}

.topic-info {
  flex: 1;
  min-width: 0;
}

.topic-title {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: rgba(255,255,255,0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  margin-bottom: 2px;
  transition: color var(--transition-fast);
}

.topic-item:hover .topic-title {
  color: rgba(255,255,255,0.9);
}

.topic-item.active .topic-title {
  color: #fff;
  font-weight: 600;
}

.topic-item.status-completed .topic-title {
  color: rgba(255,255,255,0.55);
}

.topic-meta {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.topic-status-icon {
  line-height: 0;
  flex-shrink: 0;
}

.topic-status-label {
  font-size: 11px;
  color: rgba(255,255,255,0.3);
  font-weight: 500;
}

.topic-item.status-in_progress .topic-status-label {
  color: #93c5fd;
}

.topic-item.status-completed .topic-status-label {
  color: #6ee7b7;
}

/* ─── Sidebar toggle (mobile) ────────────────────────────── */
#sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  color: var(--color-gray-600);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast), color var(--transition-fast);
}

#sidebar-toggle:hover {
  background: var(--color-gray-100);
  color: var(--color-gray-900);
}

/* Overlay for mobile sidebar */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
  z-index: 15;
  opacity: 0;
  transition: opacity var(--transition-base);
}

#sidebar-overlay.visible {
  opacity: 1;
}

/* ─── Chat Area ───────────────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface-page);
}

/* Chat header */
.chat-header {
  height: var(--chat-header-height);
  background: var(--surface-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-3);
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
}

.chat-header-icon {
  width: 34px;
  height: 34px;
  background: var(--color-primary-bg);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--color-primary);
  border: 1px solid var(--color-primary-light);
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-header-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-gray-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.chat-header-desc {
  font-size: var(--text-xs);
  color: var(--color-gray-400);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* Topic status badge */
.topic-header-status {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.01em;
}

.status-badge-pending {
  background: var(--color-gray-100);
  color: var(--color-gray-500);
  border: 1px solid var(--color-gray-200);
}

.status-badge-in_progress {
  background: var(--color-info-bg);
  color: var(--color-info);
  border: 1px solid #bfdbfe;
}

.status-badge-completed {
  background: var(--color-success-bg);
  color: #059669;
  border: 1px solid #a7f3d0;
}

/* ─── Chat Messages ───────────────────────────────────────── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--color-gray-200) transparent;
}

#chat-messages::-webkit-scrollbar {
  width: 5px;
}

#chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: var(--color-gray-200);
  border-radius: var(--radius-full);
}

/* ─── Message date separator ─────────────────────────────── */
.message-date-separator {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-2) 0;
}

.message-date-separator::before,
.message-date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

.message-date-separator span {
  font-size: var(--text-xs);
  color: var(--color-gray-400);
  font-weight: 500;
  white-space: nowrap;
}

/* Message wrapper */
.message {
  display: flex;
  flex-direction: column;
  max-width: 76%;
  animation: msg-in 0.22s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

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

.message-user {
  align-self: flex-end;
  align-items: flex-end;
}

.message-assistant {
  align-self: flex-start;
  align-items: flex-start;
}

/* Sender label */
.message-sender {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-gray-400);
  margin-bottom: var(--space-1);
  padding: 0 var(--space-1);
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.message-assistant .message-sender {
  color: var(--color-primary);
}

.message-sender-dot {
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: var(--radius-full);
  opacity: 0.6;
}

/* Message bubble */
.message-bubble {
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  line-height: 1.7;
  word-break: break-word;
}

.message-user .message-bubble {
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(79,70,229,0.25);
}

.message-assistant .message-bubble {
  background: var(--surface-card);
  color: var(--color-gray-800);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

/* Timestamp */
.message-time {
  font-size: 11px;
  color: var(--color-gray-400);
  margin-top: 4px;
  padding: 0 var(--space-1);
  font-variant-numeric: tabular-nums;
}

.message-user .message-time {
  color: rgba(79,70,229,0.5);
}

/* ─── Markdown rendered content ──────────────────────────── */
.message-assistant .message-bubble h1,
.message-assistant .message-bubble h2,
.message-assistant .message-bubble h3 {
  color: var(--color-gray-900);
  font-weight: 700;
  margin-bottom: var(--space-2);
  margin-top: var(--space-4);
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.message-assistant .message-bubble h1:first-child,
.message-assistant .message-bubble h2:first-child,
.message-assistant .message-bubble h3:first-child {
  margin-top: 0;
}

.message-assistant .message-bubble h1 { font-size: var(--text-xl); }
.message-assistant .message-bubble h2 { font-size: var(--text-lg); }
.message-assistant .message-bubble h3 {
  font-size: var(--text-base);
  color: var(--color-primary-dark);
}

.message-assistant .message-bubble p {
  margin-bottom: var(--space-3);
}

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

.message-assistant .message-bubble ul,
.message-assistant .message-bubble ol {
  padding-left: var(--space-5);
  margin-bottom: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.message-assistant .message-bubble li {
  line-height: 1.65;
}

.message-assistant .message-bubble strong {
  font-weight: 700;
  color: var(--color-gray-900);
}

.message-assistant .message-bubble em {
  font-style: italic;
  color: var(--color-gray-600);
}

.message-assistant .message-bubble a {
  color: var(--color-primary);
  text-decoration: underline;
  text-decoration-color: rgba(79,70,229,0.35);
  text-underline-offset: 2px;
}

.message-assistant .message-bubble a:hover {
  text-decoration-color: var(--color-primary);
}

.message-assistant .message-bubble code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: #f0f2ff;
  color: #4338ca;
  padding: 0.15em 0.45em;
  border-radius: var(--radius-sm);
  border: 1px solid #e0e7ff;
}

.message-assistant .message-bubble pre {
  background: #1e1b4b;
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  overflow-x: auto;
  margin: var(--space-3) 0;
  scrollbar-width: thin;
  border: 1px solid rgba(255,255,255,0.05);
}

.message-assistant .message-bubble pre code {
  background: none;
  color: #c7d2fe;
  border: none;
  padding: 0;
  font-size: var(--text-xs);
  line-height: 1.8;
}

/* Blockquote */
.message-assistant .message-bubble blockquote {
  border-left: 3px solid var(--color-primary-light);
  padding-left: var(--space-4);
  margin: var(--space-3) 0;
  color: var(--color-gray-600);
  font-style: italic;
}

/* Horizontal rule */
.message-assistant .message-bubble hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: var(--space-4) 0;
}

/* ─── Typing indicator ───────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: var(--space-1) 0;
  height: 22px;
}

.typing-indicator[hidden] {
  display: none;
}

.dot {
  width: 7px;
  height: 7px;
  background: var(--color-gray-300);
  border-radius: var(--radius-full);
  animation: typing-bounce 1.4s infinite cubic-bezier(0.45, 0.05, 0.55, 0.95);
}

.dot:nth-child(1) { animation-delay: 0s; }
.dot:nth-child(2) { animation-delay: 0.15s; }
.dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0) scale(0.75); opacity: 0.4; }
  40%            { transform: translateY(-6px) scale(1); opacity: 1; }
}

/* ─── Streaming text ─────────────────────────────────────── */
.streaming-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-streaming .message-bubble {
  border-color: rgba(99,102,241,0.2);
  background: #fafbff;
}

.streaming-text::after {
  content: '▋';
  color: var(--color-primary);
  animation: cursor-blink 0.7s step-end infinite;
  font-size: 0.8em;
  vertical-align: middle;
  margin-left: 1px;
  opacity: 0.85;
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ─── Tool indicator ─────────────────────────────────────── */
.tool-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-gray-500);
  background: var(--color-gray-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-3);
  margin-top: var(--space-3);
  font-style: normal;
  font-weight: 500;
}

.tool-indicator[hidden] {
  display: none;
}

.tool-indicator-spinner {
  width: 10px;
  height: 10px;
  border: 1.5px solid rgba(79,70,229,0.25);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

/* ─── Inline error in chat ───────────────────────────────── */
.message-error {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: #b91c1c;
  background: #fff5f5;
  border: 1px solid #fca5a5;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  margin-top: var(--space-3);
}

.message-error::before {
  content: '!';
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  background: #dc2626;
  color: #fff;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
  line-height: 1;
  text-align: center;
}

/* ─── Empty state ────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: var(--space-12) var(--space-8);
  text-align: center;
  color: var(--color-gray-500);
  margin: auto;
  animation: msg-in 0.3s ease forwards;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  background: var(--color-gray-100);
  border-radius: var(--radius-2xl);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-5);
  border: 1px solid var(--border-color);
}

.empty-state-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-gray-700);
  margin-bottom: var(--space-2);
}

.empty-state-desc {
  font-size: var(--text-sm);
  color: var(--color-gray-400);
  max-width: 300px;
  line-height: 1.65;
}

.empty-state-desc strong {
  color: var(--color-primary);
  font-weight: 600;
}

/* Empty state action hint */
.empty-state-hint {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-6);
  padding: var(--space-3) var(--space-4);
  background: var(--color-primary-bg);
  border: 1px solid var(--color-primary-light);
  border-radius: var(--radius-lg);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-primary-dark);
}

.empty-state-hint svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.empty-state-error .empty-state-title {
  color: var(--color-danger);
}

.empty-state-error .empty-state-icon {
  background: #fff5f5;
  border-color: #fca5a5;
}

/* ─── Chat loading ───────────────────────────────────────── */
.chat-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-12);
  color: var(--color-gray-400);
  font-size: var(--text-sm);
  margin: auto;
}

/* Skeleton loader */
.skeleton-messages {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-6);
  width: 100%;
}

.skeleton-message {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.skeleton-message.skeleton-user {
  align-items: flex-end;
}

.skeleton-message.skeleton-assistant {
  align-items: flex-start;
}

.skeleton-bubble {
  border-radius: var(--radius-lg);
  background: linear-gradient(90deg, var(--color-gray-100) 25%, var(--color-gray-200) 50%, var(--color-gray-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  height: 40px;
}

.skeleton-message.skeleton-user .skeleton-bubble {
  width: 55%;
  background: linear-gradient(90deg, #ddd9f8 25%, #c7c3f2 50%, #ddd9f8 75%);
  background-size: 200% 100%;
}

.skeleton-message.skeleton-assistant .skeleton-bubble {
  width: 75%;
}

.skeleton-message.skeleton-assistant .skeleton-bubble:nth-child(2) {
  width: 60%;
  height: 28px;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--color-gray-200);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spin 0.75s linear infinite;
}

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

/* ─── Chat Input Area ────────────────────────────────────── */
.chat-input-area {
  background: var(--surface-card);
  border-top: 1px solid var(--border-color);
  padding: var(--space-3) var(--space-6);
  flex-shrink: 0;
}

#chat-form {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  background: var(--surface-page);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

#chat-form:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
  background: var(--surface-card);
}

#chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  color: var(--color-gray-900);
  resize: none;
  line-height: 1.6;
  min-height: 24px;
  max-height: 120px;
  padding: var(--space-2) 0;
  scrollbar-width: thin;
}

#chat-input::placeholder {
  color: var(--color-gray-400);
}

#chat-input:disabled {
  color: var(--color-gray-400);
  cursor: not-allowed;
}

.chat-input-actions {
  display: flex;
  align-items: flex-end;
  gap: var(--space-1);
  flex-shrink: 0;
}

.char-counter {
  font-size: 11px;
  color: var(--color-gray-400);
  font-variant-numeric: tabular-nums;
  padding: 0 var(--space-1);
  align-self: center;
  line-height: 1;
  display: none;
}

.char-counter.visible {
  display: block;
}

.char-counter.warning {
  color: var(--color-warning);
  font-weight: 600;
}

.char-counter.danger {
  color: var(--color-danger);
  font-weight: 700;
}

#send-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
  align-self: flex-end;
  box-shadow: 0 1px 4px rgba(79,70,229,0.3);
  position: relative;
  overflow: hidden;
}

#send-btn:hover:not(:disabled) {
  background: var(--color-primary-dark);
  box-shadow: 0 2px 8px rgba(79,70,229,0.4);
  transform: translateY(-1px);
}

#send-btn:active:not(:disabled) {
  transform: scale(0.92) translateY(0);
  box-shadow: none;
}

#send-btn:disabled {
  background: var(--color-gray-200);
  color: var(--color-gray-400);
  cursor: not-allowed;
  box-shadow: none;
}

#send-btn.streaming {
  background: var(--color-gray-200);
  color: var(--color-gray-400);
  cursor: not-allowed;
  box-shadow: none;
}

#send-btn.streaming::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(79,70,229,0.3);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
}

#send-btn.streaming svg {
  opacity: 0;
}

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-2);
}

.input-hint {
  font-size: 11px;
  color: var(--color-gray-400);
}

/* ─── Loading overlay (initial app load) ─────────────────── */
.app-loading {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1a1740 0%, #2d2b6b 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: var(--space-4);
  color: rgba(255,255,255,0.75);
  font-size: var(--text-sm);
  z-index: 100;
}

.app-loading .spinner {
  border-color: rgba(255,255,255,0.2);
  border-top-color: #fff;
  width: 36px;
  height: 36px;
}

/* ─── Utility classes ────────────────────────────────────── */
[hidden] {
  display: none !important;
}

/* ─── Responsive — Tablet (≤1024px) ─────────────────────── */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 256px;
  }
}

/* ─── Responsive — Mobile (≤768px) ──────────────────────── */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 280px;
  }

  #sidebar-toggle {
    display: flex;
  }

  #sidebar-overlay {
    display: block;
  }

  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 20;
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
  }

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

  .message {
    max-width: 88%;
  }

  #chat-messages {
    padding: var(--space-4) var(--space-4);
    gap: var(--space-3);
  }

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

  .chat-header {
    padding: 0 var(--space-4);
  }

  .login-card,
  .welcome-card {
    padding: var(--space-8) var(--space-6);
    border-radius: var(--radius-xl);
    margin: var(--space-4);
  }

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

  .welcome-card {
    max-width: 100%;
  }

  .app-header-user span {
    display: none;
  }
}

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