:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #15803d;
  --primary-hover: #166534;
  --primary-soft: #dcfce7;
  --accent: #0284c7;
  --accent-soft: #e0f2fe;
  --income: #16a34a;
  --expense: #dc2626;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
  --sidebar-w: 224px;
  --bottom-nav-h: 62px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

.btn,
.nav-btn,
.mobile-nav-btn,
.cal-cell,
.seg-tab {
  touch-action: manipulation;
}

.btn:active,
.mobile-nav-btn:active,
.cal-cell:active {
  transform: scale(0.98);
}

.num {
  font-variant-numeric: tabular-nums;
}

.text-income { color: var(--income); }
.text-expense { color: var(--expense); }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

/* 整体布局 */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #15803d, #16a34a);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
}

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

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.nav-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.sidebar-cta {
  width: 100%;
  margin-bottom: 10px;
}

/* 主内容区 */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title-wrap {
  min-width: 0;
}

.topbar-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.topbar-sub {
  font-size: 12px;
  color: var(--text-muted);
}

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

.content {
  padding: 20px 24px 36px;
  max-width: 1220px;
  width: 100%;
  margin: 0 auto;
}

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-muted);
}

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

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-ghost-danger {
  color: var(--danger);
  border-color: #fecaca;
  background: #fff;
}

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

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 12px;
}

/* 横幅提示 */
.banner {
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border: 1px solid transparent;
}

.banner-info {
  background: var(--accent-soft);
  border-color: #bae6fd;
  color: #0369a1;
}

.banner-warning {
  background: var(--warning-soft);
  border-color: #fde68a;
  color: #92400e;
}

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

.banner-content {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
}

/* 卡片与网格 */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.kpi-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.dash-donut-layout {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
}

@media (max-width: 560px) {
  .dash-donut-layout {
    grid-template-columns: 1fr;
  }
}

.grid-buckets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

/* 进度条与标签 */
.progress-track {
  width: 100%;
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge-expense { background: #e0f2fe; color: #0369a1; }
.badge-savings { background: #dcfce7; color: #15803d; }
.badge-warning { background: var(--warning-soft); color: #b45309; }
.badge-danger { background: var(--danger-soft); color: #b91c1c; }
.badge-muted { background: #f1f5f9; color: #475569; }

/* 资金桶卡片 */
.bucket-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bucket-card.archived {
  opacity: 0.72;
  background: var(--surface-muted);
}

.bucket-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.bucket-id-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.bucket-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.bucket-name {
  font-size: 15px;
  font-weight: 700;
  word-break: break-word;
}

.bucket-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.bucket-balance-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.bucket-balance {
  font-size: 22px;
  font-weight: 700;
}

.bucket-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* 总览占比条 */
.share-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.share-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.share-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  gap: 8px;
}

/* 图表容器 */
.chart-wrap {
  position: relative;
  width: 100%;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.45;
  z-index: 30;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}

.seg-tabs {
  display: inline-flex;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.seg-tab {
  border: none;
  background: transparent;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
}

.seg-tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* 筛选条与流水列表 */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.record-group {
  margin-bottom: 16px;
}

.record-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  flex-wrap: wrap;
  gap: 6px;
}

.record-group-body {
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: var(--surface);
}

.record-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid #f1f5f9;
}

.record-row:last-child {
  border-bottom: none;
}

.record-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.record-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--surface-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.record-main {
  min-width: 0;
}

.record-title {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.record-meta {
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-word;
}

.record-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.record-amount {
  font-size: 15px;
  font-weight: 700;
  text-align: right;
}

.record-ops {
  display: flex;
  gap: 4px;
}

/* 日历视图 */
.calendar-header-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding-bottom: 8px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.cal-cell {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 76px;
  padding: 6px;
  background: var(--surface);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
}

.cal-cell:hover {
  border-color: var(--primary);
}

.cal-cell.out-month {
  opacity: 0.42;
  background: var(--surface-muted);
}

.cal-cell.selected {
  border: 2px solid var(--primary);
  background: #f0fdf4;
}

.cal-day-num {
  font-size: 12px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cal-today-dot {
  font-size: 10px;
  background: var(--primary);
  color: #fff;
  padding: 0 5px;
  border-radius: 999px;
}

.cal-nums {
  font-size: 11px;
  line-height: 1.3;
}

/* 表格 */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data-table th,
table.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

table.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  background: var(--surface-muted);
}

/* 表单元素 */
.form-group {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(21, 128, 61, 0.14);
}

.form-row-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 6px;
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius);
  background: var(--surface);
}

.empty-icon {
  font-size: 36px;
  margin-bottom: 10px;
}

.empty-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
}

.empty-desc {
  color: var(--text-muted);
  font-size: 13px;
  max-width: 440px;
  margin: 0 auto 16px;
}

.empty-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* 弹窗 Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

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

.modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px 6px;
}

.modal-body {
  padding: 18px 20px;
}

.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* 颜色图标选择器 */
.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.swatch-btn.active {
  border-color: #0f172a;
  transform: scale(1.1);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 16px;
}

.icon-btn.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

/* Toast 提示 */
.toast-container {
  position: fixed;
  top: 72px;
  right: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
  pointer-events: none;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
}

.toast.success { background: #15803d; }
.toast.warning { background: #b45309; }
.toast.danger { background: #b91c1c; }

/* 分类管理标签 */
.cat-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-muted);
  font-size: 13px;
}

/* 移动端底部导航 */
.mobile-nav {
  display: none;
}

@media (max-width: 960px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
  .main-area {
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 16px);
  }
  .topbar {
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  }
  .topbar-title {
    font-size: 16px;
  }
  .content {
    padding: 14px 12px 24px;
  }
  .kpi-value {
    font-size: 20px;
  }
  .form-row-2 {
    grid-template-columns: 1fr;
  }
  .input,
  .select,
  .textarea {
    font-size: 16px;
  }
  .modal-backdrop {
    padding: calc(16px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom));
  }
  .record-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .record-right {
    width: 100%;
    justify-content: space-between;
  }
  .cal-cell {
    min-height: 60px;
    padding: 4px;
  }
  .cal-nums {
    font-size: 10px;
  }
  .mobile-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 40;
    justify-content: space-around;
    align-items: center;
    padding: 4px 4px env(safe-area-inset-bottom);
  }
  .mobile-nav-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    gap: 2px;
    font-size: 11px;
    padding: 4px 6px;
    cursor: pointer;
  }
  .mobile-nav-btn.active {
    color: var(--primary);
    font-weight: 700;
  }
  .mobile-nav-btn .m-icon {
    font-size: 17px;
  }
}
