/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root, [data-theme="dark"] {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #a5b4fc;
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-surface: #334155;
  --bg-hover: rgba(255,255,255,0.06);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --success: #10b981;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --navbar-bg: rgba(15,23,42,0.95);
  --code-bg: #1a1a2e;
  --code-text: #e2e8f0;
  --overlay-bg: rgba(0,0,0,0.6);
  --dropdown-shadow: 0 8px 24px rgba(0,0,0,0.5);
  --danger: #f87171;
  --danger-bg: rgba(248,113,113,0.1);
  --info-text: #a0aec0;
  --toast-bg: #1e293b;
  --gradient-text: linear-gradient(135deg, #818cf8, #c084fc);
  --success-text: #6ee7b7;
  --success-bg: rgba(16,185,129,0.12);
  --success-border: rgba(16,185,129,0.3);
  --error-text: #fca5a5;
  --error-bg: rgba(239,68,68,0.12);
  --error-border: rgba(239,68,68,0.3);
  color-scheme: dark;
}

[data-theme="light"] {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #6366f1;
  --bg: #ffffff;
  --bg-card: #f6f8fa;
  --bg-surface: #e8ecf1;
  --bg-hover: rgba(0,0,0,0.04);
  --text: #1f2328;
  --text-muted: #656d76;
  --border: #d1d9e0;
  --success: #1a7f37;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --navbar-bg: rgba(255,255,255,0.95);
  --code-bg: #f6f8fa;
  --code-text: #1f2328;
  --overlay-bg: rgba(0,0,0,0.3);
  --dropdown-shadow: 0 8px 24px rgba(31,35,40,0.12);
  --danger: #d1242f;
  --danger-bg: rgba(209,36,47,0.08);
  --info-text: #656d76;
  --toast-bg: #ffffff;
  --gradient-text: linear-gradient(135deg, #4f46e5, #7c3aed);
  --success-text: #1a7f37;
  --success-bg: rgba(26,127,55,0.08);
  --success-border: rgba(26,127,55,0.3);
  --error-text: #d1242f;
  --error-bg: rgba(209,36,47,0.06);
  --error-border: rgba(209,36,47,0.3);
  color-scheme: light;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== Navbar ===== */
.navbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; height: 60px;
  background: var(--navbar-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.nav-brand { font-size: 1.25rem; font-weight: 700; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 0.4rem; }
.nav-brand-logo { width: 28px; height: 28px; }
.nav-tagline { color: var(--text-muted); font-size: 0.85rem; }
.nav-spacer { flex: 1; }

/* Nav zoom controls */
.nav-zoom {
  display: flex; align-items: center; margin-right: 16px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.nav-zoom-btn {
  background: none; border: none;
  color: var(--text); font-size: 0.95rem; font-weight: 700;
  padding: 6px 12px; cursor: pointer; transition: all 0.15s;
  font-family: inherit; line-height: 1;
}
.nav-zoom-btn:hover { background: var(--bg-hover); color: var(--primary-light); }
.nav-zoom-level {
  font-size: 0.8rem; font-weight: 500; color: var(--text-muted);
  min-width: 40px; text-align: center;
  border-left: 1px solid var(--border); border-right: 1px solid var(--border);
  padding: 6px 4px;
}

/* Nav user menu */
.nav-user-menu { position: relative; }
.nav-user-btn {
  display: flex; align-items: center;
  background: none; border: none; padding: 0; cursor: pointer;
  font-family: inherit; transition: opacity 0.15s;
}
.nav-user-btn:hover { opacity: 0.85; }
.nav-user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.82rem; font-weight: 700; color: white; flex-shrink: 0;
}
.nav-user-avatar-img {
  width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
}
.nav-user-avatar.guest {
  background: var(--bg-surface); position: relative; overflow: hidden;
}
.nav-user-avatar.guest::before {
  content: '';
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text-muted); position: absolute; top: 5px;
}
.nav-user-avatar.guest::after {
  content: '';
  width: 22px; height: 14px; border-radius: 50%;
  background: var(--text-muted); position: absolute; bottom: -3px;
}
.nav-user-dropdown {
  display: none; position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  min-width: 200px; overflow: hidden; box-shadow: var(--dropdown-shadow);
  z-index: 200;
}
.nav-user-dropdown.show { display: block; }
.nav-dropdown-header {
  padding: 10px 16px 8px; font-size: 0.82rem; font-weight: 700;
  color: var(--text); border-bottom: 1px solid var(--border);
}
.nav-dropdown-item {
  display: block; padding: 10px 16px; color: var(--text); text-decoration: none;
  font-size: 0.88rem; transition: background 0.12s;
}
.nav-dropdown-item:hover { background: var(--bg-surface); }
.nav-dropdown-logout { color: var(--danger); }
.nav-dropdown-logout:hover { background: var(--danger-bg); }
.nav-dropdown-divider { height: 1px; background: var(--border); margin: 6px 0; }
.nav-dropdown-section {
  font-size: 0.72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.05em; padding: 6px 16px 4px;
}
.nav-dropdown-toggle {
  width: 100%; text-align: left; background: none; border: none; color: var(--text);
  font-family: inherit; font-size: 0.9rem; cursor: pointer;
}
.nav-dropdown-toggle:hover { background: var(--bg-hover); }
.toggle-check {
  display: inline-block; width: 18px; color: #10b981; font-size: 0.85rem;
}

/* Card dismiss */
.home-card-wrapper { position: relative; }
.card-dismiss-btn {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  background: var(--bg-hover); border: 1px solid var(--border); border-radius: 50%;
  width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 1rem; line-height: 1; cursor: pointer;
  opacity: 0; transition: opacity 0.15s;
}
.home-card-wrapper:hover .card-dismiss-btn { opacity: 1; }
.card-dismiss-btn:hover { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }

/* ===== Auth Pages ===== */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - 60px); padding: 40px 24px;
}
.auth-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px;
  padding: 40px; width: 100%; max-width: 420px; box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 1.6rem; margin-bottom: 6px; }
