/* 식대장부 공통 스타일 — 장부 괘선 + 인주 도장 */
:root {
  --ink: #1d2b36;          /* 장부 잉크 */
  --ink-2: #4a5864;
  --muted: #6f7b84;
  --paper: #f5f7f6;        /* 장부 종이 */
  --sheet: #ffffff;
  --rule: #d6dfdb;         /* 괘선 */
  --rule-strong: #b9c7c1;
  --green: #2c6a4e;        /* 장부 녹색 */
  --green-dark: #1f4f39;
  --green-soft: #e6f0eb;
  --seal: #b42318;         /* 인주 */
  --seal-soft: #fbe9e7;
  --warn: #9a5b00;
  --warn-soft: #fff3dc;
  --focus: #1a73e8;
  --radius-s: 6px;
  --radius-m: 10px;
  --shadow-sheet: 0 -8px 30px rgba(29, 43, 54, .18);
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Noto Sans CJK KR", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  word-break: keep-all;
  overflow-wrap: anywhere;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── 상단 바 ── */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--ink);
  color: #fff;
}
.appbar .brand { font-weight: 800; font-size: 20px; letter-spacing: -.02em; }
.appbar .role { font-size: 14px; padding: 2px 8px; border: 1px solid rgba(255,255,255,.45); border-radius: 999px; }
.appbar .spacer { flex: 1; }
.appbar .iconbtn { background: transparent; border: 0; color: #fff; padding: 6px 8px; border-radius: var(--radius-s); cursor: pointer; font-size: 15px; }
.appbar .iconbtn:hover { background: rgba(255,255,255,.12); }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #8fa3ae; margin-right: 6px; vertical-align: 1px; }
.status-dot.on { background: #5fd38d; }

/* ── 하단 탭 ── */
.tabs {
  position: sticky; bottom: 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--sheet); border-top: 1px solid var(--rule-strong);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  border: 0; background: transparent; padding: 10px 4px 12px; cursor: pointer;
  font-size: 15px; color: var(--muted); position: relative;
}
.tabs button[aria-current="page"] { color: var(--green-dark); font-weight: 700; }
.tabs button[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; background: var(--green); border-radius: 0 0 3px 3px; }
.tabs .badge { position: absolute; top: 4px; right: calc(50% - 30px); }

.page { max-width: 760px; margin: 0 auto; padding: 16px 16px 32px; min-height: calc(100vh - 120px); }
.page.wide { max-width: 1040px; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 8px; letter-spacing: -.02em; }
h1 { font-size: 26px; }
h2 { font-size: 21px; }
h3 { font-size: 18px; }
p { margin: 0 0 12px; }

/* ── 장부 종이 영역 ── */
.ledger {
  background: var(--sheet);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-m);
  overflow: hidden;
}
.ledger-head {
  display: flex; align-items: baseline; gap: 8px; justify-content: space-between;
  padding: 12px 16px; border-bottom: 2px solid var(--ink);
}
.ledger-head h2, .ledger-head h3 { margin: 0; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  padding: 12px 16px; min-height: 64px;
  border-bottom: 1px solid var(--rule);
  background: transparent; width: 100%; text-align: left; border-left: 0; border-right: 0; border-top: 0;
}
.row:last-child { border-bottom: 0; }
button.row { cursor: pointer; }
button.row:hover { background: var(--green-soft); }
.row .who { font-weight: 700; font-size: 20px; }
.row .meta { font-size: 14px; color: var(--muted); grid-column: 1; }
.row .amt { grid-row: 1 / span 2; grid-column: 2; text-align: right; font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums; }
.row .amt small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }
.row .amt.low { color: var(--seal); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 19px; margin-bottom: 6px; }

