:root {
  --bg: #F7F5F0;
  --surface: #FFFFFF;
  --ink: #1D1B18;
  --muted: #6F6A61;
  --line: #E4DFD5;
  --accent: #1F6F5C;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3EFEA;
  --business: #8A5A16;
  --business-soft: #F4E9D8;
  --danger: #B3261E;
  --danger-soft: #F9E3E1;
  --c-meal: #D9734E;
  --c-cafe: #A9784F;
  --c-grocery: #5E9E50;
  --c-shopping: #7B6BC4;
  --c-transit: #3F86C6;
  --c-living: #C2508A;
  --c-etc: #8C8C8C;
  --radius: 12px;
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141311;
    --surface: #1E1C19;
    --ink: #F1EEE8;
    --muted: #A39D92;
    --line: #33302B;
    --accent: #5BBF9F;
    --accent-ink: #0E1F19;
    --accent-soft: #1E3029;
    --business: #E0A955;
    --business-soft: #33291A;
    --danger: #F2B8B5;
    --danger-soft: #3A1F1D;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #141311;
  --surface: #1E1C19;
  --ink: #F1EEE8;
  --muted: #A39D92;
  --line: #33302B;
  --accent: #5BBF9F;
  --accent-ink: #0E1F19;
  --accent-soft: #1E3029;
  --business: #E0A955;
  --business-soft: #33291A;
  --danger: #F2B8B5;
  --danger-soft: #3A1F1D;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 레이아웃 ---------- */
.shell { min-height: 100vh; }

.view {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
  outline: none;
}

.nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.brand { display: none; }
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 12px;
  color: var(--muted);
}
.nav-item[aria-current="page"] { color: var(--accent); font-weight: 600; }
.nav-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

@media (min-width: 900px) {
  .nav {
    inset: 0 auto 0 0;
    width: 220px;
    height: auto;
    flex-direction: column;
    padding: 24px 12px;
    gap: 4px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }
  .brand { display: block; font-weight: 700; font-size: 18px; padding: 4px 12px 20px; }
  .nav-item { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 15px; padding: 10px 12px; border-radius: 10px; }
  .nav-item[aria-current="page"] { background: var(--accent-soft); }
  .view { margin-left: 220px; max-width: none; padding: 32px 40px 48px; }
  .view > * { max-width: 1040px; }
  .page-narrow > * { max-width: 640px; }
}

/* ---------- 공통 요소 ---------- */
.page-title { font-size: 22px; font-weight: 700; margin: 4px 0 16px; letter-spacing: -0.01em; }
.section-title { font-size: 15px; font-weight: 600; margin: 24px 0 8px; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

.seg { display: inline-flex; padding: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; }
.seg button {
  min-height: 38px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-weight: 500;
}
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.seg button[data-value="business"][aria-pressed="true"] { background: var(--business); color: var(--surface); }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.danger.armed { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn:disabled { opacity: .5; cursor: default; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 14px; display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--bg); }

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--c-etc); }

