:root {
  --bg: #f7f5f0;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #ebe7df;
  --accent: #e87a1e;
  --accent-soft: #fff4e8;
  --accent-grad: linear-gradient(135deg, #f99b26, #e87a1e);
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --ok: #16a34a;
  --ok-soft: #f0fdf4;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(31, 35, 40, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 24px);
}

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 14px;
}

.hidden {
  display: none !important;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(247, 245, 240, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 10px;
  padding-bottom: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: var(--accent-grad);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(232, 122, 30, 0.25);
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.subtitle {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.year-picker {
  display: flex;
  align-items: center;
  gap: 4px;
}

select, input {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid #d6d2c9;
  border-radius: 10px;
  padding: 7px 10px;
}

select:focus, input:focus {
  outline: 2px solid rgba(232, 122, 30, 0.25);
  border-color: var(--accent);
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 12px;
  cursor: pointer;
  color: var(--ink);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
}

.sync-dot.synced { background: var(--ok); }
.sync-dot.syncing { background: var(--warn); }
.sync-dot.error { background: var(--danger); }

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: #d96d14;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.btn-ghost:hover {
  background: #f3efe7;
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.inline-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 0 4px;
}

/* Layout & Cards */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 14px;
  padding-bottom: 32px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.alert-banner {
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13.5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid;
}

.alert-banner.warn {
  background: var(--warn-soft);
  border-color: #fcd34d;
  color: #92400e;
}

.alert-banner.urgent {
  background: var(--danger-soft);
  border-color: #fca5a5;
  color: #991b1b;
}

/* Goal Card */
.goal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.badge-year {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
}

.goal-title {
  margin: 4px 0 0;
  font-size: 20px;
}

.progress-track {
  margin: 12px 0 8px;
  height: 10px;
  border-radius: 999px;
  background: #efeae0;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-grad);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.goal-stats {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.goal-stats strong {
  color: var(--ink);
  font-size: 15px;
}

.kpi-row {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.kpi-mini {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kpi-label {
  font-size: 11.5px;
  color: var(--muted);
}

.kpi-mini strong {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.text-danger { color: var(--danger); }
.text-accent { color: var(--accent); }
.text-muted { color: var(--muted); }
.text-small { font-size: 12.5px; }

/* Section Head */
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 16.5px;
}

.section-hint {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* Ledger Table */
.table-wrap {
  overflow-x: auto;
  margin: 0 -4px;
}

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.ledger-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.ledger-table td {
  padding: 10px 6px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  white-space: nowrap;
}

.ledger-table th.num,
.ledger-table td.num {
  text-align: right;
}

.ledger-row {
  cursor: pointer;
  transition: background 0.15s;
}

.ledger-row:hover {
  background: #faf8f4;
}

.month-cell {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 600;
}

.month-badge {
  display: inline-grid;
  place-items: center;
  background: var(--accent-grad);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  width: 22px;
  height: 22px;
  border-radius: 6px;
}

.tag-mini {
  display: inline-block;
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 5px;
  background: #f3f4f6;
  color: var(--muted);
  margin-left: 4px;
  vertical-align: middle;
}

.tag-manual {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Fixed Deposits */
.deposits-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.deposit-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.deposit-item:hover {
  background: #faf8f4;
}

.deposit-item.status-warn {
  border-color: #fcd34d;
  background: var(--warn-soft);
}

.deposit-item.status-urgent {
  border-color: #fca5a5;
  background: var(--danger-soft);
}

.deposit-item.status-matured {
  opacity: 0.65;
}

.deposit-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.deposit-title {
  font-weight: 600;
  font-size: 14.5px;
}

.deposit-meta {
  font-size: 12px;
  color: var(--muted);
}

.deposit-right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.deposit-amount {
  font-weight: 700;
  font-size: 15px;
}

.deposit-sub-label {
  font-size: 11px;
  color: var(--muted);
}

.pill {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 500;
  margin-top: 3px;
}

.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: #fef3c7; color: #92400e; }
.pill-urgent { background: #fee2e2; color: #991b1b; }
.pill-muted { background: #f3f4f6; color: var(--muted); }

/* Modals */
dialog.modal {
  border: none;
  padding: 0;
  background: transparent;
  width: min(520px, calc(100vw - 20px));
  max-height: 90vh;
}

dialog.modal::backdrop {
  background: rgba(17, 24, 39, 0.45);
  backdrop-filter: blur(2px);
}

.modal-card {
  background: var(--card);
  border-radius: 18px;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  max-height: 88vh;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
}

.icon-close {
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.spacer { flex: 1; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--muted);
}

.field input, .field select {
  width: 100%;
  font-size: 14px;
}

.cat-row {
  display: flex;
  gap: 6px;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}

.sub-head h4, .expense-add-box h5 {
  margin: 0;
  font-size: 14px;
}

.expense-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.expense-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13.5px;
}

.expense-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.expense-cat {
  display: inline-block;
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 5px;
  margin-right: 6px;
}

.expense-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}

.expense-add-box {
  background: #faf8f4;
  border: 1px dashed #dcd6ca;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* 存单弹窗卡片式布局 */
.deposit-modal-body {
  background: #f5f6f8;
  gap: 12px;
}

.dep-section {
  background: #fff;
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--line);
}

.dep-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.dep-box {
  background: #f4f5f7;
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.dep-box input,
.dep-box select {
  border: none;
  background: transparent;
  padding: 2px 0;
  font-size: 14px;
  font-weight: 500;
  width: 100%;
  border-radius: 0;
}

.dep-box input:focus,
.dep-box select:focus {
  outline: none;
}

.dep-label {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.req {
  color: var(--danger);
  font-style: normal;
  margin-right: 2px;
}

.auto-hint {
  font-style: normal;
  color: #2563eb;
  font-size: 11px;
}

.note-count {
  font-style: normal;
  color: var(--muted);
  font-size: 11px;
}

.dep-auto-val {
  font-size: 14.5px;
  font-weight: 600;
  color: #2563eb;
  padding: 2px 0;
  font-variant-numeric: tabular-nums;
}

.dep-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px;
}

.dep-switch-title {
  font-size: 14px;
  font-weight: 600;
}

.dep-switch-sub {
  font-size: 11.5px;
  color: var(--muted);
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #d1d5db;
  transition: 0.2s;
  border-radius: 999px;
}

.slider::before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background-color: #fff;
  transition: 0.2s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.switch input:checked + .slider {
  background-color: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

@media (max-width: 520px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  .ledger-table th, .ledger-table td {
    font-size: 12.5px;
    padding: 9px 4px;
  }
  .kpi-mini strong {
    font-size: 13.5px;
  }
}
