/* =========================================================================
   Family Ledger - Glassmorphism Feminine Edition
   Pastel palette + frosted glass cards + soft decorative atmosphere
   ========================================================================= */

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

:root {
  /* === Pastel Palette (warm, dreamy, feminine) === */
  --peach-50:  #FFF4EB;
  --peach-100: #FFE5D1;
  --peach-200: #FFCFAB;

  --pink-50:   #FFEEF2;
  --pink-100:  #FFD9E0;
  --pink-200:  #FBC4CE;

  --blue-50:   #EAF3FB;
  --blue-100:  #D5E7F2;
  --blue-200:  #B8D8EC;

  --lavender-50: #F1EAFA;
  --lavender-100: #E5D7F1;
  --lavender-200: #D2BFEA;

  --mint-50:   #EBF4EE;
  --mint-100:  #D8E9DD;
  --mint-200:  #B7D4BF;

  --cream:      #FCF7F0;
  --cream-warm: #F9EFDF;

  /* === Semantic (soft, muted) === */
  --expense:      #D78885;     /* soft coral */
  --expense-soft: #F9DCD9;
  --income:       #8FBA9E;     /* soft sage */
  --income-soft:  #DDEAE2;
  --warning:      #E8B07A;
  --warning-soft: #F8E4CE;
  --accent:       #C9A0E0;     /* lavender - main accent */
  --accent-soft:  #EADFF4;

  /* === Text (warm grays) === */
  --text:           #2D2A40;
  --text-secondary: #857F95;
  --text-tertiary:  #B6B2C4;
  --text-on-glass:  rgba(45, 42, 64, 0.85);

  /* === Glass surface === */
  --glass-bg:           rgba(255, 255, 255, 0.55);
  --glass-bg-strong:    rgba(255, 255, 255, 0.72);
  --glass-bg-soft:      rgba(255, 255, 255, 0.4);
  --glass-border:       rgba(255, 255, 255, 0.85);
  --glass-border-soft:  rgba(255, 255, 255, 0.5);
  --glass-shadow:
    0 10px 40px -10px rgba(190, 170, 220, 0.25),
    0 2px 8px rgba(190, 170, 220, 0.08);
  --glass-shadow-hover:
    0 16px 48px -8px rgba(190, 170, 220, 0.35),
    0 4px 14px rgba(190, 170, 220, 0.12);

  /* === Radius === */
  --r-xs: 10px;
  --r-sm: 14px;
  --r-md: 20px;
  --r-lg: 28px;
  --r-xl: 36px;
  --r-full: 999px;

  --tabbar-h: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 8px);
}

html, body {
  font-family:
    -apple-system, BlinkMacSystemFont,
    'SF Pro Rounded', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei',
    sans-serif;
  font-size: 15px;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.1px;
  min-height: 100vh;
  background:
    radial-gradient(at 8% 0%, var(--peach-100) 0%, transparent 45%),
    radial-gradient(at 100% 5%, var(--pink-100) 0%, transparent 50%),
    radial-gradient(at 92% 95%, var(--lavender-100) 0%, transparent 50%),
    radial-gradient(at 0% 90%, var(--blue-100) 0%, transparent 45%),
    linear-gradient(170deg, var(--cream) 0%, var(--cream-warm) 50%, var(--pink-50) 100%);
  background-attachment: fixed;
}

/* Decorative floating blobs */
body::before, body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}
body::before {
  top: 12%; left: -80px;
  width: 240px; height: 240px;
  background: var(--peach-200);
  animation: floatBlob 18s ease-in-out infinite;
}
body::after {
  bottom: 18%; right: -60px;
  width: 200px; height: 200px;
  background: var(--lavender-200);
  animation: floatBlob 22s ease-in-out infinite reverse;
}
@keyframes floatBlob {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(20px, -30px) scale(1.08); }
}

/* Custom scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(201, 160, 224, 0.3);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(201, 160, 224, 0.5); }

/* App container */
#app {
  max-width: 414px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  z-index: 1;
}

