/* MoneyBook 모바일 앱셸. 색·폰트·반경은 design_tokens 변수만 사용.
   표준 반영: safe-area(env), 하단 탭바(엄지 존), 44px 터치 타깃, 폰 비율 대응(dvh). */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--background); color: var(--foreground);
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
}

/* ── 앱 셸 ─────────────────────────────────────────── */
.app {
  max-width: 460px; margin: 0 auto;
  height: 100vh; height: 100dvh;
  overflow: hidden;
  display: flex; flex-direction: column;
  position: relative;
  background: var(--background);
}
@media (min-width: 480px) {
  .app { border-left: .5px solid var(--border); border-right: .5px solid var(--border); }
}

/* 상단 앱바 */
.appbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--background);
  border-bottom: .5px solid var(--border);
}
.month-sel {
  display: flex; align-items: center; gap: 5px;
  height: 44px; padding: 0 6px 0 4px; border: 0; background: transparent;
  font: inherit; font-size: 19px; font-weight: 700; letter-spacing: -.02em;
  color: var(--foreground); cursor: pointer;
}
.month-sel .ic { width: 18px; height: 18px; color: var(--muted-foreground); }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; background: transparent; color: var(--muted-foreground);
  border-radius: 12px; cursor: pointer;
}
.icon-btn:active { background: var(--muted); }
.icon-btn .ic { width: 22px; height: 22px; }

/* 본문 뷰: 앱 컬럼 안에서 내부 스크롤(body 스크롤바 제거 → 탭바·FAB가 항상 본문과 정렬) */
.view {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  padding: 16px 16px 24px;
  display: flex; flex-direction: column; gap: 16px;
}

/* ── 하단 탭바 + FAB ───────────────────────────────── */
.tabbar {
  flex: none;
  display: flex; align-items: flex-start;
  height: calc(env(safe-area-inset-bottom) + 64px);
  padding-bottom: env(safe-area-inset-bottom);
  padding-top: 8px;
  background: var(--card); border-top: .5px solid var(--border);
}
.tab {
  flex: 1; height: 48px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted-foreground); font: inherit; font-size: 10px; font-weight: 500;
}
.tab .ic { width: 23px; height: 23px; }
.tab.on { color: var(--primary); }
.fab {
  flex: none; width: 56px; height: 56px; margin: -22px 6px 0; align-self: flex-start;
  border-radius: 50%; border: 4px solid var(--background);
  background: var(--primary); color: var(--primary-foreground);
  display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 40%, transparent);
}
.fab .ic { width: 26px; height: 26px; }
.fab:active { transform: scale(.94); }

