/* ── CSS Custom Properties ────────────────────────────────────── */
:root {
  --color-bg: #f8f9fb;
  --color-surface: #ffffff;
  --color-text: #1a1a2e;
  --color-text-secondary: #6b7280;
  --color-primary: #2563eb;
  --color-primary-light: #dbeafe;
  --color-primary-bg: #eff6ff;
  --color-danger: #dc2626;
  --color-danger-light: #fef2f2;
  --color-success: #16a34a;
  --color-success-light: #f0fdf4;
  --color-warning: #f59e0b;
  --color-warning-light: #fffbeb;
  /* Sidebar paper theme */
  --color-sidebar-bg: #f5f1ea;
  --color-sidebar-text: #1a1a1a;
  --color-sidebar-muted: #6b6b6b;
  --color-sidebar-heading: #000000;
  --color-sidebar-border: #d4cfc7;
  --color-sidebar-card: #ffffff;
  --color-sidebar-hover: #e8e3d8;
  --color-sidebar-active: #1a1a1a;
  --color-idea: #8b5cf6;
  --color-idea-light: #f5f3ff;
  --color-mvp: #2563eb;
  --color-mvp-light: #eff6ff;
  --color-launch: #f59e0b;
  --color-launch-light: #fffbeb;
  --color-scale: #16a34a;
  --color-scale-light: #f0fdf4;
  --color-border: rgba(0,0,0,0.08);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', 'Cascadia Code', monospace;
}

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

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  height: 100vh;
  overflow: hidden;
}

#app { display: flex; height: 100vh; }

/* ════════════════════════════════════════════════════════════════
   SIDEBAR — Paper theme (light bg + black buttons)
   ════════════════════════════════════════════════════════════════ */
#sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--color-sidebar-bg);
  color: var(--color-sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 16px 14px;
  gap: 0;
  overflow-y: auto;
  font-size: 13px;
  border-right: 1px solid var(--color-sidebar-border);
}

/* ── Header ──────────────────────────────────────────────────── */
.sidebar-header {
  margin-bottom: 16px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: #000;
}
.logo-subtitle {
  font-size: 11px;
  color: var(--color-sidebar-muted);
  margin-top: 2px;
  padding-left: 0;
}

/* ════════════════════════════════════════════════════════════════
   SIDEBAR GROUPS — Three numbered sections
   ════════════════════════════════════════════════════════════════ */
.sidebar-group {
  margin-bottom: 14px;
  padding: 14px;
  background: var(--color-sidebar-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-sidebar-border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.group-step {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #000;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.group-header h3 {
  font-size: 13px;
  font-weight: 700;
  color: #000;
  letter-spacing: 0;
  text-transform: none;
  margin: 0;
}
.group-desc {
  font-size: 11px;
  color: var(--color-sidebar-muted);
  line-height: 1.5;
  margin-bottom: 10px;
  padding-left: 28px;
}

/* ── Step 1: Stage Tabs ─────────────────────────────────────── */
.stage-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-bottom: 10px;
}

.stage-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 4px 8px;
  border: 2px solid #d0d0d0;
  border-radius: var(--radius-sm);
  background: #fff;
  color: #555;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 11px;
  font-weight: 500;
}
.stage-tab:hover {
  border-color: #999;
  color: #222;
}
.stage-tab.active {
  background: #000;
  border-color: #000;
}
.stage-tab.active .stage-tab-label {
  color: #fff;
  font-weight: 700;
}

.stage-tab-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.stage-tab-dot.idea { background: var(--color-idea); }
.stage-tab-dot.mvp { background: var(--color-mvp); }
.stage-tab-dot.launch { background: var(--color-launch); }
.stage-tab-dot.scale { background: var(--color-scale); }

.stage-tab.active .stage-tab-dot {
  outline: 2px solid rgba(255,255,255,0.5);
}

.stage-tab-label {
  font-size: 11px;
  color: #555;
  white-space: nowrap;
}