.page {
  display: none;
  padding: 12px 16px;
}
.page.active {
  display: block;
  animation: pageIn 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================
   HEADER
   ============================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 4px 14px;
}
.page-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.page-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  font-weight: 500;
}
.page-header .header-action {
  width: 40px; height: 40px;
  border-radius: var(--r-full);
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--glass-shadow);
  transition: transform 0.2s ease;
}
.page-header .header-action:active { transform: scale(0.92); }

/* ============================================
   GLASS CARD - The core reusable element
   ============================================ */
.card {
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--glass-shadow);
  transition: box-shadow 0.3s ease, transform 0.3s ease;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
}
.card-title .ct-emoji { margin-right: 6px; }
.card-title .ct-link {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  cursor: pointer;
}

/* ============================================
   HOME - Hero card with gradient + blobs
   ============================================ */
.dashboard-hero {
  background:
    radial-gradient(at 100% 0%, rgba(255, 255, 255, 0.7) 0%, transparent 50%),
    linear-gradient(135deg, var(--peach-100) 0%, var(--pink-100) 45%, var(--lavender-100) 100%);
  border-radius: var(--r-lg);
  padding: 26px 22px;
  color: var(--text);
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--glass-shadow);
  border: 1px solid rgba(255, 255, 255, 0.7);
}
.dashboard-hero::before {
  content: '';
  position: absolute;
  top: -50px; right: -40px;
  width: 160px; height: 160px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.55) 0%, transparent 65%);
  border-radius: 50%;
}
.dashboard-hero::after {
  content: '';
  position: absolute;
  bottom: -60px; left: -30px;
  width: 140px; height: 140px;
  background: radial-gradient(circle, rgba(255, 196, 206, 0.5) 0%, transparent 65%);
  border-radius: 50%;
}
.dashboard-hero .hero-emoji {
  position: absolute;
  top: 18px; right: 18px;
  font-size: 28px;
  opacity: 0.5;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dashboard-hero .hero-emoji svg {
  color: #fff;
}
.dashboard-hero .label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.dashboard-hero .amount {
  font-size: 38px;
  font-weight: 700;
  margin-bottom: 18px;
  letter-spacing: -1.2px;
  line-height: 1.1;
}
.dashboard-hero .amount .currency {
  font-size: 20px;
  font-weight: 600;
  margin-right: 2px;
  vertical-align: top;
  color: var(--text-secondary);
}
.dashboard-hero .stats {
  display: flex;
  gap: 20px;
  position: relative;
  z-index: 1;
}
.dashboard-hero .stat-item { flex: 1; }
.dashboard-hero .stat-item .stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 2px;
  font-weight: 500;
}
.dashboard-hero .stat-item .stat-value {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.dashboard-hero .stat-item.income .stat-value { color: #5C8B6E; }
.dashboard-hero .stat-item.expense .stat-value { color: #B86E6B; }

/* ============================================
   QUICK ACTIONS - Glass icon buttons
   ============================================ */
.quick-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.quick-action {
  flex: 1;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  padding: 14px 8px;
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  box-shadow: var(--glass-shadow);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.3s ease;
}
.quick-action:active {
  transform: scale(0.96);
  box-shadow: var(--glass-shadow-hover);
}
.quick-action .icon {
  font-size: 22px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 6px;
}
.quick-action .icon svg {
  color: var(--accent);
  opacity: 0.85;
}

/* ============================================
   TRANSACTION LIST
   ============================================ */
.tx-list { list-style: none; }
.tx-item {
  display: flex;
  align-items: center;
  padding: 12px 4px;
  border-bottom: 1px solid rgba(217, 207, 240, 0.18);
  transition: background 0.2s;
}
.tx-item:last-child { border-bottom: none; }
.tx-item:active {
  background: rgba(255, 255, 255, 0.3);
  border-radius: var(--r-sm);
}
/* Category icon badge (gradient pastel + white SVG) */
.cat-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  flex-shrink: 0;
  margin-right: 14px;
  box-sizing: border-box;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 2px 8px rgba(0, 0, 0, 0.06);
}
.cat-ico svg {
  width: 58%;
  height: 58%;
  overflow: visible;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.08));
}
/* Inline variant for chat/parse card */
.cat-ico-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  vertical-align: -5px;
  margin-right: 4px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.cat-ico-inline svg {
  overflow: visible;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.1));
}
/* In category rank list, adjust spacing */
.category-rank-item .cat-ico {
  margin: 0 10px 0 2px;
}

