/* ---------- 设计令牌 ---------- */
:root {
  color-scheme: light;
  --canvas: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efeb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6d6c67;
  --line: #e3e2dc;
  --grid: #ebeae5;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: #e8f1fc;
  --track: #cde2fb;
  --s1: #2a78d6; /* 本金 / 当前计划 */
  --s2: #eb6834; /* 利息 */
  --s3: #1baf7a; /* 提前还款 */
  --ref: #9a998f; /* 参照线 */
  --good: #0a7a3f;
  --good-wash: #e5f4ea;
  --warn: #9a5b00;
  --warn-wash: #fdf1dc;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .04);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --canvas: #121211; --surface: #1a1a19; --surface-2: #232321;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #9a998f; --line: #2e2e2b; --grid: #262624;
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-wash: #16263a; --track: #184f95;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --ref: #6d6c67;
    --good: #5cc98a; --good-wash: #15291d; --warn: #e2a640; --warn-wash: #2d2210; --danger: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #121211; --surface: #1a1a19; --surface-2: #232321;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #9a998f; --line: #2e2e2b; --grid: #262624;
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-wash: #16263a; --track: #184f95;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --ref: #6d6c67;
  --good: #5cc98a; --good-wash: #15291d; --warn: #e2a640; --warn-wash: #2d2210; --danger: #e66767;
  --shadow: none;
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--canvas);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, dl, dd, ul { margin: 0; }
ul { padding: 0; list-style: none; }
a { color: var(--accent-ink); }
.boot { padding: 40px; color: var(--muted); }
.num, time, .tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- 布局 ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.nav { position: sticky; top: 0; height: 100vh; padding: 22px 14px; border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; padding: 0 10px 18px; }
.brand svg { width: 22px; height: 22px; padding: 5px; border-radius: 8px; background: var(--accent); color: #fff; box-sizing: content-box; flex: none; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-size: 14px; }
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }
.nav .spacer { flex: 1; }
.nav button.link { text-align: left; }
.content { min-width: 0; padding: 28px 32px 64px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; font-weight: 680; }
.page-head p { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stack { display: grid; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- 卡片 ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 14px; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; font-weight: 650; }
.card-head p { color: var(--muted); font-size: 12px; }

/* ---------- 表单控件 ---------- */
input, select, textarea, .btn {
  min-height: 38px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 14px;
}
input, select, textarea { padding: 6px 10px; width: 100%; }
input:hover, select:hover { border-color: var(--muted); }
input[aria-invalid="true"] { border-color: var(--danger); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 14px; cursor: pointer; white-space: nowrap; }
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 30px; padding: 2px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
button.link { border: 0; background: none; color: var(--ink-2); font: inherit; font-size: 14px; cursor: pointer; padding: 9px 12px; border-radius: 10px; display: flex; align-items: center; gap: 10px; }
button.link:hover { background: var(--surface-2); }
button.link svg { width: 18px; height: 18px; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px 14px; align-items: end; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 12px; color: var(--ink-2); }
.field .hint { font-size: 11px; color: var(--muted); }
.form .actions { display: flex; gap: 8px; align-items: center; }
.form .wide { grid-column: 1 / -1; }
.error { color: var(--danger); font-size: 13px; }
.radio-row { display: flex; gap: 6px; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; }
.segmented button { border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 13px; padding: 4px 12px; border-radius: 7px; cursor: pointer; min-height: 30px; }
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .12); }