.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; font-weight: 600; vertical-align: 1px; }
.badge.business { background: var(--business-soft); color: var(--business); }
.badge.warn { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

/* ---------- 홈 ---------- */
.home-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.home-top .page-title { margin: 0; }
.capture {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  width: 100%; min-height: 152px; border: 0; border-radius: 20px; background: var(--accent); color: var(--accent-ink);
  font-size: 24px; font-weight: 700;
}
.capture svg { width: 40px; height: 40px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.capture small { font-size: 14px; font-weight: 500; opacity: .85; }
.capture.business { background: var(--business); color: var(--surface); }
.album { width: 100%; margin-top: 10px; min-height: 52px; }
.month-sum { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-top: 16px; }
.month-sum strong { font-size: 22px; }
.month-sum .split { font-size: 13px; color: var(--muted); text-align: right; }

/* ---------- 영수증 행 ---------- */
.rows { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px 16px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row:hover { background: color-mix(in srgb, var(--accent-soft) 40%, transparent); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-amount { font-weight: 600; white-space: nowrap; }
.row.pending .row-title { color: var(--muted); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.day { margin-top: 20px; }
.day-head { display: flex; justify-content: space-between; padding: 0 4px 6px; font-size: 14px; color: var(--muted); }
.day-head strong { color: var(--ink); font-weight: 600; }

/* ---------- 목록 도구줄 ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.month-nav { display: inline-flex; align-items: center; gap: 4px; }
.month-nav button { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-size: 18px; line-height: 1; }
.month-nav span { min-width: 112px; text-align: center; font-weight: 700; font-size: 17px; }
.search { flex: 1 1 200px; min-height: 42px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }
.summary { display: flex; justify-content: space-between; align-items: baseline; margin: 16px 4px 0; }
.summary strong { font-size: 20px; }

/* ---------- 통계 ---------- */
.stats-grid { display: grid; gap: 16px; }
@media (min-width: 1100px) { .stats-grid { grid-template-columns: 1fr 1fr; align-items: start; } }
.card h2 { font-size: 16px; margin: 0 0 4px; }
.card .total { font-size: 24px; font-weight: 700; margin-bottom: 12px; }
.bar-row { display: grid; grid-template-columns: 84px 1fr auto; gap: 10px; align-items: center; min-height: 40px; }
.bar-row .label { font-size: 14px; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.bar-track { height: 12px; border-radius: 6px; background: var(--bg); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; min-width: 2px; }
.bar-row .value { font-size: 14px; text-align: right; min-width: 92px; }
.bar-row .value small { display: block; font-size: 12px; color: var(--muted); }
.bar-row.zero { opacity: .45; }
.bar-row.zero .bar-fill { min-width: 0; }

.months { display: flex; align-items: flex-end; gap: 4px; height: 200px; padding-top: 8px; }
.month-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; min-width: 0; }
.month-stack { flex: 1; width: 100%; max-width: 36px; display: flex; flex-direction: column; justify-content: flex-end; }
.month-stack span { display: block; width: 100%; }
.month-stack .p { background: var(--accent); }
.month-stack .b { background: var(--business); }
.month-stack span:first-child { border-radius: 4px 4px 0 0; }
.month-col .m { font-size: 11px; color: var(--muted); }
.month-col.current .m { color: var(--ink); font-weight: 700; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-top: 12px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.month-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
.month-table td { padding: 6px 4px; border-top: 1px solid var(--line); }
.month-table td:not(:first-child) { text-align: right; }

/* ---------- 상세 ---------- */
.detail-top { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.back { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-size: 20px; }
.photo { display: block; width: 100%; max-height: 260px; object-fit: contain; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); cursor: zoom-in; }
.banner { margin-top: 12px; padding: 12px 14px; border-radius: var(--radius); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.warn { background: var(--danger-soft); color: var(--danger); }
.banner.info { background: var(--accent-soft); color: var(--accent); }
.banner .grow { flex: 1 1 160px; }
.form { display: grid; gap: 14px; margin-top: 16px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
}
.input:focus, .search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea.input { min-height: 80px; resize: vertical; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.cat-btn {
  min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 14px;
}
.cat-btn[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); font-weight: 700; }
.items { display: grid; gap: 8px; }
.item { display: grid; grid-template-columns: 1fr 56px 96px 36px; gap: 6px; }
.item .input { min-height: 40px; padding: 6px 8px; }
.item button { border: 0; background: transparent; color: var(--muted); font-size: 20px; }
.actions { display: flex; gap: 10px; margin-top: 8px; }
.actions .btn.primary { flex: 1; }
@media (max-width: 899px) {
  .actions { position: sticky; bottom: calc(var(--nav-h) + 8px + env(safe-area-inset-bottom)); padding: 8px 0; background: var(--bg); }
}
.meta-line { font-size: 12px; color: var(--muted); margin-top: 16px; }

/* ---------- 토스트·확대 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--bg);
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 900px) { .toast { bottom: 24px; left: calc(50% + 110px); } }
.lightbox { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .88); display: flex; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ---------- 로그인 ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 16px; padding: 28px 24px; }
.login-card .page-title { margin: 0; }
.login-icon { border-radius: 14px; }
.login-error { margin: 0; min-height: 1.5em; color: var(--danger); font-size: 14px; }
.logout { border: 0; background: transparent; color: var(--muted); text-decoration: underline; padding: 8px 0; min-height: 44px; }

/* ---------- 외화·사진 없음 ---------- */
.row-amount small { display: block; text-align: right; font-size: 12px; font-weight: 500; color: var(--muted); }
.photo-none { display: flex; align-items: center; justify-content: center; min-height: 72px; color: var(--muted); font-size: 14px; cursor: default; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
