:root {
  --bg: #f3f4f1;
  --surface: #ffffff;
  --surface-alt: #f8f9f6;
  --text: #1b211e;
  --muted: #66706a;
  --line: #dfe3de;
  --line-strong: #c9d0ca;
  --green: #146b4a;
  --green-soft: #e7f2ec;
  --green-dark: #0d4a34;
  --amber: #9a5d00;
  --amber-soft: #fff2d8;
  --red: #a2372d;
  --red-soft: #fbe9e6;
  --blue: #225f8a;
  --blue-soft: #e9f2f8;
  --shadow: 0 10px 28px rgba(24, 35, 29, 0.08);
  --sidebar: 248px;
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: var(--sidebar);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  color: #f7faf8;
  background: #16231d;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 25px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 6px;
  color: #102118;
  background: #83d4aa;
  font-size: 13px;
  font-weight: 800;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 17px; }
.brand small { margin-top: 2px; color: #aebbb4; }

.main-nav { display: grid; gap: 6px; padding-top: 20px; }

.nav-item {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: #cdd6d1;
  background: transparent;
  text-align: left;
}

.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: #26553f; }
.nav-index { color: #83d4aa; font-size: 11px; font-weight: 700; }

.sidebar-footer {
  display: grid;
  gap: 4px;
  margin-top: auto;
  padding: 16px 12px 0;
  border-top: 1px solid rgba(255,255,255,.12);
  color: #b4c0ba;
  font-size: 12px;
}

.sidebar-footer strong { color: #f3f7f5; font-size: 13px; }
.scope-label { color: #83d4aa; font-weight: 700; }

.workspace { margin-left: var(--sidebar); min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 78px;
  padding: 12px clamp(20px, 3vw, 44px);
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.96);
}

.search-wrap { position: relative; width: min(620px, 65%); }
.search-wrap > label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
.search-control { display: flex; }
.search-control input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 5px 0 0 5px;
  outline: none;
}
.search-control input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(20,107,74,.1); }
.search-control button {
  min-width: 64px;
  border: 1px solid var(--green);
  border-radius: 0 5px 5px 0;
  color: #fff;
  background: var(--green);
  font-weight: 700;
}

.search-results {
  position: absolute;
  top: 66px;
  right: 0;
  left: 0;
  max-height: 360px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: var(--shadow);
}

.search-result {
  display: block;
  width: 100%;
  padding: 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  background: transparent;
  text-align: left;
}
.search-result:last-child { border-bottom: 0; }
.search-result:hover { background: var(--surface-alt); }
.search-result small { display: block; margin-top: 3px; color: var(--muted); }

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 132px;
  padding: 3px;
  margin-left: auto;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-alt);
}

