:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --card-soft: #f8fafc;
  --line: #e5eaf0;
  --text: #1c2a3a;
  --muted: #69757f;
  --faint: #9aa6b2;
  --primary: #2f6f8f;
  --primary-hover: #387ea1;
  --primary-soft: #e9f3f8;
  --green: #2f8f66;
  --green-soft: #e7f5ee;
  --amber: #c2902c;
  --amber-soft: #fff4db;
  --red: #b65656;
  --red-soft: #f9ebeb;
  --blue: #3a6ea5;
  --shadow: 0 18px 45px rgba(28, 42, 58, 0.09);
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --font: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", Arial, sans-serif;
  --mono: "DIN Alternate", "Roboto Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0; color: var(--text); font-family: var(--font);
  background: radial-gradient(circle at 12% 0%, rgba(47,111,143,.08), transparent 30%), linear-gradient(180deg, #f7fafc 0%, var(--bg) 50%, #eef2f6 100%);
  min-height: 100vh;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { width: min(1480px, calc(100vw - 48px)); margin: 0 auto; padding: 24px 0 56px; }

.topbar {
  display: flex; justify-content: space-between; gap: 24px; align-items: center;
  padding: 18px 22px; margin-bottom: 20px;
  background: rgba(255,255,255,.85); border: 1px solid rgba(229,234,240,.9);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); backdrop-filter: blur(12px);
  position: sticky; top: 12px; z-index: 30;
}
.brand-block h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.brand-block p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.eyebrow { display: inline-flex; color: var(--primary); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; font-weight: 800; }
.toolbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.save-status { color: var(--muted); font-size: 13px; border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; background: var(--card-soft); }
.perspective-switch { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 6px 3px 12px; background: var(--primary-soft); }
.perspective-switch .ps-label { color: var(--primary); font-size: 12px; font-weight: 700; }
.perspective-switch .ps-select { border: 0; background: #fff; border-radius: 999px; min-height: 30px; padding: 0 10px; color: var(--text); font-size: 13px; max-width: 160px; }
.perspective-banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 18px; margin-bottom: 16px; border: 1px solid #cfe2ec; border-radius: var(--radius-md); background: linear-gradient(90deg, var(--primary-soft), #fff); }
.perspective-banner .pb-tag { background: var(--primary); color: #fff; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700; }
.perspective-banner strong { font-size: 16px; }
.perspective-banner .pb-meta { color: var(--muted); font-size: 13px; }
.perspective-banner .link-btn { margin-left: auto; }

.primary-btn, .ghost-btn, .link-btn, .icon-btn { border: 0; border-radius: 999px; min-height: 38px; padding: 0 16px; transition: .18s ease; }
.primary-btn { background: var(--primary); color: #fff; box-shadow: 0 8px 18px rgba(47,111,143,.22); }
.primary-btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
.ghost-btn { color: var(--primary); border: 1px solid var(--line); background: #fff; }
.ghost-btn:hover { border-color: #c7d4df; background: var(--primary-soft); }
.ghost-btn.danger { color: var(--red); }
.link-btn { color: var(--primary); background: transparent; padding: 0 6px; min-height: auto; }
.icon-btn { width: 40px; padding: 0; font-size: 26px; color: var(--muted); background: var(--card-soft); }

.card { background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.hero-grid { display: grid; grid-template-columns: 0.92fr 1.58fr; grid-template-areas: "decision metrics" "safety safety"; gap: 18px; }
.decision-card { grid-area: decision; padding: 24px; display: flex; flex-direction: column; min-height: 300px; }
.metrics-card { grid-area: metrics; padding: 22px; }
.safety-card { grid-area: safety; padding: 22px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-heading h2 { font-size: 17px; margin: 4px 0 0; }
.muted { color: var(--muted); font-size: 13px; }

.decision-topline { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.traffic-light { width: 54px; height: 54px; border-radius: 50%; display: inline-block; box-shadow: inset 0 0 0 8px rgba(255,255,255,.55), 0 10px 24px rgba(28,42,58,.12); }
.traffic-light.green { background: var(--green); }
.traffic-light.amber { background: var(--amber); }
.traffic-light.red { background: var(--red); }
.decision-level { font-size: 14px; font-weight: 800; color: var(--muted); }
.decision-card h2 { font-size: 30px; letter-spacing: -0.03em; margin: 0 0 10px; }
.reason-list { margin: 18px 0 0; padding-left: 18px; color: var(--text); line-height: 1.7; }
.risk-tags { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 18px; }
.tag { display: inline-flex; border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 700; background: var(--primary-soft); color: var(--primary); }
.tag.green { background: var(--green-soft); color: var(--green); }
.tag.amber { background: var(--amber-soft); color: var(--amber); }
.tag.red { background: var(--red-soft); color: var(--red); }

.metrics-grid { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 12px; }
.metric-item { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-md); background: linear-gradient(180deg, #fff, #f9fbfd); min-height: 116px; }
.metric-label { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.metric-value { font-family: var(--mono); font-size: 26px; font-weight: 800; letter-spacing: -0.04em; }
.metric-unit { font-size: 12px; color: var(--faint); margin-left: 4px; }
.metric-delta { margin-top: 8px; color: var(--muted); font-size: 12px; }
.metric-item.good .metric-value, .positive { color: var(--green); }
.metric-item.warn .metric-value { color: var(--amber); }
.metric-item.bad .metric-value, .negative { color: var(--red); }
.metric-item.kpi { border-color: #cfe2ec; background: linear-gradient(180deg, #fff, var(--primary-soft)); }

.safety-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.safety-item { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--card-soft); }
.safety-title { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.safety-percent { font-family: var(--mono); font-weight: 800; color: var(--text); }
.progress-track { height: 10px; background: #e8edf2; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; min-width: 3px; }
.progress-fill.green { background: var(--green); }
.progress-fill.amber { background: var(--amber); }
.progress-fill.red { background: var(--red); }
.safety-note { margin-top: 8px; font-size: 12px; color: var(--faint); }

.quick-edit, .bi-grid, .module-section, .trend-section, .yearly-section { margin-top: 18px; }
.quick-edit { padding: 22px; }
.quick-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 12px; }
.input-card { border: 1px solid var(--line); border-radius: var(--radius-md); padding: 12px; background: #fff; }
.input-card label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.input-wrap { display: flex; align-items: center; gap: 6px; }
.input-wrap input, .drawer-form input, .drawer-form select { width: 100%; border: 1px solid #dbe3ea; border-radius: 10px; min-height: 38px; padding: 8px 10px; color: var(--text); background: #fff; }
.input-wrap input:focus, .drawer-form input:focus, .drawer-form select:focus { outline: 2px solid rgba(47,111,143,.16); border-color: var(--primary); }
.input-unit { color: var(--faint); font-size: 12px; min-width: fit-content; }

.trend-section { padding: 22px; }
.trend-chart { width: 100%; overflow-x: auto; position: relative; }
.trend-chart svg { display: block; width: 100%; height: auto; }
.trend-chart .trend-hit { cursor: crosshair; }
.trend-tooltip { position: absolute; display: none; z-index: 5; min-width: 184px; background: rgba(28,42,58,.95); color: #fff; border-radius: 10px; padding: 10px 12px; font-size: 12px; box-shadow: 0 10px 26px rgba(0,0,0,.22); pointer-events: none; }
.trend-tooltip .tt-title { font-weight: 700; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid rgba(255,255,255,.18); white-space: nowrap; }
.trend-tooltip .tt-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.trend-tooltip .tt-dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; flex: none; }
.trend-tooltip .tt-label { color: #c7d3de; }
.trend-tooltip .tt-val { margin-left: auto; font-family: var(--mono); font-weight: 700; }
.trend-legend { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 12px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.bi-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 18px; }
.chart-card { padding: 22px; min-height: 260px; }
.bar-row { display: grid; grid-template-columns: 92px 1fr 105px; align-items: center; gap: 12px; margin: 14px 0; }
.bar-label { color: var(--muted); font-size: 13px; }
.bar-track { height: 18px; background: #edf2f6; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #7da6bd); border-radius: 999px; }
.bar-value { font-family: var(--mono); font-size: 13px; text-align: right; }
.waterfall { display: grid; gap: 12px; }
.flow-item { display: grid; grid-template-columns: 120px 1fr 110px; align-items: center; gap: 12px; }
.flow-track { height: 12px; background: #edf2f6; border-radius: 999px; overflow: hidden; }
.flow-fill { height: 100%; border-radius: 999px; }
.flow-fill.in { background: var(--green); }
.flow-fill.out { background: var(--red); }
.flow-fill.neutral { background: var(--primary); }

.cost-chart .cost-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.cost-donut { flex: none; }
.cost-legend { display: grid; gap: 7px; flex: 1; min-width: 180px; }
.cost-legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.cost-legend-item .cl-label { color: var(--muted); min-width: 64px; }
.cost-legend-item .cl-val { margin-left: auto; font-family: var(--mono); }
.sensitivity-chart svg, .cumulative-chart svg { display: block; width: 100%; height: auto; }
.chart-tooltip { position: fixed; display: none; z-index: 200; max-width: 260px; background: rgba(28,42,58,.95); color: #fff; border-radius: 10px; padding: 9px 12px; font-size: 12px; line-height: 1.6; box-shadow: 0 10px 26px rgba(0,0,0,.22); pointer-events: none; }
.chart-tooltip b { font-size: 13px; }

.stress-section { padding: 22px; }
.stress-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stress-item { border: 1px solid var(--line); border-radius: var(--radius-md); background: linear-gradient(180deg, #fff, #fff8f8); padding: 14px; }
.stress-item.be-ok { background: linear-gradient(180deg, #fff, var(--green-soft)); border-color: #cfe7da; }
.stress-item.be-risk { background: linear-gradient(180deg, #fff, var(--red-soft)); border-color: #eccccc; }
.stress-item span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.stress-item strong { display: block; font-family: var(--mono); font-size: 22px; margin-bottom: 6px; }
.stress-item em { display: block; font-style: normal; font-size: 12px; color: var(--muted); }

.yearly-section { padding: 22px; }
.yearly-table-wrap { overflow-x: auto; max-height: 0; transition: max-height .3s ease; }
.yearly-table-wrap.open { max-height: 1200px; }
table.yearly-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 880px; }
.yearly-table th, .yearly-table td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.yearly-table th:first-child, .yearly-table td:first-child { text-align: left; position: sticky; left: 0; background: #fff; }
.yearly-table thead th { background: var(--primary); color: #fff; font-weight: 700; position: sticky; top: 0; }
.yearly-table tbody tr:nth-child(even) { background: #f7f9fc; }
.yearly-table td.neg { color: var(--red); }
.yearly-table td.pos { color: var(--green); }
.yearly-table tr.payback-row { background: var(--green-soft) !important; font-weight: 700; }

.module-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.module-card { padding: 18px; }
.module-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.module-head h3 { margin: 0; font-size: 16px; }
.module-value { font-family: var(--mono); font-weight: 800; font-size: 24px; margin-bottom: 10px; }
.module-facts { display: grid; gap: 8px; color: var(--muted); font-size: 13px; }
.fact { display: flex; justify-content: space-between; gap: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.page-section-title { margin-bottom: 14px; }

.drawer-overlay { position: fixed; inset: 0; background: rgba(18,30,42,.32); z-index: 90; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(560px, 100vw); background: #fff; border-left: 1px solid var(--line); box-shadow: -24px 0 54px rgba(28,42,58,.18); z-index: 100; transform: translateX(104%); transition: .24s ease; display: flex; flex-direction: column; }
.drawer.open { transform: translateX(0); }
.drawer-header { padding: 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 14px; }
.drawer-header h2 { margin: 0; }
.drawer-tabs { display: flex; gap: 8px; overflow-x: auto; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.drawer-tab { border: 1px solid var(--line); color: var(--primary); background: #fff; border-radius: 999px; min-height: 34px; padding: 0 12px; white-space: nowrap; }
.drawer-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.drawer-form { padding: 18px 22px; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.field-note { color: var(--muted); font-size: 11px; margin-top: 6px; }

.ownership-editor { grid-column: 1 / -1; display: grid; gap: 12px; }
.ownership-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ownership-summary div { border: 1px solid var(--line); border-radius: 12px; background: var(--card-soft); padding: 12px; }
.ownership-summary span, .ownership-summary em, .investor-rate span { display: block; color: var(--muted); font-size: 11px; font-style: normal; }
.ownership-summary strong, .investor-rate strong { display: block; font-family: var(--mono); font-size: 18px; margin: 5px 0; }
.investor-list { display: grid; gap: 8px; }
.investor-row { border: 1px solid var(--line); border-radius: 14px; background: #fff; padding: 12px; display: grid; gap: 10px; }
.investor-row-top, .investor-row-bottom { display: grid; gap: 10px; }
.investor-row-top { grid-template-columns: 1.2fr .8fr; }
.investor-row-bottom { grid-template-columns: 1fr .82fr .82fr .78fr; align-items: end; }
.investor-row label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
.investor-row input, .investor-row select { min-height: 36px; border: 1px solid #dbe3ea; border-radius: 10px; padding: 7px 9px; color: var(--text); background: #fff; }
.investor-name[readonly] { background: var(--card-soft); color: var(--muted); }
.investor-rate { border: 1px solid var(--line); border-radius: 10px; background: var(--card-soft); padding: 8px 10px; min-height: 58px; }
.investor-actions { display: flex; justify-content: flex-end; gap: 8px; }
.investor-remove:disabled { opacity: .4; cursor: not-allowed; }

.drawer-preview { margin: 0 22px 18px; padding: 14px; box-shadow: none; }
.preview-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.preview-item { background: var(--card-soft); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.preview-item strong { display: block; font-family: var(--mono); font-size: 16px; }
.preview-item span { color: var(--muted); font-size: 11px; }
.drawer-footer { margin-top: auto; display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--line); background: #fff; }

body.compact .card { border-radius: 14px; }
body.compact .metric-item, body.compact .input-card, body.compact .module-card { padding: 11px; }
body.compact .metric-value { font-size: 22px; }

@media (max-width: 1180px) {
  .app-shell { width: min(100% - 28px, 1000px); }
  .hero-grid { grid-template-columns: 1fr; grid-template-areas: "decision" "metrics" "safety"; }
  .metrics-grid { grid-template-columns: repeat(3, 1fr); }
  .quick-grid { grid-template-columns: repeat(3, 1fr); }
  .safety-list, .module-grid, .stress-grid { grid-template-columns: repeat(2, 1fr); }
  .bi-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .app-shell { width: 100%; padding: 10px 12px 36px; }
  .topbar { position: static; flex-direction: column; align-items: stretch; border-radius: 18px; padding: 16px; }
  .toolbar-actions { justify-content: flex-start; }
  .metrics-grid, .safety-list, .quick-grid, .module-grid, .stress-grid { grid-template-columns: 1fr; }
  .drawer { width: 100vw; }
  .drawer-form { grid-template-columns: 1fr; padding: 16px; }
  .ownership-summary, .investor-row-top, .investor-row-bottom { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4; margin: 12mm; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  body { background: #fff !important; color: #111; }
  .app-shell { width: 100%; padding: 0; }
  .topbar { position: static; box-shadow: none; border: 0; padding: 0 0 12px; margin-bottom: 12px; }
  .toolbar-actions, .drawer, .drawer-overlay, .quick-edit, .link-btn { display: none !important; }
  .card { box-shadow: none; border-color: #d8dee6; break-inside: avoid; background: #fff; }
  .hero-grid, .bi-grid { display: block; }
  .decision-card, .metrics-card, .safety-card, .chart-card, .stress-section, .trend-section, .yearly-section, .module-card { margin-bottom: 10px; padding: 12px; }
  .bi-grid { display: block; }
  .chart-card { margin-bottom: 10px; }
  .metrics-grid, .safety-list, .stress-grid, .module-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .metric-item, .safety-item, .stress-item, .module-card { break-inside: avoid; min-height: auto; }
  .yearly-table-wrap { max-height: none !important; }
  .traffic-light { width: 24px; height: 24px; box-shadow: none; border: 2px solid currentColor; }
  .traffic-light.green { background: var(--green) !important; color: var(--green); }
  .traffic-light.amber { background: var(--amber) !important; color: var(--amber); }
  .traffic-light.red { background: var(--red) !important; color: var(--red); }
}
