:root {
  --bg: #f3f4f8; --card: #ffffff; --text: #1d2130; --muted: #8a90a2; --line: #eceef3;
  --primary: #3f6df6; --primary-soft: #e9efff; --green: #1fb37a; --green-soft: #e3f7ee;
  --red: #f05a5a; --red-soft: #fde9e9; --yellow-soft: #fff6dc; --purple-soft: #f0ebff;
  --shadow: 0 2px 12px rgba(30, 40, 80, .06); --radius: 20px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141b; --card: #1c1f29; --text: #eef0f6; --muted: #8b91a3; --line: #2a2e3a;
    --primary: #6c8cff; --primary-soft: #232c4a; --green: #3ccf93; --green-soft: #1b3229;
    --red: #ff7676; --red-soft: #3a2125; --yellow-soft: #3a3320; --purple-soft: #2b2540;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-family: -apple-system, "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 15px; line-height: 1.45; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.hidden { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; width: 100%; min-width: 0; }
textarea { resize: vertical; min-height: 92px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--red); min-height: 1.2em; font-size: 14px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-box h1 { margin: 12px 0 0; }
.login-box form { display: grid; gap: 10px; margin-top: 24px; }
.logo { width: 64px; height: 64px; border-radius: 20px; background: var(--primary); color: #fff; font-size: 32px;
  font-weight: 700; display: grid; place-items: center; margin: 0 auto; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg); }
.month { font-weight: 700; font-size: 17px; min-width: 120px; text-align: center; }
.icon-btn { width: 36px; height: 36px; border-radius: 12px; font-size: 22px; background: var(--card); box-shadow: var(--shadow); }
main { padding: 4px 16px 16px; max-width: 640px; margin: 0 auto; display: grid; gap: 12px; }
body.wide main { max-width: 1180px; }

.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 10px; font-size: 15px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card h3 .link { font-size: 13px; color: var(--primary); font-weight: 500; }
.big { font-size: 30px; font-weight: 800; letter-spacing: -0.5px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chip { border-radius: 14px; padding: 10px 12px; }
.chip .label { font-size: 12px; color: var(--muted); }
.chip .val { font-weight: 700; }
.chip.green { background: var(--green-soft); } .chip.green .val { color: var(--green); }
.chip.red { background: var(--red-soft); } .chip.red .val { color: var(--red); }
.chip.blue { background: var(--primary-soft); } .chip.blue .val { color: var(--primary); }
.chip.yellow { background: var(--yellow-soft); }
.chip.purple { background: var(--purple-soft); }

.bar { height: 8px; border-radius: 8px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 8px; background: var(--primary); }
.bar.over > i { background: var(--red); }
.bar.green > i { background: var(--green); }
.cat-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 8px 0; }
.cat-row .bar { grid-column: 1 / -1; }
.cat-row .amt { font-weight: 600; }
.delta-up { color: var(--red); font-size: 12px; } .delta-down { color: var(--green); font-size: 12px; }

