:root {
  --grid: #d9e2ec;
  --header: #f2f6fa;
  --sheet-bg: #ffffff;
  --text: #1f2933;
  --muted: #607080;
  --blue: #00b0f0;
  --red: #d32626;
  --green: #277a46;
  --focus: #8bc6ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: #eef3f7;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

.app-shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 20px auto;
}

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

h1 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0;
}

.meta,
.status-line {
  min-height: 22px;
  color: var(--muted);
  font-size: 13px;
}

.controls {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.controls label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.controls input {
  width: 140px;
  height: 32px;
  border: 1px solid #bcc8d4;
  padding: 0 8px;
  background: #ffffff;
  color: var(--text);
}

.is-hidden {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  height: 32px;
  padding: 0 12px;
  border: 1px solid #bcc8d4;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
}

button:hover {
  background: #f6f9fc;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus,
input:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

select {
  height: 32px;
  border: 1px solid #bcc8d4;
  background: #ffffff;
  color: var(--text);
}

button.primary {
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
}

button.primary:hover {
  background: #21683c;
}

.account-panel {
  margin-bottom: 12px;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--grid);
}

.account-controls {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 140px 140px 110px repeat(4, max-content);
  gap: 8px;
  align-items: end;
}

.account-controls label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.account-controls input,
.account-controls select {
  width: 100%;
}

.account-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  min-height: 22px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.account-data {
  display: grid;
  grid-template-columns: minmax(420px, 1.3fr) minmax(360px, 1fr) minmax(360px, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.account-table-wrap {
  overflow: auto;
  border: 1px solid var(--grid);
}

.account-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  table-layout: fixed;
}

.account-table th,
.account-table td {
  height: 28px;
  border: 1px solid var(--grid);
  padding: 2px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-table th {
  background: var(--header);
  text-align: center;
}

.account-table td {
  text-align: right;
}

.account-table td:nth-child(1),
.account-table td:nth-child(2),
.account-table td:nth-child(3),
.account-table td:nth-child(4),
.account-table td:nth-child(5) {
  text-align: center;
}

.plan-panel {
  margin-bottom: 12px;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--grid);
}

.plan-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.plan-title {
  font-weight: 700;
}

.plan-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.plan-summary {
  min-height: 22px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.risk-overview {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  margin-top: 8px;
  border-top: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
}

.risk-overview span {
  min-width: 0;
  padding: 8px;
  border-right: 1px solid var(--grid);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.risk-overview span:last-child {
  border-right: 0;
}

.risk-overview strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 15px;
}

.risk-overview .risk-limit strong,
.plan-risk-blocked td {
  color: var(--red);
}

.plan-table-wrap {
  overflow: auto;
  border: 1px solid var(--grid);
}

.plan-table {
  width: 100%;
  min-width: 1520px;
  border-collapse: collapse;
  table-layout: fixed;
}

.plan-table th,
.plan-table td {
  height: 28px;
  border: 1px solid var(--grid);
  padding: 2px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.plan-table th {
  background: var(--header);
  text-align: center;
}

.plan-table td {
  text-align: right;
}

.plan-table td:nth-child(1),
.plan-table td:nth-child(2),
.plan-table td:nth-child(3),
.plan-table td:nth-child(4),
.plan-table td:nth-child(5),
.plan-table td:nth-child(6),
.plan-table td:nth-child(15) {
  text-align: center;
}

.plan-actionable td {
  font-weight: 700;
}

.r-value-cell {
  color: var(--green);
  font-weight: 700;
}

.cash-equivalent-cell {
  color: var(--muted);
  text-align: center !important;
}

.sheet-wrap {
  overflow: auto;
  background: var(--sheet-bg);
  border: 1px solid var(--grid);
}

.risk-sheet {
  width: 100%;
  min-width: 2132px;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--sheet-bg);
}

.risk-sheet th,
.risk-sheet td {
  height: 30px;
  border: 1px solid var(--grid);
  padding: 2px 6px;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.risk-sheet thead th {
  background: var(--header);
  text-align: center;
  font-weight: 700;
}

.risk-sheet th:nth-child(1),
.risk-sheet td:nth-child(1) {
  width: 44px;
}

.risk-sheet th:nth-child(2),
.risk-sheet td:nth-child(2),
.risk-sheet th:nth-child(18),
.risk-sheet td:nth-child(18),
.risk-sheet th:nth-child(19),
.risk-sheet td:nth-child(19),
.risk-sheet th:nth-child(22),
.risk-sheet td:nth-child(22),
.risk-sheet th:nth-child(23),
.risk-sheet td:nth-child(23),
.risk-sheet th:nth-child(24),
.risk-sheet td:nth-child(24) {
  width: 92px;
}

.risk-sheet th:nth-child(3),
.risk-sheet td:nth-child(3) {
  width: 112px;
}

.risk-sheet th:nth-child(4),
.risk-sheet td:nth-child(4),
.risk-sheet th:nth-child(5),
.risk-sheet td:nth-child(5),
.risk-sheet th:nth-child(6),
.risk-sheet td:nth-child(6),
.risk-sheet th:nth-child(7),
.risk-sheet td:nth-child(7),
.risk-sheet th:nth-child(8),
.risk-sheet td:nth-child(8),
.risk-sheet th:nth-child(9),
.risk-sheet td:nth-child(9),
.risk-sheet th:nth-child(10),
.risk-sheet td:nth-child(10),
.risk-sheet th:nth-child(11),
.risk-sheet td:nth-child(11),
.risk-sheet th:nth-child(12),
.risk-sheet td:nth-child(12),
.risk-sheet th:nth-child(13),
.risk-sheet td:nth-child(13),
.risk-sheet th:nth-child(14),
.risk-sheet td:nth-child(14),
.risk-sheet th:nth-child(15),
.risk-sheet td:nth-child(15),
.risk-sheet th:nth-child(16),
.risk-sheet td:nth-child(16),
.risk-sheet th:nth-child(20),
.risk-sheet td:nth-child(20),
.risk-sheet th:nth-child(21),
.risk-sheet td:nth-child(21) {
  width: 96px;
}

.risk-sheet th:nth-child(17),
.risk-sheet td:nth-child(17) {
  width: 180px;
}

.risk-sheet td.name-cell,
.risk-sheet td.error-cell,
.risk-sheet .total-label {
  text-align: center;
}

.editable-cell,
.risk-sheet thead th:nth-child(2),
.risk-sheet thead th:nth-child(18),
.risk-sheet thead th:nth-child(22) {
  color: var(--blue);
}

.auto-r-cell,
.turtle-cell,
.risk-sheet thead th:nth-child(6),
.risk-sheet thead th:nth-child(7),
.risk-sheet thead th:nth-child(8),
.risk-sheet thead th:nth-child(9),
.risk-sheet thead th:nth-child(10),
.risk-sheet thead th:nth-child(11),
.risk-sheet thead th:nth-child(12),
.risk-sheet thead th:nth-child(13),
.risk-sheet thead th:nth-child(16),
.risk-sheet thead th:nth-child(19) {
  color: var(--green);
}

.stop-cell,
.red-text,
.risk-sheet thead th:nth-child(14),
.risk-sheet thead th:nth-child(15),
.risk-sheet thead th:nth-child(23),
.risk-sheet thead th:nth-child(24) {
  color: var(--red);
}

.action-cell {
  text-align: center !important;
}

.row-head {
  background: var(--header);
  color: var(--muted);
  text-align: center;
  font-weight: 400;
}

.risk-sheet input,
.risk-sheet select {
  width: 100%;
  height: 25px;
  border: 0;
  padding: 0 2px;
  background: transparent;
  color: var(--blue);
  text-align: left;
}

.risk-sheet select {
  color: var(--blue);
  text-align: center;
}

.risk-sheet input[type="number"] {
  text-align: right;
}

.turtle-cell input {
  color: var(--green);
}

.risk-sheet td {
  text-align: right;
}

.total-label {
  color: var(--red);
  font-weight: 700;
}

.risk-sheet tfoot td {
  font-weight: 700;
}

.error-cell {
  color: var(--red);
}

.limit-exceeded {
  color: var(--red) !important;
  font-weight: 700;
}

.status-line {
  margin-top: 10px;
}

@media (max-width: 1100px) {
  .account-controls,
  .risk-overview {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .account-data {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: calc(100vw - 16px);
    margin: 12px auto;
  }

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

  .controls {
    justify-content: stretch;
  }

  .controls button {
    width: 100%;
  }

  .controls label,
  .controls input,
  .controls select {
    width: 100%;
  }

  .account-controls,
  .account-data {
    grid-template-columns: 1fr;
  }

  .account-controls button {
    width: 100%;
  }

  .risk-overview {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .risk-overview span:nth-child(2n) {
    border-right: 0;
  }

  .plan-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .plan-actions button {
    width: 100%;
  }
}
