/* ── Reset & Base ──────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --primary: #007aff;
  --danger: #ff3b30;
  --success: #34c759;
  --orange: #ff9500;
  --text: #1c1c1e;
  --text-secondary: #8e8e93;
  --separator: #c6c6c8;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: calc(80px + var(--safe-bottom));
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Auth Page ──────────────────────────────────────────────────── */
.auth-page {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-box {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.auth-logo {
  font-size: 56px;
  margin-bottom: 12px;
}

.auth-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.auth-form {
  text-align: left;
}

.auth-field {
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 12px;
  padding: 0 16px;
  border: 0.5px solid var(--separator);
}

.auth-field input {
  width: 100%;
  height: 48px;
  border: none;
  outline: none;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
}

.auth-field input::placeholder {
  color: var(--text-secondary);
}

.auth-error {
  font-size: 13px;
  color: var(--danger);
  margin-bottom: 12px;
  min-height: 18px;
}

.auth-btn {
  width: 100%;
  height: 48px;
  font-size: 17px;
  margin-top: 8px;
}

.auth-switch {
  display: block;
  width: 100%;
  text-align: center;
  border: none;
  background: none;
  font-size: 14px;
  font-family: inherit;
  color: var(--primary);
  cursor: pointer;
  padding: 16px 0 0;
}

/* ── Header (updated) ──────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(242, 242, 247, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 12px 16px 8px;
  border-bottom: 0.5px solid var(--separator);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.header-user-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #e5e5ea;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background 0.15s;
}

.header-user-btn:active {
  background: #d1d1d6;
}

.header-total {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── User Menu ─────────────────────────────────────────────────── */
.user-menu {
  position: absolute;
  top: 100%;
  right: 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  min-width: 180px;
  padding: 8px 0;
  z-index: 200;
}

.user-menu-email {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 8px 16px;
  border-bottom: 0.5px solid var(--separator);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: none;
  font-size: 15px;
  font-family: inherit;
  color: var(--danger);
  cursor: pointer;
  text-align: left;
}

.user-menu-item:active {
  background: #f0f0f5;
}

/* ── Form ──────────────────────────────────────────────────────── */
.form-section {
  background: var(--card);
  margin: 12px 16px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.form-row {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--separator);
}

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

.form-row label {
  width: 60px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  flex-shrink: 0;
}

.form-row input,
.form-row select {
  flex: 1;
  border: none;
  outline: none;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  padding: 4px 0;
  -webkit-appearance: none;
  appearance: none;
}

.form-row input::placeholder {
  color: var(--text-secondary);
}

.form-row select {
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238e8e93'/%3E%3C/svg%3E") no-repeat right center;
  padding-right: 20px;
}

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

.payment-btn {
  padding: 6px 14px;
  border-radius: 18px;
  border: 1.5px solid var(--separator);
  background: transparent;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

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

.submit-row {
  padding: 8px 16px 12px;
  display: flex;
  gap: 10px;
}

.btn {
  flex: 1;
  height: 44px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn:active {
  opacity: 0.7;
}

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

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

.btn-secondary {
  background: #e5e5ea;
  color: var(--text);
}

/* ── Filter Bar ────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

.filter-tag {
  flex-shrink: 0;
  padding: 4px 14px;
  border-radius: 16px;
  border: 1px solid var(--separator);
  background: transparent;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.filter-tag.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ── Expense List ──────────────────────────────────────────────── */
.list-section {
  margin: 4px 16px;
}

.list-date-header {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 16px 4px 6px;
}

.expense-card {
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.expense-item {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.15s;
}

.expense-item:active {
  background: #f0f0f5;
}

.expense-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  margin-right: 12px;
}

.expense-icon.wechat { background: #e8f5e9; }
.expense-icon.alipay { background: #e3f2fd; }
.expense-icon.cash   { background: #fff3e0; }
.expense-icon.card   { background: #f3e5f5; }
.expense-icon.other  { background: #f5f5f5; }

.expense-body {
  flex: 1;
  min-width: 0;
}

.expense-desc {
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.expense-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.expense-method {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  margin-left: 6px;
}

.expense-method.wechat { background: #e8f5e9; color: #2e7d32; }
.expense-method.alipay { background: #e3f2fd; color: #1565c0; }
.expense-method.cash   { background: #fff3e0; color: #e65100; }
.expense-method.card   { background: #f3e5f5; color: #6a1b9a; }
.expense-method.other  { background: #f5f5f5; color: #616161; }

.expense-amount {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
  flex-shrink: 0;
  margin-left: 8px;
}

.expense-amount::before {
  content: "¥";
  font-size: 14px;
  font-weight: 500;
}

/* ── Empty State ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state .emoji {
  font-size: 48px;
  margin-bottom: 12px;
}

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

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.show {
  display: flex;
}

.modal-sheet {
  background: var(--card);
  width: 100%;
  max-width: 420px;
  border-radius: 16px 16px 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-handle {
  width: 36px;
  height: 5px;
  background: #c6c6c8;
  border-radius: 3px;
  margin: 0 auto 16px;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 16px;
}

.modal-form .form-row {
  padding: 8px 0;
}

.modal-form .payment-btn {
  font-size: 13px;
  padding: 5px 12px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

/* ── Stats ─────────────────────────────────────────────────────── */
.stats-section {
  margin: 12px 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-card .stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.stat-card .stat-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ── Nav Bar ───────────────────────────────────────────────────── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(249, 249, 249, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--separator);
  display: flex;
  padding: 6px 0 calc(6px + var(--safe-bottom));
  z-index: 100;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: none;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color 0.15s;
}

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

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

.tab-item .tab-label {
  font-size: 10px;
  font-weight: 500;
}

/* ── Toast ─────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.78);
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  z-index: 999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
}

.toast.show {
  opacity: 1;
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (min-width: 768px) {
  body {
    max-width: 420px;
    margin: 0 auto;
    border-left: 0.5px solid var(--separator);
    border-right: 0.5px solid var(--separator);
  }
}

/* ── Confirm Dialog ────────────────────────────────────────────── */
.confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 300;
  align-items: center;
  justify-content: center;
}

.confirm-overlay.show {
  display: flex;
}

.confirm-box {
  background: var(--card);
  border-radius: 14px;
  width: 270px;
  padding: 24px 20px 16px;
  text-align: center;
}

.confirm-box p {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 8px 0 16px;
}

.confirm-box .btn-row {
  display: flex;
  gap: 8px;
}

.confirm-box .btn {
  height: 40px;
  font-size: 14px;
}
