/* ========== 雲光 Web 記帳工具 — 全域樣式 ========== */
:root {
  --purple: #5F1986;
  --purple-dark: #4A1270;
  --purple-light: #F2ECFA;
  --text: #333;
  --text-light: #888;
  --bg: #F5F3F8;
  --card: #FFFFFF;
  --border: #E0E0E0;
  --green: #27AE60;
  --red: #E74C3C;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
  min-height: 100vh; padding-bottom: 72px;
}

/* ===== Layout ===== */
.page { max-width: 480px; margin: 0 auto; padding: 16px 16px 80px; }
.page-title { font-size: 20px; font-weight: 700; color: var(--purple); margin-bottom: 16px; }

/* ===== Card ===== */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.card-title { font-size: 14px; font-weight: 600; color: var(--text-light); margin-bottom: 10px; }

/* ===== Buttons ===== */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; height: 48px; border: none; border-radius: var(--radius);
  font-size: 16px; font-weight: 600; cursor: pointer; transition: opacity 0.15s;
}
.btn:active { opacity: 0.8; }
.btn-purple { background: var(--purple); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-red { background: var(--red); color: #fff; }
.btn-outline { background: none; border: 1.5px solid var(--purple); color: var(--purple); }
.btn-sm { height: 40px; font-size: 14px; width: auto; padding: 0 16px; }
.btn-half { width: 48%; }

/* ===== Inputs ===== */
.input-group { margin-bottom: 14px; }
.input-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-light); margin-bottom: 4px; }
.input {
  width: 100%; height: 48px; padding: 0 14px; border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 16px; color: var(--text); background: #fff; outline: none; -webkit-appearance: none;
}
.input:focus { border-color: var(--purple); }
.input::placeholder { color: #C0C0C0; }
select.input { padding-right: 30px; }
textarea.input { height: auto; min-height: 80px; padding: 12px 14px; resize: vertical; }

/* ===== Navigation Bar ===== */
.navbar {
  position: fixed; bottom: 0; left: 0; right: 0; height: 64px; background: #fff;
  border-top: 1px solid var(--border); display: flex; z-index: 100;
}
.navbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; color: var(--text-light); font-size: 11px; font-weight: 500; gap: 3px;
  transition: color 0.15s;
}
.navbar a.active { color: var(--purple); }
.navbar a svg { width: 22px; height: 22px; }

/* ===== Summary Row ===== */
.summary-row { display: flex; gap: 8px; margin-bottom: 12px; }
.summary-item { flex: 1; text-align: center; padding: 12px 8px; border-radius: 10px; background: var(--purple-light); }
.summary-item.green { background: #E8F5E9; }
.summary-item.red { background: #FFEBEE; }
.summary-value { font-size: 20px; font-weight: 700; color: var(--purple); }
.summary-item.green .summary-value { color: var(--green); }
.summary-item.red .summary-value { color: var(--red); }
.summary-label { font-size: 11px; color: var(--text-light); margin-top: 2px; }

/* ===== Calendar Grid ===== */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-nav button { background: none; border: 1.5px solid var(--border); border-radius: 8px; width: 36px; height: 36px; cursor: pointer; font-size: 18px; color: var(--text); }
.cal-nav button:active { background: var(--purple-light); }
.cal-title { font-size: 16px; font-weight: 700; color: var(--purple); }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow { text-align: center; font-size: 12px; font-weight: 600; color: var(--text-light); padding: 6px 0; }
.cal-day {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 10px; font-size: 13px; cursor: pointer; position: relative; padding: 4px 2px;
}
.cal-day:active { background: var(--purple-light); }
.cal-day.has-data { background: var(--purple-light); }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--purple); }
.cal-day.selected { background: var(--purple); color: #fff; }
.cal-day.other { color: #CCC; }
.cal-day .day-num { font-weight: 600; }
.cal-day .day-val { font-size: 10px; color: var(--purple); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.cal-day.selected .day-val { color: rgba(255,255,255,0.8); }

/* ===== Transaction List ===== */
.tx-item {
  display: flex; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border);
}
.tx-item:last-child { border-bottom: none; }
.tx-left { flex: 1; }
.tx-cat { font-size: 13px; font-weight: 600; }
.tx-desc { font-size: 12px; color: var(--text-light); margin-top: 2px; }
.tx-date { font-size: 11px; color: var(--text-light); }
.tx-amount { font-size: 16px; font-weight: 700; text-align: right; }
.tx-amount.income { color: var(--green); }
.tx-amount.expense { color: var(--red); }
.tx-actions { display: flex; gap: 8px; margin-left: 10px; }
.tx-actions button { background: none; border: none; cursor: pointer; font-size: 14px; color: var(--text-light); padding: 4px; }

/* ===== Modal ===== */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 200; align-items: flex-end; justify-content: center; }
.modal-overlay.active { display: flex; }
.modal { background: var(--card); border-radius: 16px 16px 0 0; width: 100%; max-width: 480px; padding: 24px 20px 32px; max-height: 85vh; overflow-y: auto; }
.modal h3 { font-size: 18px; font-weight: 700; color: var(--purple); margin-bottom: 16px; }

/* ===== Month Card ===== */
.month-card { padding: 14px 16px; border-radius: var(--radius); background: var(--card); border: 1.5px solid var(--border); margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.month-card.current { border-color: var(--purple); background: var(--purple-light); }
.month-card-name { font-size: 16px; font-weight: 700; }
.month-card-val { font-size: 18px; font-weight: 700; color: var(--purple); }
.month-card-sub { font-size: 12px; color: var(--text-light); }

/* ===== Logo ===== */
.logo { text-align: center; margin: 32px 0 24px; }
.logo-text { font-size: 24px; font-weight: 700; color: var(--purple); }
.logo-sub { font-size: 13px; color: var(--text-light); margin-top: 4px; }

/* ===== Error / Toast ===== */
.error-msg { color: var(--red); font-size: 13px; text-align: center; margin-top: 8px; display: none; }
.error-msg.visible { display: block; }

.toast {
  position: fixed; top: -60px; left: 50%; transform: translateX(-50%);
  padding: 10px 24px; border-radius: 10px; font-size: 14px; font-weight: 500;
  color: #fff; z-index: 9999; transition: top 0.3s; background: var(--purple);
}
.toast.show { top: 20px; }
.toast.success { background: var(--green); }

/* ===== Misc ===== */
.empty-hint { text-align: center; color: var(--text-light); padding: 24px 0; font-size: 14px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.text-center { text-align: center; }
a { color: var(--purple); text-decoration: none; }
a:active { opacity: 0.7; }

/* Header bar */
.top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.top-bar-user { font-size: 16px; font-weight: 600; }
.top-bar-logout { background: none; border: none; color: var(--text-light); font-size: 13px; cursor: pointer; }