/* Stage detail card (below tabs) */
.stage-detail {
  padding: 12px;
  background: #fafaf9;
  border-radius: var(--radius-sm);
  border-left: 3px solid transparent;
  transition: border-color 0.3s;
}
.stage-detail.idea { border-left-color: var(--color-idea); }
.stage-detail.mvp { border-left-color: var(--color-mvp); }
.stage-detail.launch { border-left-color: var(--color-launch); }
.stage-detail.scale { border-left-color: var(--color-scale); }

.stage-detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.stage-detail-icon { font-size: 22px; flex-shrink: 0; }
.stage-detail-text { flex: 1; min-width: 0; }
.stage-detail-name {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: #000;
}
.stage-detail-question {
  display: block;
  font-size: 11px;
  color: var(--color-sidebar-muted);
  margin-top: 1px;
}
.stage-detail-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #000;
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
}

.stage-detail-progress {
  display: flex;
  align-items: center;
  gap: 10px;
}
.stage-detail-progress .progress-bar-container {
  flex: 1;
  background: #e0dcd5;
  border-radius: 3px;
  height: 5px;
  overflow: hidden;
}
.stage-detail-progress .progress-bar {
  height: 100%;
  background: #000;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.progress-label {
  font-size: 10px;
  color: var(--color-sidebar-muted);
  white-space: nowrap;
  min-width: 36px;
  text-align: right;
}

/* ── Step 2: Mode Radios ─────────────────────────────────────── */
.mode-radios {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mode-radio {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border: 2px solid #d0d0d0;
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--color-sidebar-text);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
  font-weight: 500;
}
.mode-radio:hover {
  border-color: #999;
}
.mode-radio.active {
  background: #000;
  border-color: #000;
}
.mode-radio.active .mode-radio-indicator {
  border-color: #fff;
  background: #000;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.3);
}
.mode-radio.active .mode-radio-label,
.mode-radio.active .mode-radio-desc {
  color: #fff;
}

.mode-radio-indicator {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid #999;
  background: #fff;
  flex-shrink: 0;
  margin-top: 2px;
  transition: all 0.2s;
  position: relative;
}
.mode-radio.active .mode-radio-indicator::after {
  content: '';
  position: absolute;
  inset: 3px;
  background: #fff;
  border-radius: 50%;
}

.mode-radio-body { flex: 1; min-width: 0; }
.mode-radio-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #000;
}
.mode-radio-desc {
  display: block;
  font-size: 11px;
  color: var(--color-sidebar-muted);
  margin-top: 2px;
}

/* ── Step 3: Tools ────────────────────────────────────────── */
.tool-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tool-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #d0d0d0;
  border-radius: var(--radius-sm);
  background: #fff;
  color: #000;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.tool-btn:hover {
  background: #000;
  border-color: #000;
  color: #fff;
}
.tool-btn-icon {
  font-size: 14px;
  flex-shrink: 0;
  width: 22px;
  text-align: center;
}
.tool-btn-label { flex: 1; }

/* ── Footer ────────────────────────────────────────────────────── */
.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.onboarding-hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-sidebar-border);
}
.hint-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }
.hint-text {
  font-size: 11px;
  color: var(--color-sidebar-muted);
  line-height: 1.5;
}

