:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e5e8;
  --row-line: #f0f1f3;
  --text: #1f2328;
  --text-muted: #6b7280;
  --badge-bg: #f1f3f5;
  --badge-text: #4b5563;
  --primary: #2f6fed;
  --primary-hover: #2459c9;
  --primary-bg: #eef3fe;
  --primary-text: #2459c9; /* 연한 파란 바탕 위 파란 글자 (수정 중 안내, "자동" 표시) */
  --link: #2f6fed; /* 글자 버튼 ("카테고리 관리", "검색 지우기" 등) */
  --danger: #d64545;
  --danger-bg: #fdf3f3;
  --expense: #dc2626;
  --income: #15803d;
  --income-bg: #e8f5ec;
  --hover-bg: #fafbfc; /* 목록·그래프 줄에 마우스를 올렸을 때 */
  --highlight-bg: #d9e5fd; /* 방금 저장한 줄을 잠깐 표시할 때 */
}

/* ---------- 다크 모드 ----------
   같은 이름의 색만 어두운 톤으로 바꾼다. (라이트 모드 값은 위 그대로)
   배경은 완전 검정 대신 눈이 편한 짙은 회색, 지출·수입 색은 어두운 바탕에서 잘 보이게 조금 밝게 */
:root[data-theme="dark"] {
  color-scheme: dark; /* 날짜 선택·숫자 칸·체크박스·스크롤바 같은 기본 입력 요소도 어둡게 */
  --bg: #15181d;
  --surface: #1e2228;
  --border: #343a44;
  --row-line: #2a2f37;
  --text: #e6e8eb;
  --text-muted: #9aa3ad;
  --badge-bg: #2a3039;
  --badge-text: #c5cbd3;
  /* --primary(버튼·그래프 막대)는 라이트 모드 값 그대로: 흰 글자 대비를 지키려고 */
  --primary-bg: #1d2a44;
  --primary-text: #a9c5ff;
  --link: #8ab4ff;
  --danger: #f47174;
  --danger-bg: #3a2124;
  --expense: #f87171;
  --income: #4ade80;
  --income-bg: #173222;
  --hover-bg: #242931;
  --highlight-bg: #2a4478;
}

/* ---------- 라이트 골드 ----------
   깨끗한 크림 바탕 + 흰 카드. 글자는 다크 브라운 계열로 또렷하게 읽히게 하고,
   타이틀·버튼·뱃지 같은 포인트 요소에만 브론즈 골드를 쓴다 */
:root[data-theme="light-gold"] {
  color-scheme: light;
  --bg: #f0e6cf; /* 다크 골드처럼 카드(--surface, 흰색)보다 살짝 어두운 골드빛 배경 */
  --surface: #ffffff;
  /* 카드·입력창 테두리("포인트 라인")는 다크 골드와 같은 골드(#d4af37)를 옅은 투명도로 깔아서 표현 */
  --border: rgba(212, 175, 55, 0.4);
  --row-line: rgba(212, 175, 55, 0.2);
  --text: #1a1a1a;
  --text-muted: #6e6e6e;
  /* 뱃지 배경은 같은 골드를 아주 옅게 깐 톤(알파), 글자는 그 위에서 또렷이 읽히는 짙은 골드 브라운으로 —
     원색 골드(#d4af37)를 글자에 그대로 쓰면 밝은 배경 위에서 흐릿해지는 문제를 이렇게 피한다 */
  --badge-bg: rgba(212, 175, 55, 0.2);
  --badge-text: #7c5c0f;
  /* 타이틀·강조 금액·선택된 탭·버튼·포인트 라인은 다크 골드와 정확히 같은 색(#d4af37 / hover #e8c14a) */
  --primary: #d4af37;
  --primary-hover: #e8c14a;
  --primary-bg: rgba(212, 175, 55, 0.14);
  --primary-text: #7c5c0f; /* --badge-text와 같은 이유로, 옅은 골드 배경 위에 얹는 글자는 짙은 톤을 쓴다 */
  --link: #7c5c0f;
  --danger: #c0392b;
  --danger-bg: #fbeceb;
  --expense: #c0392b;
  --income: #1f7a4d;
  --income-bg: #e9f6ee;
  --hover-bg: #f6f1e2;
  --highlight-bg: #f6e6b8;
}

/* ---------- 다크 골드 ----------
   진짜 블랙에 가까운 배경 + 흰색/아이보리 본문 글자로 가독성을 확보하고,
   타이틀·버튼·선택된 탭·날짜 강조 같은 포인트 요소에만 샴페인 골드를 쓴다.
   (본문 글자를 전부 금색으로 칠하지 않는다 — 강조 요소만 금색) */
:root[data-theme="dark-gold"] {
  color-scheme: dark;
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --border: rgba(212, 175, 55, 0.25); /* 카드·입력창 테두리: 아주 옅고 얇은 골드 라인 */
  --row-line: rgba(212, 175, 55, 0.14);
  --text: #f3f3f3;
  --text-muted: #a8a29a; /* 톤을 낮춘 중립 그레이 — 보조 글자까지 금색이 되지 않게 */
  --badge-bg: #242220;
  --badge-text: #e8e2d3; /* 카테고리 뱃지는 아이보리로 — 강조 요소가 아닌 일반 텍스트라 금색을 아낀다 */
  --primary: #d4af37;
  --primary-hover: #e8c14a;
  --primary-bg: #332a10;
  --primary-text: #f0d878;
  --link: #e0bb46;
  --danger: #f0645f;
  --danger-bg: #3a1f1c;
  --expense: #f0645f;
  --income: #57cf8a;
  --income-bg: #16301f;
  --hover-bg: #1d1b17;
  --highlight-bg: #4a3a12;
}

/* 드롭다운 화살표·검색 돋보기도 어두운 바탕에서 보이게 밝은 회색으로 */
:root[data-theme="dark"] select,
:root[data-theme="dark-gold"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%239aa3ad' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

:root[data-theme="dark"] .search-input,
:root[data-theme="dark-gold"] .search-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Ccircle cx='7' cy='7' r='4.5' fill='none' stroke='%239aa3ad' stroke-width='1.5'/%3E%3Cpath d='M10.5 10.5 14 14' stroke='%239aa3ad' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
}

