/* ═══════════════════════════════════════════════════════════════
   黄牛记账 — Apple Design Language
   参考: iOS Human Interface Guidelines / macOS Design
   ═══════════════════════════════════════════════════════════════ */

/* ── Design Tokens ── */
:root {
  /* iOS System Colors */
  --blue:        #007AFF;
  --blue-dark:   #0066D6;
  --green:       #34C759;
  --green-dark:  #248A3D;
  --red:         #FF3B30;
  --red-dark:    #D42A1F;
  --orange:      #FF9500;
  --yellow:      #FFCC00;
  --teal:        #5AC8FA;

  /* System Grays (slightly warm-tinted) */
  --gray-bg:     #F2F2F7;
  --gray-group:  #E8E8ED;
  --gray-light:  #E0E0E5;
  --gray-border: rgba(60, 60, 67, 0.12);
  --gray-border-strong: rgba(60, 60, 67, 0.20);
  --gray-placeholder: #C6C6C8;
  --gray-secondary: #8E8E93;
  --gray-body:   #3C3C43;
  --gray-title:  #1D1D1F;

  /* Semantic Surfaces */
  --bg-primary:   var(--gray-bg);
  --bg-card:      #FFFFFF;
  --bg-header:    rgba(255, 255, 255, 0.78);
  --text-primary: var(--gray-title);
  --text-secondary: var(--gray-secondary);
  --text-tertiary:  var(--gray-placeholder);
  --separator:    var(--gray-border);

  /* Income / Expense / AI */
  --income-bg:    rgba(52, 199, 89, 0.12);
  --income-fg:    var(--green-dark);
  --income-brd:   rgba(52, 199, 89, 0.25);
  --expense-bg:   rgba(255, 59, 48, 0.12);
  --expense-fg:   var(--red-dark);
  --expense-brd:  rgba(255, 59, 48, 0.25);
  --ai-bg:        rgba(0, 122, 255, 0.10);
  --ai-fg:        var(--blue-dark);
  --ai-brd:       rgba(0, 122, 255, 0.25);

  /* Radius */
  --radius-sm:    10px;
  --radius-md:    14px;
  --radius-lg:    20px;
  --radius-xl:    24px;
  --radius-full:  9999px;

  /* Shadows — subtle Apple elevation */
  --shadow-none:  0 0 0 transparent;
  --shadow-sm:    0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-card:  0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-float: 0 8px 24px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-modal: 0 20px 60px rgba(0, 0, 0, 0.25);

  /* Transitions */
  --transition:   0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
  --spring-in:    0.35s cubic-bezier(0.21, 1.02, 0.68, 1);
  --spring-out:   0.28s cubic-bezier(0.06, 0.79, 0.20, 0.99);

  /* Typography */
  --font-sans:    -apple-system, BlinkMacSystemFont, "SF Pro Display",
                  "PingFang SC", "HarmonyOS Sans", "Microsoft YaHei",
                  "Helvetica Neue", sans-serif;
  --font-mono:    "SF Mono", "Menlo", "Consolas", monospace;

  --text-xs:      0.75rem;    /* 12px */
  --text-sm:      0.8125rem;  /* 13px */
  --text-base:    0.9375rem;  /* 15px */
  --text-md:      1.0625rem;  /* 17px */
  --text-lg:      1.25rem;    /* 20px */
  --text-xl:      1.75rem;    /* 28px */
  --text-2xl:     2.25rem;    /* 36px */

  --leading-tight: 1.2;
  --leading-base:  1.5;
  --leading-relaxed: 1.65;

  --weight-regular:  400;
  --weight-medium:   500;
  --weight-semibold: 590;
  --weight-bold:     700;

  /* Spacing (4pt base) */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
}

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

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--leading-base);
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

/* ═══════════════════════════════════════════════════
   Header — iOS frosted glass style
   ═══════════════════════════════════════════════════ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 var(--space-4);
  background: var(--bg-header);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}

@supports not (backdrop-filter: blur(20px)) {
  .app-header {
    background: rgba(255, 255, 255, 0.95);
  }
}

.app-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.logo-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  background: linear-gradient(135deg, #FF9F0A, #FF6B00);
  box-shadow: 0 1px 3px rgba(255, 107, 0, 0.25);
}

.logo-text {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--gray-title);
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  gap: var(--space-1);
}

.btn-icon {
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue);
  font-size: 18px;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.btn-icon:hover {
  background: rgba(0, 122, 255, 0.08);
}

.btn-icon:active {
  background: rgba(0, 122, 255, 0.14);
}

/* ── AI Badge ── */
.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.01em;
  background: var(--ai-bg);
  color: var(--ai-fg);
  border: none;
}