.tx { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.tx:last-child { border-bottom: 0; }
.tx .ico { width: 40px; height: 40px; border-radius: 12px; background: var(--bg); display: grid; place-items: center;
  font-size: 19px; flex: none; }
.tx .mid { flex: 1; min-width: 0; }
.tx .title { font-weight: 600; 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-weight: 700; text-align: right; white-space: nowrap; }
.amt.income { color: var(--green); } .amt.transfer { color: var(--muted); }
.date-head { font-size: 13px; color: var(--muted); margin: 6px 2px 0; display: flex; justify-content: space-between; }
.tag { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 8px; background: var(--bg); color: var(--muted); margin-right: 4px; }
.tag.food { background: var(--green-soft); color: var(--green); }
.tag.living { background: var(--primary-soft); color: var(--primary); }

.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.filters button { flex: none; padding: 6px 12px; border-radius: 16px; background: var(--card); font-size: 13px; box-shadow: var(--shadow); }
.filters button.on { background: var(--text); color: var(--bg); }

.days { display: flex; align-items: flex-end; gap: 2px; height: 90px; }
.days i { flex: 1; background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.days i.zero { background: var(--line); }

.split { display: flex; height: 14px; border-radius: 8px; overflow: hidden; background: var(--line); margin: 8px 0; }
.split i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; }
.legend b { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.fab { position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(84px + env(safe-area-inset-bottom)); width: 56px; height: 56px;
  border-radius: 50%; background: var(--primary); color: #fff; font-size: 30px; box-shadow: 0 6px 18px rgba(63, 109, 246, .4); z-index: 6; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; padding: 8px 0 10px; font-size: 11px; color: var(--muted); display: grid; gap: 2px; justify-items: center; }
.tabs button span { font-size: 19px; filter: grayscale(1); opacity: .6; }
.tabs button.on { color: var(--text); font-weight: 700; }
.tabs button.on span { filter: none; opacity: 1; }

.btn { padding: 12px 16px; border-radius: 14px; background: var(--bg); font-weight: 600; }
a.btn { display: inline-block; text-decoration: none; color: var(--text); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.danger { color: var(--red); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; }
.btns .btn { flex: 1; }

.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-bg { position: absolute; inset: 0; background: rgba(10, 12, 20, .45); }
.sheet-body { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; background: var(--card);
  border-radius: 24px 24px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin: 4px 0 12px; font-size: 19px; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; padding: 8px; border-radius: 10px; font-size: 14px; }
.seg button.on { background: var(--card); font-weight: 700; box-shadow: var(--shadow); }
.preview { border: 1px solid var(--line); border-radius: 16px; padding: 12px; display: grid; gap: 8px; }
.items { display: grid; gap: 6px; }
.item-row { display: grid; grid-template-columns: 1fr 92px; gap: 6px; padding: 8px; border-radius: 12px; background: var(--bg); }
.item-row input, .item-row select { background: var(--card); padding: 7px 9px; font-size: 14px; }
.item-row .full { grid-column: 1 / -1; display: flex; gap: 6px; }
.item-row .full select { flex: 1; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
.hint { font-size: 13px; color: var(--muted); background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.toast { position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 14px; z-index: 30; font-size: 14px; max-width: 90vw; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 소비렌즈 탭 */
.lens-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.lens-title { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.lens-scope { min-width: 160px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi { padding: 14px 16px; }
.kv { font-size: 22px; font-weight: 800; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kv.neg { color: var(--red); }
.lens-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 12px; align-items: start; }
.mini-sel { width: auto; padding: 5px 8px; font-size: 13px; border-radius: 10px; }
.src-row { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-right: 7px; }
.dot.on { background: var(--green); }
.status-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.st { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 8px; background: var(--bg); color: var(--muted); white-space: nowrap; }
button.st { font-size: 13px; padding: 6px 10px; border-radius: 12px; }
.st.detail { background: var(--green-soft); color: var(--green); }
.st.pending { background: var(--yellow-soft); color: #b7791f; }
.st.check { background: var(--red-soft); color: var(--red); }
button.st.on { outline: 2px solid currentColor; }
.cat-line { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.warn { color: #b7791f; margin-top: 4px; }
.bill-lines { margin-top: 10px; max-height: 420px; overflow-y: auto; }
.bill-line { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.bl-main { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bl-items { display: none; padding: 6px 0 0 10px; }
.bill-line.open .bl-items { display: grid; gap: 4px; }
.mini { font-size: 12px; padding: 2px 8px; border-radius: 8px; background: var(--bg); color: var(--primary); }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 8px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr[data-tx] { cursor: pointer; }
.tbl tr[data-tx]:hover td { background: var(--bg); }
.tbl .r { text-align: right; } .nw { white-space: nowrap; }
@media (max-width: 900px) { .lens-grid { grid-template-columns: 1fr; } }
@media (max-width: 640px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kv { font-size: 18px; }
  .tbl th:nth-child(3), .tbl td:nth-child(3), .tbl th:nth-child(5), .tbl td:nth-child(5) { display: none; }
  .d-y { display: none; }
  .tbl td, .tbl th { padding: 9px 5px; }
}
@media (min-width: 900px) { .tabs { justify-content: center; } .tabs button { flex: 0 1 140px; } }
