:root {
  --bg: #000; --card: #1c1c1e; --card2: #2c2c2e; --line: #3a3a3c;
  --text: #fff; --muted: #8e8e93; --dim: #636366;
  --accent: #ff9f0a; --income: #30d158; --info: #64d2ff; --danger: #ff453a; --purple: #bf5af2;
  --top: env(safe-area-inset-top, 0px); --bottom: env(safe-area-inset-bottom, 0px);
  --sheet-h: 260px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.35 -apple-system, "SF Pro Text", "Apple SD Gothic Neo", "Pretendard", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
body.modal-open { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: var(--text); background: transparent; border: 0; outline: none; text-align: right; min-width: 0; }
/* 확대 막기: 두 번 탭 확대 금지, 입력칸은 16px 이상이어야 iOS가 자동 확대하지 않는다 */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
input, select, textarea { font-size: 16px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
/* 메인 화면은 세로로 쌓고, 기본(rest) 상태의 하단 시트가 남는 높이를 채워 바닥에 검은 여백이 보이지 않게 한다 */
body:not(.login-page) { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.app { width: 100%; max-width: 430px; margin: 0 auto; padding: calc(var(--top) + 8px) 0 16px; }
body.sheet-floating .app { padding-bottom: calc(var(--sheet-h) + var(--bottom) + 16px); }

.top { display: flex; justify-content: space-between; align-items: center; padding: 4px 20px 0; color: var(--muted); }
.top .link { color: var(--muted); font-size: 14px; }
.icons { display: flex; gap: 4px; }
.icon-btn { display: flex; align-items: center; justify-content: center; gap: 6px; width: 44px; height: 44px; color: var(--muted); }
.icon-btn:active { color: var(--accent); }
.icon-btn .icon { width: 22px; height: 22px; flex: none; }
.sync-btn { width: auto; padding: 0 4px; justify-content: flex-start; }
@keyframes sheet-icon-spin { to { transform: rotate(360deg); } }
.icon.spinning { animation: sheet-icon-spin .9s linear infinite; }
.banner { display: block; margin: 10px 16px 0; width: calc(100% - 32px); text-align: left; background: rgba(255, 159, 10, .15); color: var(--accent); border-radius: 12px; padding: 10px 14px; font-weight: 600; }
.banner[hidden] { display: none; }
.danger-banner { display: flex; align-items: center; gap: 10px; background: rgba(255, 69, 58, .18); color: var(--danger); }
.danger-banner[hidden] { display: none; }
.danger-banner span { flex: 1; }
.danger-banner button { flex: none; background: var(--danger); color: #fff; border-radius: 14px; padding: 7px 12px; font-weight: 600; font-size: 13px; }
.danger-banner button:disabled { opacity: .5; }
#addBtn[hidden] { display: none; }

.hero { padding: 12px 20px; }
.big { font: 700 44px/1.1 -apple-system, system-ui, sans-serif; letter-spacing: -.5px; margin: 4px 0 12px; }
.bar { height: 8px; background: var(--card); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #ff375f); transition: width .3s; }
.bar-cap { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); margin-top: 5px; }
.pills { display: flex; gap: 8px; margin-top: 10px; }
.pills div { flex: 1; background: var(--card); border-radius: 14px; padding: 10px 12px; }
.pills span { font-size: 11px; }
.pills b { display: block; font-size: 18px; margin-top: 3px; }
.c-use { color: var(--accent); } .c-card { color: var(--info); }

.month { display: flex; justify-content: space-between; align-items: center; padding: 2px 20px 6px; font-weight: 600; font-size: 17px; }
.month-nav { display: flex; align-items: center; }
.month-nav button { color: var(--accent); font-size: 22px; padding: 0 8px; min-height: 36px; display: inline-flex; align-items: center; }
.month-nav .icon-sm { width: 16px; height: 16px; }
/* 년/월 선택: 보이는 글자 위에 투명한 month 입력을 겹쳐 두고 누르면 iOS 휠 선택기가 뜬다 */
.month-pick { position: relative; display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.month-pick .caret { font-size: 11px; color: var(--muted); }
.month-pick input { position: absolute; inset: 0; opacity: 0; width: 100%; font-size: 16px; cursor: pointer; }
/* 입력 시트의 날짜도 다른 칸처럼 오른쪽 정렬 (iOS는 날짜 입력을 가운데 정렬한다) */
.field input[type="date"] { text-align: right; justify-content: flex-end; }
.field input[type="date"]::-webkit-date-and-time-value { text-align: right; }
.notice { margin: 0 16px 8px; padding: 10px 12px; border-radius: 12px; background: var(--card); color: var(--muted); font-size: 13px; }
.cal { padding: 0 10px; }
.grid7 { display: grid; grid-template-columns: repeat(7, 1fr); }
.dow div { text-align: center; font-size: 11px; color: var(--dim); padding-bottom: 4px; }
.day { position: relative; height: 52px; margin: 2px; border-radius: 12px; background: var(--card); padding: 5px 0 0 7px; font-size: 13px; line-height: 1.2; color: #aeaeb2; text-align: left; display: flex; align-items: flex-start; justify-content: flex-start; }
.day.empty { background: transparent; }
.day.has { background: var(--card2); color: var(--text); }
.day.sel { outline: 2px solid var(--accent); }
.day.today { font-weight: 700; }
/* 일요일 빨강, 토요일 파랑 (직접 결제 금액의 하늘색과 구분되는 진한 파랑) */
.dow .sun, .day.sun { color: var(--danger); }
.dow .sat, .day.sat { color: #0a84ff; }
.day .amt { position: absolute; left: 6px; bottom: 5px; font-size: 10px; font-weight: 600; }
.amt.use, .num.use { color: var(--accent); }
.amt.income, .num.income { color: var(--income); }
/* 내가 직접 결제한 금액은 카드 결제 색으로 */
.amt.card, .num.card { color: var(--info); }
.day .mark { position: absolute; right: 5px; top: 3px; font-size: 10px; }
.day .dot { position: absolute; right: 7px; bottom: 7px; width: 6px; height: 6px; border-radius: 50%; }
.dot.pending { background: var(--info); } .dot.failed { background: var(--danger); }

.day-sheet { width: 100%; max-width: 430px; margin: 0 auto; background: var(--card); border-radius: 26px 26px 0 0; padding: 0 16px var(--bottom); transition: height .25s; display: flex; flex-direction: column; }
.day-sheet[data-state="rest"] { position: relative; height: auto; box-shadow: none; flex: 1 0 auto; }
.day-sheet[data-state="half"], .day-sheet[data-state="full"] { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; box-shadow: 0 -8px 24px rgba(0, 0, 0, .5); }
.day-sheet[data-state="half"] { height: calc(var(--sheet-h) + var(--bottom)); }
.day-sheet[data-state="full"] { height: 72vh; }
.day-sheet.dragging { transition: none; }
/* 손잡이: 보이는 막대는 36×5지만, 시트 폭 전체 × 28px을 누르고 끌 수 있다 */
.grab { display: flex; align-items: center; justify-content: center; width: calc(100% + 32px); height: 28px; margin: 0 -16px 4px; flex: none; touch-action: none; -webkit-user-select: none; user-select: none; }
.grab::before { content: ''; width: 36px; height: 5px; border-radius: 3px; background: #48484a; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; min-height: 40px; margin-bottom: 8px; touch-action: none; -webkit-user-select: none; user-select: none; }
.sheet-head b { font-size: 17px; }
.sheet-head small { color: var(--muted); font-size: 12px; margin-left: 6px; }
.btn { background: var(--accent); color: #000; font-weight: 600; font-size: 13px; border-radius: 16px; padding: 6px 12px; touch-action: auto; }
.day-list { overflow-y: auto; flex: 1; padding-bottom: 12px; }
.day-sheet[data-state="rest"] .day-list { flex: none; overflow-y: visible; }
.item { width: 100%; display: flex; justify-content: space-between; align-items: center; background: var(--card2); border-radius: 14px; padding: 11px 14px; margin-bottom: 8px; text-align: left; }
.item small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.badge { font-size: 10px; padding: 2px 6px; border-radius: 6px; margin-left: 4px; vertical-align: 2px; }
.badge.transfer { background: rgba(191, 90, 242, .18); color: var(--purple); }
.badge.auto { background: var(--line); color: #aeaeb2; }
.status { display: inline-block; font-size: 11px; margin-top: 4px; }
.item.deleting { opacity: .45; }
.status.pending { color: var(--info); } .status.failed { color: var(--danger); } .status.review { color: var(--accent); }
.empty-text { color: var(--dim); text-align: center; margin: 24px 0; }

.dim { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 20; }
.modal { position: fixed; left: 0; right: 0; bottom: 0; top: calc(var(--top) + 34px); max-width: 430px; margin: 0 auto; background: var(--card); border-radius: 26px 26px 0 0; padding: 8px 16px calc(var(--bottom) + 16px); overflow-y: auto; z-index: 21; }
.modal .fh { display: flex; justify-content: space-between; align-items: center; font-size: 17px; margin: 2px 0 14px; }
.modal .fh .x { color: var(--muted); } .modal .fh .ok { color: var(--accent); font-weight: 600; }
.seg { display: flex; background: var(--bg); border-radius: 9px; padding: 2px; font-size: 13px; margin-bottom: 14px; }
.seg button { flex: 1; text-align: center; padding: 7px 0; border-radius: 7px; color: #aeaeb2; }
.seg button.on { background: #48484a; color: var(--text); font-weight: 600; }
.group { background: var(--card2); border-radius: 12px; margin-bottom: 14px; }
.field { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border-top: .5px solid var(--line); }
.field:first-child { border-top: 0; }
.field > span { flex: none; }
.field input, .field select { flex: 1; }
.field.zero > span, .field.zero input { color: var(--dim); }
.me-tag { color: var(--accent); font-size: 11px; margin-left: 4px; }
.glabel { font-size: 12px; color: var(--muted); margin: 0 4px 6px; display: flex; justify-content: space-between; gap: 8px; }
.ok-text { color: var(--income); } .error { color: var(--danger); font-size: 13px; margin: 0 4px 10px; }
.preview { font-size: 12px; color: var(--muted); margin: 0 4px 10px; line-height: 1.5; }
.save { display: block; width: 100%; background: var(--accent); color: #000; text-align: center; font-weight: 700; font-size: 17px; border-radius: 14px; padding: 15px; }
.save:disabled { opacity: .35; }
.danger-btn { display: block; width: 100%; margin-top: 10px; padding: 13px; border-radius: 14px; background: rgba(255, 69, 58, .15); color: var(--danger); font-weight: 600; }
.ghost-btn { display: block; width: 100%; margin-top: 10px; padding: 13px; border-radius: 14px; background: var(--card2); color: var(--info); font-weight: 600; }
.danger-btn:disabled, .ghost-btn:disabled { opacity: .5; }

.toast { position: fixed; left: 50%; bottom: calc(var(--sheet-h) + var(--bottom) + 16px); transform: translateX(-50%); background: rgba(58, 58, 60, .95); color: var(--text); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30; max-width: 360px; text-align: center; }

.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 370px; }
.login h1 { font-size: 28px; margin: 0 0 4px; }
.login .muted { margin: 0 0 24px; }
.login .field input { text-align: left; }

.lead { font-size: 13px; color: #aeaeb2; line-height: 1.45; margin: 0 2px 12px; }
.cell-card, .entry-card { background: var(--card2); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; }
.cell-card .t { font-weight: 600; display: flex; justify-content: space-between; }
.cell-card .warn { color: var(--accent); }
.vals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0; }
.vals div { background: var(--card); border-radius: 10px; padding: 7px 8px; }
.vals span { display: block; font-size: 10px; color: var(--muted); }
.vals b { font-size: 14px; }
.vals .down b { color: var(--danger); }
.cell-card .seg, .entry-card .seg { background: var(--card); margin: 0 0 8px; }
.final { display: flex; justify-content: space-between; align-items: center; background: var(--card); border-radius: 10px; padding: 9px 12px; }
.final input, .final b { color: var(--accent); font-size: 17px; font-weight: 700; }
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 10px; padding: 0 16px; }
.chips button { font-size: 13px; padding: 6px 12px; border-radius: 16px; background: var(--card2); color: #aeaeb2; white-space: nowrap; }
.chips button.on { background: var(--accent); color: #000; font-weight: 600; }
.dayh { font-size: 12px; color: var(--muted); padding: 10px 4px 6px; }
.hist { background: var(--card2); border-radius: 14px; overflow: hidden; }
.hrow { display: flex; gap: 12px; padding: 11px 14px; border-top: .5px solid var(--line); align-items: flex-start; width: 100%; text-align: left; }
.hrow:first-child { border-top: 0; }
.hrow .ic { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; flex: none; background: var(--line); }
.hrow .b { flex: 1; font-size: 14px; }
.hrow .b small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.hrow .tm { color: var(--dim); font-size: 12px; }
.diff { margin-top: 6px; background: var(--card); border-radius: 8px; padding: 7px 9px; font-size: 12px; color: #aeaeb2; line-height: 1.5; }
.diff s { color: var(--danger); } .diff em { color: var(--income); font-style: normal; }
.ic.ok { background: rgba(48, 209, 88, .18); } .ic.warn { background: rgba(255, 159, 10, .18); } .ic.info { background: rgba(100, 210, 255, .18); } .ic.danger { background: rgba(255, 69, 58, .18); }
.token-box { background: var(--card2); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; word-break: break-all; font: 13px ui-monospace, Menlo, monospace; }
pre.code { background: var(--card2); border-radius: 12px; padding: 12px; font-size: 11px; overflow-x: auto; color: #aeaeb2; }

/* 직접 결제: 인원별 분배 펼치기 버튼 */
.split-toggle { display: block; width: 100%; margin: -4px 0 14px; padding: 11px 14px; border-radius: 12px; background: var(--card2); color: var(--info); font-weight: 600; text-align: left; }
.split-toggle::after { content: '›'; float: right; color: var(--muted); }
.split-toggle.on { color: var(--muted); }
.split-toggle.on::after { content: '⌃'; }
