/* 가계부 MVP — 모바일 우선 스타일 */
:root {
  --bg: #f5f2ea;
  --paper: #fffdf8;
  --ink: #1f1d18;
  --muted: #77716a;
  --line: #e4ddd0;
  --accent: #1f7a4d;
  --accent-soft: #e3f1e8;
  --warn: #b4531a;
  --warn-soft: #fbeadf;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --gold: #a8740b;
  --gold-soft: #fbf1d9;
  --yellow: #f2c200;      /* 달력: 목표 1.5배까지 (칸·범례 색) */
  --yellow-ink: #8a6a00;  /* 노란 칸 위 글씨 */
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 29, 24, .05), 0 4px 14px rgba(31, 29, 24, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141310;
    --paper: #1d1c18;
    --ink: #f1ede4;
    --muted: #a59f93;
    --line: #34312a;
    --accent: #4cc489;
    --accent-soft: #173426;
    --warn: #f0a46d;
    --warn-soft: #3a2616;
    --danger: #ff8a80;
    --danger-soft: #3d1a17;
    --gold: #e9bf5d;
    --gold-soft: #352a12;
    --yellow: #f5d142;
    --yellow-ink: #f5d142;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }

.wrap { max-width: 520px; margin: 0 auto; padding: 16px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 6px; max-width: 520px; margin: 0 auto;
}
.topbar h1 { font-size: 19px; margin: 0; letter-spacing: -0.3px; }
.topbar .back { font-size: 15px; color: var(--muted); }

.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; }
.card h3 { font-size: 16px; margin: 0 0 6px; }

.hero .label { color: var(--muted); font-size: 13px; }
.hero .big { font-size: 32px; font-weight: 800; letter-spacing: -1px; margin: 2px 0 6px; }
.hero .sub { font-size: 13px; color: var(--muted); }

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.right { text-align: right; }
.hidden { display: none !important; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--line); color: var(--ink); white-space: nowrap;
}
.chip.gold { background: var(--gold-soft); color: var(--gold); }
.chip.ok { background: var(--accent-soft); color: var(--accent); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--danger-soft); color: var(--danger); }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 11px; padding: 10px 14px; font-size: 15px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }

input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
textarea { min-height: 90px; resize: vertical; }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* 결제(알림) 카드 */
.pay { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.pay:first-of-type { border-top: 0; }
.pay .ic {
  width: 40px; height: 40px; border-radius: 12px; background: var(--warn-soft); color: var(--warn);
  display: grid; place-items: center; font-weight: 800; flex: none;
}
.pay .ic.done { background: var(--accent-soft); color: var(--accent); }
.pay .meta { flex: 1; min-width: 0; }
.pay .meta .t { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pay .meta .s { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pay .amt { font-weight: 800; white-space: nowrap; }

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

/* 탭 (기록 방법 선택) */
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.tab {
  border: 1px solid var(--line); background: var(--paper); border-radius: 12px; padding: 12px 6px;
  text-align: center; font-weight: 700; font-size: 14px; cursor: pointer; color: var(--ink);
}
.tab small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); margin-top: 2px; }
.tab.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px 14px; text-align: center;
  color: var(--muted); cursor: pointer; display: block;
}
.drop img { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; margin: 0 auto; }

