/* ===== 极简记账本 — 全局样式 ===== */

:root {
  --primary: #3b82f6;
  --income: #10b981;
  --expense: #ef4444;
  --withdraw: #f59e0b;
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #0f172a;
  --text-2: #64748b;
  --border: #e2e8f0;
  --radius: 16px;
  --header-h: 56px;
  --tab-h: 58px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}

button,
input,
select {
  font-family: inherit;
}

button {
  cursor: pointer;
}

/* ===== 顶部标题栏 ===== */

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  height: var(--header-h);
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
}

/* ===== 内容区（桌面端 480px 居中） ===== */

.app-main {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(var(--header-h) + 12px) 16px
    calc(var(--tab-h) + 22px + env(safe-area-inset-bottom));
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* ===== 卡片与按钮 ===== */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
  padding: 14px;
}

.card + .card {
  margin-top: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn.ghost {
  background: #f1f5f9;
  border-color: transparent;
  color: var(--text);
}

.btn.danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: #dc2626;
}

.btn.full {
  width: 100%;
  margin-bottom: 10px;
}

.btn.full:last-child {
  margin-bottom: 0;
}

/* ===== 类型 Tab ===== */

.type-tabs {
  display: flex;
  gap: 8px;
}

.type-tab {
  flex: 1;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: #fff;
  color: var(--text-2);
  font-size: 14px;
  transition: all 0.15s;
}

.type-tab.active {
  color: var(--primary);
  border-color: var(--primary);
  background: #eff6ff;
  font-weight: 600;
}

.type-tab[data-type="income"].active {
  color: #059669;
  border-color: #10b981;
  background: #ecfdf5;
}

.type-tab[data-type="expense"].active {
  color: #dc2626;
  border-color: #ef4444;
  background: #fef2f2;
}

.type-tab[data-type="withdraw"].active {
  color: #b45309;
  border-color: #f59e0b;
  background: #fffbeb;
}

.type-tabs.mini .type-tab {
  flex: none;
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

/* ===== 首页 ===== */

.home-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.summary-card .label {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 6px;
}

.summary-card .amount {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.summary-card.income .amount {
  color: var(--income);
}

.summary-card.expense .amount {
  color: var(--expense);
}

.summary-card.withdraw .amount {
  color: var(--withdraw);
}

.summary-card.net .amount {
  color: var(--income);
}

.summary-card.net.negative .amount {
  color: var(--expense);
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 18px 2px 8px;
}

.home-list,
.list-card {
  padding: 6px 10px;
}

/* ===== 明细 ===== */

.filter-bar {
  padding: 12px;
}

.filter-bar input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 12px;
  font-size: 15px;
  margin-bottom: 10px;
  background: #fff;
  color: var(--text);
}

.date-group-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-2);
  padding: 14px 2px 6px;
}

.date-group-title .day-total {
  font-weight: 600;
  color: var(--text);
}

/* ===== 记录行 ===== */

.record-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px;
}

.record-row:first-child {
  padding-top: 4px;
}

.record-row:last-child {
  padding-bottom: 4px;
}

.card .record-row + .record-row {
  border-top: 1px solid #f1f5f9;
}

.record-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex: none;
  background: #f1f5f9;
}

.record-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex: none;
  background: #f1f5f9;
}

.record-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.record-name {
  font-size: 14px;
  font-weight: 600;
}

.record-note,
.record-date {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record-amount {
  font-size: 15px;
  font-weight: 700;
  flex: none;
}

.record-amount.amount-income {
  color: var(--income);
}

.record-amount.amount-expense {
  color: var(--expense);
}

.record-amount.amount-withdraw {
  color: var(--withdraw);
}

.record-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex: none;
}

.day-group {
  margin-bottom: 4px;
}

.day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-2);
  padding: 14px 2px 6px;
}

.day-total {
  font-weight: 600;
  color: var(--text);
}

.record-delete {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #94a3b8;
  font-size: 14px;
  flex: none;
}

.record-delete:active {
  background: #f1f5f9;
  color: #64748b;
}

.record-actions {
  display: flex;
  gap: 4px;
  flex: none;
  margin-left: 4px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #94a3b8;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.icon-btn.danger {
  color: #fca5a5;
}

.icon-btn:active {
  background: #f1f5f9;
  color: #64748b;
}

.icon-btn.danger:active {
  background: #fef2f2;
  color: #ef4444;
}

/* ===== 统计 ===== */

.stats-head {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.month-input {
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  font-size: 15px;
  color: var(--text);
}

.stats-totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 10px;
  text-align: center;
}

.stat-card label {
  display: block;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 4px;
}

.stat-card strong {
  font-size: 15px;
  font-weight: 700;
}

.stat-card.income strong {
  color: var(--income);
}

.stat-card.expense strong {
  color: var(--expense);
}

