:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --surface: #ffffff;
  --ink: #17202a;
  --muted: #64717f;
  --line: #d9e1df;
  --accent: #19766f;
  --manual: #fff3cf;
  --manual-line: #ddb95d;
  --danger: #b13c48;
  --danger-bg: #fff1f2;
  --ok: #287a43;
  --ok-bg: #f2faf4;
  --shadow: 0 16px 38px rgba(28, 48, 54, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(25, 118, 111, 0.08), transparent 300px),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1320px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.compact-topbar {
  justify-content: space-between;
}

.topbar-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 720;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  font-weight: 780;
}

h2 {
  font-size: 18px;
  font-weight: 760;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cbd6d6;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  outline: none;
  padding: 8px 10px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(25, 118, 111, 0.14);
}

.toggle-button {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid rgba(25, 118, 111, 0.26);
  border-radius: 7px;
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  font-weight: 760;
}

.toggle-button:hover {
  background: #f5fbfa;
}

.page-link {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric {
  min-height: 118px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 24px rgba(30, 52, 58, 0.06);
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.metric .formula-note {
  line-height: 1.4;
}

.metric strong {
  display: block;
  margin: 12px 0 9px;
  color: var(--ink);
  font-size: 27px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.metric.strong {
  background: #f9fcfb;
  border-color: rgba(25, 118, 111, 0.32);
}

.metric.alert {
  border-color: rgba(40, 122, 67, 0.3);
  background: var(--ok-bg);
}

.metric.alert.danger {
  border-color: rgba(177, 60, 72, 0.35);
  background: var(--danger-bg);
}

.metric.alert.danger strong,
.danger-text {
  color: var(--danger);
}

.panel,
.sheet-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 17px 20px;
  border-bottom: 1px solid var(--line);
  background: #fbfdfd;
}

.panel-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.section-title span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.setup-panel {
  margin-bottom: 16px;
}

.manual-field {
  position: relative;
  min-height: 40px;
}

.manual-field input,
.manual-field select {
  border-color: var(--manual-line);
  background: var(--manual);
  font-weight: 720;
}

.calc-row > .manual-field > input,
.calc-row > .manual-field > select {
  min-height: 76px;
}

.manual-field::after {
  content: "手填";
  position: absolute;
  top: -7px;
  right: 8px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #9c7422;
  color: #fff;
  font-size: 11px;
  font-weight: 760;
}

.input-suffix {
  display: grid;
  grid-template-columns: 1fr 42px;
  align-items: center;
  height: 100%;
}

.input-suffix input {
  min-height: 76px;
  border-radius: 7px 0 0 7px;
}

.input-suffix span {
  display: grid;
  place-items: center;
  min-height: 76px;
  border: 1px solid var(--manual-line);
  border-left: 0;
  border-radius: 0 7px 7px 0;
  background: #f8df9c;
  color: #624a16;
  font-weight: 760;
}

.readonly-field {
  display: grid;
  align-content: center;
  gap: 5px;
  min-height: 74px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
}

.readonly-field span,
.readonly-field small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.readonly-field strong {
  font-size: 18px;
}

.fixed-output {
  background: #f7faf9;
}

.sheet-stack {
  display: grid;
  gap: 16px;
}

.calc-table {
  padding: 16px 20px 20px;
}

.calc-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
}

.calc-row.six {
  grid-template-columns: 1.08fr 1fr 1fr 1fr 1fr 1.1fr;
}

.calc-row.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.calc-row.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.calc-row.header {
  margin-bottom: 8px;
}

.calc-row.header div {
  display: flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 6px;
  background: #eef3f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

output {
  display: grid;
  align-content: center;
  gap: 7px;
  min-height: 76px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

output strong {
  font-size: 16px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

output small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.danger-output {
  border-color: rgba(177, 60, 72, 0.35);
  background: var(--danger-bg);
}

.danger-output strong,
.danger-output small {
  color: var(--danger);
}

.risk-highlight {
  border-color: rgba(177, 60, 72, 0.65) !important;
  box-shadow: 0 0 0 3px rgba(177, 60, 72, 0.12);
}

.manual-field.risk-highlight input,
.manual-field.risk-highlight select,
input.risk-highlight {
  border-color: rgba(177, 60, 72, 0.72) !important;
  background: #fff0d9;
}

.risk-section .section-title {
  background: #fffafa;
}

.risk-list {
  display: grid;
  gap: 10px;
  padding: 16px 20px 20px;
}

.risk-item,
.risk-empty {
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.risk-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.risk-title em {
  flex: 0 0 auto;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-style: normal;
  font-weight: 780;
}

.risk-title strong {
  font-size: 14px;
}

.risk-item > span,
.risk-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.risk-item.high {
  border-color: rgba(177, 60, 72, 0.35);
  background: var(--danger-bg);
}

.risk-item.high strong {
  color: var(--danger);
}

.risk-item.high em {
  background: #d94b58;
  color: #fff;
}

.risk-item.medium {
  border-color: rgba(186, 126, 28, 0.35);
  background: #fff8e8;
}

.risk-item.medium strong {
  color: #9c6810;
}

.risk-item.medium em {
  background: #d89418;
  color: #fff;
}

.risk-item.low {
  border-color: rgba(25, 118, 111, 0.26);
  background: #f4fbfa;
}

.risk-item.low strong {
  color: var(--accent);
}

.risk-item.low em {
  background: #268f78;
  color: #fff;
}

.formula-note span {
  display: block;
}

.formula-note span + span {
  margin-top: 3px;
  color: #7b8793;
}

body.formula-collapsed .formula-note {
  display: none;
}

.status-output {
  border-color: rgba(40, 122, 67, 0.3);
  background: var(--ok-bg);
}

.status-output.danger {
  border-color: rgba(177, 60, 72, 0.35);
  background: var(--danger-bg);
}

.status-output.danger strong,
.status-output.danger small {
  color: var(--danger);
}

@media (max-width: 1120px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .calc-table {
    overflow-x: auto;
  }

  .calc-row,
  .calc-row.six,
  .calc-row.three,
  .calc-row.four {
    min-width: 900px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 24px, 1320px);
    padding-top: 18px;
  }

  h1 {
    font-size: 28px;
  }

  .summary-grid,
  .calc-row.three {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: auto;
  }

  .section-title,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions .toggle-button {
    flex: 1;
  }
}
