/* components.css —— 通用组件 */

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.15s, background 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:active { background: var(--primary-dark); }
.btn--ghost { background: var(--surface-2); color: var(--text-2); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger-ghost { background: var(--danger-light); color: var(--danger); }
.btn--block { width: 100%; }
.btn--sm { min-height: 36px; padding: 0 14px; font-size: 13px; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-2);
  background: var(--surface);
}
.icon-btn:active { background: var(--surface-2); }

.link {
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
}

/* ===== 表单 ===== */
.field { display: block; margin-bottom: 14px; }
.field__label {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 6px;
  font-weight: 500;
}
.field__input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  font-size: 16px; /* 防 iOS 聚焦缩放 */
  transition: border-color 0.15s;
}
.field__input:focus { border-color: var(--primary); }
.field__input::placeholder { color: var(--text-3); }
.field-row { display: flex; gap: 12px; }
.field--half { flex: 1; min-width: 0; }

.select {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  outline: none;
  flex: 1;
  min-width: 0;
}

/* ===== Tabs / Segmented ===== */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
}
.tab {
  flex: 1;
  min-height: 38px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
}
.tab.is-active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.seg {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}
.seg__item {
  flex: 1;
  min-height: 40px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
}
.seg__item.is-active { background: var(--surface); box-shadow: var(--shadow); }
.seg__item[data-type="expense"].is-active { color: var(--expense); }
.seg__item[data-type="income"].is-active { color: var(--income); }

/* ===== 卡片 ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

/* ===== 汇总卡（首页） ===== */
.summary-card {
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 24px;
  box-shadow: 0 8px 24px rgba(79, 70, 229, 0.28);
}
.summary-card__label { font-size: 13px; opacity: 0.85; }
.summary-card__balance {
  font-size: 38px;
  font-weight: 700;
  margin: 10px 0 18px;
  letter-spacing: -1px;
}
.summary-card__currency { font-size: 20px; margin-right: 2px; opacity: 0.9; }
.summary-card__row { display: flex; gap: 24px; }
.summary-card__col { display: flex; align-items: center; gap: 6px; font-size: 13px; opacity: 0.95; }
.summary-card__col strong { font-size: 16px; margin-left: 4px; }
.summary-card__dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.summary-card__dot--income { background: #86efac; }
.summary-card__dot--expense { background: #fca5a5; }

/* ===== 区块标题 ===== */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-head__title { font-size: 17px; font-weight: 700; }

/* ===== 账目列表 ===== */
.tx-list { display: flex; flex-direction: column; gap: 2px; }
.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--divider);
  cursor: pointer;
}
.tx-item:active { background: var(--surface-2); }
.tx-item__icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  flex-shrink: 0;
}
.tx-item__main { flex: 1; min-width: 0; }
.tx-item__title { font-size: 15px; font-weight: 600; }
.tx-item__note {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tx-item__right { text-align: right; flex-shrink: 0; }
.tx-item__amount { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tx-item__amount--expense { color: var(--expense); }
.tx-item__amount--income { color: var(--income); }
.tx-item__time { font-size: 11px; color: var(--text-3); margin-top: 2px; }

.text-income { color: var(--income) !important; }
.text-expense { color: var(--expense) !important; }

/* ===== FAB ===== */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 20px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 32px;
  font-weight: 300;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(79, 70, 229, 0.4);
  z-index: 40;
}
.fab:active { transform: scale(0.94); }
@media (min-width: 768px) {
  .fab { right: calc(50% - 410px); bottom: 32px; }
}

/* ===== Toast ===== */
#toast-root {
  position: fixed;
  top: 24px;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: rgba(31, 41, 55, 0.94);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.25s, transform 0.25s;
  max-width: 86vw;
  text-align: center;
}
.toast.is-show { opacity: 1; transform: translateY(0); }
.toast--success { background: #16a34a; }
.toast--error { background: #dc2626; }

/* ===== Loading ===== */
#loading-root {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
  background: rgba(0, 0, 0, 0.15);
}
#loading-root.is-show { display: flex; }
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Modal / Sheet ===== */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 25, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.2s;
}
.modal-mask.is-show { opacity: 1; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  transform: translateY(8px);
  transition: transform 0.2s;
  max-height: 88vh;
  overflow-y: auto;
}
.modal-mask.is-show .modal { transform: translateY(0); }
.modal__body { padding: 22px; }
.modal__title { font-size: 18px; font-weight: 700; margin-bottom: 14px; }
.modal__text { font-size: 14px; color: var(--text-2); margin-bottom: 18px; line-height: 1.6; }
.modal__actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.modal__actions .btn { flex: 1; }

/* 底部抽屉式弹窗（记账面板） */
.modal--sheet { max-width: 560px; }
.modal--sheet .sheet {
  padding: 8px 22px calc(22px + var(--safe-bottom));
}
.sheet__handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  margin: 4px auto 14px;
}
.sheet__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet__title { font-size: 18px; font-weight: 700; }
.sheet__actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet__actions .btn--block { flex: 1; }

.modal--large { max-width: 560px; }

@media (max-width: 560px) {
  .modal--sheet { align-self: flex-end; max-width: 100%; }
  .modal-mask:has(.modal--sheet) { padding: 0; align-items: flex-end; }
  .modal--sheet { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
}

/* ===== 金额输入 ===== */
.amount-input-wrap {
  display: flex;
  align-items: center;
  border-bottom: 2px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 18px;
}
.amount-input__symbol { font-size: 26px; color: var(--text-2); margin-right: 8px; }
.amount-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 42px;
  font-weight: 700;
  min-width: 0;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ===== 分类选择网格 ===== */
.cat-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
  max-height: 180px;
  overflow-y: auto;
}
.cat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  background: var(--surface-2);
}
.cat-chip.is-active { border-color: var(--primary); background: var(--primary-light); }
.cat-chip__icon { font-size: 22px; }
.cat-chip__name { font-size: 11px; color: var(--text-2); }

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  padding: 44px 20px;
  color: var(--text-3);
}
.empty-state__icon { font-size: 42px; margin-bottom: 12px; opacity: 0.7; }
.empty-state p { font-size: 14px; }

/* ===== 徽章 ===== */
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge--soft { background: var(--surface-2); color: var(--text-2); }
.badge--owner { background: var(--primary-light); color: var(--primary); font-weight: 600; }

/* ===== 筛选条 ===== */
.filter-bar { margin-bottom: 16px; }
.filter-bar__month {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: 10px;
  font-size: 15px;
}
.filter-chips { display: flex; gap: 8px; margin-bottom: 10px; }
.chip {
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-2);
}
.chip.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.filter-selects { display: flex; gap: 10px; }

.hint { font-size: 12px; color: var(--text-3); margin-top: 12px; }
.help-list { margin: 0 0 18px; padding-left: 18px; list-style: disc; }
.help-list li { font-size: 13px; color: var(--text-2); margin-bottom: 8px; line-height: 1.6; }
