/* ==========================================================
   资产台账 — Ledger / statement visual language
   Tokens: cool paper white, ink navy, brass accent used once
   ========================================================== */

:root {
  --paper: #eef1f6;
  --surface: #ffffff;
  --ink: #10192b;
  --ink-soft: #4a5568;
  --ink-faint: #8892a0;
  --line: #d7dce3;
  --line-strong: #b7bfc9;
  --accent: #a67c3d;
  --accent-soft: #a67c3d1a;
  --positive: #1f7a5c;
  --negative: #b23a2e;

  --font-serif: 'Newsreader', 'Songti SC', Georgia, serif;
  --font-sans: 'IBM Plex Sans', 'PingFang SC', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius: 3px;
  --max-width: 720px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 48px 20px 96px;
}

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.negative { color: var(--negative); }
.positive { color: var(--positive); }
.hidden { display: none !important; }

/* ---------- Masthead ---------- */

.masthead-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.masthead-title {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: 0.01em;
  margin: 0;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 0;
  min-width: 0;
}

input.masthead-title {
  font-family: var(--font-serif);
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 2px;
}

.masthead-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.masthead-rule {
  margin-top: 14px;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  height: 3px;
}

.masthead-meta {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--ink-faint);
  font-family: var(--font-mono);
}

/* ---------- Hero ---------- */

.hero {
  padding: 40px 0 32px;
  border-bottom: 1px solid var(--line);
}

.hero-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.hero-label {
  font-size: 13px;
  color: var(--ink-soft);
}

.hero-currency-select {
  padding: 3px 6px;
  font-size: 12px;
}

.fx-warning {
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-soft);
  font-style: italic;
}

.hero-value {
  font-family: var(--font-serif);
  font-weight: 500;
  line-height: 1;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.hero-currency {
  font-size: 24px;
  color: var(--ink-soft);
}

.hero-number {
  font-size: 52px;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.hero-change {
  margin-top: 10px;
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--ink-faint);
  min-height: 18px;
}

.sparkline {
  display: block;
  width: 100%;
  height: 56px;
  margin-top: 20px;
}

.sparkline-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.sparkline-area {
  fill: var(--accent-soft);
  stroke: none;
}

.sparkline-dot {
  fill: var(--accent);
}

/* ---------- Sections ---------- */

section { padding: 28px 0; border-bottom: 1px solid var(--line); }
section:last-of-type { border-bottom: none; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-head h2 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 17px;
  margin: 0;
}

.section-head-actions { display: flex; gap: 14px; align-items: center; }

/* ---------- Summary (category breakdown) ---------- */

.summary-list { display: flex; flex-direction: column; gap: 12px; }

.summary-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name value" "bar bar";
  row-gap: 6px;
  align-items: baseline;
}

.summary-row-name { grid-area: name; font-size: 14px; }
.summary-row-value { grid-area: value; font-size: 14px; text-align: right; }
.summary-row-value .pct { color: var(--ink-faint); font-size: 12px; margin-left: 6px; }

.summary-bar-track {
  grid-area: bar;
  height: 5px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.summary-bar-fill {
  height: 100%;
  background: var(--ink);
  opacity: 0.78;
}

.summary-total-row,
.line-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 14.5px;
}

.summary-total-row { font-weight: 500; }

/* ---------- Liabilities / plain line list ---------- */

.line-list { display: flex; flex-direction: column; }
.line-list .line-item-row:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.line-item-name { display: flex; flex-direction: column; gap: 2px; }
.line-item-note { font-size: 12px; color: var(--ink-faint); font-weight: 400; }
.line-item-row .row-controls { display: flex; align-items: center; gap: 10px; }

.empty-note {
  color: var(--ink-faint);
  font-size: 13.5px;
  font-style: italic;
  padding: 4px 0;
}

/* ---------- Detail (categories with items) ---------- */

.category-block { margin-bottom: 26px; }
.category-block:last-child { margin-bottom: 0; }

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.category-header h3 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 15px;
  margin: 0;
  color: var(--ink);
}

input.category-name-input {
  font-family: var(--font-serif);
  font-size: 15px;
  border: none;
  border-bottom: 1px solid var(--line-strong);
  background: transparent;
  padding: 2px 0;
  width: 100%;
  max-width: 260px;
}

.category-header .row-controls { display: flex; gap: 10px; align-items: center; }

.item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}

.category-block .item-row:first-of-type { border-top: none; }