:root[data-theme="dark"] .app-dialog::backdrop,
:root[data-theme="dark-gold"] .app-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

:root[data-theme="dark"] .chart-tooltip,
:root[data-theme="dark-gold"] .chart-tooltip {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}

/* 골드 테마 전용: 메인 타이틀·핵심 금액(총 수입/총 지출/남은 돈)에만 포인트 골드색을 준다.
   본문 글자는 --text(흰/아이보리 또는 짙은 브라운) 그대로 두고 여기만 강조색을 올린다.
   남은 돈이 마이너스일 때는 아래(더 뒤에 나오는) .stat-value.is-negative가 소스 순서상 이겨서 계속 빨간색으로 보인다 */
:root[data-theme="light-gold"] .header h1,
:root[data-theme="dark-gold"] .header h1,
:root[data-theme="light-gold"] .stat-value,
:root[data-theme="dark-gold"] .stat-value {
  color: var(--primary);
}

/* 남은 돈이 마이너스일 때는 골드 테마에서도 계속 빨간색(--expense)으로 보여야 해서,
   위 규칙보다 선택자를 하나 더 붙여 우선순위를 높였다 */
:root[data-theme="light-gold"] .stat-value.is-negative,
:root[data-theme="dark-gold"] .stat-value.is-negative {
  color: var(--expense);
}

/* 모드를 바꾸는 순간에만 색이 부드럽게 바뀌게 한다. (script.js가 잠깐 붙였다 뗀다) */
:root.theme-transition,
:root.theme-transition *,
:root.theme-transition *::before,
:root.theme-transition *::after {
  transition:
    background-color 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease,
    transform 0.25s ease !important;
}

/* 화면 모드 전환: 해(라이트) | 달(다크). 지금 모드의 아이콘 아래에 동그란 받침이 온다 */
.theme-toggle {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  width: 68px;
  height: 36px;
  padding: 3px;
  cursor: pointer;
  background: var(--badge-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.theme-toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 30px;
  height: 28px;
  background: var(--surface);
  border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform 0.25s ease;
}

:root[data-theme="dark"] .theme-toggle-thumb {
  transform: translateX(30px);
}

.theme-toggle-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 28px;
  color: var(--text-muted);
}

:root:not([data-theme="dark"]) .theme-toggle-icon.is-sun {
  color: #d97706;
}

:root[data-theme="dark"] .theme-toggle-icon.is-moon {
  color: #fcd34d;
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle-thumb {
    transition: none;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", "Noto Sans KR", sans-serif;
  line-height: 1.5;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 20px 60px;
}

/* ---------- 화면 전환 탭 (내역 · 통계 · 설정) ----------
   넓은 화면: 맨 위에 가로로. 좁은 화면(휴대폰): 맨 아래에 고정, 아이콘 위에 짧은 글자 */
.tab-bar {
  display: flex;
  z-index: 20;
  background: var(--surface);
  border-color: var(--border);
}

.tab-bar-top {
  position: sticky;
  top: 0;
  justify-content: center;
  gap: 4px;
  padding: 8px max(20px, calc((100% - 720px) / 2));
  border-bottom: 1px solid var(--border);
}

.tab-bar-bottom {
  display: none;
}

.tab-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  background: none;
  border: none;
  border-radius: 8px;
  transition: color 0.15s ease, background 0.15s ease;
}

.tab-button:hover {
  color: var(--text);
  background: var(--bg);
}

.tab-button.is-active {
  color: var(--primary);
  background: var(--primary-bg);
}

.tab-button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.tab-icon {
  flex-shrink: 0;
}

/* 탭을 바꿀 때 내용이 살짝 떠오르듯 부드럽게 나타난다 */
.tab-panel {
  animation: tab-panel-in 0.2s ease;
}

@keyframes tab-panel-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tab-panel {
    animation: none;
  }
}

@media (max-width: 640px) {
  .tab-bar-top {
    display: none;
  }

  .tab-bar-bottom {
    display: flex;
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    justify-content: space-around;
    padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
  }

  .tab-bar-bottom .tab-button {
    flex: 1;
    flex-direction: column;
    gap: 3px;
    padding: 6px 4px;
    font-size: 11px;
    border-radius: 10px;
  }
}

/* "내역" 탭에서 새 내역을 입력하는 입력 창을 여는 플로팅 "+" 버튼. 스크롤해도 늘 같은 자리에 떠 있다 */
.fab-add {
  position: fixed;
  right: max(20px, calc((100vw - 720px) / 2 + 20px));
  bottom: 24px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  color: #fff;
  cursor: pointer;
  background: var(--primary);
  border: none;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(47, 111, 237, 0.4);
  transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.fab-add:hover {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.fab-add:active {
  transform: scale(0.96);
}

.fab-add:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

@media (max-width: 640px) {
  .fab-add {
    right: 16px;
    /* 아래 고정 탭 메뉴 위로 띄운다 */
    bottom: calc(76px + env(safe-area-inset-bottom) + 12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .fab-add {
    transition: none;
  }
}

/* 헤더 */
.header {
  margin-bottom: 24px;
}

.header h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--text-muted);
}

/* 거래 내역을 일괄 추가했을 때 안내 */
.import-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 16px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--income);
  background: var(--income-bg);
  border-radius: 12px;
}

.import-notice .btn-link {
  flex-shrink: 0;
  color: var(--income);
}

/* 카드 */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

/* 입력 폼: 팝업(모바일은 바텀시트) 안이라 너비가 넉넉하지 않으므로 항상 한 줄에 하나씩 세로로 쌓는다 */
.entry-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

/* 홈 탭: 재정 목표 목록(여러 개를 등록할 수 있다) + 오늘의 재정 명언 */
/* .list-header와 달리 좁은 화면에서도 세로로 쌓이지 않는다: + 버튼이 항상 우측 상단에 있어야 해서 */
.goal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.goal-header .section-title {
  margin: 0;
}

