:root {
  color-scheme: light;
  --navy: #132c55;
  --muted: #536984;
  --blue: #0960d2;
  --cyan: #0d87b6;
  --teal: #00766e;
  --line: #d9e7f6;
  --paper: #fff;
  --wash: #f1f7fe;
  --wash-blue: #e9f4ff;
  --shadow: 0 13px 38px rgba(33, 83, 139, .075);
  --font: "Inter", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: radial-gradient(ellipse at 82% 3%, #dcf8fb 0, transparent 28rem),
    linear-gradient(180deg, #eaf4ff, #f4f8fd 34rem, #f3f7fc);
  color: var(--navy);
  font: 15px/1.52 var(--font);
}
h1, h2, h3, h4, p { margin: 0; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .56; }
button, a, input, select, summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #0590e4; outline-offset: 3px; }
button:focus:not(:focus-visible) { outline: none; }
a { color: var(--blue); }
.site-width { width: min(100% - 72px, 1440px); margin-inline: auto; }
.visually-hidden, .skip-link:not(:focus) {
  position: absolute; overflow: hidden; white-space: nowrap;
  width: 1px; height: 1px; padding: 0; margin: -1px; clip-path: inset(50%);
}
.skip-link:focus { position: fixed; z-index: 10; top: .5rem; left: .5rem; padding: 12px; background: #fff; border-radius: 8px; }

.topbar {
  background: rgba(252, 254, 255, .86);
  border-bottom: 1px solid rgba(210, 228, 246, .95);
}
.topbar-inner { min-height: 62px; display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.brand { display: flex; align-items: center; gap: 12px; color: #15457f; font-size: 16px; }
.brand img { object-fit: contain; }
.hero { padding: 31px 0 26px; }
.eyebrow { display: flex; align-items: center; gap: .5rem; color: #09639b; font-size: .81rem; font-weight: 750; letter-spacing: .11em; }
.eyebrow span { width: 8px; height: 8px; border-radius: 50%; background: #049ac1; box-shadow: 0 0 0 4px #cdeffa; }
.hero h1 { font-size: clamp(2.25rem, 4.6vw, 3.35rem); font-weight: 800; letter-spacing: -.04em; line-height: 1.16; margin-block: 9px 9px; color: #102d58; }
.hero-copy > p:last-child { color: #3d5d7f; line-height: 1.65; }

.workspace { display: grid; grid-template-columns: minmax(400px, .87fr) minmax(500px, 1.13fr); gap: 21px; align-items: start; }
.card {
  min-width: 0;
  background: var(--paper);
  border: 1px solid #dce9f6;
  box-shadow: var(--shadow);
  border-radius: 19px;
  overflow: hidden;
}
.control-head, .result-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid #e5edf6; }
.control-head h2, .result-head h2 { font-size: 1.2rem; font-weight: 760; }
.result-head { min-height: 73px; background: linear-gradient(110deg, #f8fcff, #f5fcff 70%, #edfbfb); }
.result-head p { margin-top: 3px; color: var(--muted); font-size: .84rem; }
.form-section { padding: 20px 22px 22px; border-bottom: 1px solid #e8eff7; }
.section-heading { display: flex; align-items: start; gap: 11px; margin-bottom: 15px; }
.section-heading h3, .result-section h3 { font-size: 1rem; font-weight: 750; }
.section-heading p, .field-note { color: var(--muted); font-size: .84rem; margin-top: 2px; }
.step {
  display: grid; place-items: center; flex: 0 0 31px; height: 31px; border-radius: 9px;
  color: #145dab; background: #e7f4ff; font-size: .76rem; font-weight: 790;
  font-variant-numeric: tabular-nums;
}
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 42px; padding: 8px 14px; border: 1px solid transparent;
  border-radius: 10px; white-space: nowrap; font-weight: 710;
}
.button.secondary { color: #175b9e; border-color: #c9e1f6; background: #f4faff; }
.button.secondary:hover { color: #034a9e; background: #e8f4ff; border-color: #9cc7ee; }
.button.primary { color: #fff; background: linear-gradient(110deg, #0859ce 15%, #0877ae); }
.button.primary:hover { background: linear-gradient(110deg, #034fb9 15%, #06689b); }
.button.plain { color: #375c86; background: transparent; }
.button.plain:hover { color: var(--blue); background: #eef6ff; }
.button.small, .control-head .button { min-height: 36px; padding: 6px 11px; font-size: .82rem; }
.form-submit { padding: 18px 22px; background: #fafdff; }
.form-submit .button { width: 100%; min-height: 47px; font-size: .95rem; }
.form-submit .button span { margin-left: auto; }
.form-submit .button { justify-content: space-between; }
.mode-tabs { display: flex; gap: 4px; padding: 4px; background: #edf4fc; border: 1px solid #e4eef9; border-radius: 11px; margin-bottom: 13px; }
.mode-tabs button {
  flex: 1 1 0; min-width: 0; min-height: 37px; padding: 6px 7px;
  color: #415c7c; background: none; border: 1px solid transparent; border-radius: 8px; font-weight: 690;
}
.mode-tabs button:hover { color: var(--blue); }
.mode-tabs button[aria-pressed="true"], .mode-tabs button.active, .mode-tabs button[aria-selected="true"] {
  color: #075bbb; border-color: #d6e7f8; background: #fff; box-shadow: 0 2px 6px #123d7010;
}
.investment-switch { padding: 13px 22px 0; }
.investment-tabs { margin: 0; padding: 4px; background: #eaf4ff; }
.investment-tabs button { min-height: 42px; font-weight: 750; }
.investment-tabs button[aria-pressed="true"] {
  color: #fff; border-color: transparent; background: linear-gradient(110deg, #095bcc, #0877ad);
}
.regular-layout-menu { margin: 12px 0 0; padding: 0 0 0 11px; border-left: 3px solid #b6def2; }
.layout-menu-caption { color: #4d6885; font-size: .79rem; font-weight: 710; margin-bottom: 6px; }
.layout-menu-tabs { margin: 0; background: #f2f7fd; }
.layout-menu-tabs button { font-size: .84rem; line-height: 1.3; }
.amount-quick, .period-hint { margin-top: 8px; }
.order-rate-list { display: grid; gap: 8px; }
.order-rate-entry { padding: 9px 11px; border: 1px solid #dceaf7; border-radius: 9px; background: #f7fbff; }
.order-rate-entry > .field { margin: 0; }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chips button {
  min-height: 34px; border: 1px solid #d5e7f9; border-radius: 999px; padding: 5px 10px;
  color: #215f9e; background: #f5faff; font-size: .83rem; font-weight: 675; white-space: nowrap;
}
.chips button:hover, .chips button[aria-pressed="true"] { background: #e4f2ff; border-color: #abd2f4; }
.field-group { margin-top: 13px; }
.field-grid { display: grid; gap: 10px; align-items: end; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-grid.combo-fields { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr) auto; }
#combo-custom-ratio { grid-column: 1 / -1; }
#apply-combo { grid-area: 1 / 3; }
.field { display: grid; gap: 6px; align-content: start; min-width: 0; }
.field > span, .field > label { color: #365473; font-size: .82rem; font-weight: 685; }
.input-with-clear { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
.field-group > .field + .field:not(.field-grid > .field) { margin-top: 10px; }
input:not([type=checkbox]), select {
  min-width: 0; width: 100%; min-height: 40px; border: 1px solid #cdddf0;
  border-radius: 9px; padding: 7px 10px;
  background: #fff; color: #1c3b60;
}
input::placeholder { color: #70839b; opacity: 1; }
input:not([type=checkbox]):focus, select:focus { border-color: #0b79d3; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: #bb3151; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: #096ace; margin: 0; }
.layout-meta:not(:empty) {
  margin-top: 11px; padding: 8px 11px; border: 1px solid #d4edf6; border-radius: 8px;
  color: #265c83; background: #effbfc; font-size: .82rem;
}
.combo-presets { border: 1px solid #d6e8f7; background: #f2f9ff; border-radius: 11px; padding: 10px; }
.combo-presets .button { height: 40px; }
.allocation-field { margin-block: 11px; }
.order-list { display: grid; gap: 8px; margin-bottom: 9px; }
.order-row, .layer-row {
  display: grid; gap: 8px;
  padding: 10px; background: #f7fbff; border: 1px solid #dceaf7; border-radius: 10px;
  min-width: 0;
}
.order-row-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: #234a73; font-size: .85rem; }
.order-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.order-row .order-renew { display: flex; align-items: center; gap: 8px; min-height: 26px; }
.layer-row { grid-template-columns: minmax(0, 1fr) auto; align-items: end; margin-bottom: 7px; }
.layer-row .field-note { grid-column: 1 / -1; }
.layer-row:first-child { margin-top: 8px; }
.order-row > label, .layer-row > label { min-width: 0; font-size: .82rem; color: #365473; }
.layer-row > label:not(.check-line) { display: grid; gap: 5px; }
.order-row .check-line, .order-row .order-renew, .order-row .checkbox-row { grid-column: 1 / -1; }
.layer-row button {
  min-height: 36px; border: 1px solid #d9e7f5; border-radius: 8px;
  background: #fff; color: #426181; padding: 5px 8px;
}
.layer-row button:hover { background: #eaf3fe; }
.inline-details { margin-block: 11px 7px; }
.inline-details summary, .rules-panel summary { color: #215e9c; cursor: pointer; font-weight: 685; }
.inline-details summary { font-size: .83rem; }
.inline-details .field-grid { padding-top: 9px; }
.rank-plan, .period-breakdown-list > details { padding: 9px 11px; border: 1px solid #dceaf7; border-radius: 9px; background: #f7fbff; }
.rank-plan[open] > summary, .period-breakdown-list > details[open] > summary { margin-bottom: 7px; }
#rank-change-list:not(:empty) { display: grid; gap: 8px; margin-top: 9px; }
.rank-change-row { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) auto; align-items: end; gap: 8px; }
.rank-change-row > label { display: grid; gap: 6px; min-width: 0; color: #365473; font-size: .82rem; }
.rank-change-row > button { min-height: 40px; border: 1px solid #d9e7f5; border-radius: 8px; background: #fff; color: #426181; padding: 5px 8px; }
.rank-change-row > button:hover { background: #eaf3fe; }
#add-rank-change { margin-top: 8px; }
#rank-change-summary { margin: 0; padding-inline-start: 21px; color: #4e6683; font-size: .83rem; overflow-wrap: anywhere; }
#rank-change-summary li + li { margin-top: 4px; }
.check-line { display: flex; align-items: center; gap: 8px; min-height: 32px; font-size: .84rem; color: #305471; }
.form-section > .check-line { margin-block: 6px; }
#form-errors:not(:empty), #account-errors:not(:empty), .inline-error:not(:empty) {
  border: 1px solid #f4cad5; background: #fff2f6; color: #981e41;
  margin-bottom: 9px; padding: 8px 10px; font-size: .86rem; border-radius: 8px;
}

.empty-state {
  display: grid; justify-items: center; align-content: center; text-align: center;
  min-height: 330px; padding: 30px; background: linear-gradient(180deg, #fbfdff, #f8fbff);
}
.empty-art {
  display: grid; place-items: center; width: 83px; height: 83px; margin-bottom: 15px;
  color: #0a73c4; background: linear-gradient(138deg, #e1f2ff, #e2fbfb);
  border: 1px solid #d4eaf8; border-radius: 23px;
}
.empty-state h3 { font-size: 1.16rem; }
.empty-state p { color: var(--muted); font-size: .87rem; max-width: 25rem; margin-top: 7px; }
.result-section { padding: 17px 22px 21px; }
.result-section + .result-section { border-top: 1px solid #e9f1f8; }
.result-section .field-note { margin-bottom: 10px; }
.summary-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.metric { min-width: 0; background: #f1f8ff; border: 1px solid #dcecfb; border-radius: 12px; padding: 11px; display: grid; align-content: start; gap: 3px; overflow-wrap: anywhere; }
.metric-featured { background: #e7f9f7; border-color: #d3f0e9; }
.summary-metrics > .metric:nth-child(3) { background: #e9f7ff; }
.metric > strong, .metric-value { color: #095fae; font-size: clamp(.95rem, 1.4vw, 1.23rem); font-weight: 780; font-variant-numeric: tabular-nums; }
.metric > small, .metric > span, .metric-label, .metric-secondary { color: #4a6380; font-size: .79rem; }
.metric-featured > strong, .metric-featured .metric-value { color: #00746b; }
.monthly-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(148px, 1.25fr); gap: 9px; }
.monthly-metrics .metric { padding: 9px; }
.monthly-amounts { display: grid; gap: 3px; }
.monthly-amounts .metric-value { font-size: .95rem; }
.monthly-custom { gap: 6px; }
.monthly-custom input { padding-inline: 7px; font-size: .85rem; }
.metric-periods {
  display: grid; gap: 4px; margin: 4px 0 0; padding: 6px 0 0; list-style: none;
  border-top: 1px solid #d5e7f4; color: #4a6380; font-size: .74rem; font-variant-numeric: tabular-nums;
}
.metric-periods li { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: baseline; gap: 6px; }
.metric-period-amounts { display: flex; flex-wrap: wrap; justify-content: flex-end; column-gap: 6px; text-align: right; }
.metric-period-amounts strong { color: #245785; }
#income-breakdown { margin-top: 7px; }
.period-breakdown { margin-top: 14px; }
.period-breakdown h4 { margin: 0; font-size: .9rem; }
.period-breakdown-list { display: grid; gap: 7px; }
.period-breakdown-list .inline-details { margin: 0; }
.breakdown-row {
  display: grid; grid-template-columns: minmax(85px, .75fr) minmax(0, 1.25fr);
  align-items: center; min-height: 34px; gap: 8px; padding: 5px 8px; font-size: .81rem; font-variant-numeric: tabular-nums;
}
.breakdown-row:nth-child(odd) { background: #f1f7fd; border-radius: 5px; }
.breakdown-row > :not(:first-child) { text-align: right; overflow-wrap: anywhere; }
.breakdown-row-periods { grid-template-columns: max-content minmax(0, 1fr); }
.breakdown-periods { display: block; margin-top: 2px; color: var(--muted); font-size: .75rem; }
#tree-view, #draft-tree:not(:empty) {
  max-height: 430px; min-width: 0; width: 100%; max-width: 100%;
  overflow: auto; overscroll-behavior: contain;
  border: 1px solid #dcecf9; border-radius: 11px; background: #f5faff;
}
#draft-tree:not(:empty) { margin-top: 15px; }
.tree-note { color: var(--muted); font-size: .78rem; }
#draft-tree > .tree-note { max-width: none; margin: 0; padding: 9px 10px 0; text-align: start; }
.tree-scroll { width: 100%; max-width: 100%; overflow: auto; overscroll-behavior-inline: contain; }
.tree-canvas { position: relative; margin-inline: auto; }
.tree-canvas > svg { position: absolute; inset: 0; pointer-events: none; }
.tree-layer-list { display: grid; gap: 9px; padding: 10px; }
.tree-layer { display: grid; gap: 6px; min-width: 0; }
.tree-layer > strong, .tree-layer h4, .tree-layer-label { font-size: .78rem; color: #476787; }
.tree-layer-nodes { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.tree-node {
  display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; align-content: center; gap: 2px;
  border: 1px solid #cbdff1; background: white; color: #295275; min-width: 95px;
  border-radius: 8px; min-height: 58px; padding: 5px 7px; font-size: .72rem; line-height: 1.2; text-align: center; overflow-wrap: anywhere;
}
.tree-node:hover { background: #e7f5ff; border-color: #9ecdec; }
.tree-node > strong { max-width: 100%; color: #0b62b3; font-weight: 760; }
.tree-node > span { max-width: 100%; font-variant-numeric: tabular-nums; }
.tree-order-lines { display: grid; gap: 2px; color: #486580; }
.tree-order-lines small { display: block; font-size: .62rem; }
.rank-tag { border-radius: 4px; padding: 1px 4px; background: #e7f6fb; color: #266184; font-size: .64rem; white-space: nowrap; }
.tree-node-positioned { position: absolute; transform: translate(-50%, -50%); width: 107px; }
.result-subheading { display: flex; gap: 10px; justify-content: space-between; align-items: center; }
.account-search { margin-block: 8px; }
#account-list { overflow-x: auto; }
.account-list-footer { display: flex; justify-content: flex-end; margin-top: 10px; }
.account-table { width: 100%; border-collapse: collapse; color: #315575; font-size: .82rem; font-variant-numeric: tabular-nums; }
.account-table th { background: #e8f3fe; color: #234f78; text-align: left; }
.account-table th, .account-table td { padding: 8px; white-space: nowrap; }
.account-table td small { display: block; color: var(--muted); line-height: 1.55; }
.account-table tbody tr:nth-child(even) { background: #f4f9fd; }
.account-table tbody tr + tr td { border-top: 1px solid #eaf1f8; }
.account-actions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.account-table button, .account-actions button {
  border: 1px solid #c9e1f6; color: #105c9f; background: #f3faff; padding: 4px 8px; border-radius: 7px;
}
.account-table button:hover, .account-actions button:hover { background: #e2f3ff; }
.rules-panel { border-top: 1px solid #e5edf6; padding: 14px 22px; background: #fbfdff; }
.rules-panel summary { font-size: .86rem; }
.rules-body { display: grid; gap: 6px; color: #4e6683; padding-top: 10px; font-size: .83rem; }
.rules-list { margin: 0; padding-inline-start: 21px; }
.rules-list li + li { margin-top: 4px; }
.page-footer { display: flex; justify-content: space-between; gap: 10px; margin-block: 18px 22px; color: var(--muted); font-size: .81rem; }

dialog { width: min(100% - 32px, 620px); max-height: 90dvh; padding: 0; border: 1px solid #cbdff1; border-radius: 17px; box-shadow: 0 20px 90px #12345b35; color: var(--navy); }
dialog::backdrop { background: #10264175; }
.dialog-head, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; background: #f4faff; }
.dialog-head { border-bottom: 1px solid #deebf9; }
.dialog-head h2 { font-size: 1.16rem; }
.dialog-head p { font-size: .83rem; color: var(--muted); }
.dialog-close { min-width: 43px; font-size: 1.35rem; }
.dialog-body { padding: 15px 18px; }
.dialog-body .order-list { margin-top: 10px; }
.dialog-actions { border-top: 1px solid #deebf9; }

@media (max-width: 1020px) {
  .site-width { width: min(100% - 42px, 910px); }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .empty-state { min-height: 218px; }
}
@media (max-width: 600px) {
  .monthly-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
  .monthly-custom { grid-column: 1 / -1; }
}
@media (max-width: 510px) {
  .site-width { width: calc(100% - 24px); }
  .topbar-inner { min-height: 53px; }
  .brand { font-size: .94rem; gap: 8px; }
  .brand img { width: 32px; height: 29px; }
  .hero { padding: 22px 1px 17px; }
  .hero-copy > p:last-child { font-size: .88rem; }
  .card { border-radius: 14px; }
  .control-head, .result-head, .investment-switch, .form-section, .form-submit, .result-section, .rules-panel { padding-inline: 13px; }
  .form-section { padding-block: 15px; }
  .field-grid { gap: 6px; }
  .field-grid.combo-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #apply-combo { grid-area: auto / 1 / auto / -1; }
  .field > span, .field > label { font-size: .77rem; }
  input:not([type=checkbox]), select { padding-inline: 7px; }
  .order-row { padding: 7px; gap: 5px; }
  .rank-change-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .rank-change-row > button { grid-column: 1 / -1; justify-self: end; }
  .summary-metrics { grid-template-columns: minmax(0, 1fr); gap: 5px; }
  .metric { padding: 9px; }
  .page-footer { display: grid; gap: 2px; }
}
@media (max-width: 375px) {
  .field-grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .start-date-field { grid-column: 1 / -1; }
  .dialog-actions { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
