/* style.css — 장보기앱 메인 화면 (1차 MVP, STEP 3)
   폭 380px 기준 모바일 전용. 한 손 조작. 하단 버튼은 엄지 도달권. */

:root {
  --green: #137333;
  --green-bg: #e6f6ea;
  --ink: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --adj: #b45309;      /* 차감 색 */
  --adj-bg: #fef6e7;
  --danger: #c5221f;
  --bg: #f7f7f8;
  --card: #ffffff;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
               "Segoe UI", "Malgun Gothic", sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app {
  max-width: 380px;
  margin: 0 auto;
  /* 상단: 노치/상태바 대비(웹뷰가 상태바 아래에서 시작하면 0). 하단: 고정 버튼 + 홈 인디케이터 */
  padding: env(safe-area-inset-top) 0 calc(84px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

/* ── 1. 헤더 ─────────────────────────────────────────── */
.hdr {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.hdr-date {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.hdr-store {
  flex: 1;
  min-width: 0;
  font-size: 16px;         /* iOS 자동 확대 방지: 16px 이상 */
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
}
.hdr-store:focus { outline: none; border-color: var(--green); background: #fff; }
.hdr-gear {
  font-size: 20px;
  width: 40px; height: 40px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
}
.hdr-gear:active { background: #f0f1f3; }

/* ── 2. 금액 요약 ─────────────────────────────────────── */
.summary {
  background: var(--card);
  padding: 14px 16px 16px;
  border-bottom: 1px solid var(--line);
}
.sum-label { color: var(--muted); font-size: 13px; }

.sum-qual {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--green-bg);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.sum-qual .sum-label { color: var(--green); font-weight: 600; }
.sum-qual-value {
  font-size: 34px;
  font-weight: 800;
  color: var(--green);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.sum-nonqual {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2px 4px;
}
.sum-nonqual-value {
  font-size: 14px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.sum-adj-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2px 4px;
  color: var(--adj);
  font-size: 14px;
}
.sum-adj-row .amt { font-variant-numeric: tabular-nums; }

.sum-grand {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 8px;
  padding: 10px 4px 0;
  border-top: 1px solid var(--line);
}
.sum-grand .sum-label { color: var(--ink); }
.sum-grand-value {
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ── 3. 분류 칩 (가로 스크롤 허용 — 이 줄에만) ─────────── */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px 14px;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 14px;
  white-space: nowrap;
}
.chip .count {
  display: inline-block;
  margin-left: 6px;
  font-size: 12px;
  color: #9aa0a6;
}
.chip.selected {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.chip.selected .count { color: #cdefd6; }

/* ── 4. 항목 리스트 ───────────────────────────────────── */
.list { padding: 4px 0 8px; }

.main-list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--line);
  background: #fafafa;
}
.main-list-title { min-width: 0; color: var(--muted); font-size: 13px; font-weight: 700; }
.main-select-toggle {
  flex: 0 0 auto;
  min-width: 58px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--green);
  border-radius: 9px;
  background: #fff;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}
.main-bulk-panel { padding: 0 14px calc(84px + env(safe-area-inset-bottom)); background: var(--bg); }
.main-bulk-panel > .field-label { margin-top: 10px; }
.main-target-hint { margin: 8px 2px 10px; }
.main-bulk-selector .bulk-action-bar {
  position: fixed;
  left: 50%;
  bottom: env(safe-area-inset-bottom);
  z-index: 19;
  width: 100%;
  max-width: 380px;
  margin: 0;
  transform: translateX(-50%);
}

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  user-select: none;
}
.item-main { flex: 1; min-width: 0; }
.item-name {
  font-size: 15px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-name.empty { color: #b0b4ba; }
.item-formula {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.item-amt {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.empty-hint {
  padding: 32px 16px;
  text-align: center;
  color: #9aa0a6;
  font-size: 14px;
  line-height: 1.6;
}

/* ── 5. 차감 행 ───────────────────────────────────────── */
.adj-block { margin-top: 8px; }
.adj-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 16px;
  background: var(--adj-bg);
  color: var(--adj);
  border-top: 1px solid #f0e2c8;
  border-bottom: 1px solid #f0e2c8;
  font-size: 14px;
}
.adj-item .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.adj-caption {
  padding: 6px 16px 2px;
  font-size: 11.5px;
  color: #9a7b3a;
}

/* ── 6. 하단 항목 추가 버튼 (엄지 도달권) ──────────────── */
.add-btn {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: calc(100% - 28px);
  max-width: 352px;
  padding: 16px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: var(--green);
  border: none;
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(19, 115, 51, 0.28);
  z-index: 20;
}
.add-btn:active { transform: translateX(-50%) scale(0.985); }

/* ══════════════════════════════════════════════════════════════════
   입력 시트 (STEP 4) — 바텀시트 + 커스텀 키패드
   ══════════════════════════════════════════════════════════════════ */

body.sheet-open { overflow: hidden; }

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.sheet-overlay.open { opacity: 1; visibility: visible; }

.sheet {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%) translateY(100%);
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding: 6px 14px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
  transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
  max-height: 92vh;
  overflow-y: auto;
}
.sheet-overlay.open .sheet { transform: translateX(-50%) translateY(0); }

/* 1. 핸들 */
.sheet-handle {
  width: 40px; height: 4px;
  background: #d5d7db;
  border-radius: 2px;
  margin: 6px auto 10px;
}

/* 2. 타이틀 + 닫기 */
.sheet-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.sheet-title { font-size: 17px; font-weight: 700; }
.sheet-close {
  width: 34px; height: 34px;
  border: none; background: #f0f1f3;
  border-radius: 50%;
  font-size: 15px; color: var(--muted);
}

/* 3. 분류 칩 */
.sheet-cats {
  display: flex; gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  scrollbar-width: none;
}
.sheet-cats::-webkit-scrollbar { display: none; }
.sheet-chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 14px;
  white-space: nowrap;
}
.sheet-chip.selected { background: var(--green); border-color: var(--green); color: #fff; }
.chip-check { margin-right: 4px; font-size: 12px; opacity: 0.9; }

/* 4. 상품명 (OS 키보드 허용 유일 지점) */
.sheet-name {
  width: 100%;
  font-size: 16px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafafa;
  margin: 4px 0 8px;
}
.sheet-name:focus { outline: none; border-color: var(--green); background: #fff; }

/* 5. 최근 상품 칩 */
.sheet-recent {
  display: flex; gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  min-height: 0;
  scrollbar-width: none;
}
.sheet-recent::-webkit-scrollbar { display: none; }
.recent-chip {
  flex: 0 0 auto;
  border: 1px dashed #cfd2d7;
  background: #fbfbfc;
  color: #444;
  border-radius: 16px;
  padding: 7px 12px;
  font-size: 13px;
  white-space: nowrap;
}

/* 6. 수식줄 */
.sheet-formula {
  background: #f7f8fa;
  border-radius: 12px;
  padding: 9px 14px 8px;
  margin: 6px 0 12px;
  text-align: right;
}
.sheet-trace {
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
  font-variant-numeric: tabular-nums;
}
.sheet-result {
  font-size: 30px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.sheet-calc-note {
  margin-top: 5px;
  text-align: right;
}
.sheet-calc-help {
  min-height: 24px;
  margin: 0;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: #59636e;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.15px;
  text-align: right;
  cursor: pointer;
}
.sheet-calc-help:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-radius: 4px;
}
.sheet-calc-note-text { white-space: nowrap; }

/* 7. 원탭 칩 */
.sheet-quick {
  display: flex; gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.quick-chip {
  border: 1px solid var(--green);
  background: var(--green-bg);
  color: var(--green);
  border-radius: 18px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
}

/* 8. 4×4 키패드 */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.key {
  padding: 16px 0;
  font-size: 20px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  color: var(--ink);
}
.key:active { background: #eef0f3; }
.key-op {
  background: #f2f4f7;
  color: var(--green);
  font-weight: 700;
}

/* 9. 저장 / 저장 후 계속 */
.sheet-actions {
  display: flex; gap: 10px;
}
.btn-continue, .btn-save {
  flex: 1;
  padding: 15px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 13px;
}
.btn-continue {
  background: #eef0f3;
  color: var(--ink);
}
.btn-save {
  background: var(--green);
  color: #fff;
}
.btn-save:disabled, .btn-continue:disabled {
  opacity: 0.45;
}

/* ══════════════════════════════════════════════════════════════════
   6-2. 더블탭 확대 / 텍스트 선택 / 탭 하이라이트 차단
   (iOS Safari는 user-scalable=no 를 무시 → CSS로 막는다)
   ══════════════════════════════════════════════════════════════════ */
button,
.chip, .sheet-chip, .recent-chip, .quick-chip, .key,
.item, .adj-item, .add-btn, .adj-add-btn,
.btn-save, .btn-continue, .btn-delete {
  touch-action: manipulation;          /* 더블탭 줌 제거 */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
/* 텍스트 입력란은 예외 — 선택·확대 허용 */
.sheet-name {
  -webkit-user-select: text;
  user-select: text;
  touch-action: auto;
}

/* ══════════════════════════════════════════════════════════════════
   6-3 / 6-4. 삭제 버튼 · 차감 추가 버튼 · 차감 시트
   ══════════════════════════════════════════════════════════════════ */

/* 시트 하단 삭제 버튼 (수정 모드 좌측, 빨강 테두리) */
.btn-delete {
  flex: 0 0 auto;
  padding: 15px 18px;
  font-size: 16px;
  font-weight: 700;
  border: 1.5px solid var(--danger);
  background: #fff;
  color: var(--danger);
  border-radius: 13px;
}
.btn-delete:active { background: #fdecea; }

/* 메인: "+ 차감 추가" 버튼 (항목 리스트 아래, 작게) */
.adj-add-btn {
  display: block;
  width: calc(100% - 32px);
  margin: 10px auto 4px;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  color: var(--adj);
  background: var(--adj-bg);
  border: 1px dashed #e3c98f;
  border-radius: 11px;
}
.adj-add-btn:active { background: #fbeecf; }

/* 차감 시트 금액 표시 */
.adj-formula .sheet-trace { text-align: right; }
.adj-formula .sheet-result { color: var(--adj); }

/* ══════════════════════════════════════════════════════════════════
   STEP 7. 설정 시트 (내보내기 / 가져오기 / 전체 초기화)
   ══════════════════════════════════════════════════════════════════ */
.settings-sheet { max-height: 80vh; }
.settings-menu-group + .settings-menu-group { margin-top: 12px; }
.settings-group-title {
  margin: 0 3px 6px;
  color: #6b7280;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.3;
}
.settings-menu-group .settings-item:last-child { margin-bottom: 0; }
.settings-menu-group .settings-hint { margin-bottom: 0; }
.settings-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 15px 14px;
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  background: #f4f5f7;
  border: none;
  border-radius: 12px;
}
.settings-item:active { background: #e9ebef; }
.settings-item.danger { color: var(--danger); background: #fdecea; }

.reset-confirm {
  margin: 2px 0 10px;
  padding: 12px 14px;
  border: 1px solid #f3c9c6;
  border-radius: 12px;
  background: #fff7f7;
}
.reset-chk {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: #7a2320;
  line-height: 1.4;
  margin-bottom: 10px;
}
.reset-chk input { margin-top: 2px; }
.btn-reset {
  width: 100%;
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: var(--danger);
  border: none;
  border-radius: 11px;
}
.btn-reset:disabled { opacity: 0.4; }

/* ══════════════════════════════════════════════════════════════════
   STEP 8A. 메뉴 개선 · 업데이트 배너
   ══════════════════════════════════════════════════════════════════ */

/* 새 장보기 시작 (메뉴 최상단, 강조) */
.settings-item.primary {
  color: #fff;
  background: var(--green);
  font-size: 16px;
}
.settings-item.primary:active { background: #0f5f29; }
.settings-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  margin: -2px 2px 12px;
}
.settings-version {
  margin-top: 12px;
  text-align: center;
  font-size: 12px;
  color: #b0b4ba;
}

/* 백업 및 복원 하위 시트 */
.backup-overlay { z-index: 115; }
.backup-sheet { max-height: 80vh; }
.backup-actions {
  display: grid;
  gap: 12px;
}
.backup-action {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  min-height: 92px;
  padding: 15px 16px;
  border: 1px solid #d7dce2;
  border-radius: 12px;
  background: #f7f8fa;
  color: var(--ink);
  text-align: left;
}
.backup-action:active { background: #eef0f3; }
.backup-action:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}
.backup-action-title {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.35;
}
.backup-action-desc {
  margin-top: 5px;
  color: #59636e;
  font-size: 13px;
  line-height: 1.45;
}
.backup-restore {
  border-color: #efc5c1;
  background: #fff8f7;
}
.backup-restore:active { background: #fdecea; }
.backup-impact {
  margin-top: 8px;
  padding: 4px 7px;
  border-radius: 6px;
  background: #fdecea;
  color: #8a2420;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}
.backup-note {
  margin: 12px 2px 0;
  color: #6b7280;
  font-size: 12px;
  line-height: 1.45;
}

/* 앱 내부 도움말 */
.help-overlay { z-index: 120; }
.help-sheet {
  display: flex;
  flex-direction: column;
  height: min(88vh, 760px);
  max-height: 88vh;
  overflow: hidden;
}
.help-top {
  flex: 0 0 auto;
  margin-bottom: 10px;
}
.help-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 0 10px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.help-section {
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 4px;
}
.help-section:first-child { border-top: 1px solid var(--line); }
.help-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 12px 10px;
  border: 0;
  background: var(--card);
  color: var(--ink);
  font-size: 15px;
  font-weight: 750;
  text-align: left;
}
.help-section-toggle:active { background: #f4f5f7; }
.help-section-toggle:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: -2px;
}
.help-chevron {
  flex: 0 0 auto;
  color: var(--green);
  font-size: 16px;
  font-weight: 800;
}
.help-panel {
  padding: 0 10px 15px;
  color: #30363d;
  font-size: 14px;
  line-height: 1.62;
}
.help-panel[hidden] { display: none; }
.help-panel p { margin: 0 0 10px; }
.help-panel p:last-child { margin-bottom: 0; }
.help-steps {
  margin: 0;
  padding-left: 21px;
}
.help-steps li { margin-bottom: 7px; }
.help-steps li:last-child { margin-bottom: 0; }
.help-example {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
  margin: 9px 0 5px;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--green-bg);
  color: var(--green);
  font-variant-numeric: tabular-nums;
}
.help-caption {
  color: #59636e;
  font-size: 13px;
}
.help-danger {
  color: #8a2420;
  font-weight: 700;
}

/* 고급 설정 (위험한 데이터 초기화 기능 은닉) */
.advanced-settings-toggle[aria-expanded="true"] {
  margin-bottom: 2px;
  border: 1px solid #efc5c1;
  border-bottom-right-radius: 6px;
  border-bottom-left-radius: 6px;
  color: #7a2320;
  background: #fff7f7;
}
.dev-tools {
  margin: 0 0 8px;
  padding: 12px 14px;
  border: 1px solid #f3c9c6;
  border-radius: 12px;
  background: #fff7f7;
}
.dev-title {
  margin-bottom: 6px;
  color: #7a2320;
  font-size: 15px;
  font-weight: 800;
}
.dev-warn {
  font-size: 12.5px;
  color: #7a2320;
  line-height: 1.45;
  margin-bottom: 10px;
}

/* 업데이트 배너 (상단, 사용자가 누를 때만 적용) */
.update-banner {
  position: fixed;
  top: env(safe-area-inset-top);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 20px);
  max-width: 360px;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  padding: 10px 12px 10px 16px;
  background: #1f2937;
  color: #fff;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.update-banner button {
  flex: 0 0 auto;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  color: #1f2937;
  background: #fff;
  border: none;
  border-radius: 9px;
}

/* 8B-1: 키패드 전폭 키(%) */
.key-span { grid-column: 1 / -1; }

/* ══════════════════════════════════════════════════════════════════
   8B-3: 결제 총액을 주인공으로 (34px 최상단 강조) / 8B-4 칩 소계 / 음수 항목
   ══════════════════════════════════════════════════════════════════ */
.sum-grand-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--green-bg);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.sum-grand-main .sum-label { color: var(--green); font-weight: 600; }
.sum-grand-main .sum-grand-value {
  font-size: 34px;
  font-weight: 800;
  color: var(--green);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.sum-qual-sub {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2px 4px;
}
.sum-qual-sub .sum-qual-value {
  font-size: 15px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* 8B-4: 칩 소계 (항목 수 대체). 축약하지 않고 폰트를 줄여 정확한 숫자 유지 */
.chip .subtotal {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  font-weight: 600;
  color: #9aa0a6;
  font-variant-numeric: tabular-nums;
}
.chip.selected .subtotal { color: #cdefd6; }
.chip { line-height: 1.15; }

/* 차감 칩 (분류 칩 줄 맨 끝) */
.chip-adj { border-style: dashed; }
.chip-adj.selected { background: var(--adj); border-color: var(--adj); color: #fff; }
.chip-adj.selected .subtotal { color: #f6e2c0; }

/* 시트 안 차감 칩 */
.sheet-chip.chip-adj { border-style: dashed; }
.sheet-chip.chip-adj.selected { background: var(--adj); border-color: var(--adj); color: #fff; }

/* 8B-2: 분류 내 음수 항목(할인)은 색으로 구분 */
.item-amt.neg { color: var(--adj); }

/* ══════════════════════════════════════════════════════════════════
   8B-5: 분류 설정 화면
   ══════════════════════════════════════════════════════════════════ */
.cat-sheet { max-height: 84vh; }
.cat-list { margin-bottom: 12px; }
.cat-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.cat-row.archived { opacity: 0.78; }
.cat-name-static { flex: 1; min-width: 160px; font-size: 14px; }
.chip.archived { border-style: dashed; opacity: 0.82; }
.cat-name {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
}
.cat-name:focus { outline: none; border-color: var(--green); background: #fff; }
.cat-qual {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  white-space: nowrap;
}
.cat-qual.on { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.cat-ord {
  flex: 0 0 auto;
  width: 30px;
  font-size: 15px;
  padding: 8px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
.cat-ord:disabled { opacity: 0.3; }
.cat-del {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 9px;
  border: 1px solid #f3c9c6;
  border-radius: 8px;
  background: #fff;
  color: var(--danger);
}
.cat-manage {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--green);
  border-radius: 8px;
  background: #fff;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}
.cat-row.archived .cat-qual { min-height: 44px; }

.set-manager-sheet { max-height: 90vh; }
.set-card {
  margin: 12px 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafafa;
}
.set-head, .set-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.set-head { margin-bottom: 4px; }
.set-actions { flex-wrap: wrap; margin-top: 8px; }
.field-label {
  display: block;
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.set-select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
}
.new-ledger-hint {
  margin: 9px 2px 15px;
  line-height: 1.48;
}

/* 보관 분류 일괄 관리 */
.archived-manage-sheet { max-height: 90vh; }
.archived-manage-sheet .sheet-close { width: 44px; height: 44px; }
.archived-summary {
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafafa;
}
.archived-summary strong { font-size: 17px; }
.archived-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 7px;
  border: 1px dashed #9aa0a6;
  border-radius: 10px;
  color: var(--muted);
  font-size: 11px;
}
.archived-meta { margin-top: 6px; color: var(--muted); font-size: 13px; }
.archived-target-hint { margin: 8px 2px 12px; }
.archived-move-all { margin-top: 10px; }
.archived-delete-all { margin-top: 18px; }
.settings-item:disabled, .set-select:disabled { opacity: 0.45; }
.bulk-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 0 6px;
  color: var(--muted);
  font-size: 13px;
}
.bulk-toggle {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
}
.bulk-item-list {
  max-height: 34vh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.bulk-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.bulk-item:last-child { border-bottom: none; }
.bulk-item input { width: 20px; height: 20px; accent-color: var(--green); }
.bulk-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bulk-item-amount { flex: 0 0 auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.bulk-action-bar {
  position: sticky;
  bottom: calc(-14px - env(safe-area-inset-bottom));
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(76px, 1fr) 88px 88px;
  align-items: center;
  gap: 8px;
  margin: 10px -14px 0;
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
}
.bulk-bar-summary { color: var(--muted); font-size: 13px; font-weight: 600; }
.bulk-move, .bulk-delete {
  min-height: 46px;
  border-radius: 11px;
  font-size: 15px;
  font-weight: 700;
}
.bulk-move { border: none; background: var(--green); color: #fff; }
.bulk-delete { border: 1px solid var(--danger); background: #fff; color: var(--danger); }
.bulk-move:disabled, .bulk-delete:disabled { opacity: 0.42; }
/* 8D-1: 소수점 키 추가에 따른 하단 행 (.: 1칸, %: 3칸) — 키 높이는 그대로 유지 */
.key-span3 { grid-column: span 3; }

/* ══════════════════════════════════════════════════════════════════
   8D-2: 장부(카트) 전환
   ══════════════════════════════════════════════════════════════════ */
/* 헤더 장부명 — 탭 가능 */
.hdr-date {
  cursor: pointer;
  font-weight: 700;
  color: var(--ink);
  font-size: 14px;
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 6px 8px;
  border-radius: 8px;
  background: #f4f5f7;
}
.hdr-date:active { background: #e9ebef; }

.ledger-sheet { max-height: 86vh; }
.ledger-list { margin-bottom: 10px; }
.ledger-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.ledger-row.current .ledger-main {
  background: var(--green-bg);
  border-color: var(--green);
}
.ledger-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  text-align: left;
}
.ledger-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.ledger-total {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.ledger-row.current .ledger-total { color: var(--green); font-weight: 600; }
.ledger-act {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  padding: 9px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}
.ledger-del {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  padding: 9px 8px;
  border: 1px solid #f3c9c6;
  border-radius: 8px;
  background: #fff;
  color: var(--danger);
}
.ledger-toggle {
  width: 100%;
  margin-top: 6px;
  padding: 11px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  background: #f4f5f7;
  border: none;
  border-radius: 10px;
}
.ledger-closed { margin-top: 8px; }

/* '할인'(영수증 전체 차감) 시트 캡션 — 라벨은 짧게, 정확성은 캡션이 담당 */
.sheet-adj-note {
  margin: -4px 2px 10px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.45;
  color: #9a7b3a;
  background: var(--adj-bg);
  border-radius: 9px;
}