.goal-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.goal-item {
  position: relative;
  padding: 14px 44px 12px 12px;
  border: 1px solid var(--row-line);
  border-radius: 8px;
}

/* 첫째 줄: 목표 내용 · 날짜 선택 / 둘째 줄: 모은 금액 · 목표 금액, 그 아래 진행률 막대 */
.goal-item-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.goal-item-row {
  display: flex;
  gap: 10px;
}

.goal-item-row .field {
  flex: 1;
  min-width: 130px;
}

/* 목표 금액·모은 금액·목표 내용·날짜 입력칸을 더 크고 잘 보이게 (홈 화면 첫 입력이라 시인성을 높인다) */
.goal-amount-input,
.goal-saved-input,
.goal-content-input,
.goal-date-input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  font-size: 18px;
}

/* 날짜 칸은 이제 공통 커스텀 달력 팝업을 연다(.js-date-input, script.js) — 직접 타이핑하지 않는 칸이라 포인터 커서로 알려준다 */
.js-date-input {
  cursor: pointer;
}

/* 진행률 막대: 모은 금액 대비 목표 금액 퍼센트를 막대 중앙에 겹쳐 보여준다 */
.goal-progress-labels {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.goal-progress-track {
  position: relative;
  height: 22px;
  background: var(--bg);
  border: 1px solid var(--row-line);
  border-radius: 999px;
  overflow: hidden;
}

.goal-progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 999px 0 0 999px;
  transition: width 0.2s ease;
}

.goal-progress-percent {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  text-shadow: 0 0 3px var(--surface), 0 0 3px var(--surface);
}

/* 삭제(×) 버튼은 카드 오른쪽 위 모서리에 겹쳐 배치 */
.goal-remove-button {
  position: absolute;
  top: 4px;
  right: 4px;
}

@media (max-width: 480px) {
  .goal-item-row {
    flex-direction: column;
  }
}

.finance-quote {
  margin: 0;
  padding: 14px 16px;
  font-size: 15px;
  font-style: italic;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
}

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

/* "+ 새 카테고리 추가"를 고르면 나타나는 이름 입력 줄 */
.new-category-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: var(--bg);
  border-radius: 10px;
}

.new-category-row input {
  flex: 1;
  min-width: 0;
}

.new-category-row .btn {
  flex-shrink: 0;
}

/* 창 (카테고리 관리 · 반복 지출 관리 공통) */
.app-dialog {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  overflow: auto;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.14);
}

.app-dialog::backdrop {
  background: rgba(31, 35, 40, 0.4);
}

/* ---------- 공통 날짜 선택 팝업 (.js-date-input 전부가 함께 쓴다) ----------
   그 자체가 <dialog>라 backdrop이 없다: 이미 열려 있는 다른 모달 위에도 겹쳐서 뜬다 */
.date-picker-popup {
  position: fixed;
  margin: 0;
  padding: 12px;
  width: 260px;
  max-width: calc(100vw - 24px);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
}

.date-picker-popup::backdrop {
  background: transparent;
}

.date-picker-header {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.date-picker-seg-button {
  flex: 1;
  height: 36px;
  padding: 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.date-picker-seg-button[aria-expanded="true"] {
  color: var(--primary-text);
  background: var(--primary-bg);
  border-color: var(--primary);
}

.dp-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

.dp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.dp-day {
  aspect-ratio: 1;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 6px;
}

.dp-day:hover {
  background: var(--hover-bg);
}

.dp-day.is-outside {
  color: var(--text-muted);
  opacity: 0.5;
}

.dp-day.is-today {
  font-weight: 700;
  color: var(--primary);
}

.dp-day.is-selected {
  color: #fff;
  background: var(--primary);
}

/* 연도·월 목록: 휠/터치는 기본 스크롤, 마우스 드래그는 script.js(enableDragScroll)가 더해 준다 */
.date-picker-scroll-list {
  max-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
  cursor: grab;
  user-select: none;
}

.date-picker-scroll-list:active {
  cursor: grabbing;
}

.date-picker-option {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  text-align: center;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 8px;
}

.date-picker-option:hover {
  background: var(--hover-bg);
}

.date-picker-option.is-selected {
  font-weight: 700;
  color: var(--primary-text);
  background: var(--primary-bg);
}

/* ---------- 내역 입력 창: 넓은 화면은 가운데 팝업, 좁은 화면(휴대폰)은 아래에서 올라오는 바텀시트 ----------
   여닫을 때 부드럽게: @starting-style로 dialog가 뜨는 순간의 모습을 정해 두면,
   브라우저가 그 모습 ↔ 평소 모습 사이를 자동으로 오간다. (열 때·닫을 때 둘 다) */
.entry-dialog {
  opacity: 0;
  transform: scale(0.96);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease,
    overlay 0.18s ease allow-discrete,
    display 0.18s ease allow-discrete;
}

.entry-dialog[open] {
  opacity: 1;
  transform: scale(1);
}

@starting-style {
  .entry-dialog[open] {
    opacity: 0;
    transform: scale(0.96);
  }
}

.entry-dialog::backdrop {
  background: rgba(31, 35, 40, 0);
  transition: background-color 0.18s ease, overlay 0.18s ease allow-discrete, display 0.18s ease allow-discrete;
}

.entry-dialog[open]::backdrop {
  background: rgba(31, 35, 40, 0.4);
}

@starting-style {
  .entry-dialog[open]::backdrop {
    background-color: rgba(31, 35, 40, 0);
  }
}

:root[data-theme="dark"] .entry-dialog[open]::backdrop,
:root[data-theme="dark-gold"] .entry-dialog[open]::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

@media (max-width: 640px) {
  /* 바텀시트: 화면 아래에 붙이고 위쪽만 둥글게. 시작 모습은 화면 아래로 완전히 내려간 상태 */
  .entry-dialog {
    position: fixed;
    inset: auto 0 0 0;
    margin: 0;
    width: 100%;
    max-width: 100%;
    max-height: 88vh;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateY(100%);
  }

  .entry-dialog[open] {
    transform: translateY(0);
  }

  @starting-style {
    .entry-dialog[open] {
      transform: translateY(100%);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .entry-dialog {
    transition: none;
  }
}

/* ---------- 반복 지출: 목록의 "자동" 표시 · 관리 창 ---------- */

/* 반복 지출로 자동 등록된 내역 */
.auto-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  color: var(--primary-text);
  white-space: nowrap;
  vertical-align: 1px;
  background: var(--primary-bg);
  border-radius: 999px;
}

.app-dialog.recurring-dialog {
  width: min(560px, calc(100vw - 32px));
}

.recurring-form {
  margin: 0 0 20px;
  padding: 14px;
  background: var(--bg);
  border-radius: 10px;
}

.recurring-form-title {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
}

.recurring-fields {
  display: grid;
  grid-template-columns: 1fr 120px 96px;
  gap: 10px;
  align-items: end;
}

.recurring-field-item {
  grid-column: 1 / -1;
}

.day-input {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-muted);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 14px;
  cursor: pointer;
}

.checkbox-row input {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  accent-color: var(--primary);
}

.recurring-hint {
  margin: 6px 0 0 24px;
  font-size: 12px;
  color: var(--text-muted);
}

.recurring-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.recurring-message {
  margin: -8px 0 16px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--income);
  background: var(--income-bg);
  border-radius: 8px;
}

.recurring-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--row-line);
  border-radius: 8px;
}

