/* 거래장부 — 폰 화면.  아버지가 쓰신다: 글씨를 키우고, 버튼을 크게(최소 48px),
   중요한 숫자(남은 돈)를 가장 크게 둔다. 안드로이드 크롬 기준. */

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1a1d21;
  --ink-dim: #6b7280;
  --line: #e4e6eb;
  --brand: #1f6feb;
  --brand-ink: #ffffff;
  --sale: #0f766e;      /* 매출 = 들어오는 돈 */
  --purchase: #b45309;  /* 매입 = 나가는 돈 */
  --danger: #d92d20;    /* 미수금 */
  --card-pay: #7c3aed;
  --transfer: #1f6feb;
  --cash: #0f766e;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
  --radius: 14px;
  --tap: 48px;
}

:root[data-theme="dark"],
html:not([data-theme="light"]) {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --card: #191c22;
    --ink: #f0f2f5;
    --ink-dim: #9aa3af;
    --line: #2a2f38;
    --brand: #4d8ffb;
    --sale: #2dd4bf;
    --purchase: #fbbf24;
    --danger: #ff6b60;
    --card-pay: #a78bfa;
    --transfer: #4d8ffb;
    --cash: #2dd4bf;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR",
               "Malgun Gothic", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  overscroll-behavior-y: contain;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }

/* 숫자는 자릿수가 흔들리지 않게 고정폭으로 */
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ------------------------------------------------------------------ 헤더 */

header.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  display: flex; align-items: center; gap: 10px;
}
header.top h1 { font-size: 19px; margin: 0; flex: 1; font-weight: 700; letter-spacing: -.02em; }
header.top .icon-btn {
  width: var(--tap); height: var(--tap); border-radius: 12px;
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  font-size: 20px; display: grid; place-items: center;
}

main { padding: 14px 14px 20px; max-width: 720px; margin: 0 auto; }

/* ------------------------------------------------------------------ 카드 */

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px; border: 1px solid transparent;
}
.card.tappable:active { transform: scale(.995); }