/* Legacy fallback (unused, kept for compat) */
.tx-icon {
  width: 42px; height: 42px;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  margin-right: 14px;
  flex-shrink: 0;
}

.tx-info { flex: 1; min-width: 0; }
.tx-info .tx-desc {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.tx-info .tx-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 3px;
  font-weight: 500;
}
.tx-amount {
  font-size: 16px;
  font-weight: 700;
  text-align: right;
  letter-spacing: -0.3px;
}
.tx-amount.expense { color: var(--expense); }
.tx-amount.income { color: var(--income); }

/* ============================================
   CHAT INTERFACE (Record page)
   ============================================ */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 252px);  /* fallback */
  height: calc(100dvh - 252px); /* 现代浏览器原生键盘适配：键盘弹出时 dvh=可视高度，容器自动缩小 */
  min-height: 0;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 8px 0 92px;
}
.chat-msg {
  display: flex;
  margin-bottom: 18px;
  gap: 10px;
  align-items: flex-end;
}
.chat-msg.user { flex-direction: row-reverse; }
.chat-avatar {
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(190, 170, 220, 0.18);
}
.chat-msg.user .chat-avatar {
  background: linear-gradient(135deg, var(--lavender-100), var(--pink-100));
  color: var(--accent);
}
.chat-msg.bot .chat-avatar {
  background: linear-gradient(135deg, var(--peach-100), var(--cream-warm));
  font-size: 18px;
  color: var(--accent);
}
.chat-bubble {
  max-width: 72%;
  padding: 11px 15px;
  border-radius: var(--r-md);
  font-size: 15px;
  line-height: 1.55;
  position: relative;
  word-wrap: break-word;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.chat-msg.user .chat-bubble {
  background: linear-gradient(135deg, var(--lavender-200), var(--pink-200));
  color: #fff;
  border-radius: var(--r-md) var(--r-md) 6px var(--r-md);
  box-shadow: 0 4px 14px rgba(201, 160, 224, 0.3);
}
.chat-msg.bot .chat-bubble {
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border-soft);
  color: var(--text);
  border-radius: var(--r-md) var(--r-md) var(--r-md) 6px;
  box-shadow: var(--glass-shadow);
}

/* Parse result card in chat */
.parse-card {
  background: var(--glass-bg-strong);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--r-md);
  padding: 16px;
  margin-top: 8px;
  border: 1px solid var(--glass-border-soft);
  box-shadow: var(--glass-shadow);
}
.parse-card .pc-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 13px;
}
.parse-card .pc-label { color: var(--text-secondary); font-weight: 500; }
.parse-card .pc-value { font-weight: 600; color: var(--text); }
.parse-card .pc-cat-select {
  width: 100%;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1.5px solid rgba(217, 207, 240, 0.4);
  background: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text);
  outline: none;
}
.parse-card .pc-cat-select:focus { border-color: var(--lavender-200); }
.parse-card .pc-amount {
  font-size: 26px;
  font-weight: 700;
  margin: 10px 0 4px;
  letter-spacing: -0.5px;
  text-align: center;
  padding: 10px 0;
  border-radius: var(--r-sm);
  background: rgba(255, 255, 255, 0.4);
}
.parse-card .pc-amount.expense { color: var(--expense); }
.parse-card .pc-amount.income { color: var(--income); }
.parse-card .pc-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.parse-card .pc-btn {
  flex: 1;
  padding: 10px;
  border-radius: var(--r-full);
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.3s;
}
.parse-card .pc-btn:active { transform: scale(0.97); }
.parse-card .pc-btn.confirm {
  background: linear-gradient(135deg, var(--lavender-200), var(--pink-200));
  color: #fff;
  box-shadow: 0 4px 12px rgba(201, 160, 224, 0.35);
}
.parse-card .pc-btn.cancel {
  background: rgba(255, 255, 255, 0.6);
  color: var(--text-secondary);
  border: 1px solid rgba(217, 207, 240, 0.3);
}
.parse-card .pc-confidence {
  display: inline-block;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: var(--r-full);
  background: var(--mint-100);
  color: #5C8B6E;
  margin-left: 8px;
  font-weight: 600;
}

