/* ============================================================
   记账本 · 设计系统
   黄 + 白 + 黑 · 移动端优先 · 无 emoji
   ============================================================ */

:root {
  --yellow: #F5B400;
  --yellow-deep: #D89E00;
  --yellow-soft: #FFF6DC;
  --bg: #FFFFFF;
  --bg-soft: #F6F6F3;
  --text: #111111;
  --text-2: #6B7280;
  --text-3: #A6AAB2;
  --line: #EEEEEA;
  --danger: #DC2626;
  --danger-soft: #FDECEC;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow: 0 12px 32px rgba(245, 180, 0, 0.28);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
}

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

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  /* 禁用 Safari 双击空白页放大;保留滚动,去掉点击延迟 */
  touch-action: manipulation;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input {
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  padding-bottom: calc(110px + env(safe-area-inset-bottom));
}

/* ---------- 顶部 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 20px 10px;
  background: var(--bg);
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

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

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--text-2);
  transition: background 0.15s;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.icon-btn:active {
  background: var(--bg-soft);
}

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

/* ---------- 统计卡 ---------- */

.hero {
  margin: 6px 20px 18px;
  padding: 24px 24px 22px;
  background: var(--yellow-soft);
  border-radius: var(--radius-lg);
}

.hero-label {
  font-size: 13px;
  color: var(--text-2);
  letter-spacing: 0.06em;
}

.hero-amount {
  margin-top: 6px;
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.hero-unit {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-2);
}

.hero-meta {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-2);
  display: flex;
  gap: 8px;
  align-items: center;
}

.hero-meta .dot {
  color: var(--text-3);
}

/* ---------- 日期范围切换 ---------- */

.range-tabs {
  display: flex;
  gap: 8px;
  padding: 0 20px;
  margin-bottom: 18px;
}

.tab {
  flex: 1;
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--text-2);
  transition: all 0.18s;
  white-space: nowrap;
  padding: 0 4px;
}

.tab.active {
  background: var(--yellow);
  border-color: var(--yellow);
  color: var(--text);
  font-weight: 600;
}

/* ---------- 加载指示器 ---------- */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 0;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--yellow-soft);
  border-top-color: var(--yellow);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spin {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- 卡片 ---------- */

.card {
  margin: 0 20px 18px;
  padding: 20px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
}

/* ---------- 分类统计 ---------- */

.cat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
}

.cat-icon {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: var(--yellow-soft);
  display: grid;
  place-items: center;
  color: var(--text);
}

.cat-icon svg {
  width: 20px;
  height: 20px;
}

.cat-info {
  flex: 1;
  min-width: 0;
}

.cat-name-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.cat-name {
  font-size: 14px;
}

.cat-amount {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.cat-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
}

.cat-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--yellow);
  width: 0;
  transition: width 0.4s ease;
}

.cat-percent {
  width: 44px;
  text-align: right;
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.cat-empty {
  padding: 18px 0 6px;
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}

/* ---------- 支出列表 ---------- */

.expense-group {
  margin: 0 20px 22px;
}

.group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 2px 2px 10px;
}

.group-date {
  font-size: 14px;
  font-weight: 600;
}

.group-total {
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.expense-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
}

.expense-item:last-child {
  border-bottom: none;
}

/* 左滑删除(苹果风格) */
.expense-swipe {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
}

.expense-swipe .expense-item {
  position: relative;
  z-index: 1;
  background: var(--bg);
  transition: transform 0.25s ease;
  cursor: grab;
  touch-action: pan-y;
}

.swipe-del {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 84px;
  background: var(--danger);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  border: none;
}

.item-icon {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: var(--yellow-soft);
  display: grid;
  place-items: center;
  color: var(--text);
}

.item-icon svg {
  width: 20px;
  height: 20px;
}

.item-main {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-size: 15px;
  line-height: 1.3;
}

.item-note {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-amount {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- 空状态 ---------- */

.empty {
  padding: 56px 0;
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
}

.empty svg {
  width: 44px;
  height: 44px;
  margin-bottom: 12px;
}

/* ---------- 悬浮按钮 ---------- */

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--text);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  z-index: 30;
  transition: transform 0.15s;
}

.fab svg {
  width: 26px;
  height: 26px;
}

.fab:active {
  transform: scale(0.94);
}

/* ---------- 弹层通用 ---------- */

[hidden] {
  display: none !important;
}

.mask {
  position: fixed;
  inset: 0;
  background: rgba(17, 17, 17, 0.45);
  z-index: 40;
}

.sheet {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 480px;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  max-height: 92dvh;
  animation: slide-up 0.26s ease;
}

.sheet-small {
  max-height: 72dvh;
}

@keyframes slide-up {
  from {
    transform: translateX(-50%) translateY(100%);
  }
  to {
    transform: translateX(-50%) translateY(0);
  }
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 10px auto 4px;
  flex: none;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 6px;
  flex: none;
}

.sheet-header h2 {
  font-size: 17px;
  font-weight: 700;
}

.sheet-header-actions {
  display: flex;
  gap: 4px;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}

/* ---------- 记账 · 金额 ---------- */

.amount-box {
  background: var(--yellow-soft);
  border-radius: var(--radius-md);
  padding: 18px 20px 16px;
  text-align: right;
  margin-bottom: 16px;
}

