/* ===== RESET & BASE ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { max-width: 480px; margin: 0 auto; min-height: 100vh; font-family: 'Inter', sans-serif; background: #F5F7FA; }

/* ===== PAGES ===== */
.page { display: none; min-height: 100vh; padding-bottom: 80px; }
.page.active { display: block; }

/* ===== HEADER ===== */
.hdr {
  background: linear-gradient(135deg, #166534 0%, #16a34a 100%);
  padding: max(32px, env(safe-area-inset-top) + 10px) 20px 12px;
}

/* ===== CONTENT ===== */
.content { padding: 16px; }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  display: flex; background: #fff;
  border-top: 1px solid #f1f5f9;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px;
  padding: 10px 0 12px;
  color: #9ca3af; font-size: 10px; font-weight: 500;
  background: none; border: none; cursor: pointer; transition: color .2s;
}
.nav-btn.active { color: #166534; }
.nav-btn svg { transition: color .2s; }

/* ===== TAB BAR ===== */
.tab-bar {
  display: flex; background: #fff;
  border-bottom: 1px solid #f1f5f9;
}
.tab {
  flex: 1; padding: 12px 4px; font-size: 13px; font-weight: 500;
  color: #9ca3af; border-bottom: 2px solid transparent;
  background: none; border-left: none; border-right: none; border-top: none;
  cursor: pointer; transition: all .2s;
}
.tab.active { color: #166534; border-bottom-color: #166534; }

/* ===== CARD ===== */
.card {
  background: #fff; border-radius: 16px; padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  border: 1px solid #f1f5f9;
}
.card-amber { border-color: #DDB830 !important; background: #FFFCEE !important; }
.card-inner { background: #f8fafc; border-radius: 12px; padding: 12px; }

/* ===== GRADIENT CARDS ===== */
.grad-blue {
  background: linear-gradient(135deg, #1F4E79 0%, #2E75B6 100%);
  border-radius: 16px; padding: 16px; color: #fff;
}
.grad-amber {
  background: linear-gradient(135deg, #8B6914 0%, #C9A018 100%);
  border-radius: 16px; padding: 16px; color: #fff;
}
.lbl-light { color: rgba(255,255,255,0.75); font-size: 12px; }
.val-xl { font-size: 26px; font-weight: 700; margin: 4px 0; }

/* ===== MODALS / SHEETS ===== */
.overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0); flex-direction: column; justify-content: flex-end;
  transition: background .25s;
}
.overlay.open {
  display: flex; background: rgba(0,0,0,0.4);
}
.sheet {
  background: #fff; border-radius: 20px 20px 0 0;
  max-height: 90vh; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .3s ease;
  overflow: hidden;
}
.overlay.open .sheet { transform: translateY(0); }
.sheet-handle {
  width: 40px; height: 4px; background: #e5e7eb;
  border-radius: 2px; margin: 12px auto 4px;
}
.sheet-hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 20px 12px; border-bottom: 1px solid #f1f5f9;
}
.sheet-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.sheet-foot {
  padding: 12px 20px max(24px, env(safe-area-inset-bottom) + 12px); display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  border-top: 1px solid #f1f5f9;
}
.close-btn {
  color: #9ca3af; font-size: 18px; line-height: 1;
  background: none; border: none; cursor: pointer; padding: 4px;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 12px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  border: none; text-align: center;
}
.btn-pri { background: #166534; color: #fff; }
.btn-sec { background: #fff; color: #6b7280; border: 1px solid #e5e7eb; }
.btn-block { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-del {
  color: #d1d5db; background: none; border: none; cursor: pointer;
  padding: 4px; line-height: 1; font-size: 16px; transition: color .15s;
}
.btn-del:hover { color: #ef4444; }
.btn-sm-green {
  font-size: 11px; color: #16a34a; border: 1px solid #bbf7d0;
  border-radius: 8px; padding: 3px 8px; background: none; cursor: pointer;
}
.btn-ghost-white {
  font-size: 11px; color: rgba(255,255,255,0.85);
  border: 1px solid rgba(255,255,255,0.4); border-radius: 8px;
  padding: 3px 8px; background: none; cursor: pointer;
}

/* ===== FORMS ===== */
.fg { margin-bottom: 12px; }
.fg > label { display: block; font-size: 12px; color: #6b7280; margin-bottom: 4px; }
.fi {
  width: 100%; border: 1px solid #e5e7eb; border-radius: 12px;
  padding: 10px 12px; font-size: 16px;
  outline: none; transition: border-color .2s;
  appearance: none; -webkit-appearance: none;
}
.fi:focus { border-color: #86efac; box-shadow: 0 0 0 3px rgba(134,239,172,0.2); }
.fg-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fg-grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

/* Paired value + growth rate row */
.fg-paired {
  display: grid;
  grid-template-columns: 1fr 128px;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}
.fg-paired .fg { margin-bottom: 0; }
.rate-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 8px 10px 7px;
}
.rate-box-lbl {
  font-size: 10px;
  color: #94a3b8;
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.rate-box-row {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: #64748b;
  white-space: nowrap;
}
.fi-xs {
  width: 36px;
  padding: 5px 4px;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: #1e293b;
  background: #fff;
  -moz-appearance: textfield;
}
.fi-xs::-webkit-inner-spin-button,
.fi-xs::-webkit-outer-spin-button { -webkit-appearance: none; }

/* ===== TYPE BUTTONS ===== */
.type-btn {
  padding: 10px; border-radius: 12px; font-size: 13px; font-weight: 600;
  border: 1px solid #e5e7eb; color: #6b7280; background: #fff; cursor: pointer;
  transition: all .2s;
}
.type-inc { background: #22c55e; color: #fff; border-color: #22c55e; }
.type-exp { background: #ef4444; color: #fff; border-color: #ef4444; }

/* ===== TOGGLE ===== */
.toggle-wrap { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 8px 0; }
.toggle {
  width: 44px; height: 26px; border-radius: 13px; background: #d1d5db;
  position: relative; transition: background .2s; flex-shrink: 0;
}
.toggle.on { background: #3b82f6; }
.toggle-dot {
  position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2); transition: transform .2s;
}
.toggle.on .toggle-dot { transform: translateX(18px); }

/* ===== PROGRESS BAR ===== */
.prog { height: 6px; background: #f3f4f6; border-radius: 3px; overflow: hidden; }
.prog-h3 { height: 10px; background: #f3f4f6; border-radius: 5px; overflow: hidden; }
.prog-fill { height: 100%; border-radius: inherit; transition: width .4s; }

/* ===== TRANSACTION ROW ===== */
.tx-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid #f9fafb;
}
.tx-row:last-child { border-bottom: none; }
.tx-ico {
  width: 34px; height: 34px; border-radius: 17px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}

/* ===== BADGES ===== */
.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 500;
}
.badge-green { background: #dcfce7; color: #16a34a; }
.badge-gray  { background: #f3f4f6; color: #6b7280; }
.badge-blue  { background: #dbeafe; color: #1d4ed8; }

/* ===== HINT BOXES ===== */
.hint { font-size: 12px; background: #f0f9ff; border-radius: 12px; padding: 10px 12px; color: #0369a1; }
.hint-amber { font-size: 12px; background: #fffbeb; border-radius: 12px; padding: 10px 12px; color: #92400e; }
.money-hint { font-size: 11px; color: #10b981; font-weight: 600; margin-top: 3px; min-height: 15px; }
.modal-error { font-size: 12px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 12px; padding: 10px 12px; color: #dc2626; margin-bottom: 12px; }
.cash-avail { font-size: 11px; background: #f0fdf4; border-radius: 10px; padding: 8px 12px; color: #15803d; margin-bottom: 12px; }
.cash-avail.warn { background: #fff7ed; color: #c2410c; }

/* ===== ANALYTICS VIEW CHIPS ===== */
.view-chips { display: flex; gap: 8px; margin-bottom: 12px; }
.view-chip {
  flex: 1; padding: 8px 0; border-radius: 20px; font-size: 12px; font-weight: 600;
  border: 1.5px solid #e5e7eb; color: #6b7280; background: #fff; cursor: pointer;
  transition: all .15s;
}
.view-chip.active { background: #166534; color: #fff; border-color: #166534; }

/* ===== EMPTY STATE ===== */
.empty { text-align: center; padding: 40px 20px; }

/* ===== DATA TABLE ===== */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.dtbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.dtbl th { background: #f8fafc; padding: 8px 10px; text-align: left; color: #6b7280; font-weight: 600; white-space: nowrap; }
.dtbl td { padding: 8px 10px; border-top: 1px solid #f1f5f9; white-space: nowrap; }
.dtbl tr.hl td { background: #eff6ff; font-weight: 600; }

/* ===== LEGEND ===== */
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }

/* ===== GRIDS ===== */
.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.g3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.row2 { display: flex; gap: 16px; }
.row2 > * { flex: 1; }

/* ===== MISC UTILS ===== */
.flex-bc { display: flex; justify-content: space-between; align-items: center; }
.flex-cc { display: flex; align-items: center; gap: 6px; }

/* ===== KPI GRID ===== */
.kpi-scroll {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px;
}
.kpi-card {
  background: #fff; border-radius: 14px; padding: 11px 12px;
  border: 1px solid #f1f5f9;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.kpi-teal    { background: #f0fdfa; border-color: #99f6e4; }
.kpi-gold-bg { background: #FFFCEE; border-color: #DDB830; }
.kpi-lbl { font-size: 11px; color: #6b7280; margin-bottom: 6px; font-weight: 500; }
.kpi-val { font-size: 18px; font-weight: 700; color: #111827; line-height: 1.15; }
.kpi-sub { font-size: 11px; color: #9ca3af; margin-top: 5px; }

/* ===== SECTION TITLE ===== */
.sec-title { font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 10px; }

/* ===== PIE ROW ===== */
.pie-row { display: flex; align-items: center; gap: 16px; padding: 4px 0; }
.pie-legend { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.pie-leg-item { display: flex; align-items: center; gap: 8px; }
.pie-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ===== PROGRESS 30 YEARS ===== */
.prog30-wrap {
  height: 12px; background: #e5e7eb; border-radius: 6px;
  overflow: hidden; margin: 4px 0;
}
.prog30-fill {
  height: 100%; border-radius: 6px;
  background: linear-gradient(90deg, #8B6914, #C9A018);
  transition: width .8s ease;
  min-width: 3px;
}

/* ===== ASSET BOX ===== */
.asset-box { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.asset-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: #f8fafc; border-radius: 12px;
}

/* ===== CHIP SELECTORS ===== */
.cat-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.cat-chip {
  padding: 6px 11px; border-radius: 20px; font-size: 12px; font-weight: 500;
  border: 1px solid #e5e7eb; background: #f9fafb; cursor: pointer;
  transition: all .15s; white-space: nowrap;
}
.cat-chip.cat-inc.active { background: #16a34a; color: #fff; border-color: #16a34a; }
.cat-chip.cat-exp.active { background: #ef4444; color: #fff; border-color: #ef4444; }

.bank-chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 8px; }
.bank-chip {
  padding: 4px 10px; border-radius: 16px; font-size: 11px; font-weight: 500;
  border: 1px solid #e5e7eb; background: #f9fafb; cursor: pointer; transition: all .15s;
}
.bank-chip.active { background: #0D9488; color: #fff; border-color: #0D9488; }

.term-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.term-chip {
  padding: 5px 10px; border-radius: 16px; font-size: 12px; font-weight: 600;
  border: 1px solid #e5e7eb; background: #f9fafb; cursor: pointer; transition: all .15s;
}
.term-chip.active { background: #166534; color: #fff; border-color: #166534; }

.quick-amt { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.quick-amt-btn {
  padding: 4px 9px; border-radius: 14px; font-size: 11px; font-weight: 600;
  border: 1px solid #e5e7eb; background: #f9fafb; cursor: pointer; transition: all .15s;
}
.quick-amt-btn:active { background: #e0f2fe; border-color: #7dd3fc; }

/* ===== SMART GOLD ACTION ===== */
.smart-gold {
  background: linear-gradient(135deg, #FFFCEE 0%, #FFF5CC 100%);
  border: 1px solid #DDB830; border-radius: 16px; padding: 16px;
}
.btn-gold-confirm {
  width: 100%; padding: 13px;
  background: linear-gradient(135deg, #9B7506, #C9A018);
  color: #fff; border: none; border-radius: 12px;
  font-size: 14px; font-weight: 700; cursor: pointer;
  letter-spacing: 0.2px;
}
.btn-gold-confirm:active { opacity: 0.85; }

/* ===== SELL GOLD BUTTONS ===== */
.btn-gold {
  background: linear-gradient(135deg, #9B7506, #C9A018); color: #fff;
}
.btn-sell-top {
  background: linear-gradient(135deg, #8B6914, #C9A018);
  color: #fff; border: none; border-radius: 12px; cursor: pointer;
}
.btn-sell-top:disabled { opacity: .4; cursor: not-allowed; }
.btn-sell-gold {
  font-size: 11px; color: #8B6914; border: 1px solid #DDB830;
  border-radius: 8px; padding: 3px 8px; background: #FFFCEE;
  cursor: pointer; white-space: nowrap; margin-right: 4px;
}

/* ===== LOGIN SCREEN ===== */
.login-screen {
  position: fixed; inset: 0; z-index: 999;
  background: linear-gradient(160deg, #052e16 0%, #166534 50%, #15803d 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: #fff; border-radius: 24px; padding: 36px 28px;
  width: 100%; max-width: 360px; text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25);
}
.login-logo { font-size: 48px; margin-bottom: 12px; }
.login-title { font-size: 22px; font-weight: 700; color: #111827; margin: 0 0 6px; }
.login-sub   { font-size: 13px; color: #6b7280; margin: 0 0 28px; }
.login-error {
  font-size: 12px; color: #dc2626; background: #fef2f2;
  border: 1px solid #fecaca; border-radius: 10px;
  padding: 10px 14px; margin-bottom: 16px;
}
.google-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 13px 20px; border-radius: 12px;
  border: 1.5px solid #e5e7eb; background: #fff;
  font-size: 14px; font-weight: 600; color: #374151;
  cursor: pointer; transition: all .2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.google-btn:hover   { background: #f9fafb; border-color: #d1d5db; }
.google-btn:active  { background: #f3f4f6; }
.google-btn:disabled { opacity: .6; cursor: not-allowed; }

/* ===== LOADING SCREEN ===== */
.loading-screen {
  position: fixed; inset: 0; z-index: 998;
  background: #f5f7fa;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
}
.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid #dcfce7;
  border-top-color: #166534;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.loading-text { font-size: 14px; color: #6b7280; font-weight: 500; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== USER AVATAR ===== */
.user-btn {
  background: none; border: none; cursor: pointer; padding: 0;
  opacity: .9; transition: opacity .2s;
}
.user-btn:hover { opacity: 1; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.6);
  object-fit: cover; display: block;
}

/* ===== MODAL FLASH WARNING ===== */
@keyframes shadow-flash {
  0%   { box-shadow: 0 -4px 24px rgba(0,0,0,0.12); }
  20%  { box-shadow: 0 -4px 24px rgba(0,0,0,0.12), 0 0 0 4px rgba(239,68,68,0.65); }
  45%  { box-shadow: 0 -4px 24px rgba(0,0,0,0.12), 0 0 0 1px rgba(239,68,68,0.15); }
  70%  { box-shadow: 0 -4px 24px rgba(0,0,0,0.12), 0 0 0 4px rgba(239,68,68,0.65); }
  100% { box-shadow: 0 -4px 24px rgba(0,0,0,0.12); }
}
.sheet-flash { animation: shadow-flash 0.55s ease !important; }
