/* 레이아웃: 한 열짜리 앱. 위에서 아래로 헤더, 남은 개수, 영수증형 목록. 입력창은 화면 아래에 고정 */
:root {
  --bg: #F1F3EE;
  --paper: #FFFFFF;
  --ink: #14201A;
  --muted: #667369;
  --line: #E3E8E0;
  --line2: #C5CEC1;
  --accent: #167A4B;
  --accent-ink: #FFFFFF;
  --accent-soft: #DFF0E6;
  --rec: #D8402F;
  --warn: #8A5A10;
  --warn-bg: #FBF0DC;
  --shadow: 0 1px 2px rgba(20, 32, 26, .05), 0 10px 28px rgba(20, 32, 26, .07);
  --c0: #3E9B5F; --c1: #D4553F; --c2: #4F8FD6; --c3: #8B6FCB; --c4: #C99A2E; --c5: #B5651D; --c6: #1FA3A3; --c7: #6B7B8C; --c8: #8A8F98;
  --display: "Black Han Sans", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --sans: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1512; --paper: #17211C; --ink: #E9F1EC; --muted: #93A59B; --line: #25332B; --line2: #3A4D41;
    --accent: #4CC393; --accent-ink: #062217; --accent-soft: #1B2E25; --rec: #FF6B58; --warn: #E8B75C; --warn-bg: #2B2314;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
    --c0: #5FBE80; --c1: #F07A64; --c2: #7AB0EE; --c3: #A992E6; --c4: #E3B853; --c5: #D88A45; --c6: #4CC7C7; --c7: #8E9EAF; --c8: #9AA0A9;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1512; --paper: #17211C; --ink: #E9F1EC; --muted: #93A59B; --line: #25332B; --line2: #3A4D41;
  --accent: #4CC393; --accent-ink: #062217; --accent-soft: #1B2E25; --rec: #FF6B58; --warn: #E8B75C; --warn-bg: #2B2314;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
  --c0: #5FBE80; --c1: #F07A64; --c2: #7AB0EE; --c3: #A992E6; --c4: #E3B853; --c5: #D88A45; --c6: #4CC7C7; --c7: #8E9EAF; --c8: #9AA0A9;
  color-scheme: dark;
}
* { 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(--sans); font-size: 16px; line-height: 1.5; word-break: keep-all; overflow-wrap: break-word;
  padding-block: max(8px, env(safe-area-inset-top, 0px)) 0;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
body.noscroll { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.app { max-width: 560px; margin: 0 auto; padding-block: 12px 150px; }

/* 헤더 */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding-top: 6px; }
.date { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: .02em; }
h1 { font: 400 46px/1.05 var(--display); margin: 6px 0 0; letter-spacing: -.01em; }
.head-actions { display: flex; align-items: center; gap: 10px; padding-bottom: 6px; }
.date-row { display: flex; align-items: center; gap: 10px; }
.refresh-btn { width: 32px; height: 32px; margin: -7px -6px -7px 0; flex: none; border: 0; background: transparent; color: var(--muted); border-radius: 50%; display: grid; place-items: center; padding: 0; }
.refresh-btn:hover { background: var(--line); color: var(--ink); }
.refresh-btn svg { width: 18px; height: 18px; }
.refresh-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line2); display: block; }
.dot.live { background: var(--accent); }
.dot.off { background: var(--warn); }
.fam-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 42px; border: 1px solid var(--line); background: var(--paper);
  border-radius: 999px; padding: 4px 14px 4px 6px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); }
.acct-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; min-width: 42px; border: 1px solid var(--line); background: var(--paper);
  border-radius: 999px; padding: 4px 14px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); }
.acct-btn.in { padding: 4px; }
.acct-btn .av { margin-left: 0; width: 32px; height: 32px; border-color: var(--paper); }
.avs { display: inline-flex; padding-left: 8px; }
.av { width: 28px; height: 28px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 600;
  border: 2px solid var(--paper); margin-left: -8px; position: relative; }
.avs .av:nth-child(1) { z-index: 4; }
.avs .av:nth-child(2) { z-index: 3; }
.avs .av:nth-child(3) { z-index: 2; }
.avs .av:nth-child(4) { z-index: 1; }
.av.plus { background: var(--accent-soft); color: var(--accent); font-size: 16px; }