/* ── 카드/섹션 공통 ─────────────────────────────────── */
.card { background: var(--card); border: .5px solid var(--border); border-radius: 16px; padding: 16px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 0; }
.sec-title { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.sec-more { font-size: 12.5px; font-weight: 600; color: var(--muted-foreground); background: 0; border: 0; cursor: pointer; min-height: 44px; padding: 0 6px; display: inline-flex; align-items: center; }
.sec-more.link { color: var(--primary); }
.hint { font-size: 12px; color: var(--muted-foreground); }
.empty { text-align: center; padding: 26px 12px; }
.empty .et { font-size: 14px; font-weight: 600; }
.empty .ed { font-size: 12px; color: var(--muted-foreground); margin-top: 4px; }

/* ── 홈: 예산 히어로 ─────────────────────────────────── */
.hero {
  background: var(--primary); color: var(--primary-foreground);
  border-radius: 20px; padding: 18px 20px;
}
.hero-lb { font-size: 13px; color: color-mix(in srgb, var(--primary-foreground) 78%, var(--primary)); }
.hero-val { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.hero-bar { height: 9px; border-radius: 6px; margin-top: 13px; overflow: hidden;
  background: color-mix(in srgb, var(--primary-foreground) 22%, var(--primary)); }
.hero-bar > i { display: block; height: 100%; border-radius: 6px; background: var(--primary-foreground); }
.hero-bar.over > i { background: #FFD4D4; }
.hero-meta { display: flex; justify-content: space-between; margin-top: 8px;
  font-size: 11.5px; color: color-mix(in srgb, var(--primary-foreground) 78%, var(--primary)); }
.hero-empty { font-size: 12.5px; margin-top: 8px; color: color-mix(in srgb, var(--primary-foreground) 82%, var(--primary)); }
.hero-empty b { text-decoration: underline; cursor: pointer; }

/* 카테고리 예산 미니바 */
.catbud { display: flex; flex-direction: column; gap: 13px; }
.cb-row { cursor: pointer; }
.cb-top { display: flex; align-items: center; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.cb-name { font-weight: 600; display: flex; align-items: center; gap: 5px; }
.cb-fig { color: var(--muted-foreground); font-variant-numeric: tabular-nums; font-size: 12px; }
.cb-fig.over { color: var(--destructive); font-weight: 700; }
.cb-bar { height: 7px; border-radius: 5px; background: var(--muted); overflow: hidden; }
.cb-bar > i { display: block; height: 100%; border-radius: 5px; background: var(--primary); }
.cb-bar.over > i { background: var(--destructive); }
.warn-ic { width: 13px; height: 13px; color: var(--destructive); }

/* ── 계좌 요약 ──────────────────────────────────────── */
.acc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.acc-card { background: var(--card); border: .5px solid var(--border); border-radius: 14px; padding: 12px 13px; }
.acc-top { display: flex; align-items: center; gap: 6px; }
.acc-dot { width: 8px; height: 8px; border-radius: 3px; flex: none; }
.acc-inst { font-size: 12px; color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-bal { font-size: 16px; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; }
.acc-bal.neg { color: var(--destructive); }

/* ── 거래 리스트(모바일 카드형) ─────────────────────── */
.tx-card { background: var(--card); border: .5px solid var(--border); border-radius: 16px; overflow: hidden; }
.tx-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.tx-item + .tx-item { border-top: .5px solid var(--border); }
.tx-ic { width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center; background: var(--accent); color: var(--primary); }
.tx-ic.in { background: var(--ok-bg, #E1F5EE); color: var(--ok, #0F6E56); }
.tx-ic .ic { width: 20px; height: 20px; }
.tx-body { flex: 1; min-width: 0; }
.tx-merchant { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-sub { font-size: 11.5px; color: var(--muted-foreground); margin-top: 1px; }
.tx-right { text-align: right; flex: none; }
.tx-amt { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tx-amt.in { color: var(--ok, #0F6E56); }
.tx-amt.cancelled { text-decoration: line-through; color: var(--muted-foreground); font-weight: 500; }
.tx-cat { margin-top: 5px; }
.catsel { font: inherit; font-size: 11px; font-weight: 600; border: .5px solid var(--border); border-radius: 999px;
  padding: 4px 9px; background: var(--secondary); color: var(--secondary-foreground); cursor: pointer; max-width: 120px; }

/* 검색/필터 */
.searchbar { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px;
  background: var(--card); border: .5px solid var(--input); border-radius: 12px; }
.searchbar .ic { width: 18px; height: 18px; color: var(--muted-foreground); flex: none; }
.searchbar input { flex: 1; border: 0; background: transparent; font: inherit; font-size: 14px; color: var(--foreground); outline: none; }
.chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; font-size: 12.5px; font-weight: 600; height: 34px; padding: 0 14px; border-radius: 999px;
  border: .5px solid var(--border); background: var(--card); color: var(--muted-foreground); cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--primary); border-color: transparent; }

/* ── 예산 탭 ────────────────────────────────────────── */
.bud-total { text-align: center; }
.bud-total .lb { font-size: 12.5px; color: var(--muted-foreground); }
.bud-total .val { font-size: 25px; font-weight: 700; margin-top: 2px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.bud-total .sub { font-size: 12.5px; color: var(--muted-foreground); margin-top: 4px; }
.bud-row { background: var(--card); border: .5px solid var(--border); border-radius: 14px; padding: 13px 14px; }
.bud-row.over { border-color: var(--destructive); }
.bud-row-top { display: flex; align-items: center; justify-content: space-between; }
.bud-row-name { font-size: 14px; font-weight: 600; }
.bud-tag { font-size: 10.5px; font-weight: 700; color: var(--destructive); }
.bud-set { font-size: 12.5px; font-weight: 600; color: var(--primary); background: 0; border: 0; cursor: pointer; padding: 4px; }
.bud-fig { font-size: 11.5px; color: var(--muted-foreground); margin-top: 5px; font-variant-numeric: tabular-nums; }
.bud-fig.over { color: var(--destructive); }
.bud-edit { display: flex; gap: 8px; margin-top: 10px; }
.bud-edit input { flex: 1; height: 40px; border: .5px solid var(--input); border-radius: 10px; padding: 0 12px;
  font: inherit; font-size: 14px; background: var(--card); color: var(--foreground); outline: none; }
.bud-edit input:focus { border-color: var(--ring); box-shadow: 0 0 0 3px var(--accent); }

/* ── 통계 탭 ────────────────────────────────────────── */
.stat-list { display: flex; flex-direction: column; gap: 12px; }
.stat-row .st-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.stat-row .st-amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-bar { height: 8px; border-radius: 5px; background: var(--muted); overflow: hidden; }
.stat-bar > i { display: block; height: 100%; border-radius: 5px; background: var(--primary); }

/* ── 설정 탭 / 화이트리스트 ──────────────────────────── */
.set-actions { display: flex; gap: 10px; }
.wl-list { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.wl-row { display: flex; align-items: center; gap: 10px; padding: 10px 2px; }
.wl-row + .wl-row { border-top: .5px solid var(--border); }
.wl-id { font-size: 13px; font-weight: 600; }
.wl-label { font-size: 11px; color: var(--muted-foreground); }
.wl-add { display: flex; gap: 8px; margin-top: 8px; }
.wl-add input { flex: 1; height: 44px; border: .5px solid var(--input); border-radius: 10px; padding: 0 12px;
  font: inherit; font-size: 14px; background: var(--card); color: var(--foreground); outline: none; }
.wl-add input.err, .inp.err input { border-color: var(--destructive); }

/* ── 입력 컴포넌트(시트 공용) ──────────────────────────── */
.fld { display: flex; flex-direction: column; gap: 6px; }
.fld > label { font-size: 12px; font-weight: 600; color: var(--muted-foreground); }
.row2 { display: flex; gap: 10px; }
.row2 > .fld { flex: 1; min-width: 0; }
.inp { display: flex; align-items: center; height: 46px; border: .5px solid var(--input); border-radius: 10px;
  background: var(--card); padding: 0 12px; }
.inp:focus-within { border-color: var(--ring); box-shadow: 0 0 0 3px var(--accent); }
.inp input { width: 100%; border: 0; background: transparent; font: inherit; font-size: 15px; color: var(--foreground); outline: none; }
.emsg { font-size: 11.5px; color: var(--destructive); }
.catsel-full { height: 46px; border: .5px solid var(--input); border-radius: 10px; padding: 0 12px;
  font: inherit; font-size: 15px; background: var(--card); color: var(--foreground); }
.msg-input { width: 100%; border: .5px solid var(--input); border-radius: 12px; background: var(--card); color: var(--foreground);
  font-family: var(--font-mono); font-size: 13px; padding: 12px; resize: vertical; line-height: 1.5; outline: none; }
.msg-input:focus { border-color: var(--ring); box-shadow: 0 0 0 3px var(--accent); }
.ingest-result { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.ir-item { font-size: 12px; padding: 9px 11px; border: .5px solid var(--border); border-radius: 10px; background: var(--muted); }
.ir-item.bad { border-color: var(--destructive); background: var(--dng-bg, #FCEBEB); color: var(--destructive); }

/* 세그먼트(탭 전환/지출·수입) */
.seg { display: flex; background: var(--muted); border: .5px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { flex: 1; height: 38px; min-width: 44px; border: 0; background: transparent; border-radius: 999px;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--muted-foreground); cursor: pointer; white-space: nowrap; padding: 0 12px; }
.seg button.on { background: var(--card); color: var(--primary); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

/* 버튼 */
.btn { height: 46px; padding: 0 16px; border-radius: 12px; border: .5px solid var(--border);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; background: var(--card); color: var(--foreground);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.pri { background: var(--primary); color: var(--primary-foreground); border-color: transparent; }
.btn.sec { background: var(--secondary); color: var(--secondary-foreground); border-color: transparent; }
.btn.sm { height: 40px; font-size: 13px; padding: 0 12px; }
.btn.block { width: 100%; }
.btn:active { transform: scale(.98); }
.btn.ld { opacity: .6; pointer-events: none; }
.btn .ic { width: 18px; height: 18px; }

/* ── FAB 바텀시트 ───────────────────────────────────── */
.sheet-back { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.42);
  display: flex; align-items: flex-end; justify-content: center; }
.sheet-back[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 460px; background: var(--card);
  border-radius: 22px 22px 0 0; padding: 8px 18px calc(env(safe-area-inset-bottom) + 20px);
  max-height: 88dvh; overflow-y: auto;
  animation: sheetUp .22s ease;
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 6px auto 12px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.sheet-head .seg { flex: 1; }
.add-pane { display: flex; flex-direction: column; gap: 12px; }
.add-pane .cb { font-size: 12px; color: var(--muted-foreground); }
.manual-form { display: flex; flex-direction: column; gap: 12px; }

/* 상태 pill */
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; }
.pill .o { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-bg, #E1F5EE); color: var(--ok, #0F6E56); }
.pill.warn { background: #FAEEDA; color: #854F0B; }
.pill.fail { background: var(--dng-bg, #FCEBEB); color: var(--destructive); }
.pill.run { background: var(--accent); color: var(--primary); }
