:root {
  --bg: #ecebe6;
  --paper: #faf9f5;
  --surface: #ffffff;
  --surface-muted: #f2f3ef;
  --ink: #202b30;
  --muted: #687277;
  --line: #d4d6d1;
  --line-strong: #aeb5b2;
  --navy: #203747;
  --navy-soft: #e3eaed;
  --accent: #316d67;
  --accent-soft: #dce9e5;
  --sand: #9a7354;
  --olive: #7d8f68;
  --warn: #9a553f;
  --warn-soft: #f1e3de;
  --good: #2f6d50;
  --good-soft: #dfebe4;
  --shadow: 0 18px 45px rgba(31, 43, 48, 0.08);
  --radius: 8px;
  --font-sans: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
  --font-serif: "SimSun", "Songti SC", serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  line-height: 1.55;
}
button, input, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.app-shell {
  width: min(1520px, calc(100% - 32px));
  margin: 16px auto 38px;
  background: var(--paper);
  border: 1px solid rgba(32, 43, 48, 0.12);
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 88px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(300px, 1fr) auto minmax(360px, 1fr);
  align-items: center;
  gap: 22px;
  background: rgba(250, 249, 245, 0.96);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand-block { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark {
  width: 42px;
  height: 42px;
  border: 1px solid var(--navy);
  display: grid;
  place-items: center;
  font-family: Georgia, serif;
  font-size: 24px;
  color: var(--navy);
  flex: 0 0 auto;
}
.eyebrow, .section-kicker {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.075em;
  text-transform: uppercase;
}
h1, h2, h3, h4, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(19px, 2vw, 27px); font-weight: 650; letter-spacing: -0.025em; white-space: nowrap; }
h2 { margin-bottom: 0; font-size: clamp(23px, 2.8vw, 34px); line-height: 1.25; font-weight: 650; letter-spacing: -0.035em; }
h3 { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: -0.02em; }
h4 { margin: 0; font-size: 16px; font-weight: 650; }

.main-nav {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
}
.nav-button {
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  padding: 10px 16px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.nav-button:last-child { border-right: 0; }
.nav-button.active { background: var(--navy); color: #fff; }
.nav-button:hover:not(.active) { color: var(--accent); background: var(--surface-muted); }

.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
.save-state { color: var(--muted); font-size: 11px; white-space: nowrap; }
.quiet-button, .solid-button, .text-button {
  border: 1px solid var(--line-strong);
  background: transparent;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.solid-button { border-color: var(--navy); background: var(--navy); color: #fff; }
.quiet-button:hover, .text-button:hover { border-color: var(--accent); color: var(--accent); }
.solid-button:hover { background: #294657; }
.file-button { display: inline-flex; align-items: center; }

.view { min-height: 600px; }
.page-intro {
  padding: 38px 30px 26px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 40px;
}
.page-intro > p { max-width: 520px; margin: 0; color: var(--muted); font-size: 14px; }
.workbench-intro { background: var(--navy-soft); }

.view > section:not(.page-intro), .formula-section { padding: 28px 30px; border-bottom: 1px solid var(--line); }
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}
.section-heading > div { display: flex; align-items: baseline; gap: 12px; }
.section-number { color: var(--accent); font-family: Georgia, serif; font-size: 15px; }
.context-label {
  padding: 5px 9px;
  border: 1px solid #9dbab4;
  color: var(--accent);
  background: #edf4f1;
  font-size: 11px;
}
.context-label.neutral { border-color: var(--line-strong); color: var(--muted); background: var(--surface-muted); }

.scenario-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.scenario-card {
  min-height: 178px;
  padding: 18px;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
  position: relative;
}
.scenario-card:hover { background: var(--surface-muted); }
.scenario-card.active { color: #fff; background: var(--navy); }
.scenario-card .scenario-index { font-family: Georgia, serif; font-size: 12px; opacity: 0.65; }
.scenario-card strong { display: block; margin: 13px 0 8px; font-size: 18px; font-weight: 650; }
.scenario-card p { margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.scenario-card small { display: block; color: var(--muted); font-size: 11px; line-height: 1.55; }
.scenario-card.active p, .scenario-card.active small { color: rgba(255, 255, 255, 0.72); }
.scenario-card em { position: absolute; right: 15px; bottom: 13px; font-style: normal; font-size: 11px; opacity: 0.68; }

.metric-strip {
  display: grid;
  grid-template-columns: 1.1fr repeat(5, 1fr);
  border: 1px solid var(--line);
  background: var(--surface);
}
.metric-strip article { min-height: 124px; padding: 17px; border-right: 1px solid var(--line); }
.metric-strip article:last-child { border-right: 0; }
.metric-strip span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.metric-strip strong { display: block; font-size: clamp(21px, 2.2vw, 29px); line-height: 1.15; font-weight: 650; letter-spacing: -0.035em; }
.metric-strip small { display: block; margin-top: 10px; color: var(--muted); font-size: 11px; }
.metric-primary { background: var(--navy); color: #fff; }
.metric-primary span, .metric-primary small { color: rgba(255, 255, 255, 0.7); }
.status-value.good { color: var(--good); }
.status-value.warn { color: var(--warn); }

.decision-grid { display: grid; grid-template-columns: 1.18fr 1fr 1fr; gap: 14px; margin-top: 14px; }
.decision-panel { min-height: 238px; padding: 19px; border: 1px solid var(--line); background: var(--surface); }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.panel-heading p { margin-bottom: 3px; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; }
.panel-heading strong { color: var(--accent); font-size: 13px; }
.stacked-bar { display: flex; height: 20px; margin: 34px 0 18px; background: #e8e9e5; overflow: hidden; }
.bar-segment { height: 100%; min-width: 1px; }
.revenue-legend { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 18px; }
.legend-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; }
.legend-name { display: flex; align-items: center; gap: 7px; color: var(--muted); }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.price-scale { margin-top: 42px; }
.price-track { height: 8px; position: relative; background: linear-gradient(90deg, #e1d8d3 0%, #dce9e5 55%, #bad2c9 100%); }
.marker { position: absolute; top: -7px; width: 2px; height: 22px; background: var(--ink); }
.marker::after { content: ""; position: absolute; top: -3px; left: -3px; width: 8px; height: 8px; border-radius: 50%; background: inherit; }
.marker.min { left: 0; background: var(--warn); }
.marker.current { left: 50%; background: var(--navy); }
.marker.max { right: 0; background: var(--good); }
.price-label-row { display: flex; justify-content: space-between; gap: 8px; margin-top: 15px; font-size: 11px; color: var(--muted); }
.price-label-row span:nth-child(2) { color: var(--navy); font-weight: 700; text-align: center; }
.panel-footnote { margin: 23px 0 0; color: var(--muted); font-size: 11px; }
.diagnosis-panel { background: var(--surface-muted); }
.diagnosis-copy { min-height: 58px; margin: 22px 0 14px; font-size: 13px; color: #38484d; }
.diagnosis-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 12px; }
.diagnosis-list div { border-top: 1px solid var(--line); padding-top: 9px; }
.diagnosis-list span { display: block; color: var(--muted); font-size: 10px; }
.diagnosis-list strong { display: block; margin-top: 4px; font-size: 16px; }

.parameter-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.secondary-fields { margin-top: 12px; padding-top: 16px; border-top: 1px dashed var(--line-strong); }
.parameter-field { padding: 13px; border: 1px solid var(--line); background: var(--surface); min-width: 0; }
.parameter-label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 9px; }
.parameter-label-row label { font-size: 12px; font-weight: 650; }
.source-mini { color: var(--muted); font-size: 9px; white-space: nowrap; }
.number-input { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--ink); }
.number-input input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; padding: 6px 0; font-size: 19px; color: var(--ink); }
.number-input span { color: var(--muted); font-size: 10px; white-space: nowrap; }
.parameter-field.invalid { border-color: var(--warn); background: #fff9f7; }
.field-error { min-height: 14px; margin-top: 5px; color: var(--warn); font-size: 9px; }

.condition-summary { background: var(--navy); color: #fff; }
.condition-summary h3 { font-size: 22px; }
.condition-summary > p:not(.section-kicker) { max-width: 1120px; margin: 18px 0 22px; font-family: var(--font-serif); font-size: 17px; line-height: 1.9; }
.section-kicker.light { color: #9bc5bd; }
.summary-tags { display: flex; flex-wrap: wrap; gap: 7px; }
.summary-tags span { padding: 3px 7px; border: 1px solid rgba(255, 255, 255, 0.25); color: rgba(255, 255, 255, 0.72); font-size: 10px; }

.workbench-layout { display: grid; grid-template-columns: 190px minmax(0, 1fr); }
.workbench-nav { padding: 22px 18px; border-right: 1px solid var(--line); background: #f4f4f0; position: sticky; top: 89px; align-self: start; max-height: calc(100vh - 89px); }
.workbench-nav a { display: block; padding: 9px 4px; color: var(--muted); text-decoration: none; font-size: 12px; border-bottom: 1px solid rgba(174, 181, 178, 0.5); }
.workbench-nav a:hover { color: var(--accent); }
.workbench-content { min-width: 0; }
.work-section { padding: 28px 30px; border-bottom: 1px solid var(--line); scroll-margin-top: 100px; }
.work-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.work-section-heading > div:first-child { display: flex; align-items: baseline; gap: 11px; }
.work-section-heading > div:first-child span { color: var(--accent); font-family: Georgia, serif; font-size: 14px; }
.segmented-control { display: flex; border: 1px solid var(--line-strong); }
.segmented-control button { border: 0; border-right: 1px solid var(--line-strong); padding: 7px 11px; background: var(--surface); cursor: pointer; font-size: 11px; }
.segmented-control button:last-child { border-right: 0; }
.segmented-control button.active { background: var(--navy); color: #fff; }
.notice-line { margin-bottom: 17px; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); color: #38534f; font-size: 12px; }
.notice-line.muted { border-color: var(--line-strong); background: var(--surface-muted); color: var(--muted); }
.subsection-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 22px 0 10px; }
.subsection-title span { color: var(--muted); font-size: 10px; }
.inline-actions { display: flex; gap: 8px; margin: 0 0 14px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--muted); font-size: 11px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { width: 34px; height: 18px; background: #c9cdca; position: relative; transition: background 0.15s ease; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; background: #fff; transition: left 0.15s ease; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { left: 19px; }

.result-table-wrap { margin-top: 18px; overflow-x: auto; border: 1px solid var(--line); }
.data-table { width: 100%; min-width: 760px; border-collapse: collapse; background: var(--surface); font-size: 12px; }
.data-table th, .data-table td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.data-table th:first-child, .data-table td:first-child, .data-table th:last-child, .data-table td:last-child { text-align: left; }
.data-table thead th { background: var(--surface-muted); color: var(--muted); font-weight: 650; }
.data-table tfoot th { background: var(--navy-soft); color: var(--ink); }
.data-table tbody tr:last-child td { border-bottom: 0; }

.profit-waterfall, .break-even-grid, .utilization-grid, .cashflow-grid { display: grid; gap: 10px; margin-top: 18px; }
.profit-waterfall { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.break-even-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.utilization-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cashflow-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.result-box { min-height: 104px; padding: 14px; border: 1px solid var(--line); background: var(--surface); }
.result-box span { display: block; color: var(--muted); font-size: 10px; }
.result-box strong { display: block; margin-top: 8px; font-size: 21px; line-height: 1.15; }
.result-box small { display: block; margin-top: 8px; color: var(--muted); font-size: 9px; }
.result-box.good { border-top: 3px solid var(--good); }
.result-box.warn { border-top: 3px solid var(--warn); }
.result-box.disabled { color: var(--muted); background: var(--surface-muted); }
.utilization-bar { height: 5px; margin-top: 12px; background: #e5e6e2; overflow: hidden; }
.utilization-bar i { display: block; height: 100%; background: var(--accent); }
.result-box.warn .utilization-bar i { background: var(--warn); }

.scenario-comparison { min-width: 980px; }
.scenario-comparison tr.current td { background: #eef3f1; }
.customer-ranking { border: 1px solid var(--line); background: var(--surface); }
.customer-row { display: grid; grid-template-columns: 44px minmax(190px, 1.25fr) 100px 100px 150px minmax(230px, 1.5fr); align-items: center; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line); font-size: 11px; }
.customer-row:last-child { border-bottom: 0; }
.customer-row.header { background: var(--surface-muted); color: var(--muted); font-weight: 650; }
.customer-rank { font-family: Georgia, serif; font-size: 18px; color: var(--accent); }
.score-bar { height: 5px; background: #e4e6e2; margin-top: 5px; }
.score-bar i { display: block; height: 100%; background: var(--accent); }
.customer-note { color: var(--muted); }

.evidence-grid { padding: 28px 30px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; border-bottom: 1px solid var(--line); }
.evidence-card { padding: 17px; border: 1px solid var(--line); background: var(--surface); }
.evidence-card header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 9px; }
.evidence-card header span { color: var(--accent); font-size: 10px; }
.evidence-card p { margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.evidence-card a { color: var(--navy); font-size: 11px; text-decoration: none; border-bottom: 1px solid var(--navy); }
.formula-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.formula-grid article { padding: 16px; border: 1px solid var(--line); background: var(--surface); }
.formula-grid code { display: block; margin-top: 11px; white-space: normal; color: #405156; font-family: var(--font-serif); font-size: 13px; line-height: 1.75; }

footer { display: flex; justify-content: space-between; gap: 18px; padding: 17px 24px; color: var(--muted); font-size: 10px; }
.toast { position: fixed; right: 24px; bottom: 24px; padding: 10px 14px; background: var(--navy); color: #fff; font-size: 12px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: 0.18s ease; z-index: 100; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1250px) {
  .topbar { grid-template-columns: 1fr auto; }
  .main-nav { grid-column: 1 / -1; grid-row: 2; justify-self: start; }
  .top-actions { justify-self: end; }
  .metric-strip { grid-template-columns: repeat(3, 1fr); }
  .metric-strip article:nth-child(3n) { border-right: 0; }
  .decision-grid { grid-template-columns: 1fr; }
  .parameter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .profit-waterfall, .cashflow-grid { grid-template-columns: repeat(3, 1fr); }
  .utilization-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 880px) {
  .app-shell { width: 100%; margin: 0; border: 0; }
  .topbar { position: static; grid-template-columns: 1fr; align-items: start; }
  .top-actions { justify-content: flex-start; flex-wrap: wrap; }
  .save-state { width: 100%; }
  .page-intro { align-items: flex-start; flex-direction: column; padding: 28px 20px 22px; }
  .view > section:not(.page-intro), .formula-section { padding: 24px 20px; }
  .scenario-grid { grid-template-columns: repeat(2, 1fr); }
  .parameter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workbench-layout { grid-template-columns: 1fr; }
  .workbench-nav { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; overflow-x: auto; }
  .workbench-nav a { white-space: nowrap; border-bottom: 0; }
  .work-section { padding: 24px 20px; }
  .profit-waterfall, .break-even-grid, .cashflow-grid { grid-template-columns: repeat(2, 1fr); }
  .customer-row { grid-template-columns: 36px minmax(180px, 1fr) 80px 100px; }
  .customer-row > :nth-child(5), .customer-row > :nth-child(6) { display: none; }
  .evidence-grid, .formula-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .brand-mark { display: none; }
  h1 { white-space: normal; }
  .main-nav { width: 100%; }
  .nav-button { flex: 1; padding: 9px 7px; }
  .scenario-grid, .metric-strip, .parameter-grid { grid-template-columns: 1fr; }
  .metric-strip article { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric-strip article:last-child { border-bottom: 0; }
  .scenario-card { min-height: 154px; }
  .revenue-legend, .diagnosis-list { grid-template-columns: 1fr; }
  .work-section-heading { align-items: flex-start; flex-direction: column; }
  .profit-waterfall, .break-even-grid, .utilization-grid, .cashflow-grid { grid-template-columns: 1fr; }
  .segmented-control { width: 100%; }
  .segmented-control button { flex: 1; }
  .customer-row { grid-template-columns: 30px 1fr 72px; }
  .customer-row > :nth-child(4), .customer-row > :nth-child(5), .customer-row > :nth-child(6) { display: none; }
  footer { flex-direction: column; padding: 16px 20px; }
}

@media print {
  body { background: #fff; }
  .app-shell { width: 100%; margin: 0; box-shadow: none; border: 0; }
  .topbar { position: static; }
  .top-actions, .main-nav, .parameter-section, .workbench-nav { display: none !important; }
  .view { display: none !important; }
  #overviewView { display: block !important; }
}
