/* ===== 가계부 — 직접 작성 CSS (외부 라이브러리 없음) ===== */
:root {
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --text: #1f2430;
  --text-sub: #6b7280;
  --line: #e6e8ec;
  --primary: #3b6ef6;
  --primary-dark: #2b54c6;
  --danger: #e5484d;
  --danger-bg: #fde8e8;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --maxw: 720px;
  --header-h: 56px;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "맑은 고딕", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
  /* 한국어 줄바꿈: 단어 중간이 아니라 띄어쓰기에서 끊기도록 (작은 화면에서 자연스럽게) */
  word-break: keep-all;
  overflow-wrap: anywhere;
}

#app { max-width: var(--maxw); margin: 0 auto; min-height: 100vh; position: relative; }

/* ===== 헤더 ===== */
.app-header {
  position: sticky; top: 0; z-index: 20;
  height: var(--header-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--line);
}
.app-header__inner {
  max-width: var(--maxw); margin: 0 auto; height: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
}
.app-title { font-size: 18px; font-weight: 700; margin: 0; }
.month-switch { display: flex; align-items: center; gap: 2px; }
.month-label { font-weight: 600; min-width: 60px; text-align: center; font-variant-numeric: tabular-nums; }
.icon-btn {
  width: 32px; height: 32px; border: none; background: var(--bg);
  border-radius: 8px; font-size: 18px; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: #e9ebef; }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn:disabled:hover { background: var(--bg); }
.icon-btn--help {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-sub); background: transparent;
}
.icon-btn--help:hover { background: #e9ebef; color: var(--text); }
.icon-btn--help svg { display: block; }

/* ===== 본문 ===== */
.view {
  padding: 16px 16px calc(var(--tabbar-h) + 24px);
  min-height: calc(100vh - var(--header-h));
}
.screen-title { font-size: 16px; font-weight: 700; margin: 4px 0 14px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--text-sub); margin: 20px 0 8px; text-transform: none; }

