:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1b1f24;
  --muted: #6b7280;
  --accent: #2f6df6;
  --accent-soft: #e8f0ff;
  --danger: #d93a3a;
  --good: #0f9d58;
  --radius: 12px;
  --nav-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2027;
    --surface-2: #232830;
    --border: #2e343d;
    --text: #e8eaed;
    --muted: #9aa3af;
    --accent: #5b8dff;
    --accent-soft: #223252;
    --danger: #ff6b6b;
    --good: #46c07f;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  padding: 0 0 calc(var(--nav-h) + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
    "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }

/* ---------- 레이아웃 ---------- */
.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px; }
header.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
header.top .wrap { display: flex; align-items: center; gap: 10px; height: 52px; }
header.top h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; }
header.top .who { font-size: 13px; color: var(--muted); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin: 12px 0;
}
.card h2 { font-size: 14px; margin: 0 0 10px; color: var(--muted); font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--good); }
.neg { color: var(--danger); }

/* ---------- 입력 ---------- */
label.field { display: block; margin: 0 0 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; padding: 11px 12px; font-size: 16px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-family: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input.amount { font-size: 28px; font-weight: 650; text-align: right; padding: 10px 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips label {
  display: inline-block; padding: 8px 12px; font-size: 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; cursor: pointer; user-select: none;
}
.chips input:checked + label {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
.chips.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); }
.chips.grid label { text-align: center; padding: 10px 4px; border-radius: 10px; }

button, .btn {
  padding: 12px 16px; font-size: 15px; font-weight: 600; font-family: inherit;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer;
}
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.full { width: 100%; }
button:active { transform: translateY(1px); }

/* ---------- 목록 ---------- */
ul.txs { list-style: none; margin: 0; padding: 0; }
ul.txs li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 2px; border-bottom: 1px solid var(--border);
}
ul.txs li:last-child { border-bottom: 0; }
ul.txs li.saved { animation: flash 1.4s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
.tx-date { width: 44px; font-size: 12px; color: var(--muted); flex: none; }
.tx-main { flex: 1; min-width: 0; }
.tx-desc { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { font-size: 12px; color: var(--muted); }
.tx-amt { font-weight: 650; text-align: right; white-space: nowrap; }
.tag {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 11px; color: var(--muted);
}
.tag.warn { border-color: var(--danger); color: var(--danger); }

/* ---------- 막대 ---------- */
.bar-row { margin: 9px 0; }
.bar-track { height: 7px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.trend { display: flex; gap: 8px; align-items: flex-end; height: 110px; }
.trend > div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; }
.trend .pair { display: flex; gap: 2px; align-items: flex-end; height: 84px; width: 100%; justify-content: center; }
.trend .b { width: 40%; border-radius: 3px 3px 0 0; min-height: 2px; }
.trend .b.inc { background: var(--good); opacity: .55; }
.trend .b.exp { background: var(--accent); }
.trend .lb { font-size: 11px; color: var(--muted); }
.trend .cur .lb { color: var(--text); font-weight: 700; }

/* ---------- 표 ---------- */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
table.grid th, table.grid td { padding: 6px 8px; text-align: right; white-space: nowrap; }
table.grid th:first-child, table.grid td:first-child {
  text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1;
}
table.grid thead th { color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); }
table.grid tbody tr:nth-child(even) { background: var(--surface-2); }
table.grid tbody tr:nth-child(even) td:first-child { background: var(--surface-2); }
table.grid tr.sum td { border-top: 2px solid var(--border); font-weight: 700; }
table.grid td.zero { color: var(--border); }

/* ---------- 하단 내비 ---------- */
nav.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.bottom a {
  flex: 1; text-align: center; padding: 9px 0 8px; font-size: 11px;
  color: var(--muted); text-decoration: none;
}
nav.bottom a .ic { display: block; font-size: 19px; line-height: 1.2; }
nav.bottom a.on { color: var(--accent); font-weight: 700; }

.notice { padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; margin: 12px 0; }
.err { padding: 10px 12px; border-radius: 10px; background: #fdecec; color: #a01c1c; font-size: 14px; margin: 12px 0; }
@media (prefers-color-scheme: dark) { .err { background: #3a1e1e; color: #ffb4b4; } }

/* ---------- 로그인 ---------- */
.login-wrap { max-width: 340px; margin: 12vh auto; padding: 0 20px; }
.login-wrap h1 { font-size: 22px; text-align: center; margin-bottom: 4px; }
.login-wrap p.sub { text-align: center; color: var(--muted); font-size: 14px; margin-top: 0; }

/* ---------- 데스크톱에서만 쓰는 요소는 모바일에서 숨긴다 ---------- */
nav.bottom .brand, nav.bottom .navfoot { display: none; }
.tx-head { display: none; }
.tx-flag { flex: none; }
.tx-flag:empty { display: none; }

/* ---------- 데스크톱 레이아웃 ---------- */
@media (min-width: 960px) {
  body { padding-bottom: 0; padding-left: 216px; }

  /* 하단 탭 → 좌측 사이드바 */
  nav.bottom {
    top: 0; bottom: 0; right: auto; width: 216px;
    flex-direction: column; align-items: stretch;
    border-top: 0; border-right: 1px solid var(--border);
    padding: 14px 0;
  }
  nav.bottom .brand {
    display: block; padding: 4px 20px 18px;
    font-size: 18px; font-weight: 700; color: var(--text);
  }
  nav.bottom a {
    flex: none; display: flex; align-items: center; gap: 10px;
    text-align: left; padding: 10px 14px; margin: 1px 10px;
    border-radius: 9px; font-size: 14.5px;
  }
  nav.bottom a .ic { display: inline; font-size: 16px; width: 18px; text-align: center; }
  nav.bottom a:hover { background: var(--surface-2); }
  nav.bottom a.on, nav.bottom a.on:hover { background: var(--accent-soft); }
  nav.bottom .navfoot {
    display: flex; align-items: center; gap: 8px; margin-top: auto;
    padding: 12px 16px 0; border-top: 1px solid var(--border);
  }
  nav.bottom .navfoot-name { flex: 1; font-size: 13px; color: var(--muted); }
  nav.bottom .navfoot button { flex: none; padding: 6px 10px; font-size: 12px; }

  header.top .wrap { height: 60px; }
  header.top h1 { font-size: 19px; }
  header.top .who { display: none; }
  .wrap { max-width: 1180px; padding: 0 24px; }

  /* 2단 배치 */
  .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
  .cols > .card { margin: 18px 0 0; }
  .entry-cols { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
  .list-cols { grid-template-columns: 250px minmax(0, 1fr); }
  .list-cols .filters { position: sticky; top: 76px; }
  /* 좁은 사이드 카드라 월 이동과 합계를 세로로 쌓는다 */
  .list-cols .filters > .spread { flex-direction: column; align-items: stretch; gap: 10px; }
  .list-cols .filters > .spread > div:last-child { text-align: left; }

  /* 내역: 목록 → 표 */
  .tx-head, ul.txs.tx-grid li {
    display: grid; gap: 10px; align-items: center;
    /* 내역이 남는 폭을 가져가고, 확인필요 열은 없으면 0으로 접힌다 */
    grid-template-columns: 50px minmax(0, 1fr) 74px 92px minmax(96px, max-content) auto;
  }
  .tx-head {
    padding: 2px 2px 8px; font-size: 12px; color: var(--muted);
    border-bottom: 1px solid var(--border);
  }
  .tx-head span:nth-child(5) { text-align: right; }
  ul.txs.tx-grid .tx-main, ul.txs.tx-grid .tx-meta { display: contents; }
  ul.txs.tx-grid .sep { display: none; }
  ul.txs.tx-grid .tx-cat, ul.txs.tx-grid .tx-method { font-size: 13px; color: var(--muted); }
  ul.txs.tx-grid .tx-flag:empty { display: block; }
  ul.txs.tx-grid li { padding: 8px 2px; }
  ul.txs.tx-grid li:hover { background: var(--surface-2); }

  /* 여유가 생긴 만큼 시각 요소를 키운다 */
  .trend { height: 150px; }
  .trend .pair { height: 118px; }
  input.amount { font-size: 30px; }
  table.grid { font-size: 13.5px; }
  table.grid th, table.grid td { padding: 7px 10px; }
}

/* 아주 넓은 화면 */
@media (min-width: 1400px) {
  .wrap { max-width: 1320px; }
  .entry-cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
