/* 색상은 편한가계부(Realbyte Money Manager) 기본 테마 값 */
:root {
  color-scheme: light;
  --income: #1f88ff;
  --expense: #ff603b;
  --accent: #ff5c55;
  --accent-soft: #fff1ed;
  --sun: #ff796e;
  --sat: #58a6ff;
  --bg: #f4f4f7;
  --surface: #ffffff;
  --surface-2: #f4f4f7;
  --line: #e6e6e6;
  --line-strong: #d5d5d5;
  --ink: #4b4b4b;
  --ink-strong: #222222;
  --ink-2: #7b7b7b;
  --muted: #8d8d8d;
  --transfer: #000000;
  --chip: #eeeef2;
  --backdrop: rgb(0 0 0 / 0.4);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --accent-soft: #3a2a2a;
    --bg: #18181a;
    --surface: #272a30;
    --surface-2: #353840;
    --line: #303033;
    --line-strong: #434850;
    --ink: #fafafa;
    --ink-strong: #ffffff;
    --ink-2: #b7babf;
    --muted: #8f919a;
    --transfer: #ffffff;
    --chip: #353840;
    --backdrop: rgb(0 0 0 / 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --accent-soft: #3a2a2a;
  --bg: #18181a;
  --surface: #272a30;
  --surface-2: #353840;
  --line: #303033;
  --line-strong: #434850;
  --ink: #fafafa;
  --ink-strong: #ffffff;
  --ink-2: #b7babf;
  --muted: #8f919a;
  --transfer: #ffffff;
  --chip: #353840;
  --backdrop: rgb(0 0 0 / 0.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input { min-width: 0; }
.muted { color: var(--muted); }
.error { color: var(--expense); }
.num { font-variant-numeric: tabular-nums; }
.c-income { color: var(--income); }
.c-expense { color: var(--expense); }
.c-transfer { color: var(--transfer); }
code { background: var(--chip); padding: 1px 5px; border-radius: 4px; font-size: 12px; word-break: break-all; }

/* ---------- 로그인 ---------- */
#login { max-width: 420px; margin: 0 auto; padding: 22vh 16px 0; text-align: center; }
#login form { display: grid; gap: 10px; margin-top: 24px; }
#login input { padding: 13px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); }

/* ---------- 앱 골격 ---------- */
#app { max-width: 600px; margin: 0 auto; min-height: 100vh; background: var(--bg); }
#view { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

.appbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface);
  padding-top: env(safe-area-inset-top);
}
.appbar-row { display: grid; grid-template-columns: 56px 1fr 56px; align-items: center; height: 50px; }
.appbar-title { display: flex; align-items: center; justify-content: center; gap: 2px; font-size: 17px; font-weight: 600; color: var(--ink-strong); }
.appbar-title.plain { font-size: 17px; }
.arrow { width: 36px; height: 36px; font-size: 22px; color: var(--ink-2); }
.appbar-side { display: flex; justify-content: center; }
.appbar-btn { min-width: 44px; height: 32px; font-size: 13px; color: var(--ink-2); border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 8px; }

.subtabs { display: flex; border-bottom: 1px solid var(--line); }
.subtabs button { flex: 1; height: 40px; color: var(--muted); font-size: 14px; border-bottom: 2px solid transparent; }
.subtabs button.on { color: var(--ink-strong); font-weight: 600; border-bottom-color: var(--accent); }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border-bottom: 1px solid var(--line); padding: 8px 0; text-align: center; }
.summary span { display: block; font-size: 12px; color: var(--ink-2); }
.summary b { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- 일일 ---------- */
.day { background: var(--surface); margin-top: 8px; }
.day-head { display: flex; align-items: center; gap: 6px; padding: 10px 14px 8px; border-bottom: 1px solid var(--line); }
.day-num { font-size: 20px; font-weight: 700; color: var(--ink-strong); min-width: 26px; }
.wday { font-size: 11px; color: #fff; background: #9a9aa3; border-radius: 3px; padding: 1px 5px; }
.wday.sun { background: var(--sun); }
.wday.sat { background: var(--sat); }
.day-ym { font-size: 12px; color: var(--muted); }
.day-sums { margin-left: auto; display: flex; gap: 14px; font-size: 13px; font-variant-numeric: tabular-nums; }

.tx { display: grid; grid-template-columns: 76px 1fr auto; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 8px 14px; text-align: left; }
.tx + .tx { border-top: 1px solid var(--line); }
.tx:active { background: var(--surface-2); }
.tx-cat { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-cat.need { color: var(--accent); font-weight: 600; }
.tx-main { min-width: 0; }
.tx-title { color: var(--ink-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-variant-numeric: tabular-nums; font-weight: 500; text-align: right; }
.tx.canceled .tx-title, .tx.canceled .tx-amt { text-decoration: line-through; opacity: 0.5; }
.empty { text-align: center; color: var(--muted); padding: 56px 0; }

/* ---------- 달력 ---------- */
.cal { background: var(--surface); }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-head div { text-align: center; font-size: 12px; color: var(--ink-2); padding: 6px 0; border-bottom: 1px solid var(--line); }
.cal-head div:first-child { color: var(--sun); }
.cal-head div:last-child { color: var(--sat); }
.cal-cell { min-height: 64px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 3px 3px 2px; text-align: left; display: flex; flex-direction: column; overflow: hidden; }
.cal-cell:nth-child(7n) { border-right: 0; }
.cal-cell .d { font-size: 12px; color: var(--ink); }
.cal-cell.sun .d { color: var(--sun); }
.cal-cell.sat .d { color: var(--sat); }
.cal-cell.out { background: var(--surface-2); }
.cal-cell.out .d { opacity: 0.4; }
.cal-cell.today .d { background: var(--ink-strong); color: var(--surface); border-radius: 3px; padding: 0 3px; align-self: flex-start; }
.cal-cell.sel { background: var(--accent-soft); }
.cal-cell small { display: block; font-size: 10px; line-height: 1.3; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: auto; }
.cal-cell small + small { margin-top: 0; }

/* ---------- 월별 ---------- */
.months { background: var(--surface); margin-top: 8px; }
.month-row { display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%; padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.month-row .m { font-weight: 600; color: var(--ink-strong); }
.month-row .range { font-size: 12px; color: var(--muted); }
.month-row .vals { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }
.month-row .vals div:last-child { color: var(--ink-2); font-size: 12px; }
.month-row.on { background: var(--accent-soft); }
.week-row { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; padding: 9px 14px 9px 28px; font-size: 13px; border-bottom: 1px solid var(--line); background: var(--surface-2); font-variant-numeric: tabular-nums; }

/* ---------- 통계 ---------- */
.io-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border-bottom: 1px solid var(--line); }
.io-tabs button { padding: 10px 0 8px; border-bottom: 2px solid transparent; color: var(--muted); font-size: 14px; }
.io-tabs button b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.io-tabs button.on.income { color: var(--income); border-bottom-color: var(--income); }
.io-tabs button.on.expense { color: var(--expense); border-bottom-color: var(--expense); }
.pie-wrap { background: var(--surface); display: grid; place-items: center; padding: 18px 0 10px; }
.pie-wrap svg { width: min(400px, 100%); height: auto; }
.pie-label { font-size: 9px; fill: var(--ink); }
.pie-label tspan.p { fill: var(--muted); }
.stat-list { background: var(--surface); border-top: 1px solid var(--line); }
.stat-row { display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 10px; width: 100%; padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.stat-row:active { background: var(--surface-2); }
.pct { font-size: 12px; font-weight: 600; color: #fff; border-radius: 4px; padding: 3px 0; text-align: center; font-variant-numeric: tabular-nums; }
.stat-row .amt { font-variant-numeric: tabular-nums; }

/* 예산 */
.budget-list { background: var(--surface); margin-top: 8px; }
.budget-row { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.budget-top { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.budget-top b { color: var(--ink-strong); font-weight: 600; }
.budget-top .left { font-size: 13px; font-variant-numeric: tabular-nums; }
.bar { position: relative; height: 18px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--income); border-radius: 4px; }
.bar-fill.over { background: var(--expense); }
.bar-pct { position: absolute; inset: 0 6px; display: flex; align-items: center; font-size: 11px; color: #fff; font-weight: 600; text-shadow: 0 0 2px rgb(0 0 0 / 0.3); }
.bar-today { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink-strong); opacity: 0.6; }
.budget-bottom { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.section-btn { display: block; margin: 16px auto; padding: 9px 18px; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); }

/* ---------- 자산 ---------- */
.asset-group { background: var(--surface); margin-top: 8px; }
.asset-group-head { display: flex; justify-content: space-between; padding: 10px 14px; font-size: 13px; color: var(--ink-2); border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.asset-row { display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%; min-height: 50px; padding: 8px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.asset-row:last-child { border-bottom: 0; }
.asset-row:active { background: var(--surface-2); }
.asset-row .name { color: var(--ink-strong); }
.asset-row .sub { font-size: 12px; color: var(--muted); }
.asset-row .bal { font-variant-numeric: tabular-nums; }

/* ---------- 더보기 ---------- */
.menu { background: var(--surface); margin-top: 8px; }
.menu-title { padding: 14px 14px 6px; font-size: 12px; color: var(--muted); background: var(--bg); }
.menu-item { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 50px; padding: 0 14px; text-align: left; border-bottom: 1px solid var(--line); }
.menu-item:last-child { border-bottom: 0; }
.menu-item:active { background: var(--surface-2); }
.menu-item .val { color: var(--muted); font-size: 14px; }
.menu-item .chev { color: var(--line-strong); margin-left: 8px; }

/* ---------- 하단 탭바 / FAB ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  max-width: 600px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button { position: relative; display: grid; justify-items: center; gap: 1px; padding: 7px 0 6px; color: var(--muted); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tabbar b { font-size: 10px; font-weight: 500; }
.tabbar button.on { color: var(--accent); }
.tab-date { position: absolute; top: 15px; left: 50%; transform: translateX(-50%); font-size: 9px; font-weight: 700; }
.fab {
  position: fixed; z-index: 9; right: max(18px, calc(50% - 282px)); bottom: calc(70px + env(safe-area-inset-bottom));
  width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; box-shadow: 0 4px 12px rgb(255 92 85 / 0.4);
}

/* ---------- 시트 ---------- */
dialog.sheet {
  border: 0; padding: 0; width: 100%; max-width: 600px; max-height: 94vh; margin: auto auto 0;
  border-radius: 14px 14px 0 0; background: var(--surface); color: var(--ink);
  display: flex; flex-direction: column;
}
dialog.sheet:not([open]) { display: none; }
dialog.sheet.full { height: 94vh; }
dialog.sheet::backdrop { background: var(--backdrop); }
.sheet-head { display: grid; grid-template-columns: 64px 1fr 64px; align-items: center; height: 50px; border-bottom: 1px solid var(--line); flex: none; }
.sheet-head h2 { margin: 0; font-size: 16px; text-align: center; color: var(--ink-strong); }
.sheet-head button { height: 50px; color: var(--ink-2); font-size: 15px; }
.sheet-head .right { color: var(--accent); font-weight: 600; }
.sheet-body { overflow-y: auto; flex: 1; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

/* 입력 폼 (편한가계부 TxForm) */
.type-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px 14px 6px; }
.type-tabs button { height: 34px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--muted); }
.type-tabs button.on.income { border-color: var(--income); color: var(--income); font-weight: 600; }
.type-tabs button.on.expense { border-color: var(--expense); color: var(--expense); font-weight: 600; }
.type-tabs button.on.transfer { border-color: var(--transfer); color: var(--transfer); font-weight: 600; }
.frow { display: grid; grid-template-columns: 64px 1fr; align-items: center; min-height: 46px; margin: 0 14px; border-bottom: 1px solid var(--line); }
.frow > label, .frow > span.l { font-size: 14px; color: var(--ink-2); }
.frow input, .frow .pick { width: 100%; border: 0; background: transparent; padding: 10px 0; font-size: 15px; text-align: left; color: var(--ink-strong); outline: none; }
.frow .pick:empty::before, .frow .pick.placeholder { color: var(--muted); }
.frow.active { border-bottom: 2px solid var(--accent); }
.frow .dt { display: flex; gap: 8px; }
.frow .dt input { width: auto; }
.frow input.amount { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.frow .fee { justify-self: end; }
.form-actions { display: flex; gap: 8px; padding: 18px 14px 8px; }
.form-actions button { height: 46px; border-radius: 6px; font-size: 15px; }
.btn-primary { flex: 1; background: var(--accent); color: #fff; font-weight: 600; padding: 0 18px; border-radius: 6px; height: 46px; }
.btn-line { padding: 0 18px; border: 1px solid var(--line-strong); color: var(--ink); background: var(--surface); }
.btn-danger { padding: 0 14px; border: 1px solid var(--line-strong); color: var(--expense); }
.raw-sms { margin: 8px 14px; font-size: 12px; color: var(--muted); }
.raw-sms pre { white-space: pre-wrap; background: var(--surface-2); padding: 8px; border-radius: 6px; margin: 6px 0 0; }

/* 선택 패널 (분류·자산) */
.picker { border-top: 1px solid var(--line-strong); background: var(--surface-2); margin-top: 10px; }
.picker-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; font-size: 13px; color: var(--ink-2); }
.picker-head button { color: var(--ink-2); font-size: 13px; }
.picker-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border-top: 1px solid var(--line); }
.picker-grid button { background: var(--surface); min-height: 48px; padding: 6px; font-size: 14px; color: var(--ink-strong); }
.picker-grid button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.picker-grid button small { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }

/* 관리 화면 공통 */
.list { background: var(--surface); }
.list-row { display: flex; align-items: center; gap: 8px; min-height: 50px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.list-row .grow { flex: 1; min-width: 0; text-align: left; padding: 12px 0; }
.list-row .sub { font-size: 12px; color: var(--muted); }
.icon-btn { width: 34px; height: 34px; border-radius: 6px; color: var(--ink-2); font-size: 16px; }
.icon-btn:active { background: var(--surface-2); }
.add-row { width: 100%; min-height: 50px; color: var(--accent); font-weight: 600; background: var(--surface); }
.field { display: grid; gap: 6px; padding: 10px 14px; }
.field > span { font-size: 13px; color: var(--ink-2); }
.field input, .field select { padding: 11px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
.hint { font-size: 12px; color: var(--muted); padding: 0 14px; }
.guide { padding: 4px 14px 4px 32px; display: grid; gap: 8px; font-size: 14px; }
.mini { font-size: 12px; padding: 2px 8px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); margin-left: 4px; }
.seg { display: flex; gap: 6px; padding: 10px 14px; }
.seg button { flex: 1; height: 36px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--ink-2); }
.seg button.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }

#toast { position: fixed; left: 50%; bottom: calc(140px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgb(30 30 34 / 0.92); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; max-width: calc(100% - 32px); z-index: 100; text-align: center; }
.tx-cat small { display: block; font-size: 11px; color: var(--muted); }
