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

:root {
  --bg: #ffffff;
  --surface: #f9f9f9;
  --border: #e8e8e8;
  --text: #111111;
  --text-2: #666666;
  --text-3: #999999;
  --accent: #111111;
  --accent-inv: #ffffff;
  --node-bg: #ffffff;
  --node-border: #222222;
  --dot-color: #d0d0d0;
  --line-color: #cccccc;
  --radius: 8px;
  --radius-lg: 16px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "Fira Code", monospace;
}

[data-theme="dark"] {
  --bg: #1c1a18;
  --surface: #252220;
  --border: #302d2a;
  --text: #eeecea;
  --text-2: #908c88;
  --text-3: #5a5652;
  --accent: #eeecea;
  --accent-inv: #1c1a18;
  --node-bg: #222019;
  --node-border: #dcdad8;
  --dot-color: #302e2c;
  --line-color: #363330;
}

html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}

/* ── Typography ────────────────────────────────────────────────────── */
h1 { font-size: clamp(2rem, 5vw, 3.5rem); font-weight: 700; line-height: 1.1; letter-spacing: -0.03em; }
h2 { font-size: clamp(1.4rem, 3vw, 2rem); font-weight: 600; letter-spacing: -0.02em; }
h3 { font-size: 1.1rem; font-weight: 600; }
p  { color: var(--text-2); line-height: 1.7; }
a  { color: var(--text); text-decoration: none; }

/* ── Layout ────────────────────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 0 32px; }
.container-sm { max-width: 800px; margin: 0 auto; padding: 0 32px; }

/* ── Header ────────────────────────────────────────────────────────── */
.header {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  height: 60px;
  display: flex; align-items: center;
}
.header-inner {
  width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 32px;
  display: flex; align-items: center; justify-content: space-between;
}
.logo {
  font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em;
  display: flex; align-items: center; gap: 8px;
}
.logo-dot { width: 8px; height: 8px; background: var(--text); border-radius: 50%; }
.header-nav { display: flex; align-items: center; gap: 8px; }

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 20px; border-radius: var(--radius);
  font-family: var(--font); font-size: 0.875rem; font-weight: 500;
  cursor: pointer; border: 1px solid transparent;
  transition: all 0.15s ease; white-space: nowrap;
  text-decoration: none;
}
.btn-primary {
  background: var(--accent); color: var(--accent-inv);
  border-color: var(--accent);
}
.btn-primary:hover { opacity: 0.85; }
.btn-secondary {
  background: transparent; color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--text); }
.btn-ghost {
  background: transparent; color: var(--text-2);
  border-color: transparent;
}
.btn-ghost:hover { color: var(--text); background: var(--surface); }
.btn-danger { background: #ef4444; color: #fff; border-color: #ef4444; }
.btn-danger:hover { opacity: 0.85; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }
.btn:disabled {
  opacity: 0.4; cursor: not-allowed; pointer-events: none;
}
.btn-disabled-visual {
  opacity: 0.4; cursor: not-allowed;
  position: relative;
}

/* ── Theme toggle ──────────────────────────────────────────────────── */
.theme-toggle {
  width: 24px; height: 24px; border: none; border-radius: 4px;
  background: transparent; padding: 0;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text-2); transition: color 0.15s;
}
.theme-toggle:hover { color: var(--text); }

/* ── Landing: Hero ─────────────────────────────────────────────────── */
.hero {
  min-height: calc(100vh - 60px);
  display: flex; align-items: center;
  padding: 80px 0;
}
.hero-inner {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 80px;
  align-items: center;
  width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 32px;
}
.hero-text { display: flex; flex-direction: column; gap: 24px; }
.hero-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border: 1px solid var(--border);
  border-radius: 100px; font-size: 0.75rem; color: var(--text-2);
  width: fit-content;
}
.hero-badge-dot { width: 6px; height: 6px; background: var(--text-3); border-radius: 50%; }
.hero-title { }
.hero-desc { font-size: 1.1rem; max-width: 440px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.early-access-wrap { position: relative; display: inline-block; }
.early-access-tooltip {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--accent-inv);
  padding: 6px 12px; border-radius: var(--radius); font-size: 0.75rem;
  white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity 0.15s;
}
.early-access-tooltip::after {
  content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--text);
}
.early-access-wrap:hover .early-access-tooltip { opacity: 1; }