.ai-badge.inactive {
  background: var(--gray-group);
  color: var(--gray-secondary);
}

/* ═══════════════════════════════════════════════════
   App Body
   ═══════════════════════════════════════════════════ */
.app-body {
  max-width: 560px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) 120px;
}

/* ── Month Nav ── */
.month-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.month-nav-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--blue);
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.month-nav-btn:hover {
  background: rgba(0, 122, 255, 0.08);
}

.month-nav-btn:active {
  background: rgba(0, 122, 255, 0.14);
}

.month-label {
  flex: 1;
  text-align: center;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--gray-title);
  letter-spacing: -0.01em;
}

/* ═══════════════════════════════════════════════════
   Summary Card — large title style
   ═══════════════════════════════════════════════════ */
.summary-card {
  position: relative;
  overflow: hidden;
  margin-bottom: var(--space-5);
  padding: var(--space-6);
  border-radius: var(--radius-xl);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
}

.summary-card::before {
  content: '🐂';
  position: absolute;
  right: -12px;
  top: -16px;
  font-size: 96px;
  opacity: 0.05;
  transform: scaleX(-1);
  pointer-events: none;
}

.summary-period {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--gray-secondary);
  margin-bottom: var(--space-1);
  text-transform: none;
}

.summary-balance {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--gray-title);
  letter-spacing: -0.02em;
  margin-bottom: var(--space-5);
  line-height: var(--leading-tight);
}

.summary-balance .unit {
  font-size: var(--text-lg);
  font-weight: var(--weight-medium);
  color: var(--gray-secondary);
  margin-right: var(--space-1);
}

.summary-row {
  display: flex;
  gap: var(--space-3);
}

.summary-item {
  flex: 1;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--gray-bg);
}

.summary-item .label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--gray-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: var(--space-1);
}

.summary-item .amount {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}

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

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

/* ═══════════════════════════════════════════════════
   Tab Navigation
   ═══════════════════════════════════════════════════ */
.tab-nav {
  display: flex;
  margin-bottom: var(--space-5);
  padding: 3px;
  border-radius: var(--radius-sm);
  background: rgba(118, 118, 128, 0.12);
}

.tab-btn {
  flex: 1;
  height: 34px;
  border: none;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-family: var(--font-sans);
  color: var(--gray-title);
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--gray-title);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ═══════════════════════════════════════════════════
   Section Title
   ═══════════════════════════════════════════════════ */
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: var(--space-5) 0 var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--gray-secondary);
  text-transform: none;
  letter-spacing: 0;
}

.section-title .count {
  font-weight: var(--weight-regular);
  font-size: var(--text-xs);
  color: var(--gray-placeholder);
}

/* ═══════════════════════════════════════════════════
   Record List
   ═══════════════════════════════════════════════════ */
.record-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--separator);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.record-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-card);
  transition: background var(--transition), transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.record-item:active {
  background: rgba(0, 0, 0, 0.04);
  transform: scale(0.98);
}

.record-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.record-item.income .record-icon {
  background: var(--income-bg);
}

.record-item.expense .record-icon {
  background: var(--expense-bg);
}

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

.record-name {
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--gray-title);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.record-meta {
  font-size: var(--text-xs);
  color: var(--gray-secondary);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.record-tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: var(--weight-medium);
  color: var(--gray-secondary);
  background: var(--gray-bg);
}

.record-amount {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  flex-shrink: 0;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

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

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

.record-delete {
  position: absolute;
  right: -6px;
  top: -6px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--red);
  color: #FFFFFF;
  font-size: 12px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 1;
  box-shadow: 0 2px 6px rgba(255, 59, 48, 0.3);
  transition: transform var(--transition);
}

.record-delete:active {
  transform: scale(0.9);
}

.record-item:hover .record-delete,
.record-item:active .record-delete {
  display: flex;
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-5);
  color: var(--gray-secondary);
  background: none;
}

.empty-state .icon {
  font-size: 44px;
  margin-bottom: var(--space-3);
  opacity: 0.6;
}

.empty-state p {
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--gray-secondary);
}