.stat-card.withdraw strong {
  color: var(--withdraw);
}

.chart-card h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
}

.chart-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.chart-title-row h3 {
  margin-bottom: 0;
}

.donut-wrap {
  display: flex;
  justify-content: center;
  padding: 6px 0 2px;
}

.donut {
  width: 180px;
  height: 180px;
}

.donut-total {
  font-size: 15px;
  font-weight: 700;
  fill: var(--text);
}

.donut-label {
  font-size: 11px;
  fill: var(--text-2);
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.legend-name {
  flex: 1;
  color: var(--text-2);
}

.legend-amount {
  font-weight: 600;
}

.legend-pct {
  color: var(--text-2);
  width: 44px;
  text-align: right;
}

.bar-chart {
  width: 100%;
  height: auto;
}

.grid-line {
  stroke: #eef2f7;
  stroke-width: 1;
}

.grid-label {
  font-size: 10px;
  fill: var(--text-2);
}

.bar-month {
  font-size: 10px;
  fill: var(--text-2);
}

.legend.inline {
  flex-direction: row;
  justify-content: center;
  gap: 16px;
  margin-top: 10px;
}

.legend.inline .legend-row {
  font-size: 12px;
}

/* ===== 我的 ===== */

.mine-card {
  padding: 18px 16px;
}

.mine-count {
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
  margin-bottom: 14px;
}

/* ===== 空状态 ===== */

.empty-state {
  text-align: center;
  padding: 52px 16px;
  color: var(--text-2);
}

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

.empty-state p {
  font-size: 15px;
}

.empty-state .hint {
  font-size: 13px;
  margin-top: 4px;
  color: #94a3b8;
}

.empty-icon {
  display: block;
  font-size: 44px;
  margin-bottom: 10px;
}

.empty-text {
  font-size: 15px;
}

.empty-hint {
  font-size: 13px;
  margin-top: 4px;
  color: #94a3b8;
}

/* ===== 弹层 ===== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal[hidden] {
  display: none;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.sheet {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.28s ease;
}

.modal.open .sheet {
  transform: translateY(0);
}

.sheet h2 {
  font-size: 17px;
  text-align: center;
  margin-bottom: 14px;
}

.modal-center {
  align-items: center;
  padding: 20px;
}

.confirm-box {
  position: relative;
  width: min(320px, 88vw);
  background: #fff;
  border-radius: 16px;
  padding: 22px 18px 18px;
  text-align: center;
  transform: scale(0.92);
  opacity: 0;
  transition: all 0.22s ease;
}

.modal.open .confirm-box {
  transform: scale(1);
  opacity: 1;
}

.confirm-box p {
  font-size: 15px;
  color: var(--text);
  margin-bottom: 18px;
  line-height: 1.6;
}

/* ===== 记账表单 ===== */

.amount-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  padding: 0 14px;
  margin: 14px 0 16px;
}

.amount-wrap .cur {
  font-size: 22px;
  color: var(--text-2);
  margin-right: 8px;
  font-weight: 600;
}

#record-amount {
  flex: 1;
  height: 56px;
  border: none;
  outline: none;
  font-size: 28px;
  font-weight: 700;
  background: transparent;
  color: var(--text);
  min-width: 0;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 8px;
}

.field input[type="text"],
.field input[type="date"] {
  width: 100%;
  height: 46px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 12px;
  font-size: 16px;
  background: #fff;
  color: var(--text);
}

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

.chip {
  height: 38px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 19px;
  background: #fff;
  color: var(--text-2);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chip.active {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
  font-weight: 600;
}

.category-btn {
  height: 38px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 19px;
  background: #fff;
  color: var(--text-2);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.category-btn.active {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
  font-weight: 600;
}

.cat-icon {
  font-size: 15px;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.sheet-actions .btn {
  flex: 1;
}

/* ===== Toast ===== */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + 28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 100;
  max-width: 82vw;
  background: rgba(15, 23, 42, 0.9);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.18);
}

.toast[hidden] {
  display: none;
}

/* ===== 底部 Tab ===== */

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  z-index: 40;
  display: flex;
  align-items: stretch;
  background: #fff;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  color: #94a3b8;
  font-size: 11px;
  min-height: var(--tab-h);
}

.tab-item.active {
  color: var(--primary);
  font-weight: 600;
}

.tab-icon {
  font-size: 19px;
  line-height: 1;
}

.tab-record {
  flex: 0 0 58px;
  width: 58px;
  height: 58px;
  margin-top: -16px;
  align-self: flex-start;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 26px;
  font-weight: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 4px solid var(--bg);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.tab-record:active {
  transform: scale(0.94);
}

/* 统计上报状态（我的页） */
.tracker-status {
  margin: 0 0 12px;
  font-size: 12px;
  color: #94a3b8;
  line-height: 1.5;
}

.tracker-status.connected {
  color: #10b981;
}