/* ── Landing: Node Canvas Block ────────────────────────────────────── */
.node-block {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  aspect-ratio: 1 / 1;
  max-width: 520px;
  background: var(--bg);
}
.node-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
}

/* ── Landing: Features ─────────────────────────────────────────────── */
.features { padding: 80px 0; border-top: 1px solid var(--border); }
.features-header { text-align: center; margin-bottom: 60px; }
.features-header p { margin-top: 12px; }
.features-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 32px;
}
.feature-card {
  padding: 28px; border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.feature-icon {
  width: 36px; height: 36px; border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; margin-bottom: 16px; color: var(--text-2);
}
.feature-card h3 { margin-bottom: 8px; }

/* ── Landing: Stages ───────────────────────────────────────────────── */
.stages { padding: 80px 0; border-top: 1px solid var(--border); }
.stages-header { text-align: center; margin-bottom: 60px; }
.stages-timeline {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 0; position: relative;
}
.stages-timeline::before {
  content: ''; position: absolute;
  top: 20px; left: calc(12.5% + 8px); right: calc(12.5% + 8px);
  height: 1px; background: var(--border); z-index: 0;
}
.stage-item { text-align: center; padding: 0 16px; position: relative; z-index: 1; }
.stage-num {
  width: 40px; height: 40px; border: 1px solid var(--border);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px; font-size: 0.8rem; color: var(--text-2);
  background: var(--bg);
}
.stage-item.active .stage-num {
  background: var(--accent); color: var(--accent-inv); border-color: var(--accent);
}
.stage-item h3 { font-size: 0.9rem; margin-bottom: 6px; }
.stage-item p { font-size: 0.8rem; }

/* ── Landing: Footer ───────────────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--border); padding: 32px 0;
}
.footer-inner {
  display: flex; align-items: center; justify-content: space-between;
}
.footer-copy { font-size: 0.8rem; color: var(--text-3); }

/* ── Forms ─────────────────────────────────────────────────────────── */
.form-page {
  min-height: calc(100vh - 60px);
  display: flex; align-items: center; justify-content: center;
  padding: 40px 16px;
}
.form-card {
  width: 100%; max-width: 400px;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 40px; background: var(--bg);
}
.form-card h2 { margin-bottom: 8px; }
.form-card .form-subtitle { margin-bottom: 32px; font-size: 0.9rem; }
.form-group { margin-bottom: 20px; }
.form-group label {
  display: block; font-size: 0.8rem; font-weight: 500;
  color: var(--text-2); margin-bottom: 6px; letter-spacing: 0.02em;
  text-transform: uppercase;
}
.form-group input {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: var(--font); font-size: 0.9rem;
  transition: border-color 0.15s;
  outline: none;
}
.form-group input:focus { border-color: var(--text); }
.form-group input::placeholder { color: var(--text-3); }
.form-error {
  color: #ef4444; font-size: 0.8rem; margin-top: 6px; display: none;
}
.form-actions { margin-top: 28px; display: flex; flex-direction: column; gap: 12px; }
.form-footer { text-align: center; margin-top: 24px; font-size: 0.85rem; color: var(--text-2); }
.form-footer a { color: var(--text); font-weight: 500; }

/* Registration disabled callout */
.callout {
  padding: 14px 16px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface);
  font-size: 0.85rem; color: var(--text-2); margin-bottom: 24px;
  display: flex; gap: 10px; align-items: flex-start;
}
.callout-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }
.form-disabled {
  opacity: 0.45; pointer-events: none; user-select: none;
  filter: grayscale(1);
}