/* ---------- 概览 ---------- */
.card.hero { display: grid; grid-template-columns: 1.5fr 1fr; padding: 0; overflow: hidden; }
.hero-main { padding: 24px 26px; }
.hero-side { padding: 24px 26px; border-left: 1px solid var(--line); background: var(--surface-2); display: grid; align-content: start; gap: 14px; }
.eyebrow { color: var(--ink-2); font-size: 13px; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.pill { padding: 1px 8px; border-radius: 99px; background: var(--accent-wash); color: var(--accent-ink); font-size: 12px; font-weight: 600; }
.pill.good { background: var(--good-wash); color: var(--good); }
.pill.warn { background: var(--warn-wash); color: var(--warn); }
.hero-amount { font-size: clamp(38px, 5.6vw, 56px); font-weight: 680; letter-spacing: -.03em; line-height: 1.15; margin: 6px 0 16px; }
.unit { font-size: .5em; font-weight: 500; color: var(--muted); margin-right: 3px; letter-spacing: 0; }
.split { display: flex; gap: 2px; height: 8px; }
.split span { border-radius: 99px; min-width: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 12px; }
.legend dt, .legend .lg { color: var(--ink-2); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.legend dd { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.key { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.key.line { height: 2px; width: 14px; border-radius: 1px; }
.key.dash { height: 0; width: 14px; border-top: 2px dashed var(--ref); background: none !important; }
.side-stat h3 { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.side-stat p { font-size: 20px; font-weight: 650; }
.side-stat .note { font-size: 12px; color: var(--muted); font-weight: 400; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tile { padding: 14px 16px; }
.tile h3 { font-size: 12px; font-weight: 500; color: var(--ink-2); }
.tile .value { font-size: 22px; font-weight: 650; letter-spacing: -.01em; margin-top: 2px; }
.tile .note { font-size: 12px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile.good .value { color: var(--good); }
.meter { height: 6px; border-radius: 99px; background: var(--track); margin-top: 8px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.banner { border-radius: 12px; padding: 10px 14px; font-size: 13px; background: var(--warn-wash); color: var(--warn); }
.banner.info { background: var(--accent-wash); color: var(--accent-ink); }

/* ---------- 图表 ---------- */
.chart { position: relative; height: 280px; touch-action: pan-y; }
.chart.short { height: 220px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series.dash { stroke-dasharray: 5 4; }
.chart .area { stroke: none; fill-opacity: .1; }
.chart .marker-line { stroke: var(--ink-2); stroke-width: 1; }
.chart .marker-text { fill: var(--ink-2); font-size: 11px; font-weight: 600; }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .bar { transition: opacity .1s; }
.chart .bar-group:hover .bar, .chart .bar-group.active .bar { opacity: .82; }
.chart .hit { fill: transparent; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.tooltip {
  position: absolute; top: 0; left: 0; pointer-events: none; z-index: 5;
  min-width: 170px; padding: 10px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: 0 6px 24px rgb(0 0 0 / .16);
  font-size: 12px; font-variant-numeric: tabular-nums;
}
.tooltip .tt-title { color: var(--ink-2); margin-bottom: 6px; }
.tooltip .tt-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; line-height: 1.7; }
.tooltip .tt-row span { color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.tooltip .tt-row b { font-weight: 650; }

/* ---------- 表格 ---------- */
.table-wrap { overflow: auto; max-height: 620px; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
th, td { padding: 10px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; text-align: left; }
thead th { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--muted); font-weight: 500; font-size: 12px; border-bottom-color: var(--line); }
tbody tr:hover > * { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.past > * { color: var(--muted); }
tr.next > * { background: var(--accent-wash) !important; }
tr.next th, tr.next td:first-child { color: var(--accent-ink); font-weight: 650; }
tr.prepay > * { background: color-mix(in srgb, var(--s3) 8%, var(--surface)); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--surface-2); color: var(--ink-2); }
.tag.prepay { background: color-mix(in srgb, var(--s3) 16%, var(--surface)); color: var(--ink); }
.tag.warn { background: var(--warn-wash); color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.toolbar select { width: auto; }
.count { color: var(--muted); font-size: 12px; margin-top: 10px; }

/* ---------- 策略 ---------- */
.advice { display: grid; gap: 10px; }
.advice li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.advice li .ic { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-wash); color: var(--accent-ink); }
.advice li.good .ic { background: var(--good-wash); color: var(--good); }
.advice li.warn .ic { background: var(--warn-wash); color: var(--warn); }
.advice li .ic svg { width: 16px; height: 16px; }
.advice h3 { font-size: 14px; font-weight: 650; }
.advice p { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.option { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.option.best { border-color: var(--good); background: var(--good-wash); }
.option h3 { font-size: 14px; display: flex; align-items: center; gap: 8px; }
.option dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin-top: 10px; font-size: 13px; }
.option dt { color: var(--ink-2); }
.option dd { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.result-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.result-strip div { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.result-strip h3 { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.result-strip p { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; }
.result-strip .good { color: var(--good); }
.timing { display: grid; gap: 6px; margin-top: 6px; }
.timing li { display: grid; grid-template-columns: 90px 1fr 110px; gap: 10px; align-items: center; font-size: 13px; }
.timing .bar-track { height: 10px; border-radius: 3px; background: var(--surface-2); }
.timing .bar-fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--s1); }
.timing b { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 登录 ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; display: grid; gap: 14px; }
.login h1 { display: flex; align-items: center; gap: 10px; font-size: 20px; }

/* ---------- 对话框 ---------- */
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 22px; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgb(0 0 0 / .25); }
dialog::backdrop { background: rgb(0 0 0 / .35); }
dialog h2 { font-size: 17px; margin-bottom: 14px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--canvas); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 100; }

/* ---------- 响应式 ---------- */
@media (max-width: 980px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .nav { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; overflow-x: auto; padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--line); gap: 2px; align-items: center; }
  .brand { display: none; }
  .nav a, button.link { padding: 8px 10px; font-size: 13px; white-space: nowrap; }
  .nav a svg, button.link svg { display: none; }
  .nav .spacer { display: none; }
  .content { padding: 16px 16px 48px; }
  .card.hero { grid-template-columns: 1fr; padding: 0; }
  .hero-side { border-left: 0; border-top: 1px solid var(--line); }
  .hero-main, .hero-side { padding: 18px; }
  .card { padding: 14px; }
  .compare { grid-template-columns: 1fr; }
  .chart { height: 230px; }
  input, select, .btn { min-height: 44px; font-size: 16px; }
  .timing li { grid-template-columns: 70px 1fr 90px; }
}
@media (forced-colors: active) {
  .split span, .meter span, .key, .timing .bar-fill { forced-color-adjust: none; }
}
.login h1 .brand { padding: 0; font-size: inherit; }
