
/* ========== CSS Custom Properties ========== */
:root {
  --green-50: #ecfdf5;
  --green-100: #d1fae5;
  --green-200: #a7f3d0;
  --green-300: #6ee7b7;
  --green-400: #34d399;
  --green-500: #10b981;
  --green-600: #059669;
  --green-700: #047857;
  --green-800: #065f46;
  --green-900: #064e3b;

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

  --yellow-100: #fef3c7;
  --yellow-400: #fbbf24;
  --yellow-500: #f59e0b;
  --red-100: #fee2e2;
  --red-500: #ef4444;
  --blue-100: #dbeafe;
  --blue-500: #3b82f6;
  --orange-100: #ffedd5;
  --orange-500: #f97316;

  --primary: var(--green-600);
  --primary-light: var(--green-100);
  --primary-bg: var(--green-50);
  --bg: #ffffff;
  --bg-secondary: var(--gray-50);
  --text: var(--gray-800);
  --text-secondary: var(--gray-500);
  --border: var(--gray-200);
  --sidebar-width: 280px;
  --topbar-height: 56px;
  --font-sans: "Inter", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 0.2s ease;
}

/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button { font: inherit; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-height) + 24px); }
body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ========== Top Navigation Bar ========== */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topbar-height);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 24px;
  min-width: 0;
  overflow: hidden;
}
.topbar-brand {
  font-weight: 700; font-size: 16px; color: var(--green-800);
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}
.topbar-brand .icon { font-size: 20px; }
.topbar-tabs {
  display: flex; gap: 4px;
  background: var(--gray-100);
  border-radius: 8px; padding: 3px;
  min-width: 0;
}
.topbar-tab {
  padding: 6px 16px; border-radius: 6px;
  font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; background: none;
  color: var(--gray-600);
  transition: color var(--transition), background-color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}
.topbar-tab:hover { color: var(--gray-800); }
.topbar-tab.active {
  background: var(--bg);
  color: var(--green-700);
  box-shadow: var(--shadow-sm);
}
.topbar-progress {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-secondary);
  flex-shrink: 0;
}
.topbar-progress-bar {
  width: 120px; height: 6px;
  background: var(--gray-200); border-radius: 3px;
  overflow: hidden;
}
.topbar-progress-fill {
  height: 100%; background: var(--green-500);
  border-radius: 3px;
  transition: width 0.4s ease;
}
.hamburger {
  display: none; background: none; border: none;
  cursor: pointer; padding: 4px; color: var(--gray-600);
  min-width: 40px; min-height: 40px;
  font-size: 20px;
}

/* ========== Sidebar ========== */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 50;
  transition: transform 0.3s ease;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 2px; }
.sidebar-section {
  padding: 0 12px;
  margin-bottom: 8px;
}
.sidebar-section-title {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--gray-400);
  padding: 8px 12px 4px;
}
.sidebar-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--gray-600);
  cursor: pointer;
  transition: color var(--transition), background-color var(--transition);
  text-decoration: none;
  line-height: 1.4;
}
.sidebar-item:hover {
  background: var(--gray-200);
  color: var(--gray-800);
}
.sidebar-item.active {
  background: var(--primary-light);
  color: var(--green-800);
  font-weight: 500;
}
.sidebar-item .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gray-300);
  flex-shrink: 0;
}
.sidebar-item.active .dot { background: var(--green-500); }
.sidebar-sub { padding-left: 16px; }
.sidebar-sub .sidebar-item { font-size: 12px; padding: 4px 12px; }

/* ========== Main Content ========== */
.main {
  margin-left: var(--sidebar-width);
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
}
.content-section { display: none; }
.content-section.active { display: block; }
.content-wrapper {
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 48px 80px;
}

/* ========== Typography ========== */
h1 {
  font-size: 28px; font-weight: 800;
  color: var(--gray-900);
  margin-bottom: 8px;
  line-height: 1.3;
}
h2 {
  font-size: 22px; font-weight: 700;
  color: var(--gray-900);
  margin-top: 48px; margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--green-200);
  line-height: 1.3;
  scroll-margin-top: calc(var(--topbar-height) + 24px);
}
h3 {
  font-size: 17px; font-weight: 600;
  color: var(--gray-800);
  margin-top: 32px; margin-bottom: 12px;
  scroll-margin-top: calc(var(--topbar-height) + 24px);
}
h4 {
  font-size: 15px; font-weight: 600;
  color: var(--gray-700);
  margin-top: 24px; margin-bottom: 8px;
}
p { margin-bottom: 12px; }
ul, ol { margin-bottom: 12px; padding-left: 24px; }
li { margin-bottom: 6px; }
li > ul, li > ol { margin-top: 6px; margin-bottom: 0; }
strong { color: var(--gray-900); font-weight: 600; }
hr {
  border: none; height: 1px;
  background: var(--gray-200);
  margin: 40px 0;
}

/* ========== Section Hero ========== */
.section-hero {
  background: linear-gradient(135deg, var(--green-50) 0%, var(--green-100) 100%);
  border: 1px solid var(--green-200);
  border-radius: var(--radius-lg);
  padding: 32px;
  margin-bottom: 32px;
}
.section-hero h1 { color: var(--green-900); margin-bottom: 8px; }
.section-hero .subtitle {
  color: var(--green-700); font-size: 15px;
  line-height: 1.6;
}

/* ========== Progress Timeline ========== */
.timeline {
  display: flex; align-items: flex-start;
  gap: 0; margin: 32px 0 40px;
  padding: 24px 0;
  overflow-x: auto;
}
.timeline-step {
  flex: 1; min-width: 140px;
  text-align: center; position: relative;
}
.timeline-step::after {
  content: ''; position: absolute;
  top: 18px; left: calc(50% + 20px); right: calc(-50% + 20px);
  height: 2px; background: var(--gray-200);
}
.timeline-step:last-child::after { display: none; }
.timeline-dot {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--gray-200);
  color: var(--gray-500);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 8px;
  font-size: 13px; font-weight: 700;
  position: relative; z-index: 1;
  transition: all 0.3s ease;
}
.timeline-step.status-progress .timeline-dot {
  background: var(--yellow-400); color: #fff;
  box-shadow: 0 0 0 4px var(--yellow-100);
}
.timeline-step.status-done .timeline-dot {
  background: var(--green-500); color: #fff;
  box-shadow: 0 0 0 4px var(--green-100);
}
.timeline-step.status-done::after { background: var(--green-300); }
.timeline-label {
  font-size: 11px; font-weight: 600;
  color: var(--gray-500);
  line-height: 1.3;
}
.timeline-step.status-progress .timeline-label { color: var(--yellow-500); }
.timeline-step.status-done .timeline-label { color: var(--green-600); }

/* ========== Stage Cards ========== */
.stage-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 32px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.3s ease;
}
.stage-card:hover { box-shadow: var(--shadow-md); }
.stage-header {
  display: flex; align-items: center; gap: 16px;
  flex-wrap: wrap;
  padding: 20px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}
.stage-number {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px;
  flex-shrink: 0;
}
.stage-number.s0 { background: var(--gray-200); color: var(--gray-600); }
.stage-number.s1 { background: var(--green-100); color: var(--green-700); }
.stage-number.s2 { background: var(--blue-100); color: var(--blue-500); }
.stage-number.s3 { background: var(--orange-100); color: var(--orange-500); }
.stage-number.s4 { background: var(--green-100); color: var(--green-700); }
.stage-title-area { flex: 1; min-width: 0; }
.stage-title {
  font-size: 17px; font-weight: 700;
  color: var(--gray-900); margin: 0;
}
.stage-subtitle {
  font-size: 12px; color: var(--text-secondary);
  margin-top: 2px;
}
.status-badge {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 40px; padding: 4px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
  cursor: pointer; border: none;
  transition: opacity var(--transition), transform var(--transition), background-color var(--transition);
  user-select: none;
  flex-shrink: 0;
}
.status-badge.not-started {
  background: var(--gray-100); color: var(--gray-500);
}
.status-badge.in-progress {
  background: var(--yellow-100); color: var(--yellow-500);
}
.status-badge.completed {
  background: var(--green-100); color: var(--green-600);
}
.status-badge:hover { opacity: 0.8; transform: scale(1.02); }
.stage-body { padding: 24px; }