/* ═══════════════════════════════════════════════════
   FAB (Floating Action Buttons)
   ═══════════════════════════════════════════════════ */
.fab-wrap {
  position: fixed;
  bottom: 32px;
  bottom: calc(env(safe-area-inset-bottom, 20px) + 28px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: var(--space-3);
  z-index: 200;
}

.fab {
  height: 50px;
  border: none;
  border-radius: 25px;
  cursor: pointer;
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  font-family: var(--font-sans);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-5);
  transition: transform 0.15s cubic-bezier(0.25, 0.1, 0.25, 1),
              box-shadow 0.15s cubic-bezier(0.25, 0.1, 0.25, 1);
  -webkit-tap-highlight-color: transparent;
  letter-spacing: -0.01em;
}

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

.fab-primary {
  background: var(--blue);
  color: #FFFFFF;
  box-shadow: 0 4px 16px rgba(0, 122, 255, 0.3);
}

.fab-primary:hover {
  box-shadow: 0 6px 20px rgba(0, 122, 255, 0.4);
}

.fab-voice {
  width: 50px;
  padding: 0;
  justify-content: center;
  background: var(--bg-card);
  color: var(--gray-title);
  font-size: 20px;
  box-shadow: var(--shadow-float);
  border: 0.5px solid var(--separator);
}

.fab-voice.recording {
  background: var(--red);
  color: #FFFFFF;
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(255, 59, 48, 0.4);
  animation: fabPulse 1.4s ease-in-out infinite;
}

@keyframes fabPulse {
  0%, 100% {
    box-shadow: 0 4px 16px rgba(255, 59, 48, 0.3);
  }
  50% {
    box-shadow: 0 4px 20px rgba(255, 59, 48, 0.55), 0 0 0 4px rgba(255, 59, 48, 0.08);
  }
}

/* ═══════════════════════════════════════════════════
   Drawer (iOS-style bottom sheet)
   ═══════════════════════════════════════════════════ */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 300;
  display: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

@supports not (backdrop-filter: blur(4px)) {
  .drawer-backdrop {
    background: rgba(0, 0, 0, 0.45);
  }
}

.drawer-backdrop.open {
  display: block;
}

.drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 400;
  background: var(--bg-card);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 0 0 calc(env(safe-area-inset-bottom) + var(--space-5));
  transform: translateY(100%);
  transition: transform var(--spring-in);
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
}

.drawer.open {
  transform: translateY(0);
}

.drawer-handle {
  width: 36px;
  height: 5px;
  margin: var(--space-2) auto 0;
  border-radius: 3px;
  background: rgba(60, 60, 67, 0.25);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5) var(--space-3);
  border-bottom: 0.5px solid var(--separator);
}

.drawer-title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--gray-title);
  letter-spacing: -0.01em;
}

.drawer-title-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.btn-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--gray-group);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-secondary);
  transition: background var(--transition);
}

.btn-close:active {
  background: var(--gray-light);
}

.drawer-body {
  padding: var(--space-5);
}

/* ═══════════════════════════════════════════════════
   Voice Result Box
   ═══════════════════════════════════════════════════ */
.voice-result-box {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--gray-bg);
  min-height: 64px;
  transition: background var(--transition), border-color var(--transition);
}

.voice-result-box.listening {
  background: rgba(255, 59, 48, 0.05);
  animation: listenGlow 2s ease-in-out infinite;
}

@keyframes listenGlow {
  0%, 100% { background: rgba(255, 59, 48, 0.04); }
  50%      { background: rgba(255, 59, 48, 0.08); }
}

.voice-result-box.ai-thinking {
  background: var(--ai-bg);
}

.voice-result-box .mic-icon {
  font-size: 20px;
  flex-shrink: 0;
  margin-top: 1px;
}

.voice-text {
  font-size: var(--text-sm);
  color: var(--gray-secondary);
  line-height: var(--leading-relaxed);
  flex: 1;
  white-space: pre-wrap;
  word-break: break-all;
}

.voice-text.has-text {
  color: var(--gray-body);
}

/* ── Voice Action Bar ── */
.voice-action-bar {
  display: none;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.voice-action-bar.show {
  display: flex;
}

.btn-voice-stop {
  flex: 1;
  height: 42px;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  font-family: var(--font-sans);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--red);
  color: #FFFFFF;
  animation: stopPulse 1.4s ease-in-out infinite;
}

