:root {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface-subtle: #F8FAFC;
  --border: #E5E7EB;
  --text: #111827;
  --text-secondary: #6B7280;
  --accent: #0F766E;
  --accent-light: #CCFBF1;
  --accent-dark: #115E59;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow-card: 0 1px 2px rgba(17, 24, 39, 0.04), 0 4px 12px rgba(17, 24, 39, 0.04);
}

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

html {
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  background-color: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Noto Sans TC", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img {
  display: block;
  max-width: 100%;
}

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* 頂部列（相容 iPhone 瀏海／動態島安全區） */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: rgba(245, 246, 248, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(229, 231, 235, 0.8);
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: 12px;
  padding-left: max(16px, env(safe-area-inset-left));
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(15, 118, 110, 0.25);
}

.brand-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.month-badge {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background-color: var(--accent-light);
  color: var(--accent-dark);
  font-size: 0.8125rem;
  font-weight: 600;
}

/* 主要內容區 */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 16px;
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: 16px;
  padding-left: max(16px, env(safe-area-inset-left));
}

.card {
  width: 100%;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
  overflow-wrap: anywhere;
}

/* 本月總額摘要卡 */
.summary-card {
  background: linear-gradient(135deg, #0F766E 0%, #0D9488 100%);
  border-color: transparent;
  color: #FFFFFF;
}

.summary-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.summary-label {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.88);
}

.local-badge {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  background-color: rgba(255, 255, 255, 0.18);
  color: #FFFFFF;
  font-size: 0.75rem;
  font-weight: 500;
}

.summary-amount {
  margin: 10px 0 4px;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.summary-meta {
  margin: 0;
  font-size: 0.8125rem;
  color: rgba(255, 255, 255, 0.82);
}

/* 區塊標題 */
.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-bottom: 12px;
}

.section-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.section-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* 骨架預留區 */
.skeleton-box {
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px dashed #CBD5E1;
  background-color: var(--surface-subtle);
}

.skeleton-text {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* 空狀態 */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.field { display: flex; min-width: 0; flex-direction: column; gap: 6px; color: var(--text); font-size: 0.8125rem; font-weight: 600; }
.field-amount { grid-column: 1 / -1; }
.field input, .field select { width: 100%; min-width: 0; height: 46px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--text); font: inherit; font-size: 1rem; }
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.amount-input { display: flex; align-items: center; gap: 8px; height: 52px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; color: var(--text-secondary); }
.amount-input:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.amount-input input { height: 48px; padding: 0; border: 0; outline: 0; font-size: 1.25rem; font-weight: 700; }
.optional { color: var(--text-secondary); font-weight: 400; }
.save-button { width: 100%; min-height: 48px; margin-top: 18px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font: inherit; font-size: 1rem; font-weight: 700; cursor: pointer; }
.save-button:active { background: var(--accent-dark); }
.form-message { min-height: 1.25em; margin: 8px 0 0; color: var(--accent-dark); font-size: 0.8125rem; }
.records-list { display: flex; flex-direction: column; }
.record-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.record-row:first-child { padding-top: 4px; }
.record-row:last-child { padding-bottom: 4px; border-bottom: 0; }
.record-info { min-width: 0; }
.record-title { overflow: hidden; margin: 0; font-size: 0.9375rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.record-meta { margin: 3px 0 0; color: var(--text-secondary); font-size: 0.75rem; }
.record-amount { flex-shrink: 0; margin: 0; font-size: 0.9375rem; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 360px) { .card { padding: 15px; } .form-grid { gap: 12px 8px; } }

.empty-state {
  padding: 24px 12px;
  text-align: center;
  border-radius: var(--radius-md);
  background-color: var(--surface-subtle);
}

.empty-title {
  margin: 0 0 4px;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.empty-desc {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* 底部隱私說明（相容底部 Home Indicator 安全區） */
.app-footer {
  padding-top: 8px;
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  text-align: center;
}

.app-footer p {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-secondary);
}