/* 남은 개수 */
.summary { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 6px 16px; margin-top: 20px; }
.sum-main { display: flex; align-items: baseline; gap: 6px; }
.big { font: 400 54px/1 var(--display); font-variant-numeric: tabular-nums; }
.sum-label { color: var(--muted); font-size: 15px; }
.prog { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.prog i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .3s ease; }
.sum-sub { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); min-height: 19px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--line); border-radius: 12px; margin-top: 12px; }
.seg button { border: 0; background: transparent; border-radius: 9px; min-height: 40px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(20, 32, 26, .12); }

/* 영수증형 목록 */
.paper { margin-top: 14px; background: var(--paper); border-radius: 20px; padding: 4px 18px 12px; box-shadow: var(--shadow); min-width: 0; }
.grp h3 { display: flex; align-items: center; gap: 8px; margin: 18px 0 2px; font-size: 12.5px; font-weight: 600; letter-spacing: .06em; color: var(--muted); }
.grp h3 i { width: 8px; height: 8px; border-radius: 50%; background: var(--cc); display: block; }
.grp h3 em { font-style: normal; margin-left: auto; font-size: 12px; }
.li { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.grp .li:last-child { border-bottom: 0; }
.chk { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line2); background: transparent; display: grid; place-items: center;
  padding: 0; flex: none; color: transparent; transition: background .15s, border-color .15s, transform .15s; }
.chk svg { width: 14px; height: 14px; }
.chk.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chk:active { transform: scale(.88); }
.li-main { flex: 1; min-width: 0; }
.li-line { display: flex; align-items: baseline; min-width: 0; }
.nm { font-size: 16.5px; font-weight: 500; overflow-wrap: anywhere; min-width: 0; }
.lead { flex: 1; min-width: 14px; margin: 0 8px; border-bottom: 2px dotted var(--line2); transform: translateY(-3px); }
.q { font-size: 14.5px; font-weight: 500; white-space: nowrap; }
.li.done .nm { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line2); }
.li.done .q { color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 2px; font-size: 12.5px; color: var(--muted); }
.own { display: inline-flex; align-items: center; gap: 5px; }
.own i { width: 8px; height: 8px; border-radius: 50%; display: block; }
.more-btn { border: 0; background: transparent; color: var(--muted); width: 32px; height: 32px; margin: -3px -6px 0 0; border-radius: 8px; display: grid; place-items: center; flex: none; }
.more-btn:hover { background: var(--bg); }
.more-btn svg { width: 18px; height: 18px; }
.spacer { width: 0; flex: none; }
.edit { display: grid; gap: 8px; padding: 12px; margin: 6px -8px; background: var(--bg); border-radius: 14px; }

.empty { padding: 22px 0 18px; }
.empty-t { font: 400 26px/1.2 var(--display); }
.empty p { color: var(--muted); margin: 8px 0 14px; font-size: 14.5px; }
.chips { display: grid; gap: 8px; }
.chip { text-align: left; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: 14px; line-height: 1.4; }
.chip:hover { border-color: var(--accent); }
.foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; padding-inline: 6px; font-size: 14px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.link.left { justify-self: start; padding-left: 0; }
.tabs { margin: 0 0 14px; }
.link { border: 0; background: transparent; color: var(--accent); font-weight: 600; font-size: 14px; padding: 6px 4px; }

/* 입력창 */
.composer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0;
  padding-top: 28px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: linear-gradient(to top, var(--bg) 60%, transparent); pointer-events: none; }
.composer-in { max-width: 560px; margin: 0 auto; display: flex; align-items: flex-end; gap: 6px; background: var(--paper); border: 1px solid var(--line);
  border-radius: 28px; padding: 6px 6px 6px 18px; box-shadow: 0 8px 28px rgba(20, 32, 26, .16); pointer-events: auto; }