.label { font-size: 13px; color: var(--ink-dim); font-weight: 600; letter-spacing: .01em; }
.big { font-size: 30px; font-weight: 800; letter-spacing: -.03em; line-height: 1.15; }
.huge { font-size: 38px; font-weight: 800; letter-spacing: -.035em; line-height: 1.1; }
.mid { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.small { font-size: 14px; color: var(--ink-dim); }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack { display: grid; gap: 4px; }
.mt { margin-top: 12px; }
.hr { height: 1px; background: var(--line); margin: 12px -14px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.grid2 .card { margin: 0; }

.ink-sale { color: var(--sale); }
.ink-purchase { color: var(--purchase); }
.ink-danger { color: var(--danger); }
.ink-dim { color: var(--ink-dim); }

/* ------------------------------------------------------------------ 뱃지 */

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; white-space: nowrap;
}
.badge.CARD     { background: color-mix(in srgb, var(--card-pay) 14%, transparent); color: var(--card-pay); }
.badge.TRANSFER { background: color-mix(in srgb, var(--transfer) 14%, transparent); color: var(--transfer); }
.badge.CASH     { background: color-mix(in srgb, var(--cash) 14%, transparent); color: var(--cash); }
.badge.SALE     { background: color-mix(in srgb, var(--sale) 14%, transparent); color: var(--sale); }
.badge.PURCHASE { background: color-mix(in srgb, var(--purchase) 16%, transparent); color: var(--purchase); }
.badge.COMPLETED{ background: color-mix(in srgb, var(--ink-dim) 14%, transparent); color: var(--ink-dim); }
.badge.PARTIAL  { background: color-mix(in srgb, #f59e0b 18%, transparent); color: #b45309; }
.badge.UNPAID   { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge.PARTIAL { color: #fbbf24; }
}

/* ------------------------------------------------------------------ 진행바 */

.bar { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; display: flex; }
.bar > span { display: block; height: 100%; }
.bar .paid { background: var(--sale); }
.bar .seg-CARD { background: var(--card-pay); }
.bar .seg-TRANSFER { background: var(--transfer); }
.bar .seg-CASH { background: var(--cash); }

/* ------------------------------------------------------------------ 버튼 */

button, .btn {
  font: inherit; font-weight: 700; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
  min-height: var(--tap); padding: 0 16px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:active { filter: brightness(.96); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
button.danger  { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
button.ghost   { background: transparent; }
button.block   { width: 100%; }
button:disabled { opacity: .45; }

/* 칩(필터/선택) — 손가락으로 누르는 것이라 작게 만들지 않는다 */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  min-height: 42px; padding: 0 14px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--line); background: var(--card); color: var(--ink-dim); font-weight: 700;
  font-size: 15px;
}
.chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: transparent; }

/* 큼직한 2~3칸 선택 (매출/매입, 카드/이체/현금) */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.seg button { min-height: 54px; font-size: 16px; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: transparent; }

/* FAB — 오른손 엄지가 닿는 자리 */
.fab {
  position: fixed; right: 16px; z-index: 30;
  bottom: calc(78px + 14px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--brand); color: var(--brand-ink); border: none;
  font-size: 30px; font-weight: 400; padding: 0;
  box-shadow: 0 6px 18px rgba(31, 111, 235, .4);
}

/* ------------------------------------------------------------------ 탭바 */

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  border: none; background: none; border-radius: 0; min-height: 62px;
  flex-direction: column; gap: 3px; color: var(--ink-dim); font-size: 12px; font-weight: 700;
  padding: 6px 0;
}
nav.tabs button .ico { font-size: 21px; line-height: 1; }
nav.tabs button[aria-current="page"] { color: var(--brand); }

/* ------------------------------------------------------------------ 목록 */

.list { display: grid; gap: 10px; }
.item {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; display: flex; align-items: center; gap: 12px; min-height: 60px;
  width: 100%; text-align: left; border: 1px solid transparent;
}
.day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 16px 4px 6px; font-weight: 800; font-size: 15px;
}

.empty { text-align: center; color: var(--ink-dim); padding: 40px 16px; }
.empty .ico { font-size: 42px; display: block; margin-bottom: 10px; opacity: .6; }

/* ------------------------------------------------------------------ 시트 */

.sheet-back {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-back[hidden] { display: none; }
.sheet {
  background: var(--bg); width: 100%; max-width: 720px;
  border-radius: 20px 20px 0 0; max-height: 92vh; display: flex; flex-direction: column;
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet header {
  display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line); background: var(--card);
  border-radius: 20px 20px 0 0;
}
.sheet header h2 { font-size: 18px; margin: 0; flex: 1; font-weight: 800; }
.sheet .body { overflow-y: auto; padding: 14px; -webkit-overflow-scrolling: touch; }
.sheet .foot {
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--card); display: grid; gap: 8px;
}
.sheet .foot .two { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }

/* ------------------------------------------------------------------ 입력 */

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 14px; font-weight: 700; margin-bottom: 6px; color: var(--ink-dim); }
input, select, textarea {
  font: inherit; font-size: 17px;           /* 16px 미만이면 안드로이드에서 화면이 확대된다 */
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
input.amount { font-size: 26px; font-weight: 800; text-align: right; letter-spacing: -.02em; min-height: 60px; }
textarea { min-height: 74px; resize: vertical; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.quick button { min-height: 42px; padding: 0 12px; font-size: 15px; }

.hint { font-size: 13.5px; color: var(--ink-dim); margin-top: 6px; }
.error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger); border-radius: 12px; padding: 11px 13px;
  font-size: 15px; font-weight: 600; margin-bottom: 12px;
}
.error[hidden] { display: none; }

/* 토스트 */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(96px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 999px;
  font-weight: 700; font-size: 15px; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}
.toast[hidden] { display: none; }