.recurring-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
}

.recurring-item + .recurring-item {
  border-top: 1px solid var(--row-line);
}

.recurring-item.is-editing {
  background: var(--primary-bg);
}

.recurring-info {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.recurring-name {
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.recurring-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.recurring-amount {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--expense);
  white-space: nowrap;
}

.recurring-buttons {
  display: flex;
  flex-shrink: 0;
  gap: 6px;
}

.recurring-buttons .btn + .btn {
  margin-left: 0;
}

.recurring-empty {
  margin: 0;
  padding: 20px 0;
  font-size: 13px;
  text-align: center;
  color: var(--text-muted);
}

@media (max-width: 640px) {
  .recurring-fields {
    grid-template-columns: 1fr 1fr;
  }

  .recurring-field-category {
    grid-column: 1 / -1;
  }

  .recurring-item {
    flex-wrap: wrap;
  }

  .recurring-buttons {
    justify-content: flex-end;
    width: 100%;
  }
}

/* ---------- 창 머리글 · 본문 (공통), 카테고리 관리 목록 ---------- */

.dialog-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--row-line);
}

.dialog-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  background: transparent;
}

.btn-icon:hover {
  color: var(--text);
  background: var(--bg);
}

.dialog-body {
  padding: 16px 20px 20px;
}

.dialog-hint {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.category-section + .category-section {
  margin-top: 20px;
}

.category-section-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.category-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--row-line);
  border-radius: 8px;
}

/* 카테고리 관리 창의 "새 카테고리 추가" 줄: 입력 폼의 .new-category-row와 같은 모양을 쓴다 */
.category-add-form {
  margin-top: 10px;
}

.category-item {
  padding: 8px 12px;
}

.category-item + .category-item {
  border-top: 1px solid var(--row-line);
}

.category-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}

.category-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.category-usage {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.category-tag {
  padding: 1px 8px;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  background: var(--badge-bg);
  border-radius: 999px;
}

.category-item-row .btn {
  flex-shrink: 0;
}

.category-item-row .btn + .btn {
  margin-left: 0;
}

.category-rename-input {
  flex: 1;
  min-width: 0;
  height: 32px;
  font-size: 14px;
}

/* 지출 카테고리 한 줄 안의 "지출 유형" 드롭다운 */
.category-type-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.category-type-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.category-type-select {
  width: auto;
  height: 30px;
  padding: 0 26px 0 10px;
  font-size: 12px;
}

.category-item-message {
  margin: 6px 0 2px;
  font-size: 12px;
  color: var(--income);
}

.category-item-message.is-error {
  color: var(--danger);
}

.btn-plain {
  padding: 4px 10px;
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
  border-color: var(--border);
}

.btn-plain:hover {
  color: var(--text);
  background: var(--bg);
}

input,
select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

select {
  padding-right: 36px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* 아직 선택하지 않았을 때는 안내 문구처럼 흐리게 */
select:invalid {
  color: var(--text-muted);
}

select option {
  color: var(--text);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}

input.invalid,
select.invalid {
  border-color: var(--danger);
}

/* 지출 | 수입 전환 버튼: 팝업 너비만큼 꽉 채운다 */
.type-toggle {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--badge-bg);
  border-radius: 10px;
}

.type-option {
  position: relative;
  flex: 1;
  display: block;
}

/* 실제 라디오 버튼은 투명하게 겹쳐 두어 키보드(방향키)로도 고를 수 있게 한다 */
.type-option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.type-option span {
  display: block;
  padding: 6px 22px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  color: var(--text-muted);
  border-radius: 7px;
}

.type-option input:checked + span {
  font-weight: 600;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.type-option input[value="expense"]:checked + span {
  color: var(--expense);
}

.type-option input[value="income"]:checked + span {
  color: var(--income);
}

.type-option input:focus-visible + span {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.form-actions {
  display: flex;
  gap: 8px;
}

.form-actions .btn {
  flex: 1;
  padding: 0 12px;
}

.btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 8px;
}

.btn-primary {
  height: 42px;
  padding: 0 24px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  height: 42px;
  padding: 0 18px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
}

.form-error {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--danger);
}

.form-error:empty {
  display: none;
}

/* 설정 화면 "데이터" 카드 안의 버튼 줄 (백업 · 복원, 엑셀로 내보내기 모두 같은 모양을 쓴다) */
.settings-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

/* 같은 카드 안에서 다른 기능 묶음을 구분하는 옅은 구분선 (예: 백업·복원 아래 엑셀로 내보내기) */
.settings-subsection {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--row-line);
}

.btn-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  background: var(--surface);
  border-color: var(--border);
}

.btn-tool:hover {
  background: var(--bg);
}