/* 품목 편집기 */
.item-row { display: grid; grid-template-columns: 1fr 92px; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.item-row:first-child { border-top: 0; }
.item-row .full { grid-column: 1 / -1; }
.item-row .sub { display: grid; grid-template-columns: 1fr 64px 96px 34px; gap: 6px; grid-column: 1 / -1; }
.item-row input, .item-row select { padding: 8px 10px; font-size: 14px; }
.item-row input.need { border-color: var(--warn); background: var(--warn-soft); }
.item-row input.need::placeholder { color: var(--warn); }
.item-row .x { border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; }
.sumline { display: flex; justify-content: space-between; font-weight: 800; padding-top: 10px; border-top: 2px solid var(--ink); margin-top: 6px; }

.verify { border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }
.verify.ok { background: var(--accent-soft); color: var(--accent); }
.verify.bad { background: var(--danger-soft); color: var(--danger); }
.verify.warn { background: var(--warn-soft); color: var(--warn); }
.verify b { display: block; font-size: 15px; margin-bottom: 2px; }
.checks { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* 카테고리 막대 */
.bar { margin: 8px 0; }
.bar .lbl { display: flex; justify-content: space-between; font-size: 13px; }
.bar .track { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 3px; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 99px; }

/* 월간 달력 (지출 히트맵) */
.cal-head, .cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head { font-size: 11px; color: var(--muted); text-align: center; margin-bottom: 4px; }
.cal-head span:first-child { color: var(--danger); }
.cal-head span:last-child { color: #3b6fd1; }
.cal .d {
  aspect-ratio: 1 / 1.08; min-width: 0; border-radius: 9px; border: 1px solid transparent; padding: 4px 3px 3px;
  display: flex; flex-direction: column; justify-content: space-between; font: inherit; color: var(--ink); cursor: pointer; text-align: left;
  background: var(--bg);
}
.cal .d.spent { background: var(--line); }                       /* 목표 미설정 */
.cal .d.ok   { background: color-mix(in srgb, var(--accent) 22%, var(--paper)); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.cal .d.over { background: color-mix(in srgb, var(--yellow) 30%, var(--paper)); border-color: color-mix(in srgb, var(--yellow) 75%, transparent); }
.cal .d.bad  { background: color-mix(in srgb, var(--danger) 30%, var(--paper)); border-color: color-mix(in srgb, var(--danger) 60%, transparent); }
.cal .d.ok .a { color: var(--accent); }
.cal .d.over .a { color: var(--yellow-ink); }
.cal .d.bad .a { color: var(--danger); }
.cal .d .n { font-size: 12px; font-weight: 700; line-height: 1; }
.cal .d .a { font-size: 10px; font-weight: 700; text-align: right; line-height: 1.1; white-space: nowrap; overflow: hidden; font-variant-numeric: tabular-nums; }
.cal .d.today { border-color: var(--ink); }
.cal .d.sel { outline: 2px solid var(--gold); outline-offset: 1px; }
.cal .d.future { opacity: .45; }
.cal .blank { visibility: hidden; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 11px; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.legend i.ok { background: var(--accent); } .legend i.over { background: var(--yellow); } .legend i.bad { background: var(--danger); }
.goal-form { display: flex; gap: 6px; margin-bottom: 10px; }
.goal-form input { flex: 1; min-width: 0; }
.daybar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }

details.entry { border-top: 1px solid var(--line); padding: 10px 0; }
details.entry:first-of-type { border-top: 0; }
details.entry summary { list-style: none; cursor: pointer; display: flex; gap: 10px; align-items: center; }
details.entry summary::-webkit-details-marker { display: none; }
details.entry .items { margin: 8px 0 4px 50px; font-size: 13px; }
details.entry .items div { display: flex; justify-content: space-between; padding: 2px 0; }

/* 하단 탭바 */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--paper); border-top: 1px solid var(--line);
  display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); z-index: 10;
}
.nav .in { display: flex; width: 100%; max-width: 520px; }
.nav a { flex: 1; text-align: center; padding: 9px 0 10px; color: var(--muted); font-size: 12px; font-weight: 600; }
.nav a svg { display: block; margin: 0 auto 2px; width: 22px; height: 22px; }
.nav a.on { color: var(--accent); }

.fab {
  position: fixed; right: max(16px, calc(50% - 244px)); bottom: calc(80px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--paper); border-radius: 999px; padding: 12px 18px; font-weight: 700;
  box-shadow: 0 6px 18px rgba(0,0,0,.18); z-index: 9;
}

.toast {
  position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  z-index: 50; max-width: 90vw; box-shadow: 0 6px 18px rgba(0,0,0,.2);
}
.banner { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; background: var(--gold-soft); color: var(--ink); }
.banner b { color: var(--gold); }

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  word-break: break-all; white-space: pre-wrap;
}
ol.steps { padding-left: 20px; margin: 6px 0; }
ol.steps li { margin: 5px 0; }

table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th, table.t td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { color: var(--muted); font-weight: 600; }
.scroll-x { overflow-x: auto; }

.spinner {
  width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login-logo { text-align: center; margin: 40px 0 20px; }
.login-logo img { width: 72px; height: 72px; border-radius: 18px; }
.login-logo h1 { font-size: 22px; margin: 10px 0 2px; }
