:root {
  --bg: #F2F3F7;
  --card: #FFFFFF;
  --primary: #4F6EF7;
  --primary-dark: #3A56D4;
  --accent: #FF6B6B;
  --expense: #FF9F0A;
  --text: #1C1C1E;
  --text2: #8E8E93;
  --border: #E5E5EA;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100vh; min-height: 100dvh;
  max-width: 100%; overflow-x: hidden;
  padding-top: calc(var(--safe-top) + 12px);
  padding-bottom: calc(var(--safe-bottom) + 76px);
}
.wrap { padding: 0 16px; }

/* Top date header */
.date-head { padding: 4px 0 14px; }
.date-main { font-size: 27px; font-weight: 700; line-height: 1.1; }
.date-sub { font-size: 13px; color: var(--text2); margin-top: 3px; }
.badge-row { display:flex; flex-wrap:wrap; gap:6px; margin-top:10px; }
.badge { font-size:12px; padding:4px 10px; border-radius:999px; background: var(--card); border:1px solid var(--border); color: var(--text2); }
.badge.holiday { background:#FFF1F0; border-color:#FFD6D2; color:#D03A2C; }
.badge.lunar { background:#FFF8E8; border-color:#FFE9B8; color:#B7791F; }

/* Cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px; }
.card h3 { font-size: 13px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }
.card-row { display:flex; justify-content:space-between; align-items:center; padding: 6px 0; }
.card-row + .card-row { border-top: 1px solid var(--border); }

/* Weather */
.weather-now { display:flex; align-items:center; gap:12px; }
.weather-icon { font-size: 34px; }
.weather-temp { font-size: 28px; font-weight: 700; }
.weather-desc { font-size: 13px; color: var(--text2); }
.weather-grid { display:grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin-top: 12px; font-size: 13px; }
.weather-grid .lbl { color: var(--text2); }

/* Today summary tiles */
.tiles { display:grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.tile .num { font-size: 24px; font-weight: 700; margin-top: 2px; }
.tile .lbl { font-size: 12px; color: var(--text2); }
.tile.expense .num { color: var(--expense); }

/* Todos */
.todo-item { display:flex; align-items:center; gap: 10px; padding: 10px 0; }
.todo-item + .todo-item { border-top: 1px solid var(--border); }
.todo-check { width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--border); flex:0 0 auto; display:flex; align-items:center; justify-content:center; font-size: 14px; color:#fff; }
.todo-check.done { background: var(--primary); border-color: var(--primary); }
.todo-main { flex:1; min-width:0; }
.todo-title { font-size: 15px; word-break: break-word; }
.todo-title.done { color: var(--text2); text-decoration: line-through; }
.todo-due { font-size: 12px; color: var(--accent); margin-top: 2px; }
.todo-due.overdue { color: var(--accent); font-weight: 600; }
.todo-del { color: var(--text2); font-size: 20px; padding: 4px 8px; }
.empty { text-align:center; color: var(--text2); padding: 24px 0; font-size: 14px; }

/* Expenses */
.exp-item { display:flex; align-items:center; gap:10px; padding: 9px 0; }
.exp-item + .exp-item { border-top: 1px solid var(--border); }
.exp-cat { flex:0 0 auto; width: 8px; height: 8px; border-radius: 50%; }
.exp-main { flex:1; min-width:0; }
.exp-catname { font-size: 14px; }
.exp-note { font-size: 12px; color: var(--text2); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.exp-amt { font-size: 15px; font-weight: 600; color: var(--expense); }
.exp-total { display:flex; justify-content:space-between; align-items:baseline; margin-bottom: 6px; }
.exp-total .big { font-size: 26px; font-weight: 700; }
.cat-bars { margin-top: 8px; }
.cat-bar { display:flex; align-items:center; gap: 8px; margin: 5px 0; font-size: 12px; }
.cat-bar .name { width: 76px; color: var(--text2); }
.cat-bar .track { flex:1; height: 7px; background: #EEE; border-radius: 4px; overflow:hidden; }
.cat-bar .fill { display:block; height:100%; border-radius: 4px; }
.cat-bar .amt { width: 56px; text-align: right; font-variant-numeric: tabular-nums; }

/* Donut chart */
.donut-wrap { display:flex; justify-content:center; padding: 6px 0 2px; }
.donut { position:relative; width: 190px; height: 190px; }
.donut svg { display:block; }
.donut-center { position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center; pointer-events:none; }
.donut-center .amt { font-size: 24px; font-weight: 700; }
.donut-center .lbl { font-size: 11px; color: var(--text2); letter-spacing: .5px; }
.cat-legend { display:grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; margin-top: 14px; }
.leg-item { display:flex; align-items:center; gap:8px; font-size: 13px; }
.leg-item .sw { width:10px; height:10px; border-radius:3px; flex:0 0 auto; }
.leg-item .nm { color: var(--text); }
.leg-item .pc { color: var(--text2); margin-left:auto; font-variant-numeric: tabular-nums; }

/* Month nav */
.month-nav { display:flex; align-items:center; justify-content:space-between; margin-bottom: 10px; }
.month-nav button { background: var(--card); border:1px solid var(--border); border-radius: 8px; width: 34px; height: 30px; font-size: 16px; color: var(--text); }
.month-nav .label { font-size: 15px; font-weight: 600; }

/* Tab bar */
.tabbar { position: fixed; left:0; right:0; bottom:0; z-index: 50;
  display:flex; background: rgba(242,243,247,0.92); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border); padding-bottom: var(--safe-bottom); }
.tabbar a { flex:1; text-align:center; padding: 8px 0 6px; color: var(--text2); text-decoration:none; font-size: 11px; }
.tabbar a .ic { font-size: 22px; display:block; line-height: 1.1; }
.tabbar a.active { color: var(--primary); }

/* FAB */
.fab { position: fixed; right: 18px; bottom: calc(var(--safe-bottom) + 64px); width: 54px; height: 54px;
  border-radius: 50%; background: var(--primary); color:#fff; border:none; font-size: 28px;
  box-shadow: 0 4px 14px rgba(79,110,247,0.4); display:flex; align-items:center; justify-content:center; }

/* Sheet / modal */
.scrim { position: fixed; inset:0; background: rgba(0,0,0,0.35); z-index: 90; display:none; }
.scrim.show { display:block; }
.sheet { position: fixed; left:0; right:0; bottom:0; z-index: 100; background: var(--card);
  border-radius: 18px 18px 0 0; padding: 8px 16px calc(var(--safe-bottom) + 20px); transform: translateY(100%); transition: transform .25s; }
.sheet.show { transform: translateY(0); }
.sheet .grip { width: 36px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 14px; }
.sheet h2 { font-size: 17px; margin-bottom: 14px; }
.field { margin-bottom: 14px; }
.field label { display:block; font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.field input, .field select { width: 100%; padding: 11px 12px; border:1px solid var(--border); border-radius: 10px; font-size: 16px; background: #fff; color: var(--text); }
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); }
.cat-chips { display:flex; flex-wrap:wrap; gap: 8px; }
.cat-chip { padding: 7px 14px; border-radius: 999px; border:1px solid var(--border); font-size: 14px; background:#fff; }
.cat-chip.sel { background: var(--primary); color:#fff; border-color: var(--primary); }
.sheet-actions { display:flex; gap: 10px; margin-top: 6px; }
.btn { flex:1; padding: 12px; border-radius: 11px; border:none; font-size: 16px; font-weight: 600; }
.btn.primary { background: var(--primary); color:#fff; }
.btn.ghost { background: var(--bg); color: var(--text); }
.amount-input { font-size: 22px; font-weight: 700; text-align:center; }

/* Sections / hidden */
.page { display: none; }
.page.active { display: block; }
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip: rect(0,0,0,0); }

/* Calendar */
.cal-weekdays { display:grid; grid-template-columns: repeat(7, 1fr); text-align:center; font-size:11px; color:var(--text2); font-weight:600; padding-bottom:6px; }
.cal-grid { display:grid; grid-template-columns: repeat(7, 1fr); gap:2px; }
.cal-cell { min-height:46px; border-radius:8px; padding:4px 3px 3px; text-align:center; position:relative; background:#FAFBFD; overflow:hidden; }
.cal-cell.blank { background:transparent; }
.cal-cell .cal-day { font-size:13px; font-weight:500; }
.cal-cell.today { background: var(--primary); }
.cal-cell.today .cal-day { color:#fff; font-weight:700; }
.cal-cell.today .cal-holname { color:rgba(255,255,255,0.85); }
.cal-cell.holiday .cal-day { color: var(--accent); font-weight:600; }
.cal-cell.sel { outline: 2px solid var(--primary); outline-offset: -2px; }
.cal-cell.sel.today { outline-color: var(--primary-dark); }
.cal-dot { display:block; width:5px; height:5px; border-radius:50%; background: var(--primary); margin: 2px auto 0; }
.cal-cell.holiday .cal-dot { background: var(--accent); }
.cal-holname { display:block; font-size:8px; line-height:1.15; color: var(--accent); margin-top:1px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.cal-detail-hol { font-size:14px; color: var(--accent); padding: 6px 0; font-weight: 600; }
#cal-detail .card-row { font-size:14px; }
#cal-detail h3 { margin-bottom: 4px; }