/* Chat input bar - glass + floating */
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px;
  margin: 0;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-full);
  box-shadow: var(--glass-shadow);
  position: fixed;
  left: 50%;
  /* 键盘关闭时让出底部导航；键盘打开时由 JS 改为键盘上沿偏移 */
  bottom: calc(var(--input-bottom-offset, calc(var(--tabbar-h) + 12px)) + env(safe-area-inset-bottom, 0px));
  width: min(calc(100% - 32px), 382px);
  transform: translateX(-50%);
  z-index: 110;
  transition: bottom 0.15s ease;
}
.chat-input-bar input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 14px;
  font-size: 15px;
  outline: none;
  color: var(--text);
  font-family: inherit;
}
.chat-input-bar input::placeholder { color: var(--text-tertiary); }
.chat-input-bar button {
  background: linear-gradient(135deg, var(--lavender-200), var(--pink-200));
  color: #fff;
  border: none;
  border-radius: var(--r-full);
  padding: 8px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(201, 160, 224, 0.3);
  transition: transform 0.15s;
}
.chat-input-bar button:active { transform: scale(0.95); }

.chat-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 24px 8px;
  line-height: 1.8;
}
.chat-hint .hint-title {
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 10px;
}
.chat-hint .hint-examples {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border-soft);
  border-radius: var(--r-md);
  padding: 14px 18px;
  margin-top: 12px;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--glass-shadow);
}
.chat-hint .hint-examples .hint-row {
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-hint .hint-examples .hint-arrow { color: var(--accent); font-weight: 700; }
.chat-hint .hint-emoji-bg {
  font-size: 48px;
  margin-bottom: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  filter: drop-shadow(0 4px 8px rgba(190, 170, 220, 0.2));
}
.chat-hint .hint-emoji-bg svg {
  color: var(--accent);
  opacity: 0.6;
}

/* ============================================
   ANALYSIS PAGE
   ============================================ */
.period-tabs {
  display: flex;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border-soft);
  border-radius: var(--r-full);
  padding: 4px;
  margin-bottom: 16px;
  box-shadow: var(--glass-shadow);
}
.period-tab {
  flex: 1;
  text-align: center;
  padding: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  border-radius: var(--r-full);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s;
}
.period-tab.active {
  background: linear-gradient(135deg, var(--lavender-100), var(--pink-100));
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(201, 160, 224, 0.2);
}

.summary-cards {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.summary-card {
  flex: 1;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  padding: 16px 10px;
  text-align: center;
  box-shadow: var(--glass-shadow);
}
.summary-card .sc-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.3px;
}
.summary-card .sc-value {
  font-size: 19px;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: -0.3px;
}
.summary-card.expense .sc-value { color: var(--expense); }
.summary-card.income .sc-value { color: var(--income); }
.summary-card.net .sc-value {
  font-size: 17px;
  color: var(--text);
}

.chart-card { margin-bottom: 14px; }
.chart-card canvas {
  max-height: 250px;
  width: 100% !important;
}