.btn-tool svg {
  flex-shrink: 0;
  color: var(--text-muted);
}

/* 엑셀 내보내기 창의 "전체 기간 · 이번 달 · 지난 달" 빠른 선택 버튼 */
.quick-range-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.quick-range-buttons .btn-tool.is-active {
  color: var(--primary);
  background: var(--primary-bg);
  border-color: var(--primary);
}

/* 백업·복원·엑셀 내보내기 결과: 성공은 초록 안내, 실패는 폼 오류와 같은 빨간 글자 */
.data-tools-message {
  flex-basis: 100%;
  margin: 0;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--income);
  background: var(--income-bg);
  border-radius: 8px;
  overflow-wrap: anywhere;
}

.data-tools-message.is-error {
  padding: 0;
  color: var(--danger);
  background: transparent;
}

@media (max-width: 640px) {
  /* 버튼이 여럿이라 한 줄에선 잘리므로 세로로 쌓는다 (백업 · 복원, 엑셀로 내보내기 모두) */
  .settings-buttons {
    flex-direction: column;
  }

  .settings-buttons .btn {
    width: 100%;
  }
}

/* 수정 중일 때 입력 창 (기존 드롭 그림자 위에 파란 테두리를 더한다) */
.entry-dialog.is-editing {
  border-color: var(--primary);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.14), 0 0 0 3px rgba(47, 111, 237, 0.12);
}

.edit-banner {
  margin: 0 0 14px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--primary-text);
  background: var(--primary-bg);
  border-radius: 8px;
  overflow-wrap: anywhere;
}

/* ---------- 설정 탭 세로 아코디언: 관리 · 화면 · 데이터 ---------- */
.settings-accordion-item {
  padding: 0;
}

.settings-accordion-title {
  margin: 0;
  font-size: inherit;
}

.settings-accordion-header {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 18px 20px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  background: none;
  border: none;
  border-radius: 12px;
}

.settings-accordion-header:hover {
  background: var(--hover-bg);
}

.settings-accordion-header:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.settings-accordion-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.settings-accordion-item.is-open .settings-accordion-header {
  color: var(--primary-text);
}

.settings-accordion-item.is-open .settings-accordion-chevron {
  color: var(--primary);
  transform: rotate(180deg);
}

/* 슬라이드 펼침: 높이를 0fr ↔ 1fr로 바꿔 부드럽게 여닫는다 */
.settings-accordion-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s ease;
}

.settings-accordion-item.is-open .settings-accordion-body {
  grid-template-rows: 1fr;
}

.settings-accordion-inner {
  min-height: 0;
  padding: 0 20px;
  overflow: hidden;
}

.settings-accordion-item.is-open .settings-accordion-inner {
  padding-bottom: 20px;
}

@media (prefers-reduced-motion: reduce) {
  .settings-accordion-body,
  .settings-accordion-chevron {
    transition: none;
  }
}

/* ---------- 설정: 관리 메뉴 목록 · 다크 모드 줄 ---------- */
.settings-menu {
  margin: 0;
  border: 1px solid var(--row-line);
  border-radius: 8px;
}

.settings-menu-item {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 13px 14px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  background: none;
  border: none;
}

.settings-menu-item + .settings-menu-item {
  border-top: 1px solid var(--row-line);
}

.settings-menu-item:hover {
  background: var(--hover-bg);
}

.settings-menu-item svg {
  flex-shrink: 0;
  color: var(--text-muted);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

/* 테마 선택 드롭다운: settings-row 안에서 라벨 옆에 붙는 정도의 너비만 차지하게 */
.theme-select {
  width: auto;
  min-width: 140px;
  height: 36px;
}

/* ---------- 기간(하루 · 한 주 · 한 달 · 직접 선택) 탭 ---------- */
.period-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  background: var(--badge-bg);
  border-radius: 10px;
}

.period-tab {
  position: relative;
  display: block;
}

/* 실제 라디오 버튼은 투명하게 겹쳐 두어 키보드(방향키)로도 고를 수 있게 한다 */
.period-tab input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.period-tab span {
  display: block;
  padding: 7px 0;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  color: var(--text-muted);
  border-radius: 7px;
}

.period-tab input:checked + span {
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.period-tab input:focus-visible + span {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* "하루" · "한 주" · "한 달"에서만 보인다: ◀ 큰 날짜/기간 표시 · "오늘로 돌아가기" ▶ */
.period-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 14px;
}

.period-nav-arrow {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.period-nav-arrow:hover {
  color: var(--text);
  background: var(--bg);
}

.period-nav-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  text-align: center;
}

.period-nav-label {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  overflow-wrap: anywhere;
}

.period-today-button {
  font-size: 12px;
}

.period-range {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--text-muted);
}

/* "직접 선택"의 시작·끝 날짜 입력 줄 */
.custom-range-row {
  margin: 0 0 14px;
  padding: 10px;
  background: var(--bg);
  border-radius: 10px;
}

.custom-range-fields {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.custom-range-field {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.custom-range-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.custom-range-sep {
  padding-bottom: 10px; /* 입력칸 높이(42px)에 맞춰 물결표를 살짝 내린다 */
  color: var(--text-muted);
}

/* 이 안의 오류 문구는 입력칸 바로 아래, 카드 배경과 살짝 떨어지게 */
.custom-range-row .form-error {
  margin: 8px 0 0;
}

@media (max-width: 640px) {
  .custom-range-fields {
    flex-direction: column;
    align-items: stretch;
  }

  .custom-range-sep {
    display: none;
  }
}

/* 기간을 바꿀 때 요약·그래프·목록이 부드럽게 바뀌도록 잠깐 흐리게 한다. (script.js가 붙였다 뗀다) */
.period-nav,
.period-range,
.summary-content,
.chart-card,
.table-wrap,
.empty {
  transition: opacity 0.15s ease;
}

.period-nav.period-fade,
.period-range.period-fade,
.summary-content.period-fade,
.chart-card.period-fade,
.table-wrap.period-fade,
.empty.period-fade {
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .period-nav,
  .period-range,
  .summary-content,
  .chart-card,
  .table-wrap,
  .empty {
    transition: none;
  }
}

/* 기간별 수입 · 지출 · 남은 돈 (요약 카드 안쪽 3분할 그리드) */
.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.stat {
  min-width: 0;
  padding: 0 20px;
  border-left: 1px solid var(--row-line);
}

.stat:first-child {
  padding-left: 0;
  border-left: none;
}

.stat:last-child {
  padding-right: 0;
}

.stat-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

.stat-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.stat-dot.is-income {
  background: var(--income);
}

.stat-dot.is-expense {
  background: var(--expense);
}

.stat-value {
  margin: 4px 0 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text);
  overflow-wrap: anywhere;
}

/* 지출이 수입보다 많을 때 */
.stat-value.is-negative {
  color: var(--expense);
}

.stat-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- 통계 탭: 달력 ---------- */
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
}

