@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;600;700&family=Noto+Serif+TC:wght@500;700&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  --bg: #FAF8F5;
  --surface: #FFFFFF;
  --surface-hover: #F5F3F0;
  --border: #E8E4DE;
  --border-light: #F0ECE6;
  --text: #1A1A1A;
  --text-secondary: #8A8580;
  --text-muted: #B5AFA8;
  --accent: #C8553D;
  --accent-light: #FDF0ED;
  --green: #2D8659;
  --green-light: #EDF7F0;
  --navy: #1E293B;
  --navy-deep: #0F172A;
  --gold: #D4A843;
  --gold-soft: #F5EDDA;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
}

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

body {
  font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.mono { font-family: 'JetBrains Mono', monospace; }

/* ===== LOGIN ===== */
#loginScreen {
  min-height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--navy-deep);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.login-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  background: linear-gradient(135deg, var(--accent) 0%, #E87A5F 100%);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 16px rgba(200, 85, 61, 0.3);
}

.login-title {
  font-family: 'Noto Serif TC', serif;
  font-weight: 700;
  font-size: 28px;
  color: #fff;
  margin-bottom: 8px;
}

.login-sub {
  color: rgba(255,255,255,0.45);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 36px;
}

.login-btn {
  width: 100%;
  background: #fff;
  color: var(--text);
  border: none;
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 600;
  font-family: 'Noto Sans TC', sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.15s ease;
  box-shadow: var(--shadow);
}

.login-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.login-btn svg { flex-shrink: 0; }

/* ===== APP SHELL ===== */
#appShell {
  display: none;
  min-height: 100vh;
  flex-direction: column;
}

.app-header {
  background: var(--navy-deep);
  padding: 16px 20px 28px;
  position: relative;
}

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

.greet {
  font-size: 14px;
  color: rgba(255,255,255,0.5);
}

.greet b {
  color: #fff;
  font-weight: 600;
}

.header-total { text-align: right; }

.total-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--gold);
  font-weight: 600;
  margin-bottom: 4px;
}

.total-amount {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 24px;
  color: #fff;
  letter-spacing: -0.02em;
}

.header-curve {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 20px;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
}

main {
  flex: 1;
  padding: 0 16px 100px;
  margin-top: -12px;
  position: relative;
  z-index: 1;
}

.page {
  display: none;
  padding-top: 8px;
}

.page.active {
  display: block;
  animation: fadeUp 0.2s ease;
}

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

.section-title {
  font-family: 'Noto Serif TC', serif;
  font-weight: 700;
  font-size: 16px;
  margin: 24px 0 12px;
  color: var(--text);
}

.section-title:first-child { margin-top: 8px; }

/* ===== CARDS ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
}

/* ===== TYPE TOGGLE ===== */
.type-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.type-btn {
  flex: 1;
  padding: 9px;
  border-radius: 6px;
  border: none;
  background: transparent;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-secondary);
  font-family: 'Noto Sans TC', sans-serif;
  transition: all 0.15s ease;
}

.type-btn[data-active="true"][data-type="expense"] {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 4px rgba(200, 85, 61, 0.25);
}

.type-btn[data-active="true"][data-type="income"] {
  background: var(--green);
  color: #fff;
  box-shadow: 0 1px 4px rgba(45, 134, 89, 0.25);
}

.type-btn[data-active="true"][data-type="transfer"] {
  background: var(--navy);
  color: #fff;
  box-shadow: 0 1px 4px rgba(30, 41, 59, 0.25);
}

/* ===== FORM ===== */
.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 20px 0 8px;
}

.field-label:first-child { margin-top: 0; }

.field-group { margin-bottom: 4px; }

input[type=number],
input[type=text],
input[type=date],
select {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 15px;
  font-family: 'Noto Sans TC', sans-serif;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.amount-input {
  font-family: 'JetBrains Mono', monospace;
  font-size: 32px;
  font-weight: 700;
  padding: 12px 4px;
  border: none;
  border-bottom: 2px solid var(--border);
  border-radius: 0;
  background: transparent;
  text-align: left;
  letter-spacing: -0.02em;
}

.amount-input:focus {
  outline: none;
  border-bottom-color: var(--accent);
  box-shadow: none;
}

.amount-input::placeholder { color: var(--text-muted); }

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ===== CATEGORY PILLS ===== */
.cat-pill-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.cat-pill {
  padding: 8px 16px;
  border-radius: 100px;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  color: var(--text-secondary);
  transition: all 0.12s ease;
}

.cat-pill:hover { border-color: var(--text-muted); }

.cat-pill[data-active="true"] {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}

.cat-pill.cat-pill-add {
  border-style: dashed;
  color: var(--accent);
  border-color: var(--accent);
}

.cat-pill-input {
  padding: 8px 14px;
  border-radius: 100px;
  border: 1px solid var(--accent);
  font-size: 13px;
  width: 130px;
  background: var(--surface);
}

/* ===== BUTTONS ===== */
.submit-btn {
  width: 100%;
  margin-top: 24px;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--navy-deep);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  font-family: 'Noto Sans TC', sans-serif;
  cursor: pointer;
  transition: all 0.12s ease;
}