/* ── Dashboard ─────────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: calc(100vh - 60px); }
.sidebar {
  width: 240px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 24px 0;
  display: flex; flex-direction: column;
}
.sidebar-section { padding: 0 16px; margin-bottom: 8px; }
.sidebar-label {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-3);
  padding: 0 8px; margin-bottom: 4px;
}
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: var(--radius);
  font-size: 0.875rem; color: var(--text-2);
  transition: all 0.1s; cursor: pointer;
}
.sidebar-link:hover { background: var(--surface); color: var(--text); }
.sidebar-link.active { background: var(--surface); color: var(--text); font-weight: 500; }
.sidebar-icon { width: 16px; text-align: center; font-size: 0.9rem; }
.sidebar-footer { margin-top: auto; padding: 16px; border-top: 1px solid var(--border); }
.sidebar-user { font-size: 0.8rem; color: var(--text-2); margin-bottom: 8px; }
.sidebar-user strong { display: block; color: var(--text); }

.main-content { flex: 1; padding: 32px; overflow: auto; }
.page-header { margin-bottom: 32px; }
.page-header h2 { margin-bottom: 6px; }

/* Quota bar */
.quota-bar-wrap { margin: 24px 0; }
.quota-label {
  display: flex; justify-content: space-between;
  font-size: 0.8rem; color: var(--text-2); margin-bottom: 6px;
}
.quota-bar {
  height: 4px; background: var(--border); border-radius: 2px; overflow: hidden;
}
.quota-bar-fill { height: 100%; background: var(--text); border-radius: 2px; transition: width 0.3s; }