/* ── 폼 ── */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 700; font-size: 16px; margin-bottom: 6px; }
.field > small { display: block; color: var(--muted); font-size: 14px; margin-top: 4px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 50px; padding: 10px 14px;
  border: 1.5px solid var(--rule-strong); border-radius: var(--radius-s);
  background: #fff; font-size: 18px;
}
textarea.input { min-height: 120px; line-height: 1.5; }
.input:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(44,106,78,.2); }
.search {
  position: relative;
}
.search .input { min-height: 60px; font-size: 22px; padding-left: 48px; border-width: 2px; border-color: var(--ink); }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 24px; height: 24px; color: var(--ink-2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

/* ── 버튼 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 10px 18px;
  border-radius: var(--radius-s); border: 1.5px solid var(--ink);
  background: #fff; color: var(--ink); font-weight: 700; font-size: 18px; cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: #eef2f0; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.seal { background: var(--seal); border-color: var(--seal); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--green-dark); }
.btn.ghost:hover { background: var(--green-soft); }
.btn.danger { color: var(--seal); border-color: var(--seal); }
.btn.block { width: 100%; }
.btn.big { min-height: 64px; font-size: 21px; }
.btn.sm { min-height: 40px; padding: 6px 12px; font-size: 15px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.actions.end { justify-content: flex-end; }
.actions > .grow { flex: 1; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.chip { flex: none; border: 1.5px solid var(--rule-strong); background: #fff; border-radius: 999px; padding: 6px 14px; font-size: 15px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

.badge { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--seal); color: #fff; font-size: 13px; font-weight: 700; text-align: center; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 4px; background: var(--green-soft); color: var(--green-dark); font-size: 13px; font-weight: 700; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.seal { background: var(--seal-soft); color: var(--seal); }

.notice { padding: 12px 14px; border-radius: var(--radius-s); background: var(--green-soft); border-left: 4px solid var(--green); font-size: 16px; margin: 12px 0; }
.notice.warn { background: var(--warn-soft); border-color: var(--warn); }
.notice.seal { background: var(--seal-soft); border-color: var(--seal); }

.panel { background: var(--sheet); border: 1px solid var(--rule-strong); border-radius: var(--radius-m); padding: 16px; margin-bottom: 16px; }
.panel > h2:first-child, .panel > h3:first-child { margin-bottom: 12px; }

/* ── 표 ── */
.table-wrap { overflow-x: auto; border: 1px solid var(--rule-strong); border-radius: var(--radius-s); background: #fff; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 16px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: middle; }
.tbl th { background: #eef3f0; font-size: 14px; color: var(--ink-2); white-space: nowrap; border-bottom: 2px solid var(--ink); }
.tbl td.r, .tbl th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .sub { display: block; font-size: 13px; color: var(--muted); }
.tag { white-space: nowrap; }
@media (max-width: 520px) { .tbl th, .tbl td { padding: 8px 6px; } table.tbl { font-size: 15px; } }
.tbl tfoot td { font-weight: 800; border-top: 2px solid var(--ink); border-bottom: 0; }
.tbl input { width: 100%; min-height: 40px; border: 1px solid transparent; border-radius: 4px; padding: 4px 6px; background: transparent; font-size: 16px; }
.tbl input:hover { border-color: var(--rule); }
.tbl input:focus { border-color: var(--green); background: #fff; outline: none; }
.tbl tr.bad td { background: var(--seal-soft); }

/* ── 바텀시트 / 모달 ── */
.scrim { position: fixed; inset: 0; z-index: 50; background: rgba(20, 30, 38, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; overflow: auto;
  background: var(--sheet); border-radius: 16px 16px 0 0; box-shadow: var(--shadow-sheet);
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  animation: sheet-in .22s ease-out;
}
@media (min-width: 700px) { .scrim { align-items: center; } .sheet { border-radius: 16px; } }
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--rule-strong); margin: 4px auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; }
.close-x { border: 0; background: transparent; font-size: 28px; line-height: 1; padding: 4px 10px; cursor: pointer; color: var(--muted); }
@keyframes sheet-in { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }

/* ── 금액 키패드 ── */
.amount-display { text-align: right; font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; padding: 8px 4px; border-bottom: 2px solid var(--ink); margin-bottom: 10px; min-height: 64px; }
.amount-display .unit { font-size: 22px; font-weight: 700; margin-left: 4px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button { min-height: 58px; font-size: 24px; font-weight: 700; border: 1px solid var(--rule-strong); background: #fff; border-radius: var(--radius-s); cursor: pointer; }
.keypad button:active { background: var(--green-soft); }
.quick { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.quick button { flex: 1 1 0; min-width: 90px; min-height: 46px; border: 1.5px solid var(--green); color: var(--green-dark); background: #fff; border-radius: var(--radius-s); font-weight: 700; font-size: 17px; cursor: pointer; }

/* ── 서명 패드 ── */
.sigpad { position: relative; border: 2px dashed var(--rule-strong); border-radius: var(--radius-m); background: #fff; touch-action: none; }
.sigpad canvas { display: block; width: 100%; height: 200px; border-radius: var(--radius-m); cursor: crosshair; }
.sigpad .hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #aab5bb; font-size: 22px; pointer-events: none; }
.sigpad .baseline { position: absolute; left: 24px; right: 24px; bottom: 44px; border-bottom: 1px solid var(--rule); pointer-events: none; }
.sig-thumb { height: 36px; width: auto; background: #fff; border: 1px solid var(--rule); border-radius: 4px; vertical-align: middle; }

/* ── 도장 (차감 완료) ── */
.stamp-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px 0 4px; }
.stamp {
  width: 190px; height: 190px; border-radius: 50%;
  border: 6px solid var(--seal); color: var(--seal);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transform: rotate(-12deg);
  box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 5px var(--seal);
  animation: stamp-press .38s cubic-bezier(.2, 1.4, .4, 1) both;
  text-align: center;
}
.stamp .s1 { font-size: 30px; font-weight: 900; letter-spacing: .1em; }
.stamp .s2 { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stamp .s3 { font-size: 13px; font-weight: 700; margin-top: 2px; }
@keyframes stamp-press { 0% { transform: rotate(-12deg) scale(1.9); opacity: 0; } 60% { opacity: 1; } 100% { transform: rotate(-12deg) scale(1); opacity: 1; } }
.balance-after { font-size: 18px; }
.balance-after b { font-size: 30px; font-variant-numeric: tabular-nums; }

/* ── 토스트 ── */
.toast-box { position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 480px); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--radius-s); font-size: 16px; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: sheet-in .2s ease-out; }
.toast.err { background: var(--seal); }

/* ── 잠금 화면 ── */
.lock { position: fixed; inset: 0; z-index: 90; background: var(--ink); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; }
.lock .dots { display: flex; gap: 14px; }
.lock .dots i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; }
.lock .dots i.on { background: #fff; }
.lock .keypad { width: min(320px, 90vw); }
.lock .keypad button { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.2); }

/* ── 단계 표시 ── */
.steps { counter-reset: s; display: flex; flex-direction: column; gap: 16px; }
.step { position: relative; padding-left: 52px; }
.step::before { counter-increment: s; content: counter(s); position: absolute; left: 0; top: 0; width: 36px; height: 36px; border-radius: 50%; background: var(--ink); color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.step.done::before { background: var(--green); content: "✓"; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 700; }
.fp { font-size: 30px; font-weight: 900; letter-spacing: .08em; font-variant-numeric: tabular-nums; color: var(--ink); }

hr.rule { border: 0; border-top: 1px solid var(--rule); margin: 16px 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
@media print {
  .appbar, .tabs, .actions, .no-print { display: none !important; }
  body { background: #fff; }
}