.calendar-weekdays span {
  padding: 4px 0;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  color: var(--text-muted);
}

.calendar-weekdays .is-sat {
  color: var(--primary);
}

.calendar-weekdays .is-sun {
  color: var(--expense);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

/* 날짜 칸: 그날 지출(빨강)·수입(초록)을 위에서부터 보여준다. 버튼이라 클릭·키보드 모두 된다 */
.calendar-cell {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-height: 56px;
  padding: 4px 3px;
  overflow: hidden;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--row-line);
  border-radius: 6px;
  cursor: pointer;
}

.calendar-cell:hover {
  background: var(--hover-bg);
}

.calendar-cell:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* 이번 달이 아닌(앞뒤 달에서 채워 넣은) 날짜는 옅게 */
.calendar-cell.is-outside {
  color: var(--text-muted);
  background: var(--bg);
}

/* 오늘: 테두리로 강조 */
.calendar-cell.is-today {
  border: 2px solid var(--primary);
  padding: 3px 2px;
}

/* 지금 고른 기간(하루 · 한 주 · 직접 선택)에 들어가는 날짜: 옅은 배경으로 표시 */
.calendar-cell.is-in-period {
  background: var(--primary-bg);
}

.calendar-cell.is-today.is-in-period {
  background: var(--primary-bg);
}

