/* app.css — 모바일 우선. 라이트/다크 자동. */
:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #f0f2f4;
  --line: #e3e7ea;
  --text: #161d21;
  --muted: #6b7780;
  --faint: #98a3ac;
  --accent: #0f766e;
  --accent-soft: #d7f0ec;
  --income: #1d7a4c;
  --income-soft: #dcf3e6;
  --expense: #c0392b;
  --expense-soft: #fbe4e0;
  --warn: #a35a00;
  --warn-soft: #fdefd9;
  --seg-on: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
  --tab-h: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1417;
    --surface: #171e22;
    --surface-2: #1e262b;
    --line: #2a343a;
    --text: #e8edf0;
    --muted: #94a2ab;
    --faint: #6d7c85;
    --accent: #2dd4bf;
    --accent-soft: #113b38;
    --income: #4ade80;
    --income-soft: #12331f;
    --expense: #f87171;
    --expense-soft: #3a1c1a;
    --warn: #fbbf24;
    --warn-soft: #3a2e12;
    --seg-on: #33414a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo",
        "Noto Sans KR", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.boot { padding: 4rem 1rem; text-align: center; color: var(--muted); }

/* ---------- 레이아웃 ---------- */
#app { min-height: 100dvh; }
.screen {
  padding: 0 14px calc(var(--tab-h) + env(safe-area-inset-bottom) + 84px);
  max-width: 680px; margin: 0 auto;
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 14px 8px;
  max-width: 680px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; letter-spacing: -.02em; flex: 1; }
.topbar .sub { font-size: 12px; color: var(--muted); font-weight: 500; }

/* 월 선택 */
.monthnav { display: flex; align-items: center; gap: 4px; }
.monthnav button {
  border: 0; background: transparent; color: var(--muted);
  width: 32px; height: 32px; border-radius: 8px; font-size: 17px;
}
.monthnav button:active { background: var(--surface-2); }
.monthnav .label { font-weight: 700; font-size: 16px; min-width: 92px; text-align: center; }

/* ---------- 카드 ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.card.flat { box-shadow: none; }
.card h2 { font-size: 13px; margin: 0 0 10px; color: var(--muted); font-weight: 600; letter-spacing: .01em; }

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.summary .cell { padding: 2px 0; }
.summary .k { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.summary .v { font-size: 19px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.summary .net { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 2px; }
.summary .net .v { font-size: 24px; }
.pos { color: var(--income); }
.neg { color: var(--expense); }

/* ---------- 거래 목록 ---------- */
.daygroup { margin-bottom: 4px; }
.dayhead {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 14px 4px 6px; position: sticky; top: 52px; background: var(--bg); z-index: 5;
}
.dayhead .d { font-size: 13px; font-weight: 700; color: var(--text); }
.dayhead .dow { font-size: 11px; color: var(--faint); margin-left: 5px; font-weight: 500; }
.dayhead .t { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.txlist { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tx {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px; width: 100%;
  background: transparent; border: 0; border-bottom: 1px solid var(--line); text-align: left;
}
.tx:last-child { border-bottom: 0; }
.tx:active { background: var(--surface-2); }
.tx .dot {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-size: 14px; font-weight: 700;
  background: var(--surface-2); color: var(--muted);
}
.tx .mid { flex: 1; min-width: 0; }
.tx .m1 { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .m2 { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; }
.tx .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 15px; }

.chip {
  display: inline-block; padding: 1px 7px; border-radius: 6px;
  background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 600;
}
.chip.owner { background: var(--accent-soft); color: var(--accent); }

/* ---------- 막대 목록(분석) ---------- */
.bars { display: grid; gap: 9px; }
.bar .row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.bar .row .n { font-weight: 600; }
.bar .row .v { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar .track { height: 7px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 4px; }
.bar.income .fill { background: var(--income); }
.bar.expense .fill { background: var(--expense); }

/* 월별 추이 */
.trend { display: flex; align-items: flex-end; gap: 7px; height: 130px; padding-top: 8px; }
.trend .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; }
.trend .stack { display: flex; gap: 2px; align-items: flex-end; height: 100%; }
.trend .b { flex: 1; border-radius: 3px 3px 0 0; min-height: 2px; }
.trend .b.i { background: var(--income); }
.trend .b.e { background: var(--expense); }
.trend .lab { font-size: 10px; color: var(--faint); text-align: center; }

/* ---------- 폼 ---------- */
.field { margin-bottom: 13px; }
.field > label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 5px; }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); color: var(--text);
  -webkit-appearance: none; appearance: none;
}
select.input {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' stroke='%236b7780' stroke-width='1.8' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}
.input:focus, select.input:focus, textarea.input:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
.amount-input { display: flex; gap: 8px; }
.amount-input .input.amt { font-size: 26px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.amount-input select { flex: none; width: 92px; }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: transparent; padding: 9px 4px; border-radius: 8px;
  font-weight: 600; font-size: 14px; color: var(--muted);
}
.seg button[aria-pressed="true"] {
  background: var(--seg-on); color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}
.seg button[aria-pressed="true"][data-v="income"] { color: var(--income); }
.seg button[aria-pressed="true"][data-v="expense"] { color: var(--expense); }

.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pills button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 7px 13px; font-size: 13.5px; font-weight: 600; color: var(--muted);
}
.pills button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 11px 15px; font-weight: 600;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--expense); border-color: var(--expense); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btnrow { display: flex; gap: 8px; }
.btnrow .btn { flex: 1; }