@keyframes stopPulse {
  0%, 100% {
    box-shadow: 0 2px 8px rgba(255, 59, 48, 0.25);
  }
  50% {
    box-shadow: 0 2px 12px rgba(255, 59, 48, 0.45), 0 0 0 3px rgba(255, 59, 48, 0.06);
  }
}

.btn-voice-analyze {
  flex: 1;
  height: 42px;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  font-family: var(--font-sans);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--ai-bg);
  color: var(--ai-fg);
}

.btn-voice-analyze:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.voice-countdown {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--gray-secondary);
  background: rgba(118, 118, 128, 0.1);
  border-radius: var(--radius-full);
  padding: 4px 10px;
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.voice-countdown.urgent {
  color: var(--red);
  background: rgba(255, 59, 48, 0.1);
  animation: urgentBlink 0.8s ease-in-out infinite;
}

@keyframes urgentBlink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

/* ── AI Spinner ── */
.ai-loading {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  color: var(--ai-fg);
  font-weight: var(--weight-medium);
}

.ai-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--ai-brd);
  border-top-color: var(--ai-fg);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

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

/* ═══════════════════════════════════════════════════
   Type Toggle
   ═══════════════════════════════════════════════════ */
.type-toggle {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
  padding: 3px;
  border-radius: var(--radius-sm);
  background: rgba(118, 118, 128, 0.12);
}

.type-btn {
  flex: 1;
  height: 38px;
  border: none;
  border-radius: 7px;
  background: transparent;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-family: var(--font-sans);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--gray-body);
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.type-btn.active.expense {
  background: var(--expense-bg);
  color: var(--expense-fg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.type-btn.active.income {
  background: var(--income-bg);
  color: var(--income-fg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* ═══════════════════════════════════════════════════
   Form Fields
   ═══════════════════════════════════════════════════ */
.field-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--gray-secondary);
  letter-spacing: 0.01em;
}

.field input,
.field select {
  height: 44px;
  width: 100%;
  padding: 0 var(--space-4);
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  font-family: var(--font-sans);
  color: var(--gray-title);
  background: var(--gray-group);
  outline: none;
  transition: background var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
  letter-spacing: -0.01em;
}

.field input::placeholder {
  color: var(--gray-placeholder);
}

.field input:focus,
.field select:focus {
  background: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

.field input[type="datetime-local"] {
  color-scheme: light;
}

/* ── Amount Input ── */
.amount-wrap {
  position: relative;
}

.amount-prefix {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--gray-secondary);
  pointer-events: none;
  z-index: 1;
}

.amount-wrap input {
  padding-left: 30px;
}

/* ── Parse Hint ── */
.parse-hint {
  display: none;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--ai-fg);
  background: var(--ai-bg);
  border-radius: 6px;
  padding: 3px var(--space-2);
  margin-top: var(--space-1);
}

.parse-hint.show {
  display: block;
}

/* ── Tag Grid ── */
.tag-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.tag-chip {
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--gray-group);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-family: var(--font-sans);
  cursor: pointer;
  color: var(--gray-body);
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.tag-chip:hover {
  background: rgba(118, 118, 128, 0.18);
}

.tag-chip.selected {
  background: var(--blue);
  color: #FFFFFF;
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.25);
}

/* ── Submit Button ── */
.btn-submit {
  width: 100%;
  height: 50px;
  margin-top: var(--space-6);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  font-family: var(--font-sans);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: var(--blue);
  color: #FFFFFF;
  transition: opacity var(--transition), transform 0.15s cubic-bezier(0.25, 0.1, 0.25, 1);
  -webkit-tap-highlight-color: transparent;
  letter-spacing: -0.01em;
}

.btn-submit:hover {
  opacity: 0.92;
}

.btn-submit:active {
  transform: scale(0.97);
  opacity: 0.85;
}

/* ═══════════════════════════════════════════════════
   Voice Status Bar (recording indicator)
   ═══════════════════════════════════════════════════ */
.voice-status-bar {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  padding: 7px 16px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--red);
  box-shadow: var(--shadow-float);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.voice-status-bar.visible {
  opacity: 1;
}

.voice-dots {
  display: flex;
  gap: 3px;
}

.voice-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--red);
  animation: voiceBounce 1s ease-in-out infinite;
}

.voice-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.voice-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes voiceBounce {
  0%, 80%, 100% { transform: scaleY(1); }
  40%           { transform: scaleY(1.8); }
}

