:root {
  color-scheme: light;
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --line: #e4e2dc;
  --line-strong: #cfccc3;
  --ink: #1d1d1b;
  --ink-2: #57554f;
  --ink-3: #8a877f;
  --brand: #1f4e5a;
  --brand-ink: #ffffff;
  --brand-soft: #e7eff1;
  --income: #2a78d6;
  --expense: #eb6834;
  --prior: #a9a69c;
  --good: #1a7f4b;
  --good-soft: #e5f3eb;
  --warn: #9a6400;
  --warn-soft: #fbf1dc;
  --bad: #c4332f;
  --bad-soft: #fbe7e5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 2px 8px rgba(0, 0, 0, .04);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #151514; --surface: #1e1e1c; --surface-2: #242422; --line: #34332f; --line-strong: #4a4843;
    --ink: #f2f1ec; --ink-2: #c3c2b7; --ink-3: #8f8d85; --brand: #6fb3c2; --brand-ink: #0e1b1e; --brand-soft: #1d2d31;
    --income: #3987e5; --expense: #d95926; --prior: #6d6b64;
    --good: #4fbf85; --good-soft: #17291f; --warn: #e0a83a; --warn-soft: #2d2413; --bad: #ef6f6a; --bad-soft: #321a19;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* 레이아웃 */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { font-weight: 700; font-size: 16px; padding: 4px 10px 16px; }
.side .brand small { display: block; font-weight: 500; color: var(--ink-3); font-size: 12px; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav .sep { height: 1px; background: var(--line); margin: 10px 6px; }
.badge { min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--bad); color: #fff; font-size: 12px; text-align: center; line-height: 20px; }
.userbox { margin-top: 18px; padding: 12px 10px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }
.userbox button { margin-top: 6px; }
main { padding: 28px 32px 60px; max-width: 1240px; width: 100%; }
.topbar { display: none; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.pagehead p { margin: 4px 0 0; color: var(--ink-2); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card + .card, .card + .grid, .grid + .card, .grid + .grid { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.card h2 { margin-bottom: 12px; }
.card .cardhead { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card .cardhead h2 { margin: 0; }

/* 숫자 카드 */
.stat .label { color: var(--ink-2); font-size: 13px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.stat .sub { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.stat .value small { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 2px; }

/* 버튼·입력 */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface); padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--ink); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.sm { padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=password], input[type=number], input[type=date], input:not([type]), select, textarea {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
textarea { width: 100%; min-height: 90px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
label.field > input, label.field > select, label.field > textarea { font-size: 15px; color: var(--ink); }
.form { display: grid; gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* 표 */
.tablewrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12.5px; font-weight: 600; color: var(--ink-2); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
tr.group td { background: var(--surface-2); font-weight: 600; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line-strong); }
tbody tr:hover td { background: color-mix(in srgb, var(--brand-soft) 45%, transparent); }
td.nowrap { white-space: nowrap; }

/* 상태 표시 */
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line-strong); color: var(--ink-2); white-space: nowrap; }
.tag.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.tag.info { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.in { color: var(--income); }
.out { color: var(--ink); }
.over { color: var(--bad); font-weight: 600; }

/* 진행 막대 */
.bar { position: relative; height: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; overflow: visible; min-width: 80px; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; background: var(--brand); }
.bar > i.over { background: var(--bad); }
.bar > b { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink-2); border-radius: 1px; }

/* 알림 */
.notice { padding: 12px 14px; border-radius: 8px; background: var(--brand-soft); color: var(--ink); margin-bottom: 16px; }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); }
.alerts { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.alerts a { text-decoration: none; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 8px 14px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* 대화상자 */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog .dhead { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
dialog .dbody { padding: 16px 20px; max-height: 70vh; overflow-y: auto; }
dialog .dfoot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 8px; z-index: 100; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.bad { background: var(--bad); color: #fff; }

/* 로그인 */
.loginwrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.loginwrap .card { width: min(380px, 100%); padding: 28px; }
.loginwrap h1 { margin-bottom: 4px; }

/* 차트 */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--ink-3); font-size: 11px; }
.chart .grid line { stroke: var(--line); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend i.line { height: 2px; border-radius: 1px; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; z-index: 5; }
.tip b { display: block; margin-bottom: 2px; }

pre.bulletin { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 14px; white-space: pre-wrap; font-family: inherit; margin: 0; }
.drop { border: 2px dashed var(--line-strong); border-radius: 12px; padding: 32px; text-align: center; color: var(--ink-2); cursor: pointer; background: var(--surface-2); }
.drop.over { border-color: var(--brand); background: var(--brand-soft); }
.receipt-img { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }
.consent-list { font-size: 13px; color: var(--ink-2); }
.split-row { display: grid; grid-template-columns: 1fr 1fr 130px 32px; gap: 6px; margin-bottom: 6px; }

@media (max-width: 900px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: 1fr; }
  .g2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  .side.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; }
  main { padding: 18px 16px 60px; }
  .stat .value { font-size: 20px; }
  .card { padding: 14px; }
  .split-row { grid-template-columns: 1fr 1fr; }
  .hide-m { display: none; }
  .bar { min-width: 44px; }
  th, td { padding: 8px 5px; }
}
@media print {
  .side, .topbar, .noprint { display: none !important; }
  .shell { display: block; }
  main { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}