/* FAB */
.fab {
  position: fixed; right: max(16px, calc(50% - 340px + 16px));
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: var(--accent); color: #fff; font-size: 27px; line-height: 1;
  box-shadow: 0 6px 20px rgba(15,118,110,.4); z-index: 30;
}

/* 하단 탭 */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
}
.tabs .inner { display: flex; width: 100%; max-width: 680px; margin: 0 auto; }
.tabs button {
  flex: 1; border: 0; background: transparent; color: var(--faint);
  height: var(--tab-h); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; font-weight: 600;
}
.tabs button .ic { font-size: 18px; line-height: 1; }
.tabs button[aria-current="page"] { color: var(--accent); }

/* 시트 */
.sheet { position: fixed; inset: 0; z-index: 100; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px);
  max-width: 680px; margin: 0 auto;
  animation: up .22s cubic-bezier(.2,.8,.3,1);
}
@keyframes up { from { transform: translateY(24px); opacity: .6 } to { transform: none; opacity: 1 } }
.sheet-grip { width: 38px; height: 4px; background: var(--line); border-radius: 3px; margin: 6px auto 12px; }
.sheet-panel h2 { font-size: 17px; margin: 0 0 14px; }

/* 기타 */
.empty { text-align: center; color: var(--faint); padding: 44px 16px; font-size: 14px; }
.empty .big { font-size: 34px; margin-bottom: 10px; opacity: .6; }
.note { font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.note.warn { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 10px; }
.note.info { background: var(--surface-2); padding: 10px 12px; border-radius: 10px; }
.rowlist { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.rowlist > * { background: var(--surface); padding: 12px 13px; display: flex; align-items: center; gap: 10px; }
.rowlist .grow { flex: 1; min-width: 0; }
.rowlist .sub { font-size: 12px; color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 22px);
  background: #161d21; color: #fff; padding: 11px 17px; border-radius: 11px;
  font-size: 13.5px; font-weight: 500; z-index: 200; max-width: 90vw;
  box-shadow: 0 8px 30px rgba(0,0,0,.3);
}
@media (prefers-color-scheme: dark) { .toast { background: #2f3a41; } }
table.mini { width: 100%; border-collapse: collapse; font-size: 13px; }
table.mini th, table.mini td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.mini th { color: var(--muted); font-weight: 600; font-size: 11.5px; }
table.mini td.num, table.mini th.num { text-align: right; font-variant-numeric: tabular-nums; }