.composer-in:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; resize: none; max-height: 120px; padding: 11px 0; font-size: 16px; line-height: 1.4; }
.composer textarea::placeholder { color: var(--muted); }
.mic, .send { width: 46px; height: 46px; border-radius: 50%; border: 0; display: grid; place-items: center; flex: none; }
.mic svg, .send svg { width: 22px; height: 22px; }
.mic { background: var(--accent); color: var(--accent-ink); }
.send { background: var(--accent); color: var(--accent-ink); display: none; }
.composer.has-text .mic { background: var(--accent-soft); color: var(--accent); }
.composer.has-text .send { display: grid; }
.mic.on, .composer.has-text .mic.on { background: var(--rec); color: #fff; animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--rec) 45%, transparent); } 50% { box-shadow: 0 0 0 12px transparent; } }
.vstatus { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(88px + env(safe-area-inset-bottom, 0px)); z-index: 31;
  width: max-content; max-width: min(92vw, 520px); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 13.5px; text-align: center; }
.vstatus.err { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); border-radius: 14px; }

/* 시트 */
.scrim { position: fixed; inset: 0; background: rgba(10, 16, 13, .5); opacity: 0; transition: opacity .2s; z-index: 40; }
.scrim.open { opacity: 1; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 560px; margin: 0 auto; max-height: 88vh; max-height: 88dvh; overflow-y: auto;
  background: var(--paper); border-radius: 24px 24px 0 0; box-shadow: 0 -10px 40px rgba(0, 0, 0, .25); outline: 0;
  padding-top: 10px; padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: max(20px, env(safe-area-inset-right, 0px));
  transform: translateY(100%); transition: transform .22s ease; }
.sheet.open { transform: none; }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line2); margin: 0 auto 14px; }
.sheet h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 14px; font: 400 24px/1.2 var(--display); }
.sub { font: 400 13px var(--sans); color: var(--muted); }
#reviewSheet { padding-bottom: 0; }
.sheet-actions { display: flex; gap: 8px; position: sticky; bottom: 0; margin-top: 12px; background: var(--paper); border-top: 1px solid var(--line);
  padding-top: 12px; padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  margin-left: calc(-1 * max(20px, env(safe-area-inset-left, 0px))); margin-right: calc(-1 * max(20px, env(safe-area-inset-right, 0px)));
  padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: max(20px, env(safe-area-inset-right, 0px)); }
.sheet-actions .primary { flex: 1; }

.btn { border: 1px solid var(--line); background: var(--paper); border-radius: 12px; padding: 8px 14px; min-height: 44px; font-weight: 600; font-size: 15px; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.field { width: 100%; min-height: 42px; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 12px; font-size: 16px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.block { display: grid; gap: 10px; margin-bottom: 22px; }
.label { font-size: 12.5px; font-weight: 600; letter-spacing: .05em; color: var(--muted); }
.note { font-size: 13px; color: var(--muted); }
.err-text { color: var(--warn); }
.codebox { font-size: 21px; font-weight: 500; letter-spacing: .05em; background: var(--bg); border-radius: 14px; padding: 14px 16px; overflow-wrap: anywhere; }
.more > summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); list-style: none; padding: 4px 0; }
.more > summary::-webkit-details-marker { display: none; }
.fam { display: grid; gap: 6px; }
.fam-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.fam-row .av { margin-left: 0; border-color: var(--bg); flex: none; }
.fam-main { flex: 1; min-width: 0; }
.fam-name { font-weight: 600; overflow-wrap: anywhere; }

/* 확인하고 고치기 */
.rv { display: grid; gap: 8px; }
.rv-row { display: grid; grid-template-columns: auto minmax(0, 1fr) 62px 66px; gap: 6px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.rv-row.off { opacity: .45; }
.rv-row .full { grid-column: 2 / -1; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.rv-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.rv-row .field { min-height: 38px; padding: 4px 8px; background: var(--paper); }
.rv-row select.field { width: auto; min-height: 32px; padding: 2px 8px; font-size: 14px; }
.badge { font-size: 11.5px; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 9px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(92px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; width: max-content; max-width: min(92vw, 420px); }
.toast.err { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }

@media (max-width: 400px) {
  h1 { font-size: 38px; }
  .head { flex-wrap: wrap; }
  .head-actions { gap: 8px; }
  .acct-btn { padding: 4px 12px; }
  .fam-btn { padding-right: 10px; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .mic.on { animation: none; }
  .refresh-btn.spin svg { animation-duration: 2.4s; }
  .sheet, .scrim, .prog i, .chk { transition: none; }
}