.calendar-cell-day {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.calendar-cell.is-today .calendar-cell-day {
  color: var(--primary);
}

.calendar-cell-amount {
  overflow: hidden;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* 금액이 칸보다 길면(예: "-1,234,567원") 글자를 조금 줄여서 안에 들어오게 한다 */
.calendar-cell-amount.is-long {
  font-size: 9px;
}

.calendar-cell-amount.is-expense {
  color: var(--expense);
}

.calendar-cell-amount.is-income {
  color: var(--income);
}

@media (max-width: 640px) {
  .calendar-grid {
    gap: 2px;
  }

  .calendar-cell {
    min-height: 48px;
    padding: 3px 2px;
    border-radius: 4px;
  }

  .calendar-cell-day {
    font-size: 11px;
  }

  .calendar-cell-amount {
    font-size: 9px;
  }

  .calendar-cell-amount.is-long {
    font-size: 8px;
  }
}

/* 달력에서 날짜 칸을 누르면 뜨는 그날 상세 내역 창 */
.calendar-day-summary {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.calendar-day-summary strong {
  font-weight: 600;
  color: var(--badge-text);
}

.calendar-day-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.calendar-entry-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}

.calendar-entry-item + .calendar-entry-item {
  border-top: 1px solid var(--row-line);
}

.calendar-entry-item.is-editing {
  background: var(--primary-bg);
}

.calendar-entry-info {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.calendar-entry-name-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.calendar-entry-name.is-empty {
  color: var(--text-muted);
}

.calendar-entry-amount {
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.calendar-entry-amount.is-expense {
  color: var(--expense);
}

.calendar-entry-amount.is-income {
  color: var(--income);
}

.calendar-entry-buttons {
  display: flex;
  flex-shrink: 0;
  gap: 6px;
}

.calendar-entry-buttons .btn + .btn {
  margin-left: 0;
}

@media (max-width: 640px) {
  .calendar-entry-item {
    flex-wrap: wrap;
  }

  .calendar-entry-buttons {
    justify-content: flex-end;
    width: 100%;
  }
}

/* 카테고리별 지출·수입 그래프 */
.chart-card {
  position: relative;
}

/* 지출 그래프 아래에 수입 그래프가 온다. 사이는 옅은 선으로 나눈다 */
.chart-section + .chart-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--row-line);
}

.chart {
  --value-space: 100px; /* 막대 끝에 붙는 금액 글자 자리 */
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* 순위 칸 36px 고정("11위"까지도 잘리지 않게) · 이름 칸 128px("구독/디지털서비스" 같은 긴 이름도 한 줄에).
   순위 칸을 고정 폭으로 두는 이유: auto였을 때는 줄마다 "1위"(두 글자)·"11위"(세 글자) 폭이 달라져서
   그 옆 이름·막대 시작 위치가 줄마다 어긋났었다. */
.chart-row {
  display: grid;
  grid-template-columns: 36px 128px 1fr;
  gap: 12px;
  align-items: center;
  margin: 0 -8px;
  padding: 6px 8px;
  border-radius: 8px;
}

.chart-row:hover,
.chart-row:focus-visible {
  background: var(--hover-bg);
}

.chart-row:focus-visible {
  outline: 2px solid rgba(47, 111, 237, 0.4);
  outline-offset: -2px;
}

/* 몇 번째로 큰 금액인지 (1위 · 2위 · ...). 폭을 고정하고 오른쪽 정렬해서 자릿수가 달라도 그 옆 칸 위치가 안 흔들리게 한다 */
.chart-rank {
  width: 36px;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 칸보다 긴 이름은 막대와 겹치지 않게 줄을 바꾼다 */
.chart-label {
  font-size: 14px;
  line-height: 1.35;
  color: var(--text);
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.chart-track {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* 막대: 두께 16px, 시작점은 각지게, 끝은 4px 둥글게. 지출은 빨간 계열, 수입은 초록 계열로 구분한다 */
.chart-bar {
  flex-shrink: 0;
  height: 16px;
  background: var(--expense);
  border-radius: 0 4px 4px 0;
  transition: filter 0.15s;
}

.chart-income .chart-bar {
  background: var(--income);
}

.weekday-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  color: var(--primary-text);
  white-space: nowrap;
  vertical-align: 1px;
  background: var(--primary-bg);
  border-radius: 999px;
}

.chart-row:hover .chart-bar,
.chart-row:focus-visible .chart-bar {
  filter: brightness(1.15);
}

.chart-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.chart-tooltip {
  position: absolute;
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  white-space: nowrap;
  pointer-events: none;
}

.tooltip-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

/* 비중·건수 글자: 흐린 보조색(--text-muted) 대신, 테마마다 이미 배경 위에서 읽히게 맞춰 둔
   포인트 글자색(--link)을 써서 또렷하게 보이게 한다. (다크 골드에서는 밝은 샴페인 골드가 된다) */
.tooltip-detail {
  font-size: 13px;
  font-weight: 600;
  color: var(--link);
}

@media (max-width: 640px) {
  .chart-row {
    grid-template-columns: 28px 84px 1fr;
    gap: 8px;
  }

  .chart-rank {
    width: 28px;
  }
}

/* 목록 */
.section-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.count {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
}

/* 항목 검색 */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.list-header .section-title {
  margin: 0;
}

/* 카테고리 드롭다운 + 검색창을 한 줄 툴바로 묶는다. 좁아지면 자연스럽게 줄바꿈 */
.list-header-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.list-header-tools .category-filter {
  flex: 0 0 auto;
}

.search-input {
  width: 240px;
  height: 36px;
  padding-left: 34px;
  font-size: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Ccircle cx='7' cy='7' r='4.5' fill='none' stroke='%236b7280' stroke-width='1.5'/%3E%3Cpath d='M10.5 10.5 14 14' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 11px center;
}

.list-header-tools .search-input {
  flex: 1 1 160px;
  width: auto;
  min-width: 0;
  max-width: 280px;
}

.search-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.search-summary strong {
  font-weight: 600;
  color: var(--text);
}

.btn-link {
  padding: 0;
  font: inherit;
  color: var(--link);
  background: none;
  border: none;
  cursor: pointer;
}

.btn-link:hover {
  text-decoration: underline;
}

@media (max-width: 640px) {
  .list-header {
    flex-direction: column;
    align-items: stretch;
  }

  .list-header-tools .search-input {
    max-width: none;
  }
}

/* 카테고리 필터: 체크박스 드롭다운 + "필터 초기화" */
.list-filter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.category-filter {
  position: relative; /* 드롭다운 패널이 바로 아래에 뜨도록 */
}

.btn-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  font-size: 14px; /* 검색창(.search-input)과 글자 크기를 맞춰 한 줄 툴바로 보이게 */
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

.btn-filter:hover {
  background: var(--bg);
}

.btn-filter svg {
  flex-shrink: 0;
  color: var(--text-muted);
}

.category-filter-caret {
  transition: transform 0.15s ease;
}

.btn-filter[aria-expanded="true"] .category-filter-caret {
  transform: rotate(180deg);
}

.category-filter-panel {
  position: absolute;
  z-index: 5;
  top: calc(100% + 6px);
  left: 0;
  width: min(260px, calc(100vw - 40px));
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.category-filter-panel-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  font-size: 12px;
  border-bottom: 1px solid var(--row-line);
}

/* 지출·수입 두 그룹을 합쳐서 하나로 스크롤한다 */
.category-filter-groups {
  max-height: 280px;
  overflow-y: auto;
}

.category-filter-divider {
  margin: 8px 2px;
  border-top: 1px solid var(--row-line);
}

.category-filter-group-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 6px;
}

.category-filter-group-title {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.category-filter-group-actions {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
  font-size: 11px;
}

.category-filter-group-actions .btn-link {
  font-size: 11px;
}

.category-filter-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.category-filter-item label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  font-size: 14px;
  border-radius: 6px;
  cursor: pointer;
}

.category-filter-item label:hover {
  background: var(--hover-bg);
}

.category-filter-item input {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  accent-color: var(--primary);
}

.category-filter-item span {
  overflow-wrap: anywhere;
}

.category-filter-reset-button {
  font-size: 13px;
  white-space: nowrap;
}

:root[data-theme="dark"] .category-filter-panel,
:root[data-theme="dark-gold"] .category-filter-panel {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}

/* position: relative — 표 안의 숨김 글자(.sr-only)가 스크롤 영역 밖으로 튀어나가 페이지 폭을 늘리지 않게 */
.table-wrap {
  position: relative;
  overflow-x: auto;
}

.entry-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.entry-table thead th {
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.entry-table td {
  padding: 12px;
  border-bottom: 1px solid var(--row-line);
  vertical-align: middle;
}

/* 날짜 묶음의 마지막 줄은 선 없이 끝낸다 (다음 날짜 헤더 위 여백으로 나뉜다) */
.entry-table tbody tr:last-child td {
  border-bottom: none;
}

.entry-table tbody tr:hover {
  background: var(--hover-bg);
}

/* 날짜 헤더: 연한 회색 띠에 날짜와 그날 합계. 위쪽 여백으로 날짜 묶음 사이를 넉넉히 띄운다 */
.date-header th {
  padding: 24px 0 4px;
  font-weight: 400;
  text-align: left;
}

.date-group:first-of-type .date-header th {
  padding-top: 12px;
}

.entry-table tbody tr.date-header:hover {
  background: transparent;
}

.date-header-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
}

.date-header-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.date-header-sums {
  font-size: 12px;
  color: var(--text-muted);
}

.date-header-sums strong {
  font-weight: 600;
  color: var(--badge-text);
}

/* 다크 골드에서는 배경(--bg)과 카드(--surface)가 둘 다 어두운 톤이라 날짜 구분 박스가 묻히기 쉬워서,
   테두리를 더하고 날짜 글자를 포인트 색(골드)으로 올려 눈에 더 잘 띄게 한다 */
:root[data-theme="dark-gold"] .date-header-box {
  background: var(--badge-bg);
  border: 1px solid var(--border);
}

:root[data-theme="dark-gold"] .date-header-title {
  color: var(--primary);
}

/* 수정 중인 줄 */
.entry-table tbody tr.is-editing {
  background: var(--primary-bg);
}

/* 방금 저장한 줄: 잠깐 파랗게 표시했다가 사라진다 */
.entry-table tbody tr.is-updated {
  animation: row-updated 1.8s ease-out;
}

@keyframes row-updated {
  from {
    background: var(--highlight-bg);
  }
  to {
    background: transparent;
  }
}

/* 띄어쓰기 없는 긴 상호명("주식회사지앤지커머")은 필요할 때 글자 중간에서도 줄을 바꿔
   표가 카드보다 넓어지지 않게 한다 */
.col-item {
  word-break: keep-all;
  overflow-wrap: anywhere;
}

/* 항목 글이 없는 예전 내역 */
.col-item.is-empty {
  color: var(--text-muted);
}

.col-category {
  white-space: nowrap;
}

.category-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 12px;
  color: var(--badge-text);
  background: var(--badge-bg);
  border-radius: 999px;
}

.category-badge.is-income {
  color: var(--income);
  background: var(--income-bg);
}

.num {
  text-align: right !important;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.entry-table td.num {
  font-weight: 600;
}

/* 금액: 지출은 빨간색 "-", 수입은 초록색 "+" */
.entry-table td.amount-expense {
  color: var(--expense);
}

.entry-table td.amount-income {
  color: var(--income);
}

.col-action {
  width: 1%;
  text-align: right;
  white-space: nowrap;
}

.btn-edit,
.btn-delete {
  padding: 4px 10px;
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
  border-color: var(--border);
}

.btn-edit + .btn-delete {
  margin-left: 6px;
}

.btn-edit:hover {
  color: var(--link);
  background: var(--primary-bg);
  border-color: var(--primary);
}

.btn-delete:hover {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger);
}

.empty {
  margin: 0;
  padding: 36px 0 24px;
  font-size: 14px;
  text-align: center;
  color: var(--text-muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* 좁은 화면 */
@media (max-width: 640px) {
  /* 맨 아래는 고정된 탭 메뉴에 내용이 가려지지 않게 더 띄운다 */
  .container {
    padding: 24px 14px calc(76px + env(safe-area-inset-bottom));
  }

  /* 수입 · 지출 · 남은 돈을 세로로 */
  .summary {
    grid-template-columns: 1fr;
  }

  .stat,
  .stat:first-child,
  .stat:last-child {
    padding: 12px 0;
    border-left: none;
    border-top: 1px solid var(--row-line);
  }

  .stat:first-child {
    padding-top: 0;
    border-top: none;
  }

  .stat:last-child {
    padding-bottom: 0;
  }

  /* 좁은 화면에서는 표만 옆으로 밀어서 본다 */
  .entry-table {
    min-width: 480px;
    font-size: 14px;
  }

  .entry-table thead th,
  .entry-table td {
    padding-left: 8px;
    padding-right: 8px;
  }

  .date-header-box {
    padding: 8px;
  }
}

/* ---------- 로그인 화면 (cloud.js) ----------
   로그인하고 데이터를 불러올 때까지 가계부 전체를 덮는다. 뒤의 가계부 화면은 스크롤되지 않게 막는다 */
body.is-locked {
  overflow: hidden;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 16px 24px;
  overflow-y: auto;
  background: var(--bg);
}

.auth-gate[hidden] {
  display: none;
}

.auth-box {
  width: 100%;
  max-width: 380px;
  padding: 28px 24px;
}

.auth-brand {
  margin: 0 0 20px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
}

.auth-title {
  margin: 0 0 16px;
  font-size: 17px;
  font-weight: 600;
}

.auth-form {
  display: flex;
  flex-direction: column;
}

.auth-label {
  display: block;
  margin: 12px 0 6px;
  font-size: 13px;
  color: var(--text-muted);
}

/* 제목 아래 안내 문구 (비밀번호 재설정 등) */
.auth-desc {
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-title + div .auth-label,
.auth-title + [hidden] + div .auth-label {
  margin-top: 0;
}

.auth-submit {
  width: 100%;
  margin-top: 20px;
}

.auth-cancel {
  width: 100%;
  margin-top: 8px;
}

.auth-submit:disabled {
  opacity: 0.6;
  cursor: default;
}

.auth-message {
  margin: 14px 0 0;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--income);
  background: var(--income-bg);
  border-radius: 8px;
  overflow-wrap: anywhere;
}

.auth-message.is-error {
  color: var(--danger);
  background: var(--danger-bg);
}

.auth-switch-row {
  margin: 16px 0 0;
  font-size: 14px;
  text-align: center;
  color: var(--text-muted);
}

.auth-switch-row .btn-link {
  margin-left: 4px;
  font-weight: 600;
}

.auth-loading {
  margin: 0;
  font-size: 14px;
  text-align: center;
  color: var(--text-muted);
}

.auth-loading.is-error {
  color: var(--danger);
}

.auth-choice-message {
  margin: 0 0 16px;
  font-size: 14px;
  white-space: pre-line; /* 안내 문구의 줄바꿈을 그대로 보여준다 */
}

.auth-choice-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.auth-choice-buttons .btn {
  width: 100%;
}

/* 제목 옆 저장 상태 ("서버에 저장됨" 등) */
.cloud-status {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.cloud-status:empty {
  display: none;
}

.cloud-status[data-status="offline"] {
  color: var(--danger);
}

/* 설정 > 데이터: 로그인한 계정과 로그아웃 버튼 */
.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.account-info {
  margin: 0;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.account-buttons {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}

@media (max-width: 640px) {
  /* 좁은 화면: 계정 줄 아래로 버튼 두 개를 나란히 */
  .account-row {
    flex-direction: column;
    align-items: stretch;
  }

  .account-buttons .btn {
    flex: 1;
  }
}