/* ========== Tables ========== */
.table-wrapper { overflow-x: auto; margin: 16px 0; border-radius: var(--radius); }
table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
thead th {
  background: var(--gray-800);
  color: #fff;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
thead th:first-child { border-radius: var(--radius) 0 0 0; }
thead th:last-child { border-radius: 0 var(--radius) 0 0; }
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: top;
}
tbody tr:nth-child(even) { background: var(--gray-50); }
tbody tr:hover { background: var(--green-50); }
tbody tr:last-child td { border-bottom: none; }

/* ========== Code Blocks ========== */
code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--gray-100);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--green-800);
}
pre {
  background: var(--gray-900);
  color: #e5e7eb;
  padding: 20px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 16px 0;
  font-size: 13px;
  line-height: 1.6;
}
pre code {
  background: none; padding: 0;
  color: inherit;
}
.code-comment { color: var(--gray-400); }
.code-keyword { color: #a78bfa; }
.code-string { color: #34d399; }
.code-symbol { color: #fbbf24; }

/* ========== Blockquotes / Callouts ========== */
blockquote {
  border-left: 3px solid var(--green-400);
  background: var(--green-50);
  padding: 16px 20px;
  margin: 16px 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 14px;
  color: var(--green-800);
}
blockquote p:last-child { margin-bottom: 0; }
.callout {
  padding: 16px 20px;
  border-radius: var(--radius);
  margin: 16px 0;
  display: flex; gap: 12px;
  font-size: 14px;
}
.callout-icon { font-size: 18px; flex-shrink: 0; line-height: 1.5; }
.callout.warning {
  background: var(--yellow-100); border-left: 3px solid var(--yellow-500);
}
.callout.info {
  background: var(--blue-100); border-left: 3px solid var(--blue-500);
}
.callout.danger {
  background: var(--red-100); border-left: 3px solid var(--red-500);
}

/* ========== Details / Collapsible ========== */
details {
  margin: 12px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
details[open] { box-shadow: var(--shadow-sm); }
summary {
  min-height: 44px; padding: 12px 16px;
  background: var(--bg-secondary);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--gray-700);
  list-style: none;
  display: flex; align-items: center; gap: 8px;
  transition: background var(--transition);
}
summary:hover { background: var(--gray-200); }
summary::before {
  content: '▸'; font-size: 12px;
  transition: transform 0.2s;
  color: var(--gray-400);
}
details[open] summary::before { transform: rotate(90deg); }
summary::-webkit-details-marker { display: none; }
.details-body { padding: 16px; }

/* ========== Number List with Highlights ========== */
.assumption-list { counter-reset: assumption; list-style: none; padding-left: 0; }
.assumption-list > li {
  counter-increment: assumption;
  padding: 12px 16px 12px 48px;
  position: relative;
  margin-bottom: 8px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border-left: 3px solid var(--green-300);
}
.assumption-list > li::before {
  content: counter(assumption);
  position: absolute; left: 12px; top: 12px;
  width: 24px; height: 24px;
  background: var(--green-500); color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}

/* ========== Section Divider ========== */
.section-divider {
  display: flex; align-items: center;
  gap: 16px; margin: 48px 0 32px;
}
.section-divider::before, .section-divider::after {
  content: ''; flex: 1; height: 1px;
  background: var(--gray-200);
}
.section-divider span {
  font-size: 11px; font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  white-space: nowrap;
}

/* ========== Checklist ========== */
.checklist { list-style: none; padding-left: 0; }
.checklist li {
  padding: 8px 0 8px 28px;
  position: relative;
  border-bottom: 1px solid var(--gray-100);
}
.checklist li::before {
  content: '☐'; position: absolute; left: 0; top: 8px;
  color: var(--gray-400); font-size: 16px;
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .hamburger { display: block; }
  .content-wrapper { padding: 24px 20px 60px; }
}

/* ========== Accessibility ========== */
.skip-link {
  position: fixed; left: 16px; top: 8px; z-index: 200;
  padding: 8px 12px; border-radius: 6px;
  background: var(--gray-900); color: #fff;
  transform: translateY(-150%);
  transition: transform var(--transition);
}
.skip-link:focus { transform: translateY(0); }
a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 3px solid var(--blue-500);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========== Print ========== */
@media print {
  .topbar, .sidebar, .status-badge, .timeline { display: none !important; }
  .main { margin-left: 0; margin-top: 0; }
  .content-section { display: block !important; }
  .stage-card { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ========== Misc ========== */
.tag {
  display: inline-block; padding: 2px 8px;
  border-radius: 4px; font-size: 11px; font-weight: 600;
}
.tag-a { background: var(--green-100); color: var(--green-700); }
.tag-b { background: var(--yellow-100); color: var(--yellow-500); }
.tag-c { background: var(--gray-200); color: var(--gray-600); }
.muted { color: var(--text-secondary); font-size: 13px; }
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.3); z-index: 40;
  border: 0; cursor: pointer;
}
.sidebar-overlay.open { display: block; }



/* ========== Private editor shell ========== */
[hidden] { display: none !important; }
body.auth-locked { background: var(--gray-50); }
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
}
.auth-card {
  width: min(440px, 100%);
  background: var(--bg);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.auth-card h1 { margin-bottom: 8px; }
.auth-card p { color: var(--text-secondary); }
.form-field { margin-top: 18px; }
.form-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
}
.form-field input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
.form-field input:focus-visible {
  outline: 3px solid var(--blue-100);
  border-color: var(--blue-500);
}
.primary-button, .secondary-button, .ghost-button, .danger-button {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  transition: background-color var(--transition), color var(--transition), transform var(--transition);
}
.primary-button { background: var(--green-600); color: #fff; }
.primary-button:hover { background: var(--green-700); }
.secondary-button { background: var(--gray-100); color: var(--gray-800); }
.secondary-button:hover { background: var(--gray-200); }
.ghost-button { background: transparent; color: var(--gray-600); }
.ghost-button:hover { background: var(--gray-100); color: var(--gray-900); }
.danger-button { background: var(--red-100); color: #991b1b; }
.primary-button:active, .secondary-button:active, .ghost-button:active, .danger-button:active { transform: scale(0.96); }
.primary-button:disabled, .secondary-button:disabled, .ghost-button:disabled {
  cursor: wait;
  opacity: 0.6;
}
.auth-card .primary-button { width: 100%; margin-top: 22px; }
.form-message {
  min-height: 22px;
  margin-top: 12px;
  color: #b91c1c;
  font-size: 13px;
}
.app-shell { min-height: 100vh; }
.editor-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.save-state {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.edit-banner {
  position: sticky;
  top: var(--topbar-height);
  z-index: 45;
  margin-left: var(--sidebar-width);
  padding: 9px 24px;
  background: var(--yellow-100);
  color: #92400e;
  border-bottom: 1px solid #fcd34d;
  font-size: 13px;
}
.edit-banner + .main { margin-top: 0; }
.is-editing .content-wrapper {
  outline: 2px dashed var(--green-400);
  outline-offset: -10px;
}
.editable-content[contenteditable="true"] {
  caret-color: var(--green-700);
}
.editable-content[contenteditable="true"] :is(p, li, td, th, h1, h2, h3, h4, blockquote, summary):hover {
  background: rgba(16, 185, 129, 0.08);
}
.setup-card {
  max-width: 700px;
  margin: 72px auto;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg);
  box-shadow: var(--shadow);
}
.setup-card code { overflow-wrap: anywhere; }
.empty-document {
  padding: 64px 32px;
  text-align: center;
  color: var(--text-secondary);
}
.status-badge { margin-inline-start: auto; }
.topbar .editor-actions .primary-button,
.topbar .editor-actions .secondary-button,
.topbar .editor-actions .ghost-button {
  min-height: 36px;
  padding-block: 6px;
}
@media print {
  .editor-actions, .edit-banner { display: none !important; }
}

