:root {
  --bg: #f7f6f3; --surface: #fff; --line: #eaeaea; --ink: #2f3437; --muted: #6b6a66; --primary: #111;
  --red-bg: #fdebec; --red: #9f2f2d; --green-bg: #edf3ec; --green: #346538;
  --blue-bg: #e1f3fe; --blue: #1f6c9f; --yellow-bg: #fbf3db; --yellow: #956400;
  --r: 8px;
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.pad { padding: 16px; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.brand { font-weight: 700; text-decoration: none; }
.top nav { display: flex; gap: 4px; }
.top nav a { text-decoration: none; padding: 6px 10px; border-radius: 6px; color: var(--muted); font-size: 15px; }
.top nav a[aria-current="page"] { color: var(--ink); background: var(--bg); font-weight: 600; }

main { max-width: 560px; margin: 0 auto; padding: 12px 12px 24px; display: grid; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.card h2 { font-size: 15px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }

/* 정산 */
.settle .who { font-size: 22px; font-weight: 700; margin: 0; }
.settle .how { font-size: 18px; margin: 2px 0 12px; }
.settle.done { background: var(--green-bg); border-color: transparent; }
.settle.done .who { color: var(--green); }
.settle.hold { background: var(--red-bg); border-color: transparent; }
.settle.hold .who { color: var(--red); }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px; min-width: 0; }
.kpi span { display: block; font-size: 13px; color: var(--muted); }
.kpi b { display: block; font-size: 17px; overflow-wrap: anywhere; }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.rows li:last-child { border-bottom: 0; }
details summary { cursor: pointer; color: var(--muted); padding: 4px 0; }

.btn { display: inline-flex; justify-content: center; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: #333; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.wide { width: 100%; }
.btn.danger { color: var(--red); }

.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 9999px; white-space: nowrap; }
.tag.red { background: var(--red-bg); color: var(--red); }
.tag.green { background: var(--green-bg); color: var(--green); }
.tag.blue { background: var(--blue-bg); color: var(--blue); }
.tag.yellow { background: var(--yellow-bg); color: var(--yellow); }

/* 아래 적기 버튼 */
.write { position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
.write button { min-height: 48px; border-radius: 6px; border: 0; background: var(--primary); color: #fff; font-weight: 600; font-size: 16px; cursor: pointer; }

/* 입력 창 */
dialog { width: 100%; max-width: 560px; max-height: 92dvh; overflow-x: hidden; margin: auto auto 0; border: 0; border-radius: 12px 12px 0 0; padding: 0; color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .3); }
.sheet { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 14px; }
.sheet h2 { margin: 0; font-size: 19px; }
.field { display: grid; gap: 6px; }
.field > span, .field legend { font-size: 14px; color: var(--muted); padding: 0; }
fieldset.field { border: 0; margin: 0; padding: 0; }
.field input, .field select, .field textarea { min-height: 44px; padding: 8px 10px; border: 1px solid #d6d5d1; border-radius: 6px; background: var(--surface); width: 100%; font-size: 16px; }
.field input.money { font-size: 24px; font-weight: 700; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { flex: 1 1 0; min-width: 64px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; justify-content: center; align-items: center; min-height: 44px; border: 1px solid #d6d5d1; border-radius: 6px; cursor: pointer; background: var(--surface); }
.seg input:checked + span { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }
.hint { font-size: 14px; color: var(--muted); margin: -6px 0 0; }
.note { background: var(--yellow-bg); color: var(--yellow); border-radius: 6px; padding: 8px 10px; font-size: 14px; margin: 0; }
.err { background: var(--red-bg); color: var(--red); border-radius: 6px; padding: 8px 10px; margin: 0; }
.actions { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
.actions.three { grid-template-columns: 1fr 1fr 2fr; }
.check { display: flex; gap: 8px; align-items: center; min-height: 44px; }
.check input { width: 22px; height: 22px; }

/* 기록 */
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.tabs button { min-height: 40px; padding: 0 2px; white-space: nowrap; font-size: 15px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; }
.tabs button[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }
.rec { width: 100%; text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 0; background: none; border: 0;
  border-bottom: 1px solid var(--line); cursor: pointer; }
.rec .sub { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.rec.cancelled .main, .rec.cancelled .amt { text-decoration: line-through; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%); margin: 0; z-index: 4;
  background: var(--primary); color: #fff; padding: 8px 14px; border-radius: 6px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

.help h3 { font-size: 16px; margin: 16px 0 4px; }
.help p, .help li { margin: 4px 0; }

.login { display: grid; gap: 14px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
table.rt { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
table.rt th, table.rt td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
table.rt th:first-child, table.rt td:first-child { text-align: left; }
table.rt th { color: var(--muted); font-weight: 500; }
.sheet > .actions:last-child { position: sticky; bottom: 0; background: var(--surface); margin: 0 -16px calc(-16px - env(safe-area-inset-bottom));
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.nowrap { white-space: nowrap; }
@media (max-width: 360px) { .kpi b { font-size: 15px; } .kpi { padding: 8px; } }