.mode-button { height: 30px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; }
.mode-button.active { color: #fff; background: var(--green); font-weight: 700; }
.mobile-menu { display: none; }

.sync-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px clamp(20px, 3vw, 44px);
  border-bottom: 1px solid #e4c984;
  background: var(--amber-soft);
}
.sync-banner[hidden] { display: none; }
.sync-banner div { display: flex; align-items: baseline; gap: 10px; }
.sync-banner span { color: #6f5a2d; font-size: 12px; }
.sync-banner button { min-height: 34px; padding: 0 13px; border: 1px solid var(--amber); border-radius: 5px; color: #fff; background: var(--amber); font-weight: 700; }
.sync-banner button:disabled { cursor: wait; opacity: .65; }
body.sync-offline #contentVersion::after { color: #ffcb78; content: " · 离线"; }

.loading-state, .load-error { max-width: 720px; margin: 12vh auto 0; padding: 36px; color: var(--muted); text-align: center; }
.load-error { border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.load-error h1 { color: var(--text); }

#app { padding: 34px clamp(20px, 3vw, 44px) 60px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  max-width: 1320px;
  margin: 0 auto 24px;
}
.eyebrow { margin: 0 0 7px; color: var(--green); font-size: 12px; font-weight: 800; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: 30px; line-height: 1.25; }
h2 { margin-bottom: 10px; font-size: 21px; line-height: 1.35; }
h3 { margin-bottom: 8px; font-size: 16px; line-height: 1.4; }
.page-head p { max-width: 760px; margin-bottom: 0; color: var(--muted); line-height: 1.7; }
.page-meta { flex: none; padding: 7px 10px; border-radius: 4px; color: var(--green-dark); background: var(--green-soft); font-weight: 700; }

.content-shell { max-width: 1320px; margin: 0 auto; }
.guide-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 22px; align-items: start; }

.panel {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 1px 1px rgba(24,35,29,.03);
}

.chapter-nav { position: sticky; top: 100px; overflow: hidden; }
.chapter-nav-head { padding: 16px; border-bottom: 1px solid var(--line); }
.chapter-nav-head strong { display: block; }
.chapter-nav-head small { color: var(--muted); }
.chapter-button {
  display: grid;
  grid-template-columns: 30px 1fr;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  background: transparent;
  text-align: left;
}
.chapter-button:last-child { border-bottom: 0; }
.chapter-button:hover { background: var(--surface-alt); }
.chapter-button.active { color: var(--green-dark); background: var(--green-soft); font-weight: 700; }
.chapter-num { color: var(--muted); font-size: 11px; }

.article { min-width: 0; padding: clamp(22px, 3vw, 38px); }
.article-lead { max-width: 860px; color: #49534d; font-size: 16px; line-height: 1.8; }
.article-section { padding: 24px 0; border-top: 1px solid var(--line); }
.article-section:first-of-type { margin-top: 24px; }
.article-section p, .article-section li { line-height: 1.75; }
.article-section ul, .article-section ol { padding-left: 22px; }
.article-section li + li { margin-top: 7px; }

.stage-playbook { margin-top: 30px; border-top: 2px solid var(--text); }
.playbook-section { padding: 28px 0; border-bottom: 1px solid var(--line); }
.section-kicker { margin-bottom: 7px; color: var(--green); font-size: 11px; font-weight: 800; }
.playbook-section > h3 { margin-bottom: 18px; font-size: 18px; }

.objective-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; overflow: hidden; border: 1px solid var(--line); border-radius: 5px; background: var(--line); }
.objective-item { min-height: 112px; padding: 16px; background: var(--surface-alt); }
.objective-item span { display: block; margin-bottom: 16px; color: var(--green); font-size: 11px; font-weight: 800; }
.objective-item p { margin: 0; line-height: 1.65; font-weight: 700; }

.action-sequence { counter-reset: action; }
.action-step { display: grid; grid-template-columns: 38px 1fr; gap: 14px; padding: 18px 0; border-top: 1px solid var(--line); }
.action-step:first-child { border-top: 0; padding-top: 0; }
.action-number { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 50%; color: #fff; background: var(--green); font-size: 12px; font-weight: 800; }
.action-step h4 { margin: 3px 0 7px; font-size: 15px; }
.action-step p { margin-bottom: 9px; color: #49534d; line-height: 1.75; }
.action-check { padding: 9px 11px; border-left: 3px solid var(--green); background: var(--green-soft); color: var(--green-dark); font-size: 12px; line-height: 1.6; }

.reopen-decision { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 18px 0 24px; border: 1px solid var(--line); background: var(--line); }
.reopen-column { padding: 17px; background: var(--green-soft); }
.reopen-column.danger-column { background: var(--red-soft); }
.reopen-column h4 { margin: 0 0 9px; color: var(--green-dark); font-size: 14px; }
.reopen-column.danger-column h4 { color: var(--red); }
.reopen-column ul { margin: 0; padding-left: 19px; }
.reopen-column li { margin-top: 7px; line-height: 1.65; }

.scenario-table-wrap { width: 100%; max-width: 100%; min-width: 0; overflow-x: auto; border: 1px solid var(--line); border-radius: 5px; }
.scenario-table { width: 100%; min-width: 790px; border-collapse: collapse; table-layout: fixed; }
.scenario-table th { padding: 11px 12px; color: #fff; background: #24372e; font-size: 12px; text-align: left; }
.scenario-table th:first-child { width: 21%; }
.scenario-table th:nth-child(2) { width: 27%; }
.scenario-table th:nth-child(3) { width: 30%; }
.scenario-table th:nth-child(4) { width: 22%; }
.scenario-table td { padding: 13px 12px; border-top: 1px solid var(--line); color: #4b554f; line-height: 1.6; vertical-align: top; }
.scenario-table tbody tr:nth-child(even) { background: var(--surface-alt); }
.scenario-table td:first-child { color: var(--text); }
.scenario-table td:last-child { color: var(--red); }

.gate-section { border-bottom: 0; }
.gate-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 18px; }
.gate-item { display: grid; grid-template-columns: 18px 1fr; gap: 9px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.gate-item span { width: 15px; height: 15px; margin-top: 3px; border: 2px solid var(--green); border-radius: 3px; }
.gate-item p { margin: 0; line-height: 1.6; }

.principle-divider { display: flex; align-items: center; gap: 12px; margin: 12px 0 0; color: var(--muted); font-size: 11px; font-weight: 800; }
.principle-divider::before, .principle-divider::after { height: 1px; flex: 1; background: var(--line-strong); content: ""; }

.phase-strip {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 22px;
}
.phase-step { min-height: 66px; padding: 10px; border-top: 4px solid var(--line-strong); background: #fff; font-size: 12px; }
.phase-step.active { border-color: var(--green); background: var(--green-soft); font-weight: 700; }
.phase-step span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; }

.callout { padding: 16px 18px; border-left: 4px solid var(--blue); border-radius: 0 5px 5px 0; background: var(--blue-soft); line-height: 1.7; }
.callout.warning { border-color: var(--amber); background: var(--amber-soft); }
.callout.danger { border-color: var(--red); background: var(--red-soft); }
.callout.success { border-color: var(--green); background: var(--green-soft); }
.callout strong { display: block; margin-bottom: 4px; }

.formula { margin: 14px 0; padding: 14px 16px; border: 1px dashed var(--line-strong); border-radius: 5px; background: var(--surface-alt); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; line-height: 1.7; }
.metric-grid, .scenario-grid, .sop-grid, .calculator-grid, .glossary-grid { display: grid; gap: 14px; }
.metric-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
.scenario-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
.sop-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
.calculator-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
.glossary-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }

.metric-card, .scenario-card, .sop-card, .calculator-card, .glossary-card { padding: 18px; }
.metric-card small, .scenario-card small, .sop-card small { color: var(--muted); }
.metric-card strong { display: block; margin: 8px 0 4px; font-size: 20px; }
.metric-card p, .scenario-card p, .sop-card p, .glossary-card p { margin-bottom: 0; color: var(--muted); line-height: 1.6; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; }
.status::before { width: 7px; height: 7px; border-radius: 50%; background: currentColor; content: ""; }
.status.green { color: var(--green); }
.status.amber { color: var(--amber); }
.status.red { color: var(--red); }

.primary-button, .secondary-button, .text-button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 5px;
  font-weight: 700;
}
.primary-button { border: 1px solid var(--green); color: #fff; background: var(--green); }
.primary-button:hover { background: var(--green-dark); }
.secondary-button { border: 1px solid var(--line-strong); color: var(--text); background: #fff; }
.secondary-button:hover { border-color: var(--green); color: var(--green); }
.text-button { min-height: auto; padding: 0; border: 0; color: var(--green); background: transparent; }

.scenario-card, .sop-card { display: flex; flex-direction: column; align-items: flex-start; min-height: 190px; }
.scenario-card .primary-button, .sop-card .secondary-button { margin-top: auto; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 16px; }
.tag { padding: 4px 7px; border-radius: 3px; color: #4c5751; background: #edf0ed; font-size: 11px; }

.filter-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.filter-button { min-height: 34px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--muted); background: #fff; }
.filter-button.active { border-color: var(--green); color: #fff; background: var(--green); }

.diagnosis-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); gap: 20px; align-items: start; }
.diagnosis-form, .diagnosis-result { padding: 24px; }
.diagnosis-result { position: sticky; top: 100px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.field label { display: block; margin-bottom: 6px; color: #4c5751; font-size: 12px; font-weight: 700; }
.field input, .field select {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
}
.field input:focus, .field select:focus { border-color: var(--green); outline: 3px solid rgba(20,107,74,.1); }
.field-help { margin-top: 5px; color: var(--muted); font-size: 11px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }

.finding { padding: 14px 0; border-bottom: 1px solid var(--line); }
.finding:last-child { border-bottom: 0; }
.finding-head { display: flex; justify-content: space-between; gap: 12px; }
.finding-score { flex: none; color: var(--red); font-size: 12px; font-weight: 800; }
.finding p { margin: 6px 0 0; color: var(--muted); line-height: 1.6; }
.action-list { padding-left: 20px; line-height: 1.7; }
.result-empty { padding: 30px 10px; color: var(--muted); text-align: center; }

.sop-detail { padding: clamp(20px, 3vw, 34px); }
.sop-head { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.sop-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.checklist { display: grid; gap: 9px; padding: 18px 0; }
.check-item { display: grid; grid-template-columns: 22px 1fr; gap: 10px; align-items: start; padding: 12px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface-alt); }
.check-item input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--green); }
.check-item.done span { color: var(--muted); text-decoration: line-through; }
.progress-bar { height: 8px; overflow: hidden; border-radius: 4px; background: #e6e9e6; }
.progress-bar span { display: block; height: 100%; background: var(--green); transition: width .2s ease; }
.progress-label { margin-top: 6px; color: var(--muted); font-size: 12px; }

.calculator-card h2 { font-size: 18px; }
.calc-output { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.calc-result { padding: 13px; border-radius: 5px; background: var(--green-soft); }
.calc-result span { display: block; color: var(--muted); font-size: 11px; }
.calc-result strong { display: block; margin-top: 4px; color: var(--green-dark); font-size: 21px; }

.glossary-card { min-height: 132px; }
.glossary-card h3 { color: var(--green-dark); }
.pro-only { display: none; }
body.pro-mode .newbie-only { display: none; }
body.pro-mode .pro-only { display: block; }

.empty-state { padding: 40px; color: var(--muted); text-align: center; }
.mobile-backdrop { display: none; }

@media (max-width: 1050px) {
  .metric-grid, .scenario-grid, .glossary-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .diagnosis-layout { grid-template-columns: 1fr; }
  .diagnosis-result { position: static; }
  .objective-grid { grid-template-columns: 1fr; }
  .objective-item { min-height: auto; }
}

@media (max-width: 800px) {
  :root { --sidebar: 270px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  body.menu-open .sidebar { transform: translateX(0); }
  .mobile-backdrop { position: fixed; inset: 0; z-index: 19; background: rgba(10,18,14,.42); }
  body.menu-open .mobile-backdrop { display: block; }
  .workspace { margin-left: 0; }
  .topbar { gap: 12px; padding: 10px 14px; }
  .mobile-menu { display: block; height: 38px; border: 1px solid var(--line-strong); border-radius: 5px; background: #fff; }
  .search-wrap { width: auto; flex: 1; }
  .search-wrap > label { display: none; }
  .search-results { top: 45px; }
  .mode-switch { width: 112px; }
  #app { padding: 22px 14px 48px; }
  .guide-layout { grid-template-columns: 1fr; }
  .guide-layout > * { min-width: 0; }
  .chapter-nav { position: static; }
  .chapter-buttons { display: flex; overflow-x: auto; }
  .chapter-button { flex: 0 0 190px; border-right: 1px solid var(--line); border-bottom: 0; }
  .phase-strip { grid-template-columns: repeat(8, 145px); overflow-x: auto; }
}

@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; }
  .search-wrap { order: 3; flex-basis: 100%; }
  .page-head { align-items: flex-start; flex-direction: column; }
  h1 { font-size: 25px; }
  .metric-grid, .scenario-grid, .sop-grid, .calculator-grid, .glossary-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .article, .diagnosis-form, .diagnosis-result { padding: 18px; }
  .sop-head { flex-direction: column; }
  .calc-output { grid-template-columns: 1fr; }
  .gate-list { grid-template-columns: 1fr; }
  .action-step { grid-template-columns: 32px 1fr; gap: 10px; }
  .reopen-decision { grid-template-columns: 1fr; }
  .sync-banner { align-items: flex-start; }
  .sync-banner div { display: block; }
  .sync-banner span { display: block; margin-top: 3px; }
}
