:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c1f24;
  --sub: #7a808a;
  --line: #e6e8ec;
  --accent: #3366e6;
  --in: #2f6fde;
  --out: #e0483e;
  --sel: #eaf0ff;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316; --card: #1c1e22; --text: #eceef1; --sub: #9298a2;
    --line: #2b2e34; --accent: #6b93ff; --in: #6d9dff; --out: #ff6f66; --sel: #24304d;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 15px;
  padding: env(safe-area-inset-top) 0 calc(64px + env(safe-area-inset-bottom));
}
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

.view { max-width: 520px; margin: 0 auto; padding: 0 12px 24px; }
.in { color: var(--in); }
.out { color: var(--out); }
.neg { color: var(--out); }
.hint { color: var(--sub); font-size: 13px; }

.sync-status { margin: -4px 0 8px; text-align: center; font-size: 12px; color: var(--out); }

/* 로그인 */
.lock { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; }
.lock-body { width: 100%; max-width: 340px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.lock-body img { border-radius: 18px; }
.lock-body h1 { font-size: 22px; margin: 4px 0 0; }
.lock-body input {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); font-size: 16px; text-align: center;
}
.lock-body .btn.primary { width: 100%; }
.lock-names { width: 100%; margin: 4px 0 0; background: var(--line); }
.lock-names button { padding: 10px; font-size: 16px; }

/* 내 계정 */
.pw-form { display: flex; flex-direction: column; gap: 8px; }
.pw-form input {
  padding: 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); font-size: 16px;
}
.pw-form .form-error { margin: 0; }
.form-error.ok { color: var(--in); }
.logout { width: 100%; margin-top: 6px; }

/* 월 이동 */
.month-bar { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 14px 0 10px; }
.month-label { font-size: 19px; font-weight: 700; padding: 4px 10px; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; font-size: 22px; line-height: 1; color: var(--sub); }
.icon-btn:active { background: var(--line); }

/* 요약 */
.summary {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--card); border-radius: var(--radius); padding: 12px 4px;
}
.summary div { text-align: center; }
.summary div + div { border-left: 1px solid var(--line); }
.summary .lbl { display: block; font-size: 12px; color: var(--sub); margin-bottom: 3px; }
.summary b { font-size: 16px; font-variant-numeric: tabular-nums; }

/* 예산별 지출 */
.group { margin-top: 10px; }
.group-tabs { display: flex; gap: 14px; padding: 0 4px 6px; }
.group-tabs button { font-size: 13px; color: var(--sub); padding: 2px 0; }
.group-tabs button.on { color: var(--text); font-weight: 700; }
.budget-bar { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.budget-bar::-webkit-scrollbar { display: none; }
.bchip {
  flex: 1 0 auto; display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  background: var(--card); border: 1.5px solid transparent; border-radius: 10px; padding: 8px 12px;
}
.bchip span { font-size: 13px; color: var(--sub); }
.bchip b { font-size: 14px; color: var(--out); font-variant-numeric: tabular-nums; }
.bchip.on { border-color: var(--accent); background: var(--sel); }

/* 달력 */
.calendar { background: var(--card); border-radius: var(--radius); margin-top: 10px; padding: 8px 6px 6px; }
.dow, .grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.dow span { text-align: center; font-size: 12px; color: var(--sub); padding-bottom: 6px; }
.dow .sun, .cell.sun .num { color: var(--out); }
.dow .sat, .cell.sat .num { color: var(--in); }
.cell {
  min-height: 58px; padding: 4px 1px; border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  overflow: hidden;
}
.cell .num { font-size: 13px; width: 22px; height: 22px; line-height: 22px; text-align: center; border-radius: 50%; }
.cell.today .num { background: var(--accent); color: #fff !important; font-weight: 700; }
.cell.sel { background: var(--sel); }
.cell .in, .cell .out { font-size: 10px; letter-spacing: -0.3px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* 선택한 날 */
.day { background: var(--card); border-radius: var(--radius); margin-top: 10px; padding: 12px 14px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; }
.day-head h2 { font-size: 15px; margin: 0; }
.day-head span { font-size: 13px; color: var(--sub); }
.entries { list-style: none; margin: 8px 0 0; padding: 0; }
.entries li { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.entries li:first-child { border-top: 0; }
.entries .e-main { display: flex; flex-direction: column; min-width: 0; }
.entries small { color: var(--sub); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entries li > span { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; margin-left: 10px; }
.entries .empty-msg { color: var(--sub); font-size: 13px; justify-content: center; cursor: default; }

.fab {
  position: fixed; right: max(18px, calc(50% - 242px)); bottom: calc(80px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 28px; line-height: 1;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
}

/* 하단 탭 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button { flex: 1; height: 56px; color: var(--sub); font-size: 14px; }
.tabbar button.on { color: var(--accent); font-weight: 700; }

/* 설정 */
.page-title { font-size: 19px; font-weight: 700; padding: 18px 4px 10px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.card p { margin: 0 0 10px; }
.mlist { list-style: none; margin: 0; padding: 0; }
.mlist li { display: flex; gap: 8px; padding: 4px 0; align-items: center; }
.mlist .order { display: flex; gap: 2px; }
.mlist .move {
  width: 32px; height: 36px; border-radius: 8px; background: var(--bg);
  font-size: 11px; color: var(--sub);
}
.mlist .move:active { background: var(--line); }
.mlist .move:disabled { opacity: .3; }
.mlist input, .add-row input, .field input {
  flex: 1; min-width: 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg);
  font-size: 16px; /* iOS 확대 방지 */
}
.add-row { display: flex; gap: 8px; margin-top: 8px; }
.row-btns { display: flex; gap: 8px; }

.btn { padding: 9px 14px; border-radius: 9px; background: var(--line); font-size: 14px; white-space: nowrap; }
.btn.primary { background: var(--accent); color: #fff; font-weight: 700; flex: 1; padding: 13px; font-size: 16px; }
.btn.danger { color: var(--out); padding: 13px 18px; font-size: 16px; }
.btn.ghost { background: none; color: var(--sub); }

/* 입력 시트 */
.sheet { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); }
.sheet-body {
  position: relative; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { font-size: 17px; margin: 0; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; margin: 6px 0 12px; }
.seg button { flex: 1; padding: 8px; border-radius: 8px; color: var(--sub); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.amount { display: flex; align-items: baseline; gap: 6px; border-bottom: 2px solid var(--accent); padding: 4px 2px; margin-bottom: 14px; }
.amount input { flex: 1; min-width: 0; border: 0; background: none; font-size: 28px; font-weight: 700; text-align: right; outline: none; }
.amount span { font-size: 18px; color: var(--sub); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field .lbl { font-size: 13px; color: var(--sub); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); font-size: 14px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.form-error { color: var(--out); font-size: 13px; min-height: 1em; margin: 0 0 8px; }
.sheet-actions { display: flex; gap: 8px; }