/* ── Discussion cards ──────────────────────────────────────────────── */
.discussions-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.discussion-card {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px; cursor: pointer; transition: border-color 0.15s;
  text-decoration: none; color: inherit; display: block;
}
.discussion-card:hover { border-color: var(--text); }
.discussion-card-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.discussion-question {
  font-size: 0.9rem; font-weight: 500; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.discussion-meta {
  display: flex; align-items: center; gap: 12px;
  font-size: 0.75rem; color: var(--text-3);
}
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 100px;
  font-size: 0.7rem; font-weight: 500; white-space: nowrap;
  border: 1px solid var(--border);
}
.badge-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-active { color: #22c55e; border-color: #22c55e30; background: #22c55e10; }
.badge-paused { color: #f59e0b; border-color: #f59e0b30; background: #f59e0b10; }
.badge-finished { color: var(--text-3); }
.badge-idle { color: var(--text-3); }

.empty-state {
  text-align: center; padding: 80px 20px;
  color: var(--text-3);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 16px; opacity: 0.4; }

/* New discussion form */
.new-discussion-form {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 24px; margin-bottom: 32px;
}
.new-discussion-form textarea {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: var(--font); font-size: 0.9rem; resize: vertical;
  min-height: 80px; outline: none; transition: border-color 0.15s;
}
.new-discussion-form textarea:focus { border-color: var(--text); }
.new-discussion-form textarea::placeholder { color: var(--text-3); }
.form-row { display: flex; gap: 12px; margin-top: 12px; justify-content: flex-end; }

/* ── Discussion page ───────────────────────────────────────────────── */
.discussion-layout {
  display: flex; flex-direction: column;
  height: calc(100vh - 60px);
}
.discussion-topbar {
  border-bottom: 1px solid var(--border);
  padding: 16px 32px;
  display: flex; align-items: center; gap: 16px;
  flex-shrink: 0;
}
.discussion-question-display {
  flex: 1; font-size: 0.9rem; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.discussion-body {
  display: flex; flex: 1; overflow: hidden;
}
.discussion-feed {
  flex: 1; overflow-y: auto; padding: 24px 32px;
  display: flex; flex-direction: column; gap: 16px;
}

/* Stage indicator */
.stage-bar {
  display: flex; gap: 0; border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; flex-shrink: 0;
}
.stage-tab {
  padding: 6px 14px; font-size: 0.75rem; color: var(--text-3);
  border-right: 1px solid var(--border); white-space: nowrap;
}
.stage-tab:last-child { border-right: none; }
.stage-tab.active { background: var(--text); color: var(--accent-inv); }
.stage-tab.done { color: var(--text-2); }

/* AI message */
.ai-message {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden; animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.ai-message-header {
  padding: 12px 16px; display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.ai-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700; color: var(--text-2);
  flex-shrink: 0;
}
.ai-name { font-size: 0.8rem; font-weight: 600; }
.ai-role { font-size: 0.75rem; color: var(--text-3); }
.ai-thesis {
  font-size: 0.8rem; color: var(--text-2); font-style: italic; margin-left: auto;
  max-width: 40%; text-align: right; line-height: 1.3;
}
.ai-message-body { padding: 16px; font-size: 0.875rem; line-height: 1.7; }
.ai-message-body p { color: var(--text); margin-bottom: 8px; }
.ai-message-body p:last-child { margin-bottom: 0; }

/* Status messages */
.status-message {
  text-align: center; font-size: 0.8rem; color: var(--text-3);
  padding: 8px; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.spinner {
  width: 14px; height: 14px; border: 1.5px solid var(--border);
  border-top-color: var(--text-2); border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Control dropdown */
.discussion-controls { padding: 16px 32px; border-top: 1px solid var(--border); flex-shrink: 0; }
.controls-row { display: flex; gap: 12px; align-items: center; }
.inject-input {
  flex: 1; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: var(--font); font-size: 0.875rem; outline: none;
}
.inject-input:focus { border-color: var(--text); }
.inject-input::placeholder { color: var(--text-3); }

/* Dropdown menu */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; bottom: calc(100% + 8px); right: 0;
  min-width: 260px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
  padding: 6px; z-index: 50;
  display: none;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
  padding: 10px 12px; border-radius: var(--radius);
  cursor: pointer; transition: background 0.1s;
  display: flex; flex-direction: column; gap: 2px;
}
.dropdown-item:hover { background: var(--surface); }
.dropdown-item-label { font-size: 0.875rem; font-weight: 500; }
.dropdown-item-desc { font-size: 0.75rem; color: var(--text-3); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }
.dropdown-item.danger .dropdown-item-label { color: #ef4444; }

/* User answer prompt */
.user-answer-block {
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px;
  background: var(--surface);
}
.user-answer-block h4 { margin-bottom: 12px; font-size: 0.9rem; }
.user-answer-row { display: flex; gap: 8px; }
.user-answer-row input {
  flex: 1; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 0.875rem; outline: none;
}
.user-answer-row input:focus { border-color: var(--text); }

/* ── Admin ─────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 32px;
}
.stat-card {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px;
}
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; margin-bottom: 6px; }
.stat-label { font-size: 0.8rem; color: var(--text-3); }

.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--surface); }
th {
  padding: 12px 16px; text-align: left;
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-2);
  border-bottom: 1px solid var(--border);
}
td { padding: 14px 16px; font-size: 0.875rem; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface); }
.table-actions { display: flex; gap: 6px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 32px;
  width: 100%; max-width: 480px;
  transform: translateY(16px); transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal h3 { margin-bottom: 24px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 24px; }

/* Toast */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px; z-index: 300;
}
.toast {
  padding: 12px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg);
  font-size: 0.875rem; min-width: 240px;
  animation: slideIn 0.2s ease;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
.toast-success { border-color: #22c55e30; background: #22c55e08; }
.toast-error { border-color: #ef444430; background: #ef444408; }

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .hero-inner { grid-template-columns: 1fr; gap: 40px; }
  .node-block { max-width: 100%; }
  .features-grid { grid-template-columns: 1fr; }
  .stages-timeline { grid-template-columns: 1fr 1fr; gap: 24px; }
  .stages-timeline::before { display: none; }
}
@media (max-width: 640px) {
  .container, .container-sm { padding: 0 16px; }
  .header-inner { padding: 0 16px; }
  .hero-inner { padding: 0 16px; }
  .sidebar { display: none; }
  .main-content { padding: 20px 16px; }
  .discussion-topbar { padding: 12px 16px; }
  .discussion-feed { padding: 16px; }
  .discussion-controls { padding: 12px 16px; }
}

/* ── Back to top ───────────────────────────────────────────────────── */
#backToTop {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s, color .15s;
  z-index: 900;
}
#backToTop.visible { opacity: 1; pointer-events: auto; }
#backToTop:hover { color: var(--accent); transform: translateY(-2px); }
