/* 우리집 가계부 — 차분한 통장/장부 느낌 */
:root {
  --green-900: #143628;
  --green-800: #1f4d3a;
  --green-700: #2b6249;
  --green-500: #4f8a6c;
  --green-300: #9cc2ad;
  --green-100: #dfeae3;
  --bg: #eef2ee;
  --paper: #fbfcfa;
  --line: #d5ddd6;
  --ink: #1d2621;
  --ink-soft: #56625b;
  --ink-faint: #8a958e;
  --mustard: #c99a1e;
  --mustard-bg: #f6ecd0;
  --mustard-ink: #7a5b08;
  --rust: #9a3f2f;
  --rust-bg: #f5e1dc;
  --seg-fixed: #6f7f76;
  --seg-shared: #2b6249;
  --seg-allowance: #b98a2a;
  --seg-remaining: #9cc2ad;
  --radius: 14px;
  --tab-h: 60px;
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Noto Sans KR", "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
    calc(var(--tab-h) + 28px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
.page-login .wrap { padding-bottom: 32px; }

h1 { font-size: 1.25rem; margin: 0; letter-spacing: -0.01em; }
h2 { margin: 0; }
a { color: var(--green-700); }
small { font-size: 0.8em; color: var(--ink-faint); }

.money { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; white-space: nowrap; }
.money.big { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
.muted { color: var(--ink-faint); }
.hint { color: var(--ink-soft); font-size: 0.85rem; margin: 2px 0 10px; }
.empty { text-align: center; color: var(--ink-faint); padding: 32px 0; list-style: none; }

:focus-visible { outline: 3px solid var(--mustard); outline-offset: 2px; border-radius: 6px; }

/* ---------- 카드 */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 14px;
  box-shadow: 0 1px 0 rgba(20, 54, 40, 0.04);
}
.card-title {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  font-size: 1rem; margin-bottom: 10px;
}
.eyebrow { font-size: 0.8rem; font-weight: 600; color: var(--ink-soft); letter-spacing: 0.02em; margin-bottom: 6px; }
.stack > * + * { margin-top: 12px; }

/* ---------- 상단 */
.month-nav, .page-head {
  display: flex; align-items: center; gap: 8px; margin: 4px 0 12px;
}
.month-nav { justify-content: space-between; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; border-radius: 12px;
  text-decoration: none; font-size: 1.6rem; line-height: 1; color: var(--green-800);
}
.icon-btn:hover { background: var(--green-100); }

/* ---------- 돈 흐름 */
.flow { border-color: var(--green-300); }
.flow-income { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.flow-income > span { color: var(--ink-soft); font-weight: 600; }
.flowbar {
  display: flex; height: 18px; margin: 12px 0 14px; border-radius: 9px; overflow: hidden;
  background: var(--green-100);
}
.flowbar .seg { display: block; height: 100%; }
.flowbar .seg + .seg { border-left: 2px solid var(--paper); }
.seg-fixed { background: var(--seg-fixed); }
.seg-shared { background: var(--seg-shared); }
.seg-allowance { background: var(--seg-allowance); }
.seg-remaining { background: var(--seg-remaining); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; vertical-align: 0; }
.flow-legend { list-style: none; margin: 0; padding: 0; }
.flow-legend li {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px;
  padding: 6px 0; border-bottom: 1px dashed var(--line);
}
.flow-legend .pct { color: var(--ink-faint); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.flow-legend .dot { margin: 0; }
.flow-remaining {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 12px; padding: 12px; border-radius: 10px; background: var(--green-100);
}
.flow-remaining > span { font-weight: 600; }
.flow-remaining small { display: block; font-weight: 400; margin-left: 18px; }
.flow-remaining strong { color: var(--green-800); }
.flow-remaining.is-negative { background: var(--rust-bg); }
.flow-remaining.is-negative strong { color: var(--rust); }
.warn-text { color: var(--rust); font-size: 0.9rem; margin: 8px 0 0; }
.flow-basis { margin: 2px 0 0; font-size: 0.8rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; text-align: right; }
.flow-hint { margin: 12px 0 0; padding: 12px; border-radius: 10px; background: var(--green-100); color: var(--ink-soft); font-size: 0.9rem; }

.notice-link {
  display: flex; align-items: center; min-height: 48px; padding: 10px 16px; margin: 0 0 14px;
  border-radius: var(--radius); background: var(--mustard-bg); color: var(--mustard-ink);
  font-weight: 600; text-decoration: none; border: 1px solid #e8d6a2;
}

/* ---------- 막대 */
.meter-row + .meter-row, .bar-row + .bar-row { margin-top: 14px; }
.meter-head, .bar-head { display: flex; justify-content: space-between; gap: 8px; }
.meter-head .name { font-weight: 600; }
.meter, .bar { height: 10px; background: var(--green-100); border-radius: 5px; overflow: hidden; margin: 6px 0 4px; }
.meter .fill, .bar span { display: block; height: 100%; border-radius: 5px; background: var(--green-700); }
.meter .fill.warn { background: var(--mustard); }
.meter .fill.danger { background: var(--rust); }
.meter-foot { font-size: 0.85rem; color: var(--ink-soft); text-align: right; }
.meter-foot.neg, .meter-foot.neg .money { color: var(--rust); font-weight: 600; }
.bar span { background: var(--green-500); }
.diff { font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.diff.up { color: var(--rust); }
.diff.down { color: var(--green-700); }
.plain { list-style: none; margin: 0; padding: 0; }
.plain li { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.plain li:last-child { border-bottom: 0; }
.plain li .diff { flex-basis: 100%; text-align: right; }
.member + .member { margin-top: 16px; }

/* ---------- 폼 */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 0.8rem; font-weight: 600; color: var(--ink-soft); }
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=radio]), select {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
input:not([type=checkbox]):not([type=radio]):focus, select:focus { border-color: var(--green-700); outline: none; box-shadow: 0 0 0 3px var(--green-100); }
input[name=amount] { font-variant-numeric: tabular-nums; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--green-700); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 8px 18px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--green-100); }
.btn-primary { background: var(--green-800); border-color: var(--green-800); color: #fff; }
.btn-primary:hover { background: var(--green-900); }
.btn-danger { background: #fff; border-color: var(--rust); color: var(--rust); }
.btn-danger:hover { background: var(--rust-bg); }
.btn-small { min-height: 44px; padding: 6px 14px; font-size: 0.9rem; }
form.stack > .btn, .logout .btn { width: 100%; }

.seg-control { display: flex; background: var(--green-100); border-radius: 10px; padding: 3px; }
.seg-control label { flex: 1; }
.seg-control input { position: absolute; opacity: 0; pointer-events: none; }
.seg-control span {
  display: flex; align-items: center; justify-content: center; min-height: 40px; border-radius: 8px;
  font-weight: 600; color: var(--ink-soft); cursor: pointer;
}
.seg-control input:checked + span { background: #fff; color: var(--green-800); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg-control input:focus-visible + span { outline: 3px solid var(--mustard); }

/* ---------- 빠른 입력 */
.quick { border-color: var(--green-300); }
.quick-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.quick-row + .quick-row { margin-top: 10px; }
.quick-row .add-btn { min-width: 0; }
.amount-field input { font-size: 1.15rem; }
.more { margin-top: 10px; }
.more > summary, details.item > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 44px; cursor: pointer; list-style: none; font-weight: 600; color: var(--green-800);
}
.more > summary::-webkit-details-marker, details.item > summary::-webkit-details-marker { display: none; }
.more > summary::after { content: "▾"; color: var(--ink-faint); }
.more[open] > summary::after { content: "▴"; }

/* ---------- 예산·적립 */
.bar.has-budget span.ok { background: var(--green-700); }
.bar span.warn { background: var(--mustard); }
.bar span.danger { background: var(--rust); }
.saved-line { margin: 10px 0 0; font-size: 0.9rem; color: var(--green-800); display: flex; justify-content: space-between; }
.save-panel { margin-top: 10px; }
.save-panel > summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; font-weight: 600; color: var(--green-800); }
.save-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.save-form .field-wide { grid-column: 1 / -1; }

/* ---------- 요약 링크와 일별 그래프 */
.row-link { display: block; color: inherit; text-decoration: none; border-radius: 8px; margin: 0 -6px; padding: 4px 6px; }
.row-link:hover { background: #f1f5f2; }
.bar-head.row-link { display: flex; }
.li-link { display: flex; justify-content: space-between; gap: 8px; width: 100%; min-height: 32px; align-items: center; }
.plain li > .li-link { margin: 0; padding: 0; }
.more-link { font-size: 0.85rem; font-weight: 600; text-decoration: none; }
.dbars { display: flex; align-items: flex-end; gap: 2px; height: 96px; margin-top: 14px; border-bottom: 1px solid var(--line); }
.dbar { flex: 1; height: 100%; display: flex; align-items: flex-end; min-width: 0; }
.dbar span { display: block; width: 100%; min-height: 0; background: var(--green-500); border-radius: 2px 2px 0 0; }
.dbar.is-max span { background: var(--mustard); }
.dbar.is-future span { background: var(--green-100); }
.dbar-axis { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--ink-faint); margin-top: 4px; }

/* ---------- 내역 보기 전환·필터 */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 8px; }
.toolbar .filters { margin: 0; }
.seg-links { display: inline-flex; background: var(--green-100); border-radius: 10px; padding: 3px; }
.seg-links a { display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 8px; text-decoration: none; color: var(--ink-soft); font-weight: 600; }
.seg-links a.is-active { background: #fff; color: var(--green-800); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.filter-panel { padding: 4px 16px; }
.filter-panel > summary { display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; font-weight: 600; color: var(--green-800); list-style: none; }
.filter-panel > summary::-webkit-details-marker { display: none; }
.filter-panel > summary::after { content: "▾"; margin-left: auto; color: var(--ink-faint); }
.filter-panel[open] > summary::after { content: "▴"; }
.filter-panel form { padding: 4px 0 14px; }
.filter-apply { align-self: end; }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chip-x { background: var(--green-800); border-color: var(--green-800); color: #fff; }
.chips .clear { min-height: 44px; display: inline-flex; align-items: center; padding: 0 4px; }
.day-head { display: flex; justify-content: space-between; gap: 8px; }
.day-head .money { font-weight: 600; color: var(--ink-soft); }

/* ---------- 달력 */
.cal-head .card-title { margin-bottom: 2px; }
.cal { display: grid; gap: 3px; }
.cal-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.cal-week span { text-align: center; font-size: 0.75rem; font-weight: 600; color: var(--ink-faint); padding: 2px 0; }
.cal-cell {
  display: flex; flex-direction: column; justify-content: space-between; min-height: 52px; padding: 4px 3px;
  border-radius: 8px; text-decoration: none; color: var(--ink); background: #f3f6f3; min-width: 0;
}
.cal-cell.is-blank { background: transparent; }
.cal-cell.lv1 { background: #dcebe1; }
.cal-cell.lv2 { background: #b4d3be; }
.cal-cell.lv3 { background: #6fa587; color: #fff; }
.cal-cell.lv4 { background: var(--green-800); color: #fff; }
.cal-cell.is-future { opacity: 0.5; }
.cal-cell.is-today { box-shadow: inset 0 0 0 2px var(--mustard); }
.cal-cell.is-selected { box-shadow: inset 0 0 0 3px var(--ink); }
.cal-day { font-size: 0.75rem; font-weight: 600; }
.cal-day.sun { color: var(--rust); }
.cal-day.sat { color: #3a6ea5; }
.cal-cell.lv3 .cal-day, .cal-cell.lv4 .cal-day { color: inherit; }
.cal-week .sun { color: var(--rust); }
.cal-week .sat { color: #3a6ea5; }
.cal-amt { font-size: 0.72rem; font-weight: 700; text-align: right; overflow: hidden; text-overflow: clip; letter-spacing: -0.02em; }
.cal-none { font-size: 0.68rem; color: var(--green-700); text-align: right; }

/* ---------- 검색 */
.search { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; margin: 0 0 12px; }
.search select { width: auto; }
.search-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.search-head a { min-height: 44px; display: inline-flex; align-items: center; padding: 0 4px; }
.search-totals { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 8px 0 0; }
.search-totals div { display: flex; flex-direction: column; }
.search-totals dt { font-size: 0.8rem; color: var(--ink-soft); }
.search-totals dd { margin: 0; font-size: 1.2rem; font-weight: 700; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 필터와 목록 */
.filters { display: flex; gap: 8px; margin: 0 0 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 22px;
  background: var(--paper); border: 1px solid var(--line); text-decoration: none; color: var(--ink-soft); font-weight: 600;
}
.chip.is-active { background: var(--green-800); border-color: var(--green-800); color: #fff; }
.day-head { font-size: 0.85rem; color: var(--ink-soft); font-weight: 600; margin: 16px 4px 6px; }
.tx-list { list-style: none; margin: 0; padding: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card.tx-list { padding: 0; }
.tx-list > li + li { border-top: 1px solid var(--line); }
.tx-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  min-height: 56px; padding: 10px 14px; color: inherit; text-decoration: none;
}
a.tx-row:hover { background: #f3f6f3; }
.tx-main { display: flex; flex-direction: column; min-width: 0; }
.tx-title { font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.tx-meta { font-size: 0.82rem; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; }
.tx-amount { font-weight: 700; }
.tx-income .tx-amount { color: var(--green-700); }
.tx-refund .tx-amount { color: var(--ink-soft); }
.tx-transfer .tx-amount, .tx-transfer .tx-title { color: var(--ink-faint); font-weight: 500; }
.badge {
  display: inline-block; padding: 0 7px; border-radius: 6px; font-size: 0.72rem; font-weight: 600; line-height: 1.6;
  background: var(--green-100); color: var(--green-800);
}
.badge-fixed { background: #e4e8e5; color: var(--seg-fixed); }
.badge-allow { background: var(--mustard-bg); color: var(--mustard-ink); }
.trash-row { display: flex; align-items: center; gap: 8px; padding-right: 12px; }
.trash-row .tx-row { flex: 1; min-width: 0; }

/* ---------- 알림 */
.flash { padding: 12px 14px; border-radius: 12px; margin: 0 0 12px; background: var(--green-100); color: var(--green-900); font-weight: 500; }
.flash-error { background: var(--rust-bg); color: var(--rust); }
.notice { padding: 12px 14px; border-radius: 12px; background: var(--mustard-bg); color: var(--mustard-ink); font-size: 0.92rem; margin: 0 0 12px; }
.error { color: var(--rust); margin: 0; }

/* ---------- 설정 */
details.item { border-top: 1px solid var(--line); }
details.item:first-of-type { border-top: 0; }
details.item > summary > span:first-child { color: var(--ink); }
details.item > summary .muted { font-weight: 400; font-size: 0.85rem; text-align: right; }
details.item[open] { padding-bottom: 14px; }
details.item.add > summary > span { color: var(--green-700); }
.is-off { text-decoration: line-through; color: var(--ink-faint) !important; }
.danger-zone { margin: 8px 0 14px; }
.danger-zone > .btn { width: 100%; }
.logout { margin: 8px 0 14px; }
dialog.confirm { border: 0; border-radius: var(--radius); padding: 20px; max-width: min(360px, 90vw); }
dialog.confirm::backdrop { background: rgba(20, 54, 40, 0.4); }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- 로그인 */
.login { max-width: 400px; margin: 10vh auto 0; }
.brand { text-align: center; color: var(--green-800); font-size: 1.5rem; margin-bottom: 20px; }
.user-pick { border: 0; padding: 0; margin: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.user-pick legend { font-size: 0.8rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.pick { flex: 1 1 100px; }
.pick input { position: absolute; opacity: 0; }
.pick span {
  display: flex; align-items: center; justify-content: center; min-height: 52px; border-radius: 12px;
  border: 1px solid var(--line); background: #fff; font-weight: 700; cursor: pointer;
}
.pick input:checked + span { background: var(--green-800); color: #fff; border-color: var(--green-800); }
.pick input:focus-visible + span { outline: 3px solid var(--mustard); outline-offset: 2px; }
.code { background: var(--green-100); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 0.85rem; }

/* ---------- 하단 탭 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: rgba(251, 252, 250, 0.96); border-top: 1px solid var(--line);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  backdrop-filter: blur(8px);
}
.tab {
  flex: 1; max-width: 213px; height: var(--tab-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 0.75rem; font-weight: 600; color: var(--ink-faint); text-decoration: none;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.is-active { color: var(--green-800); }

@media (max-width: 380px) {
  .money.big { font-size: 1.35rem; }
  .card { padding: 14px 12px; }
  .tx-row { padding: 10px 12px; }
}