.category-rank { list-style: none; }
.category-rank-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(217, 207, 240, 0.15);
}
.category-rank-item:last-child { border-bottom: none; }
.cr-rank {
  width: 24px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-tertiary);
  text-align: center;
  flex-shrink: 0;
}
.cr-rank.top1 { color: #D78885; }
.cr-rank.top2 { color: #C9A0E0; }
.cr-rank.top3 { color: #8FBA9E; }
/* When .cat-ico is used in rank list, override margin */
.category-rank-item .cat-ico { margin: 0 10px 0 2px; }
.cr-info { flex: 1; min-width: 0; }
.cr-info .cr-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.cr-info .cr-bar {
  height: 5px;
  background: rgba(217, 207, 240, 0.25);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}
.cr-info .cr-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.cr-amount {
  font-size: 14px;
  font-weight: 700;
  color: var(--expense);
  letter-spacing: -0.2px;
}
.cr-pct {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
  text-align: right;
}

/* ============================================
   FAMILY PAGE
   ============================================ */
.family-header {
  text-align: center;
  margin-bottom: 18px;
  padding: 8px 0;
}
.family-header .fh-avatar {
  width: 72px; height: 72px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--peach-100), var(--lavender-100));
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  box-shadow: var(--glass-shadow);
  border: 3px solid rgba(255, 255, 255, 0.7);
}
.family-header .fh-avatar svg {
  color: var(--accent);
  opacity: 0.7;
}
.family-header .fh-name {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.family-header .fh-code {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}
.family-header .fh-code span {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border-soft);
  color: var(--accent);
  padding: 5px 14px;
  border-radius: var(--r-full);
  font-weight: 700;
  font-family: 'SF Mono', monospace;
  letter-spacing: 1px;
  font-size: 13px;
  display: inline-block;
  cursor: pointer;
}

.member-list { list-style: none; }
.member-item {
  display: flex;
  align-items: center;
  padding: 14px 4px;
  border-bottom: 1px solid rgba(217, 207, 240, 0.15);
}
.member-item:last-child { border-bottom: none; }
.member-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  margin-right: 14px;
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.member-avatar.bg-peach    { background: linear-gradient(135deg, var(--peach-100), var(--peach-50)); }
.member-avatar.bg-pink     { background: linear-gradient(135deg, var(--pink-100), var(--pink-50)); }
.member-avatar.bg-blue     { background: linear-gradient(135deg, var(--blue-100), var(--blue-50)); }
.member-avatar.bg-lavender { background: linear-gradient(135deg, var(--lavender-100), var(--lavender-50)); }
.member-avatar.bg-mint     { background: linear-gradient(135deg, var(--mint-100), var(--mint-50)); }

.member-info { flex: 1; }
.member-info .mi-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.member-info .mi-role {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.role-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--r-full);
  font-size: 11px;
  font-weight: 600;
}
.role-tag.admin  { background: var(--lavender-100); color: #7B5BA6; }
.role-tag.member { background: var(--mint-100);    color: #5C8B6E; }
.role-tag.viewer { background: var(--cream-warm);  color: var(--text-secondary); }

.member-stats { text-align: right; }
.member-stats .ms-amount {
  font-size: 16px;
  font-weight: 700;
  color: var(--expense);
  letter-spacing: -0.3px;
}
.member-stats .ms-count {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.current-member-badge {
  font-size: 11px;
  color: #5C8B6E;
  background: var(--mint-100);
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-weight: 600;
}

.add-member-btn {
  width: 100%;
  padding: 16px;
  border: 1.5px dashed rgba(201, 160, 224, 0.4);
  border-radius: var(--r-md);
  background: var(--glass-bg-soft);
  backdrop-filter: blur(10px);
  font-size: 14px;
  color: var(--accent);
  cursor: pointer;
  margin-top: 14px;
  font-weight: 600;
  transition: all 0.2s;
}
.add-member-btn:active {
  background: var(--glass-bg);
  border-style: solid;
}

/* ============================================
   GLASS TAB BAR (floating, iOS-style)
   ============================================ */
.tabbar {
  position: fixed;
  bottom: calc(8px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 382px;
  height: var(--tabbar-h);
  background: var(--glass-bg-strong);
  backdrop-filter: blur(30px) saturate(1.6);
  -webkit-backdrop-filter: blur(30px) saturate(1.6);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-full);
  display: flex;
  z-index: 100;
  box-shadow:
    0 12px 40px -8px rgba(190, 170, 220, 0.35),
    0 4px 12px rgba(190, 170, 220, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color 0.25s, transform 0.2s;
  font-weight: 500;
}
.tab .tab-icon {
  font-size: 22px;
  margin-bottom: 3px;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.tab .tab-icon svg {
  transition: stroke 0.25s;
}
.tab.active {
  color: var(--accent);
  font-weight: 600;
}
.tab.active .tab-icon {
  transform: translateY(-2px) scale(1.15);
}

/* ============================================
   MODAL
   ============================================ */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(45, 42, 64, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border-radius: var(--r-lg);
  border: 1px solid var(--glass-border);
  width: 85%;
  max-width: 320px;
  padding: 22px;
  box-shadow: var(--glass-shadow-hover);
  animation: modalIn 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.9) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal h3 {
  font-size: 17px;
  margin-bottom: 18px;
  text-align: center;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.modal .form-group { margin-bottom: 14px; }
.modal label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}
.modal input, .modal select {
  width: 100%;
  background: rgba(255, 255, 255, 0.6);
  border: 1.5px solid rgba(217, 207, 240, 0.4);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-size: 15px;
  outline: none;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.2s, background 0.2s;
}
.modal input:focus, .modal select:focus {
  border-color: var(--lavender-200);
  background: rgba(255, 255, 255, 0.9);
}
.modal .modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.modal .modal-btn {
  flex: 1;
  padding: 12px;
  border-radius: var(--r-full);
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s;
}
.modal .modal-btn:active { transform: scale(0.97); }
.modal .modal-btn.primary {
  background: linear-gradient(135deg, var(--lavender-200), var(--pink-200));
  color: #fff;
  box-shadow: 0 4px 12px rgba(201, 160, 224, 0.3);
}
.modal .modal-btn.secondary {
  background: rgba(217, 207, 240, 0.2);
  color: var(--text-secondary);
}
.modal .modal-btn.danger {
  background: rgba(250, 81, 81, 0.1);
  color: var(--expense);
  border: 1.5px solid rgba(250, 81, 81, 0.25);
}
.modal .edit-field { margin-bottom: 12px; }
.modal .edit-field:last-of-type { margin-bottom: 0; }

/* ============================================
   TOAST
   ============================================ */
.toast {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(45, 42, 64, 0.85);
  backdrop-filter: blur(20px);
  color: #fff;
  padding: 12px 22px;
  border-radius: var(--r-full);
  font-size: 14px;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.02);
}

/* ============================================
   EMPTY STATE
   ============================================ */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-tertiary);
  font-size: 14px;
}
.empty-state .icon {
  font-size: 56px;
  margin-bottom: 16px;
  display: block;
  filter: drop-shadow(0 6px 12px rgba(190, 170, 220, 0.2));
}
.empty-state .empty-icon {
  margin-bottom: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.empty-state .empty-icon svg {
  color: var(--text-tertiary);
  opacity: 0.5;
}
.empty-state .text {
  color: var(--text-secondary);
  font-weight: 500;
}

/* ============================================
   MEMBER SWITCHER (chips)
   ============================================ */
.member-switcher {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 4px 12px;
  scrollbar-width: none;
}
.member-switcher::-webkit-scrollbar { display: none; }
.member-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px 6px 6px;
  border-radius: var(--r-full);
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border-soft);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  color: var(--text-secondary);
  font-weight: 500;
  transition: all 0.2s;
}
.member-chip.active {
  background: linear-gradient(135deg, var(--lavender-100), var(--pink-100));
  border-color: rgba(201, 160, 224, 0.3);
  color: var(--text);
  font-weight: 600;
}
.member-chip .mc-avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.7);
}