/* ═══════════════════════════════════════════════════
   Toast
   ═══════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  z-index: 600;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: #FFFFFF;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition);
  max-width: 320px;
  text-align: center;
  line-height: var(--leading-base);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ═══════════════════════════════════════════════════
   Statistics Tab
   ═══════════════════════════════════════════════════ */
.stats-row {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.stat-card {
  flex: 1;
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.stat-card .stat-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--gray-secondary);
  margin-bottom: var(--space-1);
}

.stat-card .stat-value {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

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

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

.stat-card.net .stat-value {
  color: var(--gray-title);
}

/* ── Category Bar Chart ── */
.tag-bar-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.tag-bar-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-xs);
}

.tag-bar-label {
  width: 64px;
  flex-shrink: 0;
  color: var(--gray-secondary);
  font-weight: var(--weight-medium);
}

.tag-bar-track {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--gray-group);
  overflow: hidden;
}

.tag-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s cubic-bezier(0.32, 0.72, 0, 1);
}

.tag-bar-amount {
  width: 64px;
  text-align: right;
  font-weight: var(--weight-medium);
  color: var(--gray-body);
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════
   Settings Drawer
   ═══════════════════════════════════════════════════ */
.settings-section {
  margin-bottom: var(--space-6);
}

.settings-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--gray-secondary);
  margin-bottom: var(--space-2);
  letter-spacing: 0.01em;
}

.settings-input-wrap {
  position: relative;
}

.settings-input {
  width: 100%;
  height: 44px;
  padding: 0 44px 0 var(--space-4);
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-family: var(--font-mono);
  color: var(--gray-title);
  background: var(--gray-group);
  outline: none;
  transition: background var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
}

.settings-input:focus {
  background: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

.settings-eye {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--gray-secondary);
  padding: var(--space-1);
}

.settings-hint {
  font-size: var(--text-xs);
  color: var(--gray-secondary);
  margin-top: var(--space-2);
  line-height: var(--leading-relaxed);
}

.settings-hint a {
  color: var(--blue);
  text-decoration: none;
  font-weight: var(--weight-medium);
}

.settings-hint code {
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--gray-group);
}

.btn-save-settings {
  width: 100%;
  height: 46px;
  margin-top: var(--space-2);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  font-family: var(--font-sans);
  cursor: pointer;
  background: var(--blue);
  color: #FFFFFF;
  transition: opacity var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.btn-save-settings:hover {
  opacity: 0.92;
}

.btn-save-settings:active {
  opacity: 0.85;
}

/* ── API Status Row ── */
.api-status-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--gray-group);
  font-size: var(--text-xs);
  color: var(--gray-secondary);
  line-height: var(--leading-base);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.ok {
  background: var(--green);
  box-shadow: 0 0 0 2px rgba(52, 199, 89, 0.2);
}

.status-dot.empty {
  background: var(--gray-placeholder);
}

/* ═══════════════════════════════════════════════════
   Scrollbar (subtle)
   ═══════════════════════════════════════════════════ */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(60, 60, 67, 0.18);
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(60, 60, 67, 0.28);
}

/* ═══════════════════════════════════════════════════
   Responsive — narrow screens
   ═══════════════════════════════════════════════════ */
@media (max-width: 380px) {
  .summary-balance {
    font-size: var(--text-xl);
  }

  .summary-card {
    padding: var(--space-5) var(--space-4);
  }

  .fab {
    height: 46px;
    font-size: var(--text-sm);
    padding: 0 var(--space-4);
  }

  .fab-voice {
    width: 46px;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ═══════════════════════════════════════════════
   AI 分析功能样式
   ═══════════════════════════════════════════════ */
.analysis-section {
  margin-top: var(--space-6);
  margin-bottom: var(--space-6);
}

.analysis-section .section-title {
  margin-bottom: var(--space-4);
}

/* 周期选择器 */
.period-selector {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-1);
  background: rgba(118, 118, 128, 0.12);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
}

.period-btn {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--gray-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: all 0.2s ease;
}

.period-btn.active {
  background: var(--blue);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.period-btn:not(.active):hover {
  background: rgba(118, 118, 128, 0.08);
}

/* 自定义日期范围 */
.custom-date-range {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.custom-date-range .field {
  flex: 1;
  margin-bottom: 0;
}

.custom-date-range .date-sep {
  color: var(--gray-secondary);
  font-size: var(--text-sm);
  flex-shrink: 0;
}

/* AI 分析按钮 */
.btn-ai-analyze {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  padding: 12px var(--space-5);
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.1s ease;
}

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

.btn-ai-analyze:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* 分析结果容器 */
.analysis-result {
  display: none; /* 默认隐藏，JS 控制显示 */
  margin-top: var(--space-5);
  padding: var(--space-5);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Loading 状态 */
.analysis-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--space-4);
  background: var(--ai-bg);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
}

.ai-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(0, 122, 255, 0.18);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: var(--space-3);
}

.analysis-loading-text {
  font-size: var(--text-sm);
  color: var(--gray-secondary);
  text-align: center;
  margin: 0;
}

/* 分析结果内容样式 */
.analysis-content {
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--gray-body);
}

