:root {
  --alloc-bg: #f6f8fb;
  --alloc-panel: #ffffff;
  --alloc-ink: #152238;
  --alloc-muted: #617087;
  --alloc-line: #dce4ef;
  --alloc-blue: #2f65d8;
  --alloc-teal: #07866f;
  --alloc-red: #c2414d;
  --alloc-gold: #b06c08;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body.allocation-tool-page {
  margin: 0;
  background: var(--alloc-bg);
  color: var(--alloc-ink);
  font: 16px/1.6 system-ui, "Noto Sans TC", sans-serif;
}
.allocation-tool-page .nav {
  background: #0d1b32;
  color: #fff;
}
.allocation-tool-page .nav .brand { color: #fff; }
.allocation-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 20px 52px;
}
.tool-crumb {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  color: var(--alloc-muted);
  font-size: 14px;
}
.tool-crumb a { color: var(--alloc-blue); font-weight: 800; }
.tool-hero {
  max-width: 850px;
  padding: 8px 0 18px;
}
.tool-hero h1 {
  margin: 8px 0 10px;
  color: var(--alloc-ink);
  font-size: clamp(30px, 5vw, 52px);
  line-height: 1.12;
  letter-spacing: -0.035em;
}
.tool-hero p { margin: 0; max-width: 790px; color: var(--alloc-muted); }
.badge-row, .article-jump, .input-actions, .chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.badge-row { margin-top: 15px; }
.badge-row span {
  border: 1px solid var(--alloc-line);
  border-radius: 99px;
  padding: 4px 10px;
  color: var(--alloc-muted);
  font-size: 12px;
  font-weight: 800;
}
.article-jump {
  position: sticky;
  top: 0;
  z-index: 3;
  margin: 4px 0 20px;
  padding: 10px 0;
  background: color-mix(in srgb, var(--alloc-bg) 92%, transparent);
  backdrop-filter: blur(10px);
}
.article-jump a {
  padding: 7px 11px;
  border: 1px solid var(--alloc-line);
  border-radius: 9px;
  color: var(--alloc-blue);
  font-size: 13px;
  font-weight: 800;
}
.tool-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.panel, .result, .source-box {
  min-width: 0;
  background: var(--alloc-panel);
  border: 1px solid var(--alloc-line);
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(18, 42, 79, 0.07);
}
.panel, .result { padding: 22px; }
.input-panel, .rules-panel { grid-column: span 1; }
.result-panel { grid-column: 1; }
.section-kicker {
  color: var(--alloc-teal);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
}
h2 { margin: 5px 0 10px; font-size: 22px; line-height: 1.3; }
h3 { margin: 0 0 10px; font-size: 17px; }
.helper { margin: 0 0 14px; color: var(--alloc-muted); font-size: 14px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.asset-input-table { min-width: 610px; }
.asset-input-table th, .asset-input-table td,
.result-table th, .result-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--alloc-line);
  text-align: left;
  vertical-align: middle;
}
th { color: var(--alloc-muted); font-size: 12px; font-weight: 900; }
.asset-input-table input {
  width: 100%;
  min-width: 118px;
  border: 1px solid var(--alloc-line);
  border-radius: 7px;
  padding: 8px 9px;
  background: #fbfcfe;
  color: var(--alloc-ink);
  font: inherit;
}
.asset-input-table .asset-name { min-width: 130px; }
.remove-asset {
  border: 1px solid #f0c7cb;
  border-radius: 7px;
  padding: 7px 9px;
  background: #fff7f7;
  color: var(--alloc-red);
  font-weight: 800;
  cursor: pointer;
}
.input-actions { margin-top: 12px; }
.button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 13px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.button:disabled { cursor: not-allowed; opacity: .5; }
.button.primary { width: 100%; margin-top: 15px; background: var(--alloc-blue); color: #fff; }
.button.secondary { background: #edf3ff; border-color: #c9d8fa; color: #2453b6; }
.button.ghost { background: transparent; border-color: var(--alloc-line); color: var(--alloc-muted); }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; margin-top: 15px; }
.field-grid label { display: grid; gap: 5px; color: var(--alloc-muted); font-size: 13px; font-weight: 800; }
.field-grid input, .field-grid select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--alloc-line);
  border-radius: 7px;
  padding: 9px;
  background: #fbfcfe;
  color: var(--alloc-ink);
  font: inherit;
}
.field-grid select { color-scheme: light; }
.mode-help, .note-box {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 9px;
  background: #f2f7ff;
  color: var(--alloc-muted);
  font-size: 13px;
}
.note-box { border-left: 3px solid var(--alloc-gold); background: #fff9ee; }
.status { min-height: 23px; margin-top: 9px; color: var(--alloc-muted); font-size: 13px; }
.status.ok { color: var(--alloc-teal); font-weight: 800; }
.status.error { color: var(--alloc-red); font-weight: 800; }
.rule-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.rule-cards article { padding: 12px; border: 1px solid var(--alloc-line); border-radius: 10px; background: #fafcff; }
.rule-cards strong { color: var(--alloc-ink); }
.rule-cards p { margin: 6px 0 0; color: var(--alloc-muted); font-size: 13px; }
.formula-note { margin-top: 12px; padding: 13px; border-left: 3px solid var(--alloc-blue); border-radius: 8px; background: #f5f8ff; color: var(--alloc-muted); font: 14px/1.8 ui-monospace, SFMono-Regular, Consolas, monospace; overflow-x: auto; }
.result-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.result-heading .button { flex: 0 0 auto; }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin: 15px 0; }
.metric { min-width: 0; padding: 12px; border: 1px solid var(--alloc-line); border-radius: 10px; background: #fbfcfe; }
.metric-label, .metric small { display: block; color: var(--alloc-muted); font-size: 12px; }
.metric strong { display: block; margin: 4px 0; color: var(--alloc-blue); font-size: 20px; overflow-wrap: anywhere; }
.result-caption { margin: 0 0 12px; color: var(--alloc-muted); font-size: 13px; }
.visual, .cost-box { margin-top: 15px; padding: 14px; border: 1px solid var(--alloc-line); border-radius: 11px; background: #fbfcfe; }
.allocation-chart { display: grid; gap: 12px; }
.chart-row { display: grid; grid-template-columns: 70px minmax(0, 1fr) minmax(120px, auto); align-items: center; gap: 10px; }
.chart-label { overflow-wrap: anywhere; font-size: 13px; font-weight: 800; }
.chart-track { position: relative; height: 12px; border-radius: 99px; background: #e8edf5; }
.chart-current { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #5486e5, #13a98e); }
.chart-target { position: absolute; top: -4px; width: 3px; height: 20px; border-radius: 3px; background: var(--alloc-red); }
.chart-row > span { color: var(--alloc-muted); font-size: 12px; text-align: right; }
.chart-legend { margin-top: 12px; color: var(--alloc-muted); font-size: 12px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend i { display: inline-block; width: 18px; height: 7px; border-radius: 99px; }
.legend-current { background: #5486e5; }
.legend-target { width: 3px !important; height: 16px !important; border-radius: 3px !important; background: var(--alloc-red); }
.result-table { min-width: 860px; }
.result-table th { background: #f1f5fb; }
.result-table td { color: var(--alloc-ink); font-size: 13px; }
.result-table .buy { color: var(--alloc-teal); }
.result-table .sell { color: var(--alloc-red); }
.result-table .hold { color: var(--alloc-muted); }
.result-table .action-amount { display: block; color: inherit; font-size: 12px; }
.unallocated-row td { background: #fff9ee; color: var(--alloc-gold); }
.cost-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.cost-item { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--alloc-line); color: var(--alloc-muted); font-size: 13px; }
.cost-item strong { color: var(--alloc-ink); text-align: right; }
.source-box { margin-top: 18px; padding: 20px; scroll-margin-top: 60px; }
.source-box p { color: var(--alloc-muted); }
.source-box a { color: var(--alloc-blue); font-weight: 800; }
.disclaimer { border-top: 1px solid var(--alloc-line); padding-top: 12px; font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (min-width: 900px) {
  .tool-layout { grid-template-columns: minmax(0, 1.15fr) minmax(310px, .85fr); align-items: start; }
  .input-panel { grid-column: 1; grid-row: span 2; }
  .rules-panel { grid-column: 2; }
  .result-panel { grid-column: 1 / -1; }
}

@media (max-width: 700px) {
  .allocation-shell { padding: 16px 13px 38px; }
  .tool-crumb { align-items: flex-start; flex-direction: column; gap: 5px; }
  .tool-hero h1 { font-size: 32px; }
  .article-jump { flex-wrap: nowrap; overflow-x: auto; }
  .article-jump a { flex: 0 0 auto; white-space: nowrap; }
  .panel, .result, .source-box { padding: 16px; border-radius: 12px; }
  .field-grid, .rule-cards, .metric-grid, .cost-grid { grid-template-columns: 1fr; }
  .result-heading { display: block; }
  .result-heading .button { margin-top: 4px; }
  .chart-row { grid-template-columns: 58px minmax(0, 1fr); gap: 6px; }
  .chart-row > span { grid-column: 2; text-align: left; }
  .cost-item { display: block; }
  .cost-item strong { display: block; margin-top: 2px; text-align: left; }
}

@media (prefers-color-scheme: dark) {
  body.allocation-tool-page { color-scheme: dark; }
}