/* ============================================
   LOGIN PAGE
   ============================================ */
.login-page {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #FFE5D1 0%, #FFD9E0 35%, #E5D7F1 70%, #D5E7F2 100%);
  overflow-y: auto;
}
.login-page::before {
  content: '';
  position: absolute;
  top: -60px; right: -40px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  filter: blur(40px);
  animation: float-orb 8s ease-in-out infinite;
}
.login-page::after {
  content: '';
  position: absolute;
  bottom: -50px; left: -30px;
  width: 180px; height: 180px;
  border-radius: 50%;
  background: rgba(201, 160, 224, 0.25);
  filter: blur(40px);
  animation: float-orb 10s ease-in-out infinite reverse;
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 360px;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 28px;
  padding: 36px 28px 28px;
  box-shadow: 0 20px 60px -15px rgba(190, 170, 220, 0.3),
              0 4px 16px rgba(190, 170, 220, 0.1);
}
.login-logo {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  border-radius: 20px;
  background: linear-gradient(135deg, #FFCFAB, #FBC4CE, #D2BFEA);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px -6px rgba(201, 160, 224, 0.4);
}
.login-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.login-subtitle {
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 28px;
}
.login-field {
  margin-bottom: 16px;
}
.login-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  padding-left: 4px;
}
.login-field input {
  width: 100%;
  height: 46px;
  padding: 0 16px;
  border: 1.5px solid rgba(255, 255, 255, 0.8);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.5);
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: all 0.2s;
}
.login-field input::placeholder {
  color: var(--text-tertiary);
}
.login-field input:focus {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 0 3px rgba(201, 160, 224, 0.15);
}
.login-error {
  display: none;
  margin: -8px 0 16px;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--expense-soft);
  color: var(--expense);
  font-size: 13px;
  text-align: center;
}
.login-error.show {
  display: block;
  animation: shake 0.4s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.login-btn {
  width: 100%;
  height: 48px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #C9A0E0, #B885C9);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 6px 20px -4px rgba(201, 160, 224, 0.5);
}
.login-btn:active {
  transform: scale(0.97);
  box-shadow: 0 3px 12px -2px rgba(201, 160, 224, 0.4);
}
.login-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 20px;
  line-height: 1.6;
}