.analysis-content h1,
.analysis-content h2,
.analysis-content h3 {
  margin: var(--space-5) 0 var(--space-3) 0;
  font-weight: var(--weight-semibold);
  color: var(--gray-title);
}

.analysis-content h1 { font-size: var(--text-lg); }
.analysis-content h2 { font-size: var(--text-base); }
.analysis-content h3 { font-size: var(--text-base); }

.analysis-content p {
  margin: 0 0 var(--space-3) 0;
}

.analysis-content ul,
.analysis-content ol {
  margin: var(--space-2) 0 var(--space-4) 0;
  padding-left: var(--space-5);
}

.analysis-content li {
  margin-bottom: var(--space-2);
  padding-left: var(--space-2);
}

.analysis-content ul li::marker {
  color: var(--blue);
}

.analysis-content ol li::marker {
  color: var(--gray-secondary);
}

.analysis-content strong {
  font-weight: var(--weight-semibold);
  color: var(--gray-title);
}

.analysis-content em {
  font-style: normal;
  color: var(--orange);
  font-weight: var(--weight-medium);
}

.analysis-content hr {
  border: none;
  border-top: 1px solid var(--separator);
  margin: var(--space-5) 0;
}

.analysis-content a {
  color: var(--blue);
  text-decoration: none;
}

.analysis-content a:hover {
  text-decoration: underline;
}

.analysis-content code {
  background: rgba(118, 118, 128, 0.1);
  padding: 1px 4px;
  border-radius: var(--radius-xs);
  font-size: 0.92em;
}

.analysis-content pre {
  background: var(--bg-card);
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  overflow-x: auto;
  margin: var(--space-3) 0;
  font-size: var(--text-sm);
}

.analysis-content pre code {
  background: none;
  padding: 0;
}

/* 响应式：窄屏适配 */
@media (max-width: 380px) {
  .period-selector {
    flex-wrap: wrap;
  }
  .period-btn {
    flex: 1 1 calc(50% - var(--space-2));
    text-align: center;
  }
  .custom-date-range {
    flex-direction: column;
    gap: var(--space-2);
  }
  .custom-date-range .date-sep {
    display: none;
  }
}

/* ═══════════════════════════════════════════════════
   底部导航栏 — Bottom Navigation Bar
   ═══════════════════════════════════════════════════ */

/* Page Panel — 页面面板 */
.page-panel {
  display: none;
  animation: fadeInUp 0.3s var(--spring-in);
}

.page-panel.active {
  display: block;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  height: 56px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--gray-secondary);
  font-size: 10px;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--transition);
  padding: 4px 0;
}

.nav-btn:active {
  opacity: 0.7;
}

.nav-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  transition: transform var(--transition);
}

.nav-btn.active .nav-icon {
  color: var(--blue);
  transform: scale(1.05);
}

.nav-label {
  font-size: 10px;
  font-weight: var(--weight-medium);
  line-height: 1.2;
  transition: color var(--transition);
}

.nav-btn.active .nav-label {
  color: var(--blue);
  font-weight: var(--weight-semibold);
}

/* 调整 app-body 底部间距，防止内容被底栏遮挡 */
.app-body {
  padding-bottom: 72px !important;
}

/* 调整 FAB 位置，提升到导航栏上方 */
.fab-wrap {
  bottom: 68px !important;
}

/* 安全区域适配（iPhone X 及以上） */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav {
    height: calc(56px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }
  .app-body {
    padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important;
  }
  .fab-wrap {
    bottom: calc(68px + env(safe-area-inset-bottom)) !important;
  }
}