/* Mode indicator (bottom bar) */
.mode-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #fff;
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: #000;
  border: 1px solid var(--color-sidebar-border);
}
.mode-dot { width: 7px; height: 7px; border-radius: 50%; background: #000; flex-shrink: 0; }
.mode-indicator.da .mode-dot { background: var(--color-danger); animation: pulse 1.5s infinite; }
.mode-indicator.assessment .mode-dot { background: var(--color-primary); animation: pulse 1.5s infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ════════════════════════════════════════════════════════════════
   MAIN AREA
   ════════════════════════════════════════════════════════════════ */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.top-bar-left { display: flex; align-items: center; gap: 14px; }
.top-bar-stage {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.top-bar-stage h2 { font-size: 16px; font-weight: 600; }
.stage-subtitle { font-size: 12px; color: var(--color-text-secondary); }
.top-bar-right { display: flex; align-items: center; gap: 12px; font-size: 11px; color: var(--color-text-secondary); }
.session-id { font-family: var(--font-mono); }
.api-status .status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--color-success); }
.api-status.offline .status-dot { background: var(--color-warning); }

/* Chat */
.chat-container { flex: 1; overflow-y: auto; padding: 24px; }

.chat-messages {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  padding: 16px 20px;
  border-radius: var(--radius-md);
  max-width: 88%;
  font-size: 14px;
  line-height: 1.75;
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
  padding: 12px 18px;
  font-size: 14px;
}

.message.agent {
  align-self: flex-start;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
}

.message.system {
  align-self: center;
  background: var(--color-primary-bg);
  color: var(--color-primary);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 20px;
  max-width: none;
}

/* ── Agent Message Content ───────────────────────────────────── */

.message.agent > p:first-child { margin-top: 0; }
.message.agent > p:last-child { margin-bottom: 0; }

.message.agent h1 { font-size: 1.25em; font-weight: 700; margin: 1.2em 0 0.5em; color: var(--color-text); }
.message.agent h1:first-child { margin-top: 0; }
.message.agent h2 { font-size: 1.15em; font-weight: 700; margin: 1em 0 0.5em; padding-bottom: 6px; border-bottom: 2px solid var(--color-border); color: var(--color-text); }
.message.agent h3 { font-size: 1.05em; font-weight: 600; margin: 0.8em 0 0.4em; color: var(--color-text); }
.message.agent h4 { font-size: 1em; font-weight: 600; margin: 0.6em 0 0.3em; }

.message.agent p { margin: 0.4em 0; }
.message.agent strong { font-weight: 600; color: var(--color-text); }
.message.agent em { font-style: italic; }

.message.agent ul,
.message.agent ol {
  margin: 0.5em 0;
  padding-left: 1.6em;
}
.message.agent li { margin: 0.25em 0; }
.message.agent ul > li { list-style-type: disc; }
.message.agent ul > li::marker { color: var(--color-primary); }
.message.agent ol > li::marker { color: var(--color-text-secondary); font-weight: 600; font-size: 0.9em; }
.message.agent li > ul,
.message.agent li > ol { margin: 0.2em 0; }

.message.agent code {
  background: var(--color-bg);
  padding: 2px 7px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.88em;
  color: var(--color-danger);
  border: 1px solid var(--color-border);
}

.code-block {
  position: relative;
  margin: 0.8em 0;
  border-radius: var(--radius-sm);
  background: #1e1e2e;
  overflow: hidden;
}
.code-lang {
  position: absolute;
  top: 0; right: 0;
  padding: 3px 10px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: rgba(255,255,255,0.4);
  background: rgba(255,255,255,0.05);
  border-radius: 0 0 0 var(--radius-sm);
}
.code-block pre {
  margin: 0;
  padding: 16px 18px;
  overflow-x: auto;
  font-size: 0.85em;
  line-height: 1.6;
}
.code-block code {
  font-family: var(--font-mono);
  color: #e0def4;
  background: none;
  border: none;
  padding: 0;
}

.message.agent table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.8em 0;
  font-size: 0.93em;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--color-border);
}
.message.agent thead { background: var(--color-bg); }
.message.agent th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 0.9em;
  color: var(--color-text-secondary);
  border-bottom: 2px solid var(--color-border);
}
.message.agent td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}
.message.agent tbody tr:last-child td { border-bottom: none; }
.message.agent tbody tr:hover { background: var(--color-bg); }

.message.agent blockquote {
  border-left: 3px solid var(--color-primary);
  padding: 8px 16px;
  margin: 0.6em 0;
  background: var(--color-primary-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--color-text-secondary);
  font-style: italic;
}

