:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --soft-line: #e8e8ed;
  --accent: #0071e3;
  --accent-soft: #eaf4ff;
  --green: #248a3d;
  --gold: #a86f00;
  --red: #d70015;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "PingFang TC", "Noto Sans TC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: #fff;
  background: var(--accent);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: #0a84ff;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px max(22px, calc((100vw - 1440px) / 2 + 22px));
  background: rgba(245, 245, 247, 0.88);
  border-bottom: 1px solid rgba(210, 210, 215, 0.72);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.brand p,
.headline p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.brand strong {
  display: block;
  font-size: 18px;
  line-height: 1.25;
}

.status-pill {
  flex: 0 0 auto;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.78);
  font-size: 13px;
  font-weight: 700;
}

main {
  width: min(1440px, calc(100% - 40px));
  margin: 22px auto 42px;
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.controls,
.section-panel,
.chart-panel,
.detail-switcher,
.source-notes,
.metric {
  background: var(--panel);
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls {
  position: sticky;
  top: 86px;
  padding: 16px;
}

.results {
  min-width: 0;
}

.panel-title,
.section-head,
.chart-head,
.headline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-title span,
.section-head span,
.chart-head span,
.scenario-select span,
.customer-fields span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.panel-title strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.panel-title.compact {
  margin-top: 18px;
}

.scenario-select,
.customer-fields,
.facts,
.allocation-list {
  display: grid;
}

.scenario-select,
.customer-fields {
  gap: 8px;
  margin-top: 12px;
}

.scenario-select select,
.customer-fields select,
.customer-fields input,
.allocation-list input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font-weight: 700;
}

.scenario-select select,
.customer-fields select {
  width: 100%;
  padding: 0 10px;
  font-size: 14px;
}

.customer-fields label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px 34px;
  align-items: center;
  gap: 8px;
}

.customer-fields input {
  width: 92px;
  padding: 0 8px;
  font-size: 15px;
  text-align: center;
}

.customer-fields em,
.allocation-list em {
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
  font-weight: 700;
}

.facts {
  gap: 0;
  margin: 13px 0 0;
}

.facts div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  padding: 9px 0;
  border-top: 1px solid var(--soft-line);
}

.facts dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.facts dd {
  margin: 0;
  text-align: right;
  font-size: 13px;
  font-weight: 800;
}

.allocation-list {
  gap: 8px;
  margin-top: 10px;
}

.allocation-list label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 70px 18px;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  padding: 8px 10px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #fbfbfd;
}

.allocation-list span {
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.allocation-list input {
  width: 70px;
  padding: 0 8px;
  font-size: 15px;
  text-align: center;
}

.error-box {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #ffb8c0;
  border-radius: 8px;
  color: var(--red);
  background: #fff2f4;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}

.rule-card {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #fbfbfd;
}

.rule-card strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 13px;
}

.rule-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.headline {
  margin-bottom: 16px;
}

.headline h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1.08;
  letter-spacing: 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.metric {
  min-height: 108px;
  padding: 16px;
  box-shadow: none;
}

.metric.primary {
  background: #fbfffc;
  border-color: rgba(18, 129, 74, 0.24);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 27px;
  line-height: 1.08;
  word-break: keep-all;
}

.metric.primary strong {
  font-size: 32px;
}

.metric em {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.4;
}

.metric.positive strong {
  color: var(--green);
}

.metric.negative strong {
  color: var(--red);
}

.metric.blue strong {
  color: var(--accent);
}

.metric.gold strong {
  color: var(--gold);
}

.chart-panel {
  margin-top: 12px;
  padding: 16px;
}

.chart-head {
  margin-bottom: 10px;
}

.chart-head strong {
  display: block;
  margin-top: 3px;
  font-size: 15px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.line {
  display: inline-block;
  width: 20px;
  height: 3px;
  margin: 7px 0 0 4px;
  border-radius: 3px;
  vertical-align: top;
}

.line.account {
  background: var(--green);
}

.line.paid {
  background: var(--gold);
}

canvas {
  display: block;
  width: 100%;
  height: 330px;
  min-height: 300px;
}

.detail-switcher {
  margin-top: 16px;
  padding: 16px;
}

.detail-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-tab {
  min-width: 104px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
}

.detail-tab:hover {
  color: #fff;
  border-color: var(--accent);
}

.detail-tab.is-active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.detail-tab[hidden],
.detail-page[hidden] {
  display: none !important;
}

.detail-pages {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.section-panel {
  min-width: 0;
  margin-top: 16px;
  padding: 16px;
}

.detail-pages .section-panel {
  margin-top: 0;
}

.section-head {
  margin-bottom: 12px;
}

.section-head h2,
.source-notes h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #fff;
  table-layout: auto;
}

.proposal-table {
  min-width: 1240px;
}

.monthly-fee-table {
  min-width: 1840px;
}

.rebalance-table {
  min-width: 1180px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--soft-line);
  text-align: right;
  vertical-align: top;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

.proposal-table th:nth-child(2),
.proposal-table td:nth-child(2) {
  text-align: right;
}

.proposal-table th:nth-child(3),
.proposal-table td:nth-child(3) {
  text-align: left;
}

.monthly-fee-table th:nth-child(5),
.monthly-fee-table td:nth-child(5),
.monthly-fee-table th:nth-child(6),
.monthly-fee-table td:nth-child(6),
.monthly-fee-table th:nth-child(13),
.monthly-fee-table td:nth-child(13) {
  text-align: left;
  white-space: normal;
}

.monthly-fee-table th:nth-child(5),
.monthly-fee-table td:nth-child(5) {
  min-width: 160px;
}

.monthly-fee-table th:nth-child(6),
.monthly-fee-table td:nth-child(6) {
  min-width: 420px;
}

.monthly-fee-table th:nth-child(13),
.monthly-fee-table td:nth-child(13) {
  min-width: 300px;
}

.rebalance-table th:nth-child(3),
.rebalance-table td:nth-child(3),
.rebalance-table th:nth-child(5),
.rebalance-table td:nth-child(5) {
  text-align: left;
  white-space: normal;
}

.rebalance-table th:nth-child(5),
.rebalance-table td:nth-child(5) {
  min-width: 320px;
}

.trade-list {
  display: grid;
  gap: 5px;
  min-width: 280px;
}

.trade-line {
  display: grid;
  grid-template-columns: minmax(92px, 1fr) auto;
  gap: 4px 10px;
  align-items: baseline;
}

.trade-line strong {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.trade-line small {
  grid-column: 1 / -1;
}

.trade-line.buy span {
  color: var(--blue);
}

.trade-line.sell span {
  color: var(--gold);
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #fbfbfd;
  font-size: 12px;
  font-weight: 800;
}

td {
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
}

td small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.45;
  white-space: normal;
}

.compare-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.6;
}

.source-notes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.85fr);
  gap: 16px;
  margin-top: 16px;
  padding: 16px;
  box-shadow: none;
}