.item-name { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.item-note { font-size: 12px; color: var(--ink-faint); }
.item-value { flex-shrink: 0; margin-left: 12px; }
.item-row .row-controls { display: flex; align-items: center; gap: 10px; margin-left: 12px; }

.add-item-row { padding-top: 10px; }

/* ---------- Edit-mode fields ---------- */

.edit-only { }

.field-input,
.field-input-name,
.field-input-value,
.field-input-note {
  font-family: var(--font-sans);
  font-size: 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 6px 8px;
  color: var(--ink);
}

.field-input-value, .field-input-note.mono-field {
  font-family: var(--font-mono);
}

.row-edit-fields {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 0;
  align-items: center;
}

.row-edit-fields .field-input-name { flex: 1.4; min-width: 0; }
.row-edit-fields .field-input-value { width: 100px; text-align: right; }
.row-edit-fields .field-input-note { flex: 1; min-width: 0; }

.field-select {
  width: 76px;
  flex-shrink: 0;
  background: var(--surface);
}

.item-edit-lines { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.item-edit-block { align-items: flex-start; }
.item-edit-block .row-controls { margin-top: 2px; }

.kind-toggle {
  display: flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.kind-btn {
  font-family: var(--font-sans);
  font-size: 12px;
  border: none;
  background: var(--surface);
  color: var(--ink-soft);
  padding: 6px 10px;
  cursor: pointer;
}
.kind-btn + .kind-btn { border-left: 1px solid var(--line-strong); }
.kind-btn.active { background: var(--ink); color: var(--paper); }

.holding-auto-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.checkbox-inline { display: flex; align-items: center; gap: 6px; }
.checkbox-inline input { margin: 0; }

/* ---------- Buttons ---------- */

.btn {
  font-family: var(--font-sans);
  font-size: 13px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 7px 13px;
  cursor: pointer;
  background: transparent;
  color: var(--ink);
  line-height: 1.2;
}

.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-ghost { border-color: var(--line-strong); background: var(--surface); }
.btn-ghost:hover { border-color: var(--ink-soft); }

.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn-primary:hover { background: #24314a; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-text { background: transparent; border: none; color: var(--accent); padding: 4px 0; }
.btn-text:hover { text-decoration: underline; }

.btn-icon {
  border-color: var(--line-strong);
  background: var(--surface);
  width: 32px; height: 32px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px;
}

.btn-delete {
  background: transparent;
  border: none;
  color: var(--ink-faint);
  font-size: 15px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}
.btn-delete:hover { color: var(--negative); }

/* ---------- Edit bar (sticky save) ---------- */

.edit-bar {
  position: sticky;
  bottom: 16px;
  margin-top: 24px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(16, 25, 43, 0.25);
}

.edit-status { font-size: 12.5px; color: #c9d0dc; font-family: var(--font-mono); }

.edit-bar-actions { display: flex; gap: 8px; }

.edit-bar .btn-ghost {
  background: transparent;
  border-color: #3a4762;
  color: var(--paper);
}
.edit-bar .btn-primary { background: var(--accent); border-color: var(--accent); color: var(--ink); }
.edit-bar .btn-primary:hover { background: #b98c4c; }

/* ---------- Footer ---------- */

.page-footer {
  margin-top: 40px;
  font-size: 12px;
  color: var(--ink-faint);
  font-family: var(--font-mono);
}
.page-footer code { font-family: var(--font-mono); }

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(16, 25, 43, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-card {
  background: var(--surface);
  border-radius: 6px;
  padding: 28px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-card h3 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 19px;
  margin: 0 0 6px;
}

.modal-hint { font-size: 13px; color: var(--ink-soft); margin: 0 0 20px; }

.modal-card label {
  display: block;
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-bottom: 14px;
}

.modal-card label input[type="text"],
.modal-card label input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--paper);
  color: var(--ink);
}

.checkbox-row { display: flex !important; align-items: flex-start; gap: 8px; }
.checkbox-row input { margin-top: 3px; }

.modal-warning {
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--paper);
  border-left: 2px solid var(--accent);
  padding: 10px 12px;
  margin: 4px 0 20px;
}

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(16, 25, 43, 0.3);
  z-index: 60;
}
.toast.toast-error { background: var(--negative); }

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: no-preference) {
  .hero { animation: fade-in 0.4s ease-out; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Responsive ---------- */

@media (max-width: 480px) {
  .hero-number { font-size: 38px; }
  .row-edit-fields { flex-wrap: wrap; }
  .row-edit-fields .field-input-value { width: 90px; }
  .masthead-title { font-size: 19px; }
}
