:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --text: #1f2430;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ---------- 登入畫面 ---------- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #2563eb 0%, #1e3a8a 100%);
}
.login-card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 36px 28px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,.25);
}
.login-emoji { font-size: 48px; margin-bottom: 8px; }
.login-card h1 { margin: 0 0 8px; font-size: 22px; }
.login-sub { color: var(--text-muted); font-size: 14px; line-height: 1.6; margin-bottom: 28px; }
.login-hint { color: var(--text-muted); font-size: 12px; margin-top: 16px; }
.btn-google {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-google:active { background: #f3f4f6; }

/* ---------- App Shell ---------- */
#app-screen { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--blue);
  color: #fff;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
}
.topbar-title { font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 10px; font-size: 12px; opacity: .9; }
.btn-text {
  background: none;
  border: none;
  color: inherit;
  text-decoration: underline;
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
}

#main-content {
  flex: 1;
  padding: 16px 16px 90px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- Bottom Nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.nav-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 10px 0 8px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.nav-btn.active { color: var(--blue); font-weight: 700; }
.nav-icon { font-size: 20px; }

/* ---------- 卡片與摘要 ---------- */
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.summary-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  border-left: 4px solid var(--blue);
}
.card-cash { border-left-color: var(--green); }
.summary-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.summary-value { font-size: 18px; font-weight: 700; }
.summary-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.category-breakdown {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 14px;
}
.category-breakdown summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.breakdown-list { list-style: none; margin: 8px 0 0; padding: 0; }
.breakdown-list li { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; color: var(--text-muted); }
.breakdown-list li span:last-child { color: var(--text); font-weight: 600; }

.progress-block { background: var(--card-bg); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.progress-row { margin-bottom: 10px; }
.progress-row:last-child { margin-bottom: 0; }
.progress-row-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.progress-bar-track { background: #e5e7eb; border-radius: 6px; height: 8px; overflow: hidden; }
.progress-bar-fill { background: var(--green); height: 100%; border-radius: 6px; transition: width .2s; }

/* ---------- 篩選 chips ---------- */
.filter-chips { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
}
.chip.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---------- 清單標頭與新增按鈕 ---------- */
.list-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.list-header h2 { font-size: 16px; margin: 0; }
.btn-fab {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-fab:active { background: var(--blue-dark); }

/* ---------- 表單 ---------- */
.inline-form {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.inline-form label {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.inline-form input,
.inline-form select {
  font-size: 16px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
}
.segmented { display: flex; gap: 8px; }
.seg-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.seg-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.btn-primary {
  flex: 1;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:active { background: var(--blue-dark); }

/* ---------- 項目清單 ---------- */
.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item-row {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.item-main { flex: 1; min-width: 0; }
.item-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.item-amount { font-size: 15px; font-weight: 700; white-space: nowrap; }
.tag {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--blue);
  margin-right: 4px;
}
.tag-cash { background: #ecfdf5; color: var(--green); }
.item-actions { display: flex; gap: 4px; }
.icon-btn {
  border: none;
  background: none;
  font-size: 16px;
  padding: 6px;
  cursor: pointer;
  color: var(--text-muted);
}
.checkbox-toggle { width: 22px; height: 22px; flex-shrink: 0; }

.empty-hint { color: var(--text-muted); font-size: 13px; text-align: center; padding: 24px 0; }
.about-text { font-size: 13px; color: var(--text-muted); line-height: 1.7; }

/* ---------- 離線提示 / toast ---------- */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #f59e0b;
  color: #fff;
  text-align: center;
  font-size: 12px;
  padding: 6px;
  z-index: 50;
}
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 60;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}

@media (min-width: 640px) {
  .bottom-nav { max-width: 560px; left: 50%; transform: translateX(-50%); border-radius: 16px 16px 0 0; }
}