.message.agent hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 1em 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  vertical-align: middle;
  margin: 0 2px;
}
.badge-yes { background: var(--color-success); color: #fff; }
.badge-empty { background: transparent; border: 2px solid var(--color-border); color: var(--color-text-secondary); }
.badge-no { background: var(--color-danger); color: #fff; }
.badge-partial { background: var(--color-warning); color: #fff; }

/* ── Devil's Advocate Mode ─────────────────────────────────── */
body.da-mode .message.agent { border-left: 3px solid var(--color-danger); }
body.da-mode .top-bar { border-bottom-color: var(--color-danger-light); }
body.da-mode .input-wrapper { border-color: var(--color-danger); }

/* ── Suggestions Bar ──────────────────────────────────────── */
.suggestions-bar {
  display: none;
}
.suggestions-label { font-size: 12px; color: var(--color-text-secondary); white-space: nowrap; flex-shrink: 0; }
#suggestionChips { display: flex; gap: 6px; flex-wrap: wrap; }
.suggestion-chip {
  padding: 5px 14px;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  font-family: var(--font-mono);
}
.suggestion-chip:hover { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ── Assessment Mode ──────────────────────────────────────── */
body.assessment-mode .input-wrapper { border-color: var(--color-primary); }
.assessment-options {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--color-border);
  flex-wrap: wrap;
}
.assessment-option {
  padding: 7px 16px;
  border: 2px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-bg);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.assessment-option:hover { border-color: var(--color-primary); color: var(--color-primary); background: var(--color-primary-bg); }
.assessment-option.selected { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ── Input Area ────────────────────────────────────────────── */
.input-area {
  position: relative;
  padding: 16px 24px 20px;
  background: transparent;
  border-top: none;
  flex-shrink: 0;
}
.input-container { max-width: 960px; margin: 0 auto; }
.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 16px;
  background: transparent;
  border: 2px solid #c4c4cf;
  border-radius: var(--radius-lg);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrapper:focus-within {
  border-color: #6b7280;
  box-shadow: 0 0 0 3px rgba(107,114,128,0.12), 0 0 0 1px rgba(107,114,128,0.2);
  background: transparent;
}
#messageInput {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  font-family: var(--font-sans);
  outline: none;
  resize: none;
  min-height: 66px;
  max-height: 150px;
  line-height: 1.5;
  padding: 4px 0;
}
.send-btn {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.send-btn:hover { opacity: 0.85; }
.send-btn:disabled { opacity: 0.4; cursor: default; }
.input-hint {
  font-size: 11px;
  color: var(--color-text-secondary);
  margin-top: 6px;
  text-align: right;
  opacity: 0.5;
}

/* ── Typing Indicator ──────────────────────────────────────── */
.typing-indicator { display: flex; gap: 4px; padding: 14px 20px; }
.typing-indicator span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--color-text-secondary);
  animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ── Command Palette ──────────────────────────────────────────── */
.command-palette {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 24px;
  right: 24px;
  max-width: 960px;
  margin: 0 auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
}
.command-list { padding: 6px 0; }
.command-group {
  padding: 8px 14px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-secondary);
  font-weight: 600;
}
.command-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.1s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 14px;
  font-family: var(--font-sans);
  color: var(--color-text);
}
.command-item:hover,
.command-item.active {
  background: var(--color-primary-bg);
  color: var(--color-primary);
}
.command-name {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
  min-width: 100px;
}
.command-item:hover .command-name,
.command-item.active .command-name { color: var(--color-primary); }
.command-desc {
  font-size: 13px;
  color: var(--color-text-secondary);
  flex: 1;
}
.command-item:hover .command-desc,
.command-item.active .command-desc { color: var(--color-text); }

/* ════════════════════════════════════════════════════════════════
   HISTORY PANEL (right side)
   ════════════════════════════════════════════════════════════════ */
#historyPanel {
  width: 260px;
  min-width: 260px;
  background: var(--color-sidebar-bg);
  border-left: 1px solid var(--color-sidebar-border);
  display: flex;
  flex-direction: column;
  font-size: 13px;
  overflow: hidden;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 10px;
  flex-shrink: 0;
}
.history-header h3 {
  font-size: 13px;
  font-weight: 700;
  color: #000;
  margin: 0;
}

.btn-new-session {
  width: 28px; height: 28px;
  border: 2px solid #000;
  border-radius: 50%;
  background: #000;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  line-height: 1;
}
.btn-new-session:hover {
  background: #333;
  border-color: #333;
}

.history-search {
  padding: 0 14px 8px;
  flex-shrink: 0;
}
.history-search input {
  width: 100%;
  padding: 8px 12px;
  border: 2px solid #d0d0d0;
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 12px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.2s;
}
.history-search input:focus {
  border-color: #999;
}
.history-search input::placeholder {
  color: #aaa;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item {
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  border: 2px solid transparent;
  background: #fff;
}
.history-item:hover {
  background: var(--color-sidebar-hover);
  border-color: #ccc;
}
.history-item.active {
  background: #000;
  border-color: #000;
}
.history-item.active .history-item-title,
.history-item.active .history-item-meta,
.history-item.active .history-item-badge {
  color: #fff;
}
.history-item.active .history-stage-bar {
  opacity: 0.8;
}

.history-item-title {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #000;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--color-sidebar-muted);
}

.history-item-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--color-sidebar-hover);
  color: var(--color-sidebar-muted);
  font-weight: 500;
}

.history-stage-bar {
  width: 100%;
  height: 3px;
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.history-stage-bar.idea { background: var(--color-idea-light); }
.history-stage-bar.mvp { background: var(--color-mvp-light); }
.history-stage-bar.launch { background: var(--color-launch-light); }
.history-stage-bar.scale { background: var(--color-scale-light); }
.history-stage-bar-inner {
  height: 100%;
  border-radius: 2px;
  width: 0;
  transition: width 0.3s;
}
.history-stage-bar.idea .history-stage-bar-inner { background: var(--color-idea); }
.history-stage-bar.mvp .history-stage-bar-inner { background: var(--color-mvp); }
.history-stage-bar.launch .history-stage-bar-inner { background: var(--color-launch); }
.history-stage-bar.scale .history-stage-bar-inner { background: var(--color-scale); }

.history-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-sidebar-muted);
  font-size: 12px;
}

/* Continuation badge */
.history-continuation-badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--color-primary-light);
  color: var(--color-primary);
  margin-left: 4px;
  font-weight: 500;
}

/* Main chat area width adjustment for history panel */
#historyPanel ~ #main .chat-messages {
  max-width: 780px;
}
#historyPanel ~ #main .input-container {
  max-width: 780px;
}
#historyPanel ~ #main .command-palette {
  max-width: 780px;
}
/* Also adjust chat max-width when main is adjacent to history panel */
#main:has(~ #historyPanel) .chat-messages { max-width: 780px; }
#main:has(~ #historyPanel) .input-container { max-width: 780px; }
#main:has(~ #historyPanel) .command-palette { max-width: 780px; }

/* ════════════════════════════════════════════════════════════════
   CONTEXT MENU
   ════════════════════════════════════════════════════════════════ */
.context-menu {
  position: fixed;
  z-index: 1000;
  min-width: 160px;
  background: #fff;
  border: 1px solid var(--color-sidebar-border);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: 4px 0;
  font-size: 13px;
  animation: fadeIn 0.1s ease;
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: none;
  color: var(--color-sidebar-text);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font-sans);
  text-align: left;
  transition: background 0.1s;
}
.context-menu-item:hover {
  background: var(--color-sidebar-hover);
}
.context-menu-item.danger {
  color: var(--color-danger);
}
.context-menu-item.danger:hover {
  background: var(--color-danger-light);
}

.context-menu-divider {
  height: 1px;
  background: var(--color-sidebar-border);
  margin: 4px 0;
}

/* ── Knowledge Button ────────────────────────────────────────── */
.knowledge-btn {
  width: 100%;
  padding: 10px 12px;
  border: 2px dashed #999;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-sidebar-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-sans);
  margin-bottom: 8px;
}
.knowledge-btn:hover {
  border-color: #000;
  color: #000;
  background: var(--color-sidebar-hover);
}

/* ── Knowledge Modal ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}
.modal-panel {
  width: 640px;
  max-width: 90vw;
  max-height: 80vh;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 40px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 12px;
  flex-shrink: 0;
}
.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}
.modal-close {
  width: 30px; height: 30px;
  border: none;
  background: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--color-sidebar-muted);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.modal-close:hover {
  background: var(--color-bg);
  color: #000;
}

.modal-tabs {
  display: flex;
  gap: 0;
  padding: 0 22px;
  border-bottom: 2px solid var(--color-border);
  flex-shrink: 0;
}
.modal-tab {
  padding: 10px 18px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-sidebar-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
  font-family: var(--font-sans);
}
.modal-tab:hover { color: #000; }
.modal-tab.active {
  color: #000;
  font-weight: 700;
  border-bottom-color: #000;
}

.modal-tab-content {
  padding: 18px 22px 22px;
  overflow-y: auto;
  flex: 1;
}

/* Ingest tab */
.ingest-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
}
.ingest-tab {
  flex: 1;
  padding: 8px 0;
  border: none;
  border-bottom: 2px solid var(--color-border);
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-sidebar-muted);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-sans);
}
.ingest-tab.active {
  color: #000;
  font-weight: 700;
  border-bottom-color: #000;
}
.ingest-url-input {
  width: 100%;
  padding: 14px;
  border: 2px solid #d0d0d0;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.2s;
}
.ingest-url-input:focus { border-color: #999; }
.ingest-url-hint {
  font-size: 11px;
  color: var(--color-sidebar-muted);
  margin-top: 8px;
  line-height: 1.5;
}
.ingest-textarea {
  width: 100%;
  min-height: 200px;
  padding: 14px;
  border: 2px solid #d0d0d0;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-sans);
  line-height: 1.7;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}
.ingest-textarea:focus { border-color: #999; }
.ingest-meta {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.ingest-meta input {
  flex: 1;
  padding: 8px 12px;
  border: 2px solid #d0d0d0;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--font-sans);
  outline: none;
}
.ingest-meta input:focus { border-color: #999; }
.ingest-submit {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  background: #000;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: opacity 0.15s;
}
.ingest-submit:hover { opacity: 0.85; }
.ingest-submit:disabled { opacity: 0.4; cursor: default; }
.ingest-status {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.6;
}
.ingest-status.success {
  background: var(--color-success-light);
  color: var(--color-success);
}
.ingest-status.error {
  background: var(--color-danger-light);
  color: var(--color-danger);
}

/* List tab */
.knowledge-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.knowledge-item {
  padding: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
}
.knowledge-item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.knowledge-item-title {
  font-size: 14px;
  font-weight: 600;
  color: #000;
}
.knowledge-item-meta {
  font-size: 11px;
  color: var(--color-sidebar-muted);
  margin-bottom: 4px;
}
.knowledge-item-summary {
  font-size: 12px;
  color: var(--color-text-secondary);
  line-height: 1.5;
}
.knowledge-item-delete {
  width: 24px; height: 24px;
  border: none;
  background: none;
  color: var(--color-sidebar-muted);
  cursor: pointer;
  border-radius: 50%;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.knowledge-item-delete:hover {
  background: var(--color-danger-light);
  color: var(--color-danger);
}
.knowledge-empty {
  text-align: center;
  padding: 40px 0;
  color: var(--color-sidebar-muted);
  font-size: 13px;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar { display: none; }
  #historyPanel { display: none; }
  .message { max-width: 95%; }
  .chat-messages { max-width: 100% !important; padding: 16px; }
  .input-container { max-width: 100% !important; }
  .command-palette { max-width: 100% !important; left: 16px; right: 16px; }
}
@media (max-width: 1024px) {
  #historyPanel { width: 220px; min-width: 220px; }
}

/* ── Top Bar Login Button ─────────────────────────────────────── */

.top-login-btn {
  padding: 6px 20px;
  background: #1a1a2e;
  color: #fff;
  border: none; border-radius: 8px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: background .2s;
  margin-right: 12px;
}

.top-login-btn:hover { background: #2d2d44; }

.top-user-area {
  display: flex; align-items: center; gap: 6px;
  margin-right: 12px;
}

.user-email {
  font-size: 12px; color: #666;
  max-width: 160px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

.logout-btn {
  background: none; border: 1px solid #ddd;
  border-radius: 6px; padding: 3px 10px;
  font-size: 12px; color: #999;
  cursor: pointer; transition: all .2s;
  white-space: nowrap;
}

.logout-btn:hover { border-color: #e74c3c; color: #e74c3c; }

/* ── Login Panel (Modal) ──────────────────────────────────────── */

.login-panel {
  background: #fff;
  border-radius: 20px;
  width: 420px; max-width: 92vw;
  padding: 40px 36px 32px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.28);
  position: relative;
  text-align: center;
  animation: loginFadeIn .25s ease;
}

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

.login-panel-close {
  position: absolute; top: 14px; right: 18px;
  background: none; border: none;
  font-size: 22px; color: #bbb;
  cursor: pointer; line-height: 1;
  padding: 4px;
}

.login-panel-close:hover { color: #555; }

.login-panel-top {
  margin-bottom: 28px;
}

.login-panel-top h3 {
  font-size: 18px; font-weight: 700;
  color: #1a1a2e; margin: 0 0 6px;
}

.login-panel-top p {
  font-size: 13px; color: #999; margin: 0;
}

.login-field {
  margin-bottom: 4px;
}

.login-input-v2 {
  width: 100%; padding: 14px 16px;
  border: 2px solid #e8e8e8;
  border-radius: 12px;
  font-size: 15px; outline: none;
  transition: border-color .2s, box-shadow .2s;
  box-sizing: border-box;
  text-align: center;
}

.login-input-v2:focus {
  border-color: #6c5ce7;
  box-shadow: 0 0 0 3px rgba(108,92,231,0.1);
}

.login-btn-v2 {
  width: 100%; padding: 14px;
  margin-top: 16px;
  background: #1a1a2e;
  color: #fff;
  border: none; border-radius: 12px;
  font-size: 15px; font-weight: 600;
  cursor: pointer;
  transition: background .2s, opacity .2s, transform .1s;
}

.login-btn-v2:hover { background: #2d2d44; }
.login-btn-v2:active { transform: scale(0.98); }
.login-btn-v2:disabled { opacity: 0.45; cursor: not-allowed; }

.login-hint {
  margin: 8px 0 0;
  font-size: 12px; color: #e74c3c;
  min-height: 18px;
}

.login-code-hint {
  font-size: 13px; color: #777;
  margin: 0 0 16px;
}

.login-code-hint strong { color: #1a1a2e; }

.code-input-row {
  display: flex; gap: 12px;
  justify-content: center;
  margin-bottom: 4px;
}

.code-digit-v2 {
  width: 48px; height: 56px;
  text-align: center;
  font-size: 24px; font-weight: 700;
  border: 2px solid #e8e8e8;
  border-radius: 12px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  -moz-appearance: textfield;
}

.code-digit-v2::-webkit-outer-spin-button,
.code-digit-v2::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}

.code-digit-v2:focus {
  border-color: #6c5ce7;
  box-shadow: 0 0 0 3px rgba(108,92,231,0.12);
}

.login-link {
  background: none; border: none;
  color: #6c5ce7; font-size: 13px;
  cursor: pointer; margin-top: 14px;
  padding: 6px;
}


.login-link:hover { text-decoration: underline; }