.submit-btn:hover { background: var(--navy); }
.submit-btn:active { transform: scale(0.98); }

.small-btn {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
  font-family: 'Noto Sans TC', sans-serif;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.12s ease;
}

.small-btn:hover { background: var(--surface-hover); }
.danger-text { color: var(--accent); }

/* ===== STAMP EFFECT ===== */
.stamp-fx {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.4) rotate(-12deg);
  width: 100px;
  height: 100px;
  border: 4px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-family: 'Noto Serif TC', serif;
  font-weight: 700;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  z-index: 999;
}

.stamp-fx.go {
  animation: stampIn 0.8s cubic-bezier(0.2, 1.2, 0.4, 1) forwards;
}

@keyframes stampIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(3) rotate(-12deg); }
  25% { opacity: 0.8; transform: translate(-50%, -50%) scale(0.95) rotate(-12deg); }
  40% { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(-12deg); }
  55% { transform: translate(-50%, -50%) scale(1) rotate(-12deg); }
  85% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-12deg); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1) rotate(-12deg); }
}

/* ===== TRANSACTION LIST ===== */
.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-light);
}

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

.tx-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.tx-mid { flex: 1; min-width: 0; }
.tx-cat { font-size: 14px; font-weight: 500; }
.tx-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.tx-amt {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}

.tx-amt.expense { color: var(--accent); }
.tx-amt.income { color: var(--green); }
.tx-amt.transfer { color: var(--text-secondary); }

.tx-del {
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.12s ease;
}

.tx-del:hover {
  color: var(--accent);
  background: var(--accent-light);
}

.empty-hint {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.7;
}

/* ===== CHART PAGE ===== */
.balance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 4px;
}

.bal-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.bal-card .acct-icon { margin-bottom: 8px; color: var(--text-secondary); }
.bal-card .acct-name { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }

.bal-card .val {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.budget-row { margin-bottom: 16px; }
.budget-row:last-child { margin-bottom: 0; }

.budget-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 8px;
}

.budget-name { font-weight: 500; }
.budget-val { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--text-secondary); }

.budget-bar-bg {
  height: 6px;
  background: var(--border-light);
  border-radius: 100px;
  overflow: hidden;
}

.budget-bar-fill {
  height: 100%;
  border-radius: 100px;
  background: var(--green);
  transition: width 0.3s ease;
}

.budget-bar-fill.over { background: var(--accent); }

/* ===== SETTINGS ===== */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.settings-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.theme-swatches { display: flex; gap: 10px; }

.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.12s ease;
}

.swatch:hover { transform: scale(1.1); }
.swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text); }

.acct-manage-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}

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

.icon-choice-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.icon-choice {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--surface);
  transition: all 0.12s ease;
}

.icon-choice:hover { border-color: var(--text-muted); }

.icon-choice[data-active="true"] {
  border-color: var(--text);
  background: var(--bg);
}

.cat-manage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.cat-manage-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cat-manage-item input {
  flex: 1;
  padding: 10px 12px;
  font-size: 14px;
}

.cat-manage-item input.budget-num { max-width: 100px; }

/* ===== BOTTOM NAV ===== */
nav.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border-light);
  display: flex;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
}

.nav-btn {
  flex: 1;
  padding: 10px 4px 8px;
  text-align: center;
  cursor: pointer;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  font-family: 'Noto Sans TC', sans-serif;
  transition: color 0.12s ease;
}

.nav-btn .nav-ic {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-btn[data-active="true"] { color: var(--accent); }

/* ===== MODAL ===== */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}

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

.modal-box {
  background: var(--surface);
  width: 100%;
  max-width: 420px;
  border-radius: 16px 16px 0 0;
  padding: 24px 20px 32px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}

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

.modal-title {
  font-family: 'Noto Serif TC', serif;
  font-weight: 700;
  font-size: 18px;
  margin-bottom: 16px;
}

.modal-close {
  float: right;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  padding: 4px;
}

.modal-close:hover { color: var(--text); }

@media (min-width: 480px) {
  #loginScreen .login-card { max-width: 360px; }
}