/* 우리집 가계부: 밝은 테마, 모바일 우선. 390px·800px 에서 가로 스크롤이 생기지 않게 모든 칸이 줄어들고 줄바꿈된다. */
:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --ink: #1d2733;
  --muted: #5f6b7a;
  --line: #dde3ec;
  --brand: #2563eb;
  --brand-ink: #ffffff;
  --brand-soft: #e8f0fe;
  --in: #15803d;
  --out: #b42318;
  --warn: #92400e;
  --warn-soft: #fff4dc;
  --warn-line: #f3d48b;
  --bad: #b91c1c;
  --bad-soft: #fde8e8;
  --radius: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; min-width: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  overflow-wrap: anywhere;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--brand); }
h1 { font-size: 21px; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 4px 0 10px; }
h3 { font-size: 15px; margin: 14px 0 6px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.loading { padding: 24px 16px; }

header.top { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.wrap { max-width: 760px; margin: 0 auto; padding: 12px 16px; }
.brand { font-weight: 800; font-size: 18px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.who { font-size: 13px; color: var(--muted); font-weight: 500; }
.devbar { background: #fff7d6; border-bottom: 1px solid #ecd98a; font-size: 13px; }
.devbar .wrap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding-top: 6px; padding-bottom: 6px; }
.devbar select { min-height: 32px; padding: 2px 8px; font-size: 13px; }

main.view { max-width: 760px; margin: 0 auto; padding: 16px; }

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
nav.tabs a {
  flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 48px; padding: 4px 2px; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-weight: 700; font-size: 13px; line-height: 1.2; text-align: center;
}
nav.tabs a.on { background: var(--brand-soft); color: var(--brand); }
nav.tabs .count:not(:empty) { background: var(--out); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; line-height: 16px; }
@media (min-width: 700px) {
  nav.tabs { justify-content: center; gap: 6px; }
  nav.tabs a { flex: 0 1 130px; flex-direction: row; font-size: 14px; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.error { border-color: #f1b8b8; background: var(--bad-soft); color: var(--bad); }
.warn { background: var(--warn-soft); border: 1px solid var(--warn-line); color: var(--warn); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
p.warn { padding: 8px 10px; }
.notice { background: var(--brand-soft); color: #1e40af; border-radius: 10px; padding: 8px 10px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 420px) { .grid3 { grid-template-columns: 1fr; } }

button, .btn {
  font: inherit; font-weight: 700; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 10px 14px; border-radius: 10px; cursor: pointer; min-height: 44px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  max-width: 100%;
}
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--bad); border-color: #f1b8b8; }
button.small { min-height: 36px; padding: 6px 10px; font-size: 14px; }
button.link { border: 0; background: none; color: var(--brand); min-height: 28px; padding: 0 4px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select {
  font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
  min-height: 44px; width: 100%; max-width: 100%;
}
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; margin: 0; flex: 0 0 auto; }
input[type="file"] { padding: 8px; }
label.field { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
label.check { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; margin: 6px 0; }
.row input[type="search"], .row input:not([type]) { flex: 1 1 160px; width: auto; }
.row select { flex: 1 1 160px; width: auto; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  font-weight: 700; font-size: 14px; cursor: pointer; min-height: 38px;
}
.chip.small { min-height: 34px; font-size: 13px; padding: 5px 10px; }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chip.static { cursor: default; display: inline-flex; align-items: center; gap: 2px; min-height: 34px; font-weight: 600; }
.chip.off { opacity: .55; text-decoration: line-through; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--brand-soft); color: #1e40af; }
.warn-badge { background: var(--warn-soft); color: var(--warn); }
.bad-badge { background: var(--bad-soft); color: var(--bad); }

/* 이번 달 */
.month-nav { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; margin-bottom: 8px; }
.month-nav h1 { text-align: center; margin: 0; }
.hero { text-align: center; }
.profit { font-size: 36px; font-weight: 800; line-height: 1.15; margin: 4px 0; }
.profit.pos { color: var(--ink); }
.profit.neg { color: var(--out); }
.line { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line strong { text-align: right; }
.line.total strong { font-size: 17px; }
.line.in strong { color: var(--in); }
.line.out strong { color: var(--out); }
.bar-row { margin: 8px 0; }
.bar-label { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.bar-track { height: 10px; background: var(--brand-soft); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.bar-fill { height: 100%; background: var(--brand); border-radius: 999px; }
.compare-block { padding: 6px 0; }

/* 거래 카드 */
.tx-summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; align-items: start; margin: 6px 0; }
.tx-summary .tx-meta, .tx-summary .tx-desc, .tx-summary .muted { grid-column: 1; }
.tx-summary .amount { grid-column: 2; grid-row: 1 / span 3; align-self: center; text-align: right; white-space: nowrap; }
.tx-meta { font-size: 13px; color: var(--muted); }
.tx-desc { font-weight: 700; }
.amount { font-weight: 800; }
.amount.in { color: var(--in); }
.amount.out { color: var(--out); }
.note { font-size: 14px; color: var(--muted); }
.pair-option { border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 8px; }
.bulk { position: sticky; top: 56px; z-index: 4; border-color: var(--brand); }
.editor { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; display: grid; gap: 8px; }
.filters { display: grid; gap: 8px; }
.filters .grid2 { margin-bottom: 0; }

/* 올리기 */
.preview-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.preview-row .tx-meta, .preview-row .tx-desc, .preview-row .muted, .preview-row .badge { grid-column: 1; justify-self: start; }
.preview-row .amount { grid-column: 2; grid-row: 1 / span 2; align-self: center; white-space: nowrap; }
.summary { font-weight: 800; }
.import-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.import-row:last-child { border-bottom: 0; }

/* 설정 */
.account, .rule { padding: 10px 0; border-bottom: 1px solid var(--line); }
.account.off, .rule.off { opacity: .7; }
.cat-group { margin-bottom: 10px; }
.rule-form { display: grid; gap: 8px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 20;
  max-width: calc(100% - 32px); background: #1d2733; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
}
.toast.bad { background: var(--bad); }
.save-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