/* Logout button in family page */
.logout-btn {
  width: 100%;
  height: 44px;
  border: 1.5px solid var(--expense-soft);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--expense);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s;
}
.logout-btn:active {
  background: var(--expense-soft);
}

/* ============================================
   RECORDS PAGE (All Records with Filters)
   ============================================ */
.records-summary {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.records-summary .rs-item {
  flex: 1;
  padding: 12px 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  text-align: center;
}
.records-summary .rs-item.expense { background: rgba(250, 81, 81, 0.06); }
.records-summary .rs-item.income { background: rgba(7, 193, 96, 0.06); }
.records-summary .rs-item.net { background: rgba(201, 160, 224, 0.08); }
.records-summary .rs-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 2px;
}
.records-summary .rs-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.records-filters {
  margin-bottom: 12px;
}
.filter-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.filter-tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 12px;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.6);
}
.filter-tab {
  flex: 1;
  text-align: center;
  padding: 7px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.2s;
}
.filter-tab.active {
  background: linear-gradient(135deg, #C9A0E0, #B885C9);
  color: #fff;
  box-shadow: 0 2px 8px -2px rgba(201, 160, 224, 0.4);
}
.filter-select {
  flex: 1;
  height: 38px;
  padding: 0 10px;
  border: 1.5px solid rgba(255, 255, 255, 0.7);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
  font-size: 13px;
  color: var(--text);
  outline: none;
  cursor: pointer;
  appearance: auto;
}
.filter-select:focus {
  border-color: var(--accent);
}
.filter-search {
  width: 100%;
  height: 38px;
  padding: 0 14px;
  border: 1.5px solid rgba(255, 255, 255, 0.7);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
  font-size: 13px;
  color: var(--text);
  outline: none;
}
.filter-search::placeholder {
  color: var(--text-tertiary);
}
.filter-search:focus {
  border-color: var(--accent);
}

.records-list {
  margin-top: 4px;
}
.records-date-group {
  margin-bottom: 16px;
}
.rdg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.5);
  margin-bottom: 8px;
}
.rdg-date {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.rdg-summary {
  font-size: 12px;
  font-weight: 600;
}

/* ============================================
   AI TYPING INDICATOR
   ============================================ */
.ai-typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}
.ai-typing-indicator .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.5;
  animation: ai-dot-bounce 1.2s infinite;
}
.ai-typing-indicator .dot:nth-child(2) {
  animation-delay: 0.2s;
}
.ai-typing-indicator .dot:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes ai-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ============================================
   MULTI PARSE CARD (multiple transactions)
   ============================================ */
.multi-parse-card {
  padding: 14px !important;
}
.mpc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1.5px solid rgba(201, 160, 224, 0.2);
}
.mpc-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}
.mpc-total {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.mpc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.mpc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.6);
}
.mpc-icon {
  flex-shrink: 0;
}
.mpc-info {
  flex: 1;
  min-width: 0;
}
.mpc-desc {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mpc-cat {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 1px;
}
.mpc-amount {
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}
.mpc-amount.expense { color: var(--expense); }
.mpc-amount.income { color: var(--income); }
.mpc-summary {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  padding: 8px;
  border-radius: 10px;
  background: rgba(201, 160, 224, 0.08);
  margin-bottom: 12px;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 360px) {
  .dashboard-hero .amount { font-size: 32px; }
  .summary-cards .sc-value { font-size: 17px; }
  .records-summary .rs-value { font-size: 14px; }
  .filter-tab { font-size: 11px; padding: 6px 2px; }
  html, body { font-size: 14px; }
}