.source-notes p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.source-notes a {
  display: inline-block;
  margin: 0 12px 8px 0;
  font-weight: 800;
}

.warning {
  padding: 0;
}

footer {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 0 20px 30px;
  color: var(--muted);
  font-size: 13px;
}

footer strong {
  color: var(--ink);
}

@media (max-width: 1180px) {
  main {
    width: min(100% - 24px, 1120px);
    margin-top: 14px;
  }

  .topbar {
    padding: 10px 18px;
  }

  .brand img {
    width: 38px;
    height: 38px;
  }

  .brand strong {
    font-size: 16px;
  }

  .workspace {
    grid-template-columns: 282px minmax(0, 1fr);
    gap: 12px;
  }

  .controls {
    top: 70px;
    max-height: calc(100dvh - 84px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px;
  }

  .headline h1 {
    font-size: 32px;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric {
    min-height: 104px;
    padding: 12px;
  }

  .metric strong {
    margin-top: 8px;
    font-size: 24px;
  }

  .metric.primary strong {
    font-size: 26px;
  }

  .metric em {
    margin-top: 6px;
    font-size: 11px;
  }

  canvas {
    height: 290px;
  }

  .detail-pages,
  .source-notes {
    grid-template-columns: 1fr;
  }

  .detail-pages {
    gap: 12px;
  }
}

@media (max-width: 820px) {
  .topbar {
    position: static;
    align-items: flex-start;
    padding: 14px 16px;
  }

  .status-pill {
    font-size: 12px;
  }

  main {
    width: min(100% - 24px, 780px);
  }

  .workspace {
    display: flex;
    flex-direction: column;
  }

  .results {
    order: 1;
  }

  .controls {
    position: static;
    order: 2;
    width: 100%;
    max-height: none;
  }

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

  .headline h1 {
    font-size: 30px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .metric.primary strong {
    font-size: 28px;
  }

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

  .legend {
    justify-content: flex-start;
  }

  footer {
    flex-direction: column;
    align-items: center;
  }
}

@media (min-width: 700px) and (max-width: 820px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .topbar {
    flex-direction: column;
  }

  .status-pill {
    width: 100%;
    text-align: center;
  }

  .customer-fields label {
    grid-template-columns: minmax(0, 1fr) 78px 30px;
  }

  .customer-fields input {
    width: 78px;
  }

  .allocation-list label {
    grid-template-columns: minmax(0, 1fr) 64px 16px;
  }

  .allocation-list input {
    width: 64px;
  }

  .section-panel,
  .chart-panel,
  .controls,
  .detail-switcher,
  .source-notes {
    padding: 14px;
  }
}
