:root {
  color-scheme: light;
  --canvas: #f5f6f2;
  --surface: #fff;
  --ink: #192a23;
  --muted: #52625b;
  --line: #dfe5df;
  --soft: #f4f7f3;
  --accent: #20563f;
  --accent-hover: #16412f;
  --accent-soft: #e7f2eb;
  --gain: #216747;
  --loss: #a43430;
  --loss-soft: #fbeeed;
  --warn: #775012;
  --warn-soft: #fcf3df;
  --chart-income: #3d8165;
  --chart-expense: #b18451;
  --radius: 16px;
  --shadow: 0 2px 4px #213b2d08;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[v-cloak] { display: none; }
body { margin: 0; background: var(--canvas); color: var(--ink); font: 14px/1.55 var(--sans); }
h1, h2, p, dl, dd { margin: 0; }
button, input, select { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid #28785a; outline-offset: 3px; }
h1[tabindex="-1"]:focus, h2[tabindex="-1"]:focus { outline: none; }
.num { font-variant-numeric: tabular-nums lining-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 8px 15px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-weight: 650;
  line-height: 1.4;
  white-space: nowrap;
  transition: background-color .15s, border-color .15s;
}
.primary { background: var(--accent); color: #fff; }
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.primary:disabled { color: #536359; background: #e3e9e3; }
.primary > span { font-size: 19px; line-height: .9; font-weight: 500; }
.ghost { background: var(--surface); border-color: var(--line); }
.ghost:hover:not(:disabled) { background: var(--soft); border-color: #a9bbae; }
.ghost:disabled { color: var(--muted); opacity: .65; }

.brand { display: inline-flex; gap: 11px; align-items: center; text-align: left; font-weight: 700; }
.brand-mark { display: block; flex: none; }
.brand-button { background: transparent; border: 0; padding: 0; }
.brand-copy { display: grid; gap: 1px; line-height: 1.35; }
.brand-copy strong { font-size: 14px; }
.brand-copy > span { font-size: 11px; color: var(--muted); font-weight: 500; }
.top { border-bottom: 1px solid var(--line); background: var(--surface); }
.top-inner, .content { width: min(100% - 64px, 1264px); margin-inline: auto; }
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 66px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions .btn { min-height: 38px; }
.content { padding-block: 28px 52px; }
.page-head { display: flex; justify-content: space-between; gap: 12px; align-items: end; margin-bottom: 18px; }
.page-head h1, .login-card h1 { font-size: clamp(25px, 3vw, 33px); font-weight: 750; line-height: 1.25; }
.page-head p, .login-card > p.muted { margin-top: 6px; }
.currency { color: var(--muted); font-size: 12px; white-space: nowrap; }
.back { padding-inline: 0; min-height: 32px; margin-bottom: 10px; background: transparent; color: var(--accent); }
.back:hover { text-decoration: underline; text-underline-offset: 3px; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.metric {
  display: flex;
  flex-direction: column;
  gap: 11px;
  min-width: 0;
  min-height: 111px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.metric > dt, .metric > span, .metric > label { color: var(--muted); font-weight: 600; font-size: 13px; }
.metric > dd, .metric > strong {
  font-size: clamp(17px, 2.2vw, 30px);
  line-height: 1.18;
  letter-spacing: -.035em;
  font-weight: 710;
  font-variant-numeric: tabular-nums lining-nums;
  overflow-wrap: anywhere;
}
.metric.balance { background: var(--accent); border-color: var(--accent); color: #fff; }
.metric.balance dt, .metric-note { color: #d0e7d9; }
.metric-note { display: block; font-size: 11px; font-weight: 500; letter-spacing: 0; margin-top: 5px; }

.surface { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.surface + .surface { margin-top: 16px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; }
.section-head h2, .empty h2 { font-size: 18px; font-weight: 720; line-height: 1.35; }
.section-head p { color: var(--muted); font-size: 12px; margin-top: 3px; }
.section-head > strong.num { font-size: 19px; }
.empty { padding: 36px 20px; text-align: center; }
.empty p { color: var(--muted); margin-top: 6px; }
.empty .btn { margin-top: 15px; }

.legend { display: flex; gap: 13px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: flex; gap: 6px; align-items: center; }
.legend i { width: 9px; height: 9px; border-radius: 2px; }
.income-key { background: var(--chart-income); }
.expense-key { background: var(--chart-expense); }
.chart {
  --plot-height: 92px;
  --plot-label-height: 25px;
  display: flex;
  gap: 8px;
  margin: 2px 23px 13px 20px;
}
.chart-axis {
  display: flex;
  height: var(--plot-height);
  flex-direction: column;
  justify-content: space-between;
  align-items: end;
  min-width: 32px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.chart-axis span { line-height: 0; white-space: nowrap; }
.chart-plot { position: relative; display: flex; flex: 1; min-width: 0; }
.chart-lines {
  position: absolute;
  inset: 0 0 var(--plot-label-height);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}
.chart-lines i { height: 1px; background: var(--line); }
.chart-month {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  border-radius: 5px;
  padding: 0;
  background: transparent;
}
.chart-month:hover { background: #1d5b4110; }
.chart-pair { display: flex; justify-content: center; gap: 4px; align-items: end; height: var(--plot-height); }
.chart-pair i { width: clamp(8px, 2.2vw, 24px); border-radius: 4px 4px 0 0; }
.chart-label {
  display: grid;
  place-items: center;
  height: var(--plot-label-height);
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.chart-month:hover .chart-label { color: var(--accent); }

.table-scroll {
  position: relative;
  overflow-x: auto;
  border-radius: 0 0 var(--radius) var(--radius);
}
.table-scroll:focus-visible { outline-offset: -3px; }
.table-scroll.tall { max-height: 58vh; overflow-y: auto; border-radius: 0; }
.scroll-hint { display: none; }
table { width: 100%; border-collapse: separate; border-spacing: 0; text-align: left; }
.ledger { min-width: 730px; }
.grid { min-width: 670px; }
.grid.categories { min-width: 430px; }
th, td { padding: 11px 17px; border-bottom: 1px solid var(--line); }
thead th {
  padding-block: 9px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: var(--soft);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
table th:first-child, table td:first-child { padding-inline-start: 20px; }
table th:last-child, table td:last-child { padding-inline-end: 20px; }
table .r { text-align: right; }
.tall thead th { position: sticky; top: 0; z-index: 2; }
tbody tr:last-child > * { border-bottom: 0; }
tbody tr:hover > *, tbody tr:focus-within > * { background: #f1f7f1; }
.lrow { cursor: pointer; }
.ledger tbody th { font-weight: 680; white-space: nowrap; }
.ledger tbody th, .ledger thead th:first-child { position: sticky; left: 0; z-index: 1; }
.ledger tbody th { background: var(--surface); }
.ledger tbody tr:hover th, .ledger tbody tr:focus-within th { background: #f1f7f1; }
.month-link { color: var(--accent); border: 0; padding: 3px 0; background: transparent; font-weight: inherit; }
.month-link:hover { text-decoration: underline; text-underline-offset: 4px; }
.net-value { display: inline-block; border-radius: 6px; background: var(--soft); font-weight: 650; padding: 3px 8px; }
.net-value.gain { background: var(--accent-soft); }
.net-value.loss { background: var(--loss-soft); }
.balance-value { font-weight: 650; }
.count { color: var(--muted); }
.row-arrow { width: 38px; text-align: right; color: var(--accent); font-size: 22px; line-height: 1; }
.table-empty { border-top: 1px solid var(--line); color: var(--muted); padding: 14px 20px; }
.flag > *, .flag:hover > *, .flag:focus-within > * { background: #fffbf1; }
.tag { display: inline-block; padding: 3px 8px; border-radius: 6px; background: var(--soft); font-size: 12px; white-space: nowrap; }

.field { display: grid; gap: 6px; align-content: start; font-weight: 650; }
.field-hint { font-size: 12px; color: var(--muted); font-weight: 400; }
input, select {
  width: 100%;
  min-width: 0;
  min-inline-size: 0;
  height: 42px;
  padding: 7px 11px;
  border: 1px solid #c9d6cc;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}
input:disabled, select:disabled { background: var(--soft); color: var(--muted); opacity: 1; }
.balance-edit { display: flex; gap: 6px; align-items: center; }
.balance-edit input { padding-inline: 7px; }
.balance-edit .btn { padding-inline: 10px; }

.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(100%, 420px);
  padding: clamp(22px, 6vw, 36px);
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 18px 50px #213b2d12;
}
.login-logo { display: block; margin: 0 0 14px -10px; }
.login-card > p.muted { margin-bottom: 22px; }
.login-card .field + .field { margin-top: 13px; }
.login-card > .btn { width: 100%; margin-top: 20px; }
.login-card > .notice { margin-top: 12px; }

.import-card { padding: 16px 20px 20px; }
.import-card > .section-head { padding: 0 0 14px; }
.import-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; max-width: 640px; }
.file-drop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  margin-top: 16px;
  border: 1px dashed #a4b8a9;
  border-radius: 10px;
  background: var(--soft);
}
.file-drop.dragging { border-color: var(--accent); background: var(--accent-soft); }
.file-drop.locked { border-style: solid; }
.file-copy { display: grid; gap: 3px; min-width: 0; overflow-wrap: anywhere; }
.file-copy span { font-size: 12px; color: var(--muted); }
.file-picker { position: relative; cursor: pointer; }
.file-picker input { position: absolute; inset: 0; height: 100%; opacity: 0; cursor: inherit; }
.file-picker:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }
.file-picker.locked { cursor: default; opacity: .65; }
.import-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.notice { border-radius: 8px; padding: 9px 12px; overflow-wrap: anywhere; }
.error { background: var(--loss-soft); color: var(--loss); }
.success { background: var(--accent-soft); color: var(--gain); }
.warning { background: var(--warn-soft); color: var(--warn); }
.neutral { background: var(--soft); color: var(--muted); }
.notice .btn { min-height: 34px; margin-inline-start: 5px; }
.import-card > .notice { margin-top: 12px; }
.preview-summary { padding: 0 20px 14px; }
.preview-totals { display: flex; gap: 12px 26px; flex-wrap: wrap; margin-top: 13px; }
.preview-totals dt { color: var(--muted); font-size: 12px; }
.preview-totals dd { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.preview-footer { padding: 15px 20px 20px; border-top: 1px solid var(--line); }
.preview-footer > .notice { margin-bottom: 10px; }
.grid select { width: auto; height: 35px; }

.toast-wrap { position: fixed; inset: auto 16px max(20px, env(safe-area-inset-bottom)) auto; max-width: calc(100% - 32px); z-index: 3; }
.toast { padding: 10px 16px; border-radius: 9px; background: var(--accent-hover); color: #fff; box-shadow: 0 5px 20px #213b2d24; }
.toast-error { background: #85302c; }

@media (max-width: 900px) {
  .top-inner, .content { width: min(100% - 40px, 1264px); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric > dd, .metric > strong { font-size: clamp(18px, 3.4vw, 26px); }
}
@media (max-width: 520px) {
  .top-inner, .content { width: calc(100% - 24px); }
  .top-inner { min-height: 58px; }
  .top-actions { gap: 5px; }
  .top-actions .btn { padding-inline: 8px; font-size: 12px; }
  .content { padding-block: 20px 36px; }
  .page-head { align-items: start; flex-direction: column; gap: 4px; margin-bottom: 13px; }
  .metrics { gap: 8px; }
  .metric { min-height: 92px; padding: 10px 10px 11px; border-radius: 12px; }
  .metric > dt, .metric > span, .metric > label { font-size: 12px; }
  .section-head, .import-card { padding: 13px 12px; }
  .chart { margin-inline: 12px; }
  .scroll-hint { display: inline; }
  th, td { padding-inline: 11px; }
  table th:first-child, table td:first-child { padding-inline-start: 12px; }
  table th:last-child, table td:last-child { padding-inline-end: 12px; }
  .import-fields { grid-template-columns: 1fr; gap: 10px; }
  .file-drop { padding: 10px; }
  .balance-edit { flex-wrap: wrap; }
  .balance-edit .btn { min-height: 34px; width: 100%; }
  .preview-summary, .preview-footer { padding-inline: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