.auth-subtitle { color: var(--text-muted); font-size: 0.92rem; margin-bottom: 24px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.auth-optional { font-weight: 400; opacity: 0.6; }
.auth-input {
  padding: 12px 14px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.95rem;
  outline: none; transition: border-color 0.2s; font-family: inherit;
}
.auth-input:focus { border-color: var(--primary); }
.auth-pw-wrap { position: relative; display: flex; align-items: center; }
.auth-pw-wrap .auth-input { flex: 1; padding-right: 42px; }
.pw-eye {
  position: absolute; right: 10px; background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 4px; display: flex; align-items: center;
}
.pw-eye:hover { color: var(--text); }
.auth-hint { font-size: 0.78rem; font-weight: 400; color: var(--text-muted); opacity: 0.7; }
.auth-submit { margin-top: 8px; width: 100%; padding: 14px; font-size: 1rem; }
.auth-forgot { text-align: right; margin: 8px 0 0; font-size: 0.85rem; }
.auth-forgot a { color: var(--text-muted); text-decoration: none; }
.auth-forgot a:hover { color: var(--primary-light); text-decoration: underline; }
.auth-success {
  background: var(--success-bg); border: 1px solid var(--success-border);
  color: var(--success-text); padding: 10px 14px; border-radius: var(--radius); font-size: 0.88rem; margin-bottom: 16px;
}
.auth-switch { text-align: center; color: var(--text-muted); font-size: 0.88rem; margin-top: 20px; }
.auth-switch a { color: var(--primary-light); text-decoration: none; font-weight: 600; }
.auth-switch a:hover { text-decoration: underline; }
.auth-error {
  background: var(--error-bg); border: 1px solid var(--error-border);
  border-radius: var(--radius); padding: 10px 14px; color: var(--error-text);
  font-size: 0.88rem; margin-bottom: 8px;
}
.auth-success {
  background: var(--success-bg); border: 1px solid var(--success-border);
  border-radius: var(--radius); padding: 10px 14px; color: var(--success-text);
  font-size: 0.88rem; margin-bottom: 8px;
}
.auth-back {
  display: block; text-align: center; margin-top: 16px;
  color: var(--text-muted); font-size: 0.85rem; text-decoration: none;
}
.auth-back:hover { color: var(--primary-light); }

/* Social login buttons */
.social-login-buttons { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.social-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 0.92rem; font-weight: 600;
  text-decoration: none; cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.social-btn:hover { border-color: var(--text-muted); background: var(--bg-surface); }
.social-icon { width: 20px; height: 20px; flex-shrink: 0; }
.social-google:hover { border-color: #4285F4; }
.social-facebook:hover { border-color: #1877F2; }
.social-twitter:hover { border-color: var(--text); }

.auth-divider {
  display: flex; align-items: center; gap: 16px; margin: 20px 0;
  color: var(--text-muted); font-size: 0.82rem;
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ===== Home Page ===== */
.home-page { max-width: 720px; margin: 0 auto; padding: 60px 24px 80px; }
.home-hero { text-align: center; margin-bottom: 28px; }
.home-hero h1 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; line-height: 1.1; letter-spacing: -1.5px; margin-bottom: 16px; }
.gradient-text { background: linear-gradient(135deg, var(--primary-light), var(--primary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.home-hero-subtitle { font-size: 1.1rem; color: var(--text-muted); max-width: 550px; margin: 0 auto; }
.home-input-section {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.home-title {
  font-size: 1.6rem; font-weight: 700; margin-bottom: 16px;
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.home-input-row { display: flex; gap: 10px; margin-bottom: 12px; }
.home-topic-input {
  flex: 1; padding: 14px 18px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 1.05rem; outline: none;
  transition: border-color 0.2s; font-family: inherit;
}
.home-topic-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(99,102,241,0.15); }
.home-topic-input::placeholder { color: var(--text-muted); }
.home-topic-input.shake { animation: shake 0.4s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.home-start-btn {
  padding: 14px 28px; background: var(--primary); color: white; border: none;
  border-radius: var(--radius); font-weight: 600; font-size: 1.05rem; cursor: pointer;
  transition: background 0.15s, transform 0.1s; font-family: inherit; white-space: nowrap;
}
.home-start-btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
.home-start-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.home-suggestions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.home-model-row {
  position: relative; display: flex; align-items: center; gap: 8px;
}
.home-model-row > div { position: relative; }
.home-format-toggle { display: flex; align-items: center; gap: 6px; }
.home-format-toggle .format-toggle { min-width: 100px; }
.home-model-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 0.85rem; font-weight: 500;
  cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.home-model-btn:hover { border-color: var(--primary); background: rgba(99,102,241,0.08); }
.home-model-btn.open { border-color: var(--primary); border-radius: 6px 6px 0 0; }
.home-model-btn .model-select-arrow { font-size: 0.6rem; color: var(--text-muted); transition: transform 0.2s; }
.home-model-btn.open .model-select-arrow { transform: rotate(180deg); }

/* Session feed */
.home-feed { }
.home-feed-title {
  font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 1px; margin-bottom: 16px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.home-feed-loading { text-align: center; padding: 40px; }
.home-empty { text-align: center; color: var(--text-muted); padding: 60px 20px; }
.home-empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.home-empty-hint { font-size: 0.85rem; opacity: 0.7; }

/* Session cards */
.session-card {
  display: block; text-decoration: none; color: var(--text);
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px 24px; margin-bottom: 12px; box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.session-card:hover {
  border-color: var(--primary); box-shadow: 0 4px 20px rgba(99,102,241,0.12);
  transform: translateY(-1px);
}
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.card-title { font-size: 1.1rem; font-weight: 700; line-height: 1.3; }
.card-delete {
  background: none; border: none; color: var(--text-muted); font-size: 1.2rem;
  cursor: pointer; padding: 0 4px; line-height: 1; opacity: 0;
  transition: all 0.15s; flex-shrink: 0;
}
.session-card:hover .card-delete { opacity: 1; }
.card-delete:hover { color: var(--danger); }
.card-meta {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 0.88rem; color: var(--text-muted); margin-bottom: 10px;
}
.card-phase { display: flex; align-items: center; gap: 5px; font-weight: 600; }
.card-phase-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.card-sep { opacity: 0.4; }
.card-time { margin-left: auto; }

/* Progress bar in card */
.card-progress-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-progress-track {
  flex: 1; height: 4px; background: var(--bg-surface); border-radius: 2px; overflow: hidden;
}
.card-progress-fill { height: 100%; border-radius: 2px; transition: width 0.3s; }
.card-progress-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; white-space: nowrap; }

/* Step dots in card */
.card-step-dots { display: flex; gap: 6px; flex-wrap: wrap; }
.card-dot {
  width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700; color: var(--text-muted);
  background: var(--bg-surface); border-radius: 50%; flex-shrink: 0;
  transition: all 0.15s;
}
.card-dot.done { background: var(--success); color: white; }

/* ===== Custom Model Dropdown ===== */
.model-select-wrap { position: relative; min-width: 220px; }
.model-select-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px; background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.9rem; font-weight: 500;
  cursor: pointer; transition: all 0.2s; font-family: inherit;
}
.model-select-btn:hover { border-color: var(--primary); background: rgba(99,102,241,0.08); }
.model-select-btn.open { border-color: var(--primary); border-radius: var(--radius) var(--radius) 0 0; }
.model-select-arrow { font-size: 0.65rem; color: var(--text-muted); transition: transform 0.2s; }
.model-select-btn.open .model-select-arrow { transform: rotate(180deg); }
.model-select-list {
  display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
  background: var(--bg-card); border: 1px solid var(--primary); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius); overflow: hidden;
  box-shadow: var(--dropdown-shadow);
}
.model-select-list.open { display: block; }
.model-select-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 14px; cursor: pointer; transition: background 0.12s;
  border-bottom: 1px solid rgba(51,65,85,0.5);
}
.model-select-item:last-child { border-bottom: none; }
.model-select-item:hover { background: rgba(99,102,241,0.1); }
.model-select-item.selected { background: rgba(99,102,241,0.15); }
.model-select-item-name { font-size: 0.88rem; font-weight: 600; color: var(--text); }
.model-select-item-desc { font-size: 0.75rem; color: var(--text-muted); line-height: 1.3; }

/* ===== Tabs (shared) ===== */
.tab-bar {
  display: flex; gap: 0;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px; margin-bottom: 20px;
}
.tab-btn {
  flex: 1; background: none; border: none; color: var(--text-muted); font-size: 0.9rem;
  font-weight: 600; padding: 10px 20px; cursor: pointer; border-radius: 8px;
  transition: all 0.2s; font-family: inherit;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--primary); color: white; }


/* ===== Progress Bars ===== */

/* Content nav progress bar */
.step-progress-bar {
  height: 3px; background: var(--bg-surface); position: relative;
  flex-shrink: 0; cursor: default;
}
.step-progress-fill {
  height: 100%; background: var(--primary); border-radius: 2px;
  transition: width 1s linear;
}
.step-progress-tooltip {
  display: none; position: absolute; right: 8px; top: -28px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 10px; font-size: 0.72rem; color: var(--text-muted);
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  white-space: nowrap; pointer-events: none;
}
.step-progress-bar:hover .step-progress-tooltip { display: block; }

/* Sidebar step progress bar */
.sidebar-progress {
  display: flex; align-items: center; gap: 6px; margin-top: 4px;
  position: relative;
}
.sidebar-progress-track {
  flex: 1; height: 3px; background: var(--bg-surface); border-radius: 2px;
  overflow: hidden;
}
.sidebar-progress-fill {
  height: 100%; background: var(--primary); border-radius: 2px;
  transition: width 1s linear;
}
.sidebar-progress-tip {
  font-size: 0px; color: var(--text-muted); white-space: nowrap;
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  transition: font-size 0.15s;
  overflow: hidden;
}
.step-item:hover .sidebar-progress-tip {
  font-size: 0.68rem;
}

/* ===== Step Mark Done ===== */
.btn-done {
  background: var(--bg-surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 20px; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s; white-space: nowrap; font-family: inherit;
}
.btn-done:hover { border-color: var(--success); color: var(--success); }
.btn-done.completed { background: rgba(16,185,129,0.15); border-color: var(--success); color: var(--success); }
.step-item .step-num { transition: background 0.2s; }
.step-item.has-content .step-num { background: var(--primary); }


.topic-suggestions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; color: var(--text-muted); font-size: 0.85rem; }
.suggestion-chip { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 20px; padding: 6px 14px; color: var(--text); font-size: 0.9rem; cursor: pointer; transition: all 0.2s; }
.suggestion-chip:hover { background: var(--primary); border-color: var(--primary); }

.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 40px; }
.feature-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; text-align: center; }
.feature-icon { font-size: 2rem; margin-bottom: 12px; }
.feature-card h3 { font-size: 1.1rem; margin-bottom: 8px; }
.feature-card p { color: var(--text-muted); font-size: 0.9rem; }

.home-donate { text-align: center; margin-top: 48px; padding: 32px 20px; border-top: 1px solid var(--border); }
.home-donate p { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 14px; }
.donate-btn {
  display: inline-block; padding: 10px 28px; border-radius: var(--radius);
  background: var(--bg-surface); color: var(--text); border: 1px solid var(--border);
  font-size: 0.95rem; font-weight: 600; text-decoration: none; transition: all 0.2s;
}
.donate-btn { display: inline-flex; align-items: center; gap: 8px; }
.donate-btn:hover { background: var(--primary); color: white; border-color: var(--primary); transform: translateY(-1px); }
.donate-paypal-logo { height: 18px; vertical-align: middle; }

/* ===== Buttons ===== */
.btn-primary { background: var(--primary); color: white; border: none; border-radius: var(--radius); padding: 12px 24px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.2s; white-space: nowrap; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-secondary { background: var(--bg-surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 20px; font-size: 1rem; cursor: pointer; transition: all 0.2s; }
.btn-secondary:hover { background: var(--border); }
.btn-danger {
  background: #dc2626; color: white; border: none; border-radius: var(--radius);
  padding: 10px 20px; font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: background 0.2s; font-family: inherit;
}
.btn-danger:hover { background: #b91c1c; }
.btn-danger:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Session Layout ===== */
/* ===== Resize Handles ===== */
.resize-handle {
  width: 5px; flex-shrink: 0; cursor: col-resize;
  background: transparent; position: relative; z-index: 10;
  transition: background 0.15s;
}
.resize-handle:hover,
.resize-handle.active {
  background: var(--primary);
}
.resize-handle::after {
  content: ''; position: absolute; inset: 0 -3px;
}
body.resizing { cursor: col-resize !important; user-select: none !important; }
body.resizing * { cursor: col-resize !important; user-select: none !important; }

.sidebar { width: 280px; flex-shrink: 0; background: var(--bg-card); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-header { padding: 20px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 8px; line-height: 1.3; }
.phase-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; background: var(--primary); color: white; }
.model-select {
  margin-top: 8px; width: 100%; padding: 5px 8px; font-size: 0.78rem;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer; font-family: inherit; outline: none;
  transition: border-color 0.2s;
}
.model-select:hover, .model-select:focus { border-color: var(--primary); }
.format-toggle {
  display: flex; margin-top: 8px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
}
.format-btn {
  flex: 1; padding: 4px 8px; font-size: 0.75rem; font-weight: 600; font-family: inherit;
  background: transparent; color: var(--text-muted); border: none; cursor: pointer;
  transition: all 0.2s;
}
.format-btn.active { background: var(--primary); color: #fff; }
.format-btn:hover:not(.active):not(.vip-locked) { background: var(--bg-hover); color: var(--text); }
.format-btn.vip-locked { opacity: 0.5; cursor: not-allowed; }
.vip-badge {
  display: inline-block; padding: 1px 6px; font-size: 0.65rem; font-weight: 700;
  background: linear-gradient(135deg, #f59e0b, #d97706); color: #000; border-radius: 4px;
  text-transform: uppercase; letter-spacing: 0.5px; vertical-align: middle; margin-left: 4px;
}
.vip-badge-profile {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px;
  background: linear-gradient(135deg, #f59e0b, #d97706); color: #000; border-radius: 6px;
  font-size: 0.8rem; font-weight: 700; text-transform: uppercase;
}
.model-select-item.vip-locked { opacity: 0.5; }
.model-select-item.vip-locked .model-select-item-name::after {
  content: ' VIP'; font-size: 0.6rem; font-weight: 700; padding: 1px 4px; margin-left: 4px;
  background: linear-gradient(135deg, #f59e0b, #d97706); color: #000; border-radius: 3px;
  vertical-align: middle;
}
.html-iframe-wrapper {
  width: 100%; height: calc(100vh - 160px); border: none; border-radius: 8px;
  background: #1a1b2e;
}
.sidebar-steps { flex: 1; overflow-y: auto; padding: 16px; }
.sidebar-hint { color: var(--text-muted); font-size: 0.85rem; text-align: center; margin-top: 20px; line-height: 1.6; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
.btn-customize {
  width: 100%; padding: 10px; border: 1px dashed var(--border); border-radius: var(--radius);
  background: transparent; color: var(--text-muted); font-size: 0.92rem; font-weight: 500;
  cursor: pointer; transition: all 0.2s; font-family: inherit;
}
.btn-customize:hover { border-color: var(--primary); color: var(--primary-light); background: rgba(99,102,241,0.08); }

.sidebar-toolkit { display: flex; flex-direction: column; gap: 10px; }
.zoom-controls {
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.zoom-btn {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-muted); font-size: 0.82rem; font-weight: 600; padding: 4px 10px;
  cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.zoom-btn:hover { border-color: var(--primary); color: var(--primary-light); }
.zoom-level {
  font-size: 0.78rem; color: var(--text-muted); min-width: 36px; text-align: center;
}

/* Adjust Plan Modal */
.modal-overlay {
  position: fixed; inset: 0; background: var(--overlay-bg); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px; width: 480px; max-width: 90vw; box-shadow: var(--shadow);
}
.modal-box h3 { margin: 0 0 8px; font-size: 1.3rem; color: var(--text); }
.modal-box p { font-size: 1rem; line-height: 1.6; }
.modal-box textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-surface); color: var(--text); font-size: 1rem; font-family: inherit;
  resize: vertical; min-height: 80px;
}
.modal-box textarea:focus { outline: none; border-color: var(--primary); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.step-item { display: flex; align-items: flex-start; gap: 12px; padding: 12px; border-radius: var(--radius); cursor: pointer; transition: background 0.15s; margin-bottom: 8px; border: 1px solid transparent; }
.step-item:hover { background: var(--bg-surface); }
.step-item.active { background: rgba(99,102,241,0.15); border-color: var(--primary); }
.step-item.completed .step-num { background: var(--success); }
.step-num { width: 28px; height: 28px; border-radius: 50%; background: var(--bg-surface); display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; flex-shrink: 0; }
.step-info { flex: 1; min-width: 0; }
.step-title { font-size: 0.95rem; font-weight: 600; line-height: 1.3; }
.step-time { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }

/* ===== Main Content ===== */
.main-content { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

/* ===== Chat ===== */
.chat-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.message { display: flex; gap: 12px; max-width: 85%; animation: fadeUp 0.3s ease; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.message-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--bg-surface); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.message.user .message-avatar { background: var(--primary); }
.message-bubble { background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 12px 16px; font-size: 0.95rem; line-height: 1.6; }
.message.user .message-bubble { background: var(--primary); border-color: var(--primary); color: white; border-top-right-radius: 4px; }
.message.assistant .message-bubble { border-top-left-radius: 4px; }
.message-bubble.streaming::after { content: '▋'; animation: blink 0.7s infinite; color: var(--primary); }
@keyframes blink { 50% { opacity: 0; } }

.chat-input-area { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 12px; background: var(--bg-card); }
#chatInput { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; color: var(--text); font-size: 0.95rem; resize: none; outline: none; font-family: inherit; transition: border-color 0.2s; }
#chatInput:focus { border-color: var(--primary); }

/* ===== Content Panel ===== */
.content-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.content-nav { display: flex; align-items: center; gap: 12px; padding: 16px 24px; border-bottom: 1px solid var(--border); background: var(--bg-card); flex-wrap: wrap; }
.content-body { flex: 1; overflow-y: auto; padding: 32px; }
.content-placeholder { text-align: center; color: var(--text-muted); margin-top: 60px; font-size: 1.1rem; }

/* ===== Lesson Content (Markdown rendered) ===== */
.lesson-content { font-size: 1.05rem; line-height: 1.8; }
.lesson-content h1, .lesson-content h2, .lesson-content h3 { color: var(--text); margin: 1.5em 0 0.5em; line-height: 1.3; }
.lesson-content h1 { font-size: 1.8rem; }
.lesson-content h2 { font-size: 1.4rem; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.lesson-content h3 { font-size: 1.15rem; }
.lesson-content p { margin-bottom: 1em; }
.lesson-content ul, .lesson-content ol { padding-left: 1.5em; margin-bottom: 1em; }
.lesson-content li { margin-bottom: 0.4em; }
.lesson-content code { background: var(--bg-surface); border-radius: 4px; padding: 2px 6px; font-family: 'Fira Code', 'Cascadia Code', monospace; font-size: 0.88em; color: var(--primary-light); }
.lesson-content pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; overflow-x: auto; margin: 1.2em 0; position: relative; }
.lesson-content pre code { background: none; padding: 0; color: var(--code-text); font-size: 0.9em; }
.code-copy-btn {
  position: absolute; top: 8px; right: 8px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 10px; font-size: 0.75rem;
  color: var(--info-text); cursor: pointer; font-family: inherit;
  transition: all 0.15s; opacity: 0;
}
.lesson-content pre:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { background: var(--bg-hover); color: var(--code-text); }
.code-copy-btn.copied { background: rgba(16,185,129,0.2); color: #10b981; border-color: rgba(16,185,129,0.3); }
.lesson-content blockquote { border-left: 3px solid var(--primary); padding-left: 16px; margin: 1em 0; color: var(--text-muted); font-style: italic; }
.lesson-content details { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin: 0.8em 0; }
.lesson-content summary { cursor: pointer; color: var(--primary-light); font-weight: 600; }
.lesson-content table { width: 100%; border-collapse: collapse; margin: 1em 0; }
.lesson-content th, .lesson-content td { padding: 10px 14px; border: 1px solid var(--border); text-align: left; }
.lesson-content th { background: var(--bg-surface); font-weight: 600; }

/* ===== Step Quiz ===== */
.quiz-container { max-width: 720px; padding: 8px 0; }
.quiz-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 4px; }
.quiz-subtitle { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 28px; }
.quiz-loading, .quiz-error { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.quiz-loading .spinner { margin: 0 auto 16px; }
.quiz-error .btn-primary { margin-top: 12px; }

.quiz-question {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px;
}
.quiz-q-num {
  display: inline-block; background: var(--primary); color: white;
  font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 4px;
  margin-bottom: 8px;
}
.quiz-q-text { font-size: 1.05rem; font-weight: 600; margin-bottom: 14px; line-height: 1.5; }

.quiz-choices { display: flex; flex-direction: column; gap: 8px; }
.quiz-choice {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-surface); border: 2px solid transparent; border-radius: var(--radius);
  padding: 12px 16px; cursor: pointer; transition: all 0.15s;
  text-align: left; font-family: inherit; font-size: 0.95rem; color: var(--text);
}
.quiz-choice:hover { border-color: var(--primary); background: rgba(99,102,241,0.08); }
.quiz-choice.selected { border-color: var(--primary); background: rgba(99,102,241,0.15); }
.quiz-choice.correct { border-color: var(--success); background: rgba(16,185,129,0.12); }
.quiz-choice.incorrect { border-color: #ef4444; background: rgba(239,68,68,0.12); }
.quiz-choice-letter {
  width: 28px; height: 28px; border-radius: 50%; background: var(--bg-card);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.82rem; font-weight: 700; flex-shrink: 0; color: var(--text-muted);
}
.quiz-choice.selected .quiz-choice-letter { background: var(--primary); color: white; }
.quiz-choice.correct .quiz-choice-letter { background: var(--success); color: white; }
.quiz-choice.incorrect .quiz-choice-letter { background: #ef4444; color: white; }
.quiz-choice-text { flex: 1; }

.quiz-explanation {
  margin-top: 12px; padding: 10px 14px; border-radius: 8px;
  font-size: 0.9rem; line-height: 1.5;
}
.quiz-explanation.correct { background: var(--success-bg); color: var(--success-text); }
.quiz-explanation.incorrect { background: var(--error-bg); color: var(--error-text); }
.quiz-q-text code, .quiz-choice-text code, .quiz-explanation code {
  background: var(--bg-surface); border-radius: 4px; padding: 1px 5px;
  font-family: 'Fira Code', 'Cascadia Code', monospace; font-size: 0.88em;
}

.quiz-submit-area {
  display: flex; align-items: center; gap: 16px; margin-top: 24px; padding-top: 16px;
  border-top: 1px solid var(--border);
}
.quiz-submit-btn { padding: 12px 32px; font-size: 1rem; }
.quiz-answered-count { color: var(--text-muted); font-size: 0.88rem; }

.quiz-score {
  display: flex; align-items: center; gap: 12px; padding: 16px 0;
}
.quiz-score-emoji { font-size: 2rem; }
.quiz-score-text { font-size: 1.2rem; font-weight: 700; }
.quiz-score-actions { display: flex; gap: 8px; margin-top: 8px; }
.quiz-best-score { color: var(--success); font-size: 0.9rem; font-weight: 600; }
.quiz-attempts { color: var(--text-muted); font-size: 0.85rem; }

/* Quiz button in content nav */
.btn-quiz {
  background: rgba(139,92,246,0.15); color: #a78bfa; border: 1px solid rgba(139,92,246,0.3);
  border-radius: var(--radius); padding: 6px 14px; font-size: 0.88rem; font-weight: 600;
  cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.btn-quiz:hover { background: rgba(139,92,246,0.25); border-color: #a78bfa; }
.btn-refresh {
  background: rgba(100,100,100,0.15); color: var(--text-muted); border: 1px solid rgba(100,100,100,0.3);
  border-radius: var(--radius); padding: 6px 10px; font-size: 1rem; font-weight: 600;
  cursor: pointer; transition: all 0.15s; font-family: inherit; line-height: 1;
}
.btn-refresh:hover { background: rgba(100,100,100,0.3); color: var(--text); }
.btn-copy-all {
  background: rgba(100,100,100,0.15); color: var(--text-muted); border: 1px solid rgba(100,100,100,0.3);
  border-radius: var(--radius); padding: 6px 10px; font-size: 0.85rem;
  cursor: pointer; transition: all 0.15s; font-family: inherit; line-height: 1;
}
.btn-copy-all:hover { background: rgba(100,100,100,0.3); color: var(--text); }

/* Quiz badge in sidebar step */
.step-quiz-badge {
  display: inline-block; font-size: 0.72rem; font-weight: 600; padding: 2px 8px;
  border-radius: 10px; cursor: pointer; transition: all 0.15s; margin-top: 4px;
}
.step-quiz-badge.new {
  background: rgba(139,92,246,0.12); color: #a78bfa; border: 1px solid rgba(139,92,246,0.25);
}
.step-quiz-badge.new:hover { background: rgba(139,92,246,0.25); }
.step-quiz-badge.done {
  background: rgba(16,185,129,0.12); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.25);
}
.step-quiz-badge:not(.new):not(.done) {
  background: rgba(99,102,241,0.12); color: var(--primary-light); border: 1px solid rgba(99,102,241,0.25);
}

/* Step loading skeleton */
.step-loading { padding: 8px 0; animation: fadeIn 0.3s ease; }
.step-loading-header { display: flex; align-items: center; gap: 16px; margin-bottom: 28px; }
.step-loading-title { font-size: 1.1rem; font-weight: 600; color: var(--text); }
.step-loading-sub { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; }
.skeleton-lines { display: flex; flex-direction: column; gap: 14px; }
.skeleton-line {
  height: 14px; border-radius: 6px;
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--border) 50%, var(--bg-surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}
.skeleton-line.short { height: 14px; margin-top: 6px; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Streaming text */
.streaming-content { font-family: inherit; line-height: 1.7; }
.stream-cursor { animation: blink 0.7s infinite; color: var(--primary); }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: var(--overlay-bg); display: flex; align-items: center; justify-content: center; z-index: 1000; animation: fadeIn 0.3s; }
@keyframes fadeIn { from { opacity: 0; } }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px; padding: 40px; max-width: 560px; width: 90%; text-align: center; box-shadow: var(--shadow); animation: slideUp 0.3s; }
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-icon { font-size: 3rem; margin-bottom: 16px; }
.modal h2 { font-size: 1.6rem; margin-bottom: 12px; }
.modal p { color: var(--text-muted); margin-bottom: 20px; }
.plan-step-preview { background: var(--bg); border-radius: var(--radius); padding: 10px 14px; text-align: left; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; font-size: 0.9rem; }
.plan-step-preview .num { width: 24px; height: 24px; background: var(--primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; flex-shrink: 0; }

/* ===== Spinner ===== */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
.large-spinner { width: 48px; height: 48px; border-width: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Thinking Panel ===== */
.thinking-panel {
  border-bottom: 1px solid var(--border);
  background: rgba(99, 102, 241, 0.04);
  flex-shrink: 0;
  max-height: 220px;
  display: flex;
  flex-direction: column;
}
.thinking-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--primary-light);
  user-select: none;
  border-bottom: 1px solid rgba(99,102,241,0.15);
}
.thinking-header:hover { background: rgba(99,102,241,0.08); }
.thinking-chevron { margin-left: auto; font-size: 0.7rem; }
.thinking-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 20px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  white-space: pre-wrap;
  line-height: 1.5;
}

/* ===== Plan Generating State ===== */
.plan-generating {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  gap: 24px;
}
.plan-gen-header {
  display: flex;
  align-items: center;
  gap: 24px;
}
.plan-gen-header h2 { font-size: 1.5rem; }

.plan-gen-progress {
  width: 100%; max-width: 480px;
  display: flex; flex-direction: column; gap: 0;
}
.plan-gen-step {
  padding: 10px 16px; font-size: 0.9rem; color: var(--text);
  border-left: 2px solid var(--primary); margin-left: 8px;
  animation: fadeSlideIn 0.4s ease;
}
.plan-gen-step-num {
  font-weight: 700; color: var(--primary-light); margin-right: 8px;
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.3px;
}
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Plan Overview Cards ===== */
.plan-overview { max-width: 760px; margin: 0 auto; }
.plan-overview-header { margin-bottom: 24px; }
.plan-overview-header h1 { font-size: 1.8rem; margin-bottom: 8px; }
.plan-overview-meta { color: var(--primary-light); font-weight: 600; font-size: 0.95rem; }

.plan-abstract {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 28px; line-height: 1.65;
}
.plan-abstract-label {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--primary-light); margin-bottom: 6px;
}
.plan-abstract p { color: var(--text-muted); font-size: 0.92rem; margin: 0; }

.plan-cards { display: flex; flex-direction: column; gap: 12px; }
.plan-card {
  display: flex;
  align-items: center;
  gap: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  cursor: pointer;
  transition: all 0.2s;
}
.plan-card:hover {
  border-color: var(--primary);
  background: rgba(99,102,241,0.08);
  transform: translateX(4px);
}
.plan-card-num {
  width: 40px; height: 40px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem;
  flex-shrink: 0;
}
.plan-card-body { flex: 1; min-width: 0; }
.plan-card-title { font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
.plan-card-desc { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 10px; }
.plan-card-footer { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.plan-card-time { font-size: 0.8rem; color: var(--text-muted); }
.concept-tag {
  background: rgba(99,102,241,0.15);
  color: var(--primary-light);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 0.75rem;
}
.plan-card-arrow { color: var(--text-muted); font-size: 1.2rem; }
.plan-card-loading {
  cursor: default; opacity: 0.6; border-style: dashed;
  animation: pulse-loading 1.5s ease-in-out infinite;
}
.plan-card-loading:hover { transform: none; border-color: var(--border); background: var(--bg-card); }
@keyframes pulse-loading { 0%, 100% { opacity: 0.6; } 50% { opacity: 0.3; } }

/* ===== Chat Aside (right panel) ===== */
.chat-aside {
  width: 480px; flex-shrink: 0;
  background: var(--bg-card); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.chat-aside.collapsed { width: 0; min-width: 0; border-left: none; }
.chat-aside.collapsed .chat-aside-header,
.chat-aside.collapsed .chat-messages,
.chat-aside.collapsed .chat-input-area,
.chat-aside.collapsed .doc-viewer { display: none; }

.chat-aside-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.chat-aside-title { font-weight: 700; font-size: 1.05rem; }
.chat-header-actions { display: flex; gap: 6px; align-items: center; }
.chat-toggle-btn, .chat-clear-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 1rem; padding: 4px 8px; cursor: pointer;
  transition: all 0.15s;
}
.chat-toggle-btn:hover, .chat-clear-btn:hover { border-color: var(--primary); background: rgba(99,102,241,0.08); }
.chat-clear-btn { font-size: 0.85rem; }

.chat-aside .chat-messages {
  flex: 1; overflow-y: auto; padding: 16px; display: flex;
  flex-direction: column; gap: 12px;
}
.chat-welcome {
  text-align: center; color: var(--text-muted); font-size: 0.85rem;
  padding: 40px 16px; line-height: 1.5;
}

.chat-msg { display: flex; gap: 8px; animation: fadeUp 0.2s ease; }
.chat-msg.user { flex-direction: row-reverse; }
.chat-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--bg-surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; flex-shrink: 0;
}
.chat-msg.user .chat-msg-avatar { background: var(--primary); }
.chat-msg-bubble {
  background: var(--bg-surface); border-radius: 12px; padding: 8px 12px;
  font-size: 0.95rem; line-height: 1.5; max-width: 85%;
  white-space: pre-wrap; word-break: break-word;
}
.chat-msg.user .chat-msg-bubble {
  background: var(--primary); color: white; border-top-right-radius: 4px;
}
.chat-msg.assistant .chat-msg-bubble { border-top-left-radius: 4px; }
.chat-msg-bubble.streaming .stream-cursor { animation: blink 0.7s infinite; color: var(--primary-light); }
.chat-msg-bubble p { margin: 0 0 6px; }
.chat-msg-bubble p:last-child { margin-bottom: 0; }
.chat-msg-bubble ul { margin: 4px 0; padding-left: 18px; }
.chat-msg-bubble li { margin-bottom: 2px; }
.chat-msg-bubble code {
  background: var(--bg-surface); padding: 1px 5px; border-radius: 4px;
  font-size: 0.82rem; font-family: 'Fira Code', 'Cascadia Code', monospace;
}
.chat-msg-bubble pre {
  background: var(--bg); border-radius: 6px; padding: 8px 10px;
  overflow-x: auto; margin: 6px 0; font-size: 0.8rem;
}
.chat-msg-bubble pre code { background: none; padding: 0; }
.chat-msg-bubble strong { font-weight: 700; }

.chat-aside .chat-input-area {
  padding: 14px 16px; border-top: 1px solid var(--border);
  flex-shrink: 0; background: var(--bg-card);
  display: flex; flex-direction: column; gap: 8px;
}
.chat-aside #chatInput {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px; color: var(--text);
  font-size: 0.95rem; resize: none; outline: none; font-family: inherit;
  min-height: 72px; max-height: 150px; line-height: 1.5;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}
.chat-aside #chatInput:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}
.chat-input-footer {
  display: flex; align-items: center; justify-content: space-between;
}
.chat-input-hint {
  font-size: 0.72rem; color: var(--text-muted); user-select: none;
}
.chat-send-btn {
  background: var(--primary); color: white; border: none; border-radius: 8px;
  padding: 7px 16px; font-size: 0.82rem; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 4px;
  transition: background 0.15s, transform 0.1s; font-family: inherit;
}
.chat-send-btn .send-arrow { font-size: 1rem; line-height: 1; }
.chat-send-btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
.chat-send-btn:active { transform: translateY(0); }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ===== Profile Page ===== */
.profile-page {
  max-width: 800px; margin: 0 auto; padding: 40px 24px 80px;
}
.profile-toast {
  padding: 12px 18px; border-radius: var(--radius); font-size: 0.9rem;
  font-weight: 600; margin-bottom: 20px; transition: opacity 0.5s;
}
.profile-toast.success { background: var(--success-bg); border: 1px solid var(--success-border); color: var(--success-text); }
.profile-toast.error { background: var(--error-bg); border: 1px solid var(--error-border); color: var(--error-text); }

.profile-header-card {
  display: flex; align-items: center; gap: 24px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px;
  padding: 32px; margin-bottom: 24px; box-shadow: var(--shadow);
}
.profile-avatar-area { flex-shrink: 0; }
.profile-avatar-img {
  width: 80px; height: 80px; border-radius: 50%; object-fit: cover;
  border: 3px solid var(--primary);
}
.profile-avatar-letter {
  width: 80px; height: 80px; border-radius: 50%; background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; color: white;
}
.profile-header-info h1 { font-size: 1.5rem; margin-bottom: 4px; }
.profile-email { color: var(--text-muted); font-size: 0.92rem; }
.profile-joined { color: var(--text-muted); font-size: 0.8rem; margin-top: 4px; opacity: 0.7; }

.profile-grid { display: flex; flex-direction: column; gap: 20px; }
.profile-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px;
  padding: 24px; box-shadow: var(--shadow);
}
.profile-card h2 { font-size: 1.1rem; margin-bottom: 16px; }
.profile-hint { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 16px; line-height: 1.5; }
.profile-form { display: flex; flex-direction: column; gap: 14px; }
.profile-save-btn { align-self: flex-start; padding: 10px 24px; font-size: 0.88rem; }
.about-textarea {
  min-height: 120px; resize: vertical; line-height: 1.6; font-size: 0.9rem;
}

/* Stats */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px;
}
.stat-item {
  background: var(--bg); border-radius: var(--radius); padding: 16px 12px;
  text-align: center; display: flex; flex-direction: column; gap: 4px;
}
.stat-value { font-size: 1.6rem; font-weight: 800; color: var(--primary-light); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-extra { color: var(--text-muted); font-size: 0.82rem; margin-bottom: 12px; }
.recent-topics { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.recent-topics-label { font-size: 0.82rem; color: var(--text-muted); font-weight: 600; }
.topic-chip {
  background: rgba(99,102,241,0.12); color: var(--primary-light); border-radius: 20px;
  padding: 4px 12px; font-size: 0.78rem; font-weight: 500;
}

/* API key rows */
.key-input-row { display: flex; gap: 8px; align-items: center; }
.key-input-row .auth-input { flex: 1; }
.key-status {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  margin-left: 8px;
}
.key-status.connected { color: var(--success); }
.btn-clear-key {
  background: none; border: 1px solid var(--danger); color: var(--danger);
  border-radius: 8px; padding: 10px 14px; font-size: 0.8rem; cursor: pointer;
  transition: all 0.15s; white-space: nowrap; font-family: inherit;
}
.btn-clear-key:hover { background: var(--danger-bg); border-color: var(--danger); }

/* Key help */
.key-label-row { display: flex; align-items: center; gap: 8px; }
.key-help-btn {
  width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--text-muted);
  background: none; color: var(--text-muted); font-size: 0.7rem; font-weight: 700;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s; font-family: inherit; padding: 0; line-height: 1;
}
.key-help-btn:hover { border-color: var(--primary-light); color: var(--primary-light); }
.key-help-panel {
  display: none; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin: 8px 0 4px; font-size: 0.82rem; color: var(--text-muted);
  line-height: 1.6; animation: fadeUp 0.2s ease;
}
.key-help-panel.show { display: block; }
.key-help-panel p { margin-bottom: 8px; }
.key-help-panel p:last-child { margin-bottom: 0; }
.key-help-panel ol { padding-left: 20px; margin-bottom: 10px; }
.key-help-panel li { margin-bottom: 4px; }
.key-help-panel a { color: var(--primary-light); text-decoration: none; }
.key-help-panel a:hover { text-decoration: underline; }
.key-help-panel code {
  background: var(--bg-surface); padding: 1px 5px; border-radius: 4px;
  font-size: 0.78rem; font-family: 'Fira Code', 'Cascadia Code', monospace;
}

/* Connected accounts */
.connected-list { display: flex; flex-direction: column; gap: 10px; }
.connected-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg); border-radius: var(--radius); padding: 12px 16px;
}
.connected-provider {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 0.9rem; min-width: 100px;
}
.connected-uid { color: var(--text-muted); font-size: 0.85rem; }

/* Danger zone */
.danger-zone { border-color: rgba(239,68,68,0.25); }
.danger-zone h2 { color: var(--danger); }

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .chat-aside { width: 380px; }
}

/* ===== Debug view toggle ===== */
.debug-view-toggle {
  position: fixed; bottom: 8px; right: 8px; z-index: 9999;
  background: rgba(30,30,50,0.85); color: #888; border: 1px solid #444;
  border-radius: 6px; padding: 4px 10px; font-size: 0.7rem; cursor: pointer;
  font-family: inherit; opacity: 0.6; transition: opacity 0.15s;
}

/* ===== Mobile toggle buttons (hidden on desktop) ===== */
.mobile-toolbar { display: none; }
.mobile-bottom-bar { display: none; }

/* ===== Connection / Error Toast ===== */
.sf-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 10000;
  background: var(--toast-bg); color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 20px;
  font-size: 0.88rem;
  box-shadow: var(--dropdown-shadow);
  display: flex; align-items: center; gap: 10px;
  animation: toastSlideUp 0.3s ease;
  max-width: 90vw;
}
.sf-toast.error { border-color: rgba(239,68,68,0.4); }
.sf-toast.error .sf-toast-icon { color: var(--danger); }
.sf-toast.warning { border-color: rgba(245,158,11,0.4); }
.sf-toast.warning .sf-toast-icon { color: #f59e0b; }
.sf-toast.success { border-color: rgba(16,185,129,0.4); }
.sf-toast.success .sf-toast-icon { color: var(--success); }
.sf-toast-icon { font-size: 1.1rem; flex-shrink: 0; }
.sf-toast-close {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 1rem; padding: 0 0 0 8px;
}
@keyframes toastSlideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