.amount-expr {
  min-height: 18px;
  font-size: 13px;
  color: var(--text-3);
  word-break: break-all;
}

.amount-preview {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 4px;
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.amount-symbol {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-2);
}

/* ---------- 表单 ---------- */

.field {
  margin-bottom: 16px;
}

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

.field-input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  font-size: 15px;
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  color: var(--text);
}

.field-input svg {
  width: 18px;
  height: 18px;
  color: var(--text-2);
  flex: none;
}

.field-input .chevron {
  margin-left: auto;
  width: 16px;
  color: var(--text-3);
}

/* ---------- 分类选择网格 ---------- */

.category-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px 8px;
}

.cat-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 2px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}

.cat-opt-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--bg-soft);
  display: grid;
  place-items: center;
  color: var(--text-2);
  transition: all 0.15s;
}

.cat-opt-icon svg {
  width: 22px;
  height: 22px;
}

.cat-opt-name {
  font-size: 12px;
  color: var(--text-2);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cat-opt.active {
  border-color: var(--yellow);
  background: var(--yellow-soft);
}

.cat-opt.active .cat-opt-icon {
  background: var(--yellow);
  color: var(--text);
}

.cat-opt.active .cat-opt-name {
  color: var(--text);
  font-weight: 600;
}

/* ---------- 数字键盘 ---------- */

.keypad {
  flex: none;
  border-top: 1px solid var(--line);
  padding: 8px 12px 5px;
  background: var(--bg);
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.key {
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  display: grid;
  place-items: center;
  transition: transform 0.08s, background 0.12s;
  font-variant-numeric: tabular-nums;
}

.key svg {
  width: 22px;
  height: 22px;
}

.key:active {
  transform: scale(0.95);
  background: var(--line);
}

.key-op {
  background: var(--yellow-soft);
  font-size: 22px;
  color: var(--yellow-deep);
}

.key-c {
  background: var(--bg);
  color: var(--text-3);
  font-size: 16px;
  font-weight: 600;
}

.key-save {
  background: var(--yellow);
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  height: 44px;
  border-radius: var(--radius-sm);
}

.key-save:active {
  background: var(--yellow-deep);
  transform: scale(0.98);
}

/* ---------- 分类管理 ---------- */

.category-manage-list {
  list-style: none;
}

.cat-manage-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.cat-manage-item:last-child {
  border-bottom: none;
}

.cat-manage-name {
  flex: 1;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.cat-manage-name .cat-icon {
  width: 34px;
  height: 34px;
}

.cat-manage-name .cat-icon svg {
  width: 18px;
  height: 18px;
}

.cat-manage-actions {
  display: flex;
  gap: 4px;
}

.cat-manage-actions .icon-btn {
  width: 36px;
  height: 36px;
}

.cat-manage-actions .icon-btn svg {
  width: 19px;
  height: 19px;
}

.cat-manage-actions .icon-btn.danger {
  color: var(--danger);
}

.cat-manage-actions .icon-btn.drag-handle {
  color: var(--text-3);
}

.cat-manage-item {
  transition: transform 0.18s ease;
}

.cat-manage-item.dragging {
  opacity: 0.85;
  transform: scale(0.98);
  box-shadow: 0 8px 20px rgba(17, 17, 17, 0.15);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.category-add-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.category-add-row input {
  flex: 1;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  outline: none;
}

.category-add-row input:focus {
  border-color: var(--yellow);
}

.btn-primary {
  height: 46px;
  padding: 0 22px;
  border-radius: var(--radius-sm);
  background: var(--yellow);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

.btn-primary:active {
  background: var(--yellow-deep);
}

.btn-block {
  width: 100%;
  height: 48px;
  margin-top: 10px;
}

/* ---------- 日期范围弹层 ---------- */

.range-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.range-row label {
  font-size: 13px;
  color: var(--text-2);
  width: 40px;
  flex: none;
}

.range-row input[type="date"] {
  flex: 1;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  background: var(--bg);
  color: var(--text);
}

/* ---------- 日期滚轮(苹果闹钟式,黄白黑) ---------- */

.date-wheel {
  display: flex;
  gap: 10px;
  margin: 8px 0 6px;
}

.wheel-col {
  flex: 1;
  position: relative;
}

.wheel-viewport {
  height: 200px;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scroll-padding: 78px;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  scrollbar-width: none;
}

.wheel-viewport::-webkit-scrollbar {
  display: none;
}

.wheel-list .wheel-pad {
  height: 78px;
}

.wheel-item {
  height: 44px;
  line-height: 44px;
  text-align: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-2);
  scroll-snap-align: center;
  font-variant-numeric: tabular-nums;
}

.wheel-highlight {
  position: absolute;
  left: 0;
  right: 0;
  top: 78px;
  height: 44px;
  pointer-events: none;
  border-top: 2px solid var(--yellow);
  border-bottom: 2px solid var(--yellow);
  background: rgba(245, 180, 0, 0.10);
  border-radius: var(--radius-sm);
}

.date-actions {
  margin-top: 4px;
}

.date-actions .btn-primary {
  width: 100%;
  height: 48px;
}

input[type="date"]:focus {
  outline: none;
  border-color: var(--yellow);
}

/* ---------- 其它 ---------- */

::-webkit-scrollbar {
  display: none;
}