/* 합계 헤더 (제목 + 강조 금액) */
.sec-total { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 20px 0 8px; }
.sec-total__label { font-size: 14px; font-weight: 700; color: var(--text); }
.sec-total__amount { font-size: 19px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sec-total__amount.is-income { color: var(--success); }
.sec-total__amount.is-expense { color: var(--danger); }
/* 리스트 카드 안의 합계 줄 */
.list-summary {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.list-summary__label { font-size: 12px; font-weight: 600; color: var(--text-sub); }
.list-summary__amount { font-size: 18px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ===== 카드 ===== */
.card {
  background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}
.card--pad0 { padding: 0; overflow: hidden; }

/* 접기/펼치기 (details/summary) */
.collapse { margin-top: 20px; }
.collapse__summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; background: var(--card-bg); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); font-weight: 700; font-size: 14px;
}
.collapse__summary > span:first-child { margin-right: auto; }
.collapse__summary::-webkit-details-marker { display: none; }
.collapse__summary::after { content: "▾"; color: var(--text-sub); transition: transform .2s ease; }
.collapse[open] .collapse__summary::after { transform: rotate(180deg); }
.collapse[open] .collapse__summary { border-radius: var(--radius) var(--radius) 0 0; border-bottom: none; }
.collapse__hint { font-size: 12px; font-weight: 600; color: var(--text-sub); white-space: nowrap; }

/* 요약 통계 카드 그리드 */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 4px; }
.stat {
  background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px;
}
.stat__label { font-size: 12px; color: var(--text-sub); margin-bottom: 6px; }
.stat__value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat--total { grid-column: 1 / -1; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; box-shadow: 0 4px 14px rgba(59,110,246,0.28); }
.stat--total .stat__label { color: rgba(255,255,255,0.85); }
/* 그라데이션 카드 위에서는 금액 색(amount-pos/neg)을 무시하고 항상 흰색 */
.stat--total .stat__value { color: #fff; }
.stat--total .stat__sub { color: rgba(255,255,255,0.92); font-size: 12px; margin-top: 6px; font-variant-numeric: tabular-nums; }
/* 위험(카드대금일 잔액 음수 = 연체 위험) 강조 */
.stat--danger { background: linear-gradient(135deg, #f0616a, var(--danger)); box-shadow: 0 4px 14px rgba(229,72,77,0.30); }
/* 현금흐름 타임라인: 카드대금일 최저 잔액 시점 강조 */
.list-item--min { background: #fff7ed; box-shadow: inset 3px 0 0 var(--warning); }
.list-item--min:hover { background: #fff7ed; }

.amount-pos { color: var(--text); }
.amount-neg { color: var(--danger); }

/* ===== 폼 ===== */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; font-weight: 600; color: var(--text-sub); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
  font-family: inherit;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,110,246,0.15); }
.input--amount { font-size: 22px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.form-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.help { font-size: 12px; color: var(--text-sub); margin-top: 6px; }

/* 토글 */
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }
.switch { position: relative; width: 46px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch__slider {
  position: absolute; inset: 0; background: #cbd2dd; border-radius: 26px; transition: .2s; cursor: pointer;
}
.switch__slider::before {
  content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .switch__slider { background: var(--primary); }
.switch input:checked + .switch__slider::before { transform: translateX(20px); }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 13px 18px; font-size: 15px; font-weight: 600; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer;
  font-family: inherit; transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { background: #f7f8fa; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-dark); }
.btn--danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger-bg); }
.btn--block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--pulse { animation: btnPulse 1.3s ease-in-out infinite; }
@keyframes btnPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(59,110,246,0.5); } 50% { box-shadow: 0 0 0 6px rgba(59,110,246,0); } }
.btn:disabled:hover { background: #fff; }
.btn--danger:disabled:hover { background: #fff; }
.btn--sm { padding: 7px 12px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; margin-top: 8px; }

/* 칩 (분류 선택 등) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; font-size: 14px; cursor: pointer; user-select: none;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.chip:hover { border-color: var(--primary); }
.chip--active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip--active:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

/* ===== 리스트 (거래/항목) ===== */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  border-bottom: 1px solid var(--line); background: #fff;
  transition: background .12s ease;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: #fafbfc; }
.list-item--tap { cursor: pointer; }
.list-item--tap:active { background: #f1f5f9; }
.list-item--carry { background: #f8fafc; border-top: 2px solid var(--line); }
.list-item--carry .list-item__amount { font-weight: 700; }
.list-item__icon {
  width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 18px; background: var(--bg); flex-shrink: 0;
}
.list-item__body { flex: 1; min-width: 0; }
.list-item__title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item__sub { font-size: 12px; color: var(--text-sub); }
.list-item__sub .card-name { font-weight: 700; color: var(--text); }
.list-item__amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px;
  background: var(--bg); color: var(--text-sub); margin-left: 6px;
}
.badge--inst { background: #eef2ff; color: var(--primary-dark); }
.badge--adj { background: #fef3e6; color: var(--warning); }

.date-group-header {
  font-size: 12px; font-weight: 700; color: var(--text-sub);
  padding: 12px 16px 4px; background: var(--bg);
}

/* ===== 차트 (CSS bar) ===== */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-row__label { width: 92px; font-size: 13px; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row__track { flex: 1; background: var(--bg); border-radius: 6px; height: 22px; overflow: hidden; }
.bar-row__fill { height: 100%; border-radius: 6px; background: var(--primary); min-width: 2px; }
.bar-row__val { width: 96px; text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.bar-row--tap { cursor: pointer; border-radius: 8px; padding: 4px; margin: -4px -4px 6px; transition: background .12s; }
.bar-row--tap:hover { background: var(--bg); }
.bar-row--tap:active { background: #e9ebef; }

.trend { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.trend__col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.trend__bar { width: 60%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; }
.trend__bar--current { background: var(--primary-dark); }
.trend__mlabel { font-size: 10px; color: var(--text-sub); }
/* 누적(일시불/할부/현금) 막대 */
.trend__stack { width: 64%; min-height: 2px; border-radius: 4px 4px 0 0; overflow: hidden; display: flex; flex-direction: column; }
.trend__stack--current { outline: 2px solid var(--text); outline-offset: 1px; }
.trend__seg--lump { background: var(--primary); }
.trend__seg--inst { background: #f6b73c; }
.trend__seg--cash { background: var(--success); }
.trend__amt { font-size: 9px; color: var(--text-sub); font-variant-numeric: tabular-nums; }
.trend__col--tap { cursor: pointer; }
.trend__col--sel .trend__stack { outline: 2px solid var(--primary-dark); outline-offset: 1px; }
/* 추이 상세 줄 (막대 탭/호버 시 그 달 금액) */
.trend-detail { font-size: 12px; color: var(--text-sub); margin-bottom: 6px; line-height: 1.5; }
.trend-detail__m { color: var(--text); }
.trend-detail__t { color: var(--text); font-weight: 700; margin-right: 6px; }
.trend-detail__b { display: block; }
/* 차트 범례 */
.legend { display: flex; gap: 14px; justify-content: flex-end; flex-wrap: wrap; margin-bottom: 8px; }
.legend__item { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-sub); }
.legend__dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend__dot--lump { background: var(--primary); }
.legend__dot--inst { background: #f6b73c; }
.legend__dot--cash { background: var(--success); }

/* ===== 기타 ===== */
.empty {
  text-align: center; color: var(--text-sub); padding: 48px 16px; font-size: 14px;
}
.empty__icon { font-size: 40px; display: block; margin-bottom: 12px; opacity: 0.5; }

.fab {
  position: fixed; right: max(16px, calc((100vw - var(--maxw))/2 + 16px));
  bottom: calc(var(--tabbar-h) + 16px); z-index: 30;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; font-size: 28px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(59,110,246,0.4);
  transition: background .15s ease, transform .1s ease;
}
.fab:hover { background: var(--primary-dark); }
.fab:active { transform: scale(0.94); }
/* FAB 버튼이 마지막 항목을 가리지 않도록 하단 여백 */
.fab-spacer { height: 88px; }

/* 맨 위로 가기 버튼 (좌하단, FAB와 겹치지 않게) */
.scrolltop {
  position: fixed; left: max(16px, calc((100vw - var(--maxw))/2 + 16px));
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom, 0px)); z-index: 30;
  width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(255,255,255,0.95); color: var(--text-sub);
  font-size: 22px; line-height: 1; cursor: pointer; box-shadow: 0 3px 12px rgba(0,0,0,0.18);
  display: none; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .2s ease;
}
.scrolltop--show { display: flex; opacity: 1; }
.scrolltop:hover { background: #fff; color: var(--text); }
.scrolltop:active { transform: scale(0.92); }

/* 탭바 */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  max-width: var(--maxw); margin: 0 auto;
  height: var(--tabbar-h); background: var(--card-bg); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.tabbar__btn {
  border: none; background: none; cursor: pointer; color: var(--text-sub);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 10px; font-family: inherit;
}
.tabbar__ico { font-size: 20px; line-height: 1; filter: grayscale(0.4); opacity: 0.7; }
.tabbar__btn--active { color: var(--primary); font-weight: 700; }
.tabbar__btn--active .tabbar__ico { filter: none; opacity: 1; }

/* 토스트 */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) translateY(20px);
  background: #1f2430; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 200; white-space: nowrap;
}
.toast--show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 새 버전 알림 배너 */
/* AI 인식 진행 메시지 */
.ai-progress {
  text-align: center; font-size: 13px; color: var(--primary);
  padding: 8px 0; animation: aiDot 1.2s ease-in-out infinite;
}
@keyframes aiDot {
  0%,100% { opacity: 1; } 50% { opacity: 0.4; }
}

.update-banner {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 12px;
  background: var(--primary-dark); color: #fff; z-index: 300;
  padding: 10px 12px 10px 16px; border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25); font-size: 14px;
  max-width: calc(100% - 32px);
}
.update-banner__btn {
  background: #fff; color: var(--primary-dark); border: none;
  padding: 7px 14px; border-radius: 8px; font-weight: 700; font-size: 13px; cursor: pointer; white-space: nowrap;
}

/* 배경 스크롤 잠금 (모달 열림 동안) — 현재 위치에 고정해 닫을 때 튀지 않게 */
body.modal-open { overflow: hidden; position: fixed; left: 0; right: 0; width: 100%; }

/* 모달 */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,24,40,0.45); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity .2s ease;
}
.modal-backdrop--show { opacity: 1; }
.modal {
  background: var(--card-bg); width: 100%; max-width: var(--maxw); border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 86vh; overflow-y: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  transform: translateY(16px); transition: transform .22s ease;
}
.modal-backdrop--show .modal { transform: translateY(0); }
.modal__title { font-size: 17px; font-weight: 700; margin: 0 0 16px; }

/* 분류 아이콘 빠른 선택 그리드 */
.icon-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 6px; margin: 0 0 16px; max-height: 168px; overflow-y: auto;
  padding: 2px; overscroll-behavior: contain;
}
.icon-pick {
  font-size: 20px; line-height: 1; padding: 8px 0; cursor: pointer;
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
}
.icon-pick:hover { background: #f4f6fb; }
.icon-pick--active { border-color: var(--primary); background: #eef3ff; box-shadow: 0 0 0 1px var(--primary) inset; }

@media (min-width: 480px) {
  .modal { border-radius: 18px; margin-bottom: 10vh; transform: translateY(24px) scale(0.98); }
  .modal-backdrop--show .modal { transform: translateY(0) scale(1); }
  .modal-backdrop { align-items: center; }
}

/* 헤더 오른쪽 묶음 (월 이동 + 도움말) */
.header-right { display: flex; align-items: center; gap: 4px; }
.app-header__inner { gap: 8px; }
.app-title { white-space: nowrap; }

/* 도움말(사용 설명서) */
.help-doc { display: flex; flex-direction: column; gap: 8px; }
.help-sec {
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); overflow: hidden;
}
.help-sec__title {
  list-style: none; cursor: pointer; padding: 12px 14px;
  font-weight: 600; font-size: 14px; user-select: none;
  display: flex; align-items: center; justify-content: space-between;
}
.help-sec__title::-webkit-details-marker { display: none; }
.help-sec__title::after { content: "›"; color: var(--text-sub); transition: transform .15s ease; }
.help-sec[open] .help-sec__title::after { transform: rotate(90deg); }
.help-sec__title:hover { background: #eef1f6; }
.help-sec__body {
  padding: 4px 14px 14px; font-size: 13px; line-height: 1.65; color: var(--text);
}
.help-sec__body p { margin: 0 0 8px; }
.help-sec__body ul, .help-sec__body ol { margin: 0 0 8px; padding-left: 20px; }
.help-sec__body li { margin: 3px 0; }
.help-sec__body b { color: var(--text); }
