:root {
  --paper: #f6f1e7;
  --card: #fffdf8;
  --ink: #1d2422;
  --muted: #5f6b67;
  --line: #e2d9c8;
  --green: #1f3a34;
  --accent: #e8593c;
  --ok: #2f7d4f;
  --warn: #b5541b;
  --radius: 14px;
  --shadow: 0 1px 0 rgba(29, 36, 34, 0.04), 0 6px 18px rgba(29, 36, 34, 0.06);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  padding-bottom: 76px;
}
button, input, select, textarea { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  max-width: 860px; margin: 0 auto; padding: 18px 18px 6px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 1.45rem; letter-spacing: -0.01em; font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; }
.sub { margin: 0; color: var(--muted); font-size: 0.92rem; }
.top-actions { display: flex; gap: 8px; }
.count { display: inline-block; min-width: 1.4em; padding: 0 6px; border-radius: 99px; background: var(--green); color: #fff; font-size: 0.75rem; text-align: center; margin-left: 4px; }
main { max-width: 860px; margin: 0 auto; padding: 6px 18px 24px; }
.titlebar { display: flex; align-items: baseline; gap: 12px; margin: 10px 0 14px; flex-wrap: wrap; }
.bill-title {
  flex: 1 1 260px; border: 0; border-bottom: 2px dashed var(--line); background: transparent;
  font-size: 1.3rem; font-family: Georgia, "Iowan Old Style", serif; padding: 6px 2px;
}
.bill-title:focus { outline: none; border-bottom-color: var(--accent); }
.bill-date { color: var(--muted); font-size: 0.9rem; }
.step { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 16px 18px; margin-bottom: 16px; }
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.step-head h2 { margin: 0; font-size: 1.1rem; }
.step-no { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--green); color: #fff; font-weight: 700; font-size: 0.9rem; flex: none; }
.step-aside { margin-left: auto; color: var(--muted); font-size: 0.88rem; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 6px 0 10px; }
.empty { color: var(--muted); font-style: italic; margin: 8px 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
button { cursor: pointer; border-radius: 10px; border: 1px solid transparent; padding: 9px 14px; min-height: 42px; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(232, 89, 60, 0.35); outline-offset: 2px; }
.primary { background: var(--green); color: #fff; font-weight: 600; }
.primary:hover { background: #17302a; }
.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.ghost { background: transparent; border-color: var(--line); }
.ghost:hover { background: #f1eadc; }
.danger { color: #a3321d; }
.tabs { display: flex; gap: 4px; background: #efe7d7; padding: 4px; border-radius: 12px; width: fit-content; max-width: 100%; margin-bottom: 12px; }
.tab { background: transparent; border: 0; min-height: 36px; padding: 6px 14px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.tab[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.drop {
  display: grid; justify-items: center; gap: 4px; text-align: center; cursor: pointer;
  border: 2px dashed #cbbfa8; border-radius: 12px; padding: 22px 16px; background: #fbf7ef; color: var(--green);
}
.drop:hover, .drop.over { border-color: var(--accent); background: #fff6ef; }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.drop:focus-within { outline: 3px solid rgba(232, 89, 60, 0.35); outline-offset: 2px; }
.drop-main { font-weight: 700; color: var(--ink); }
.drop-sub { color: var(--muted); font-size: 0.86rem; }
.ocr { margin-top: 12px; }
.ocr-row { display: flex; gap: 12px; align-items: center; }
.ocr-row img { width: 64px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #eee; }
.ocr-status { flex: 1; }
.ocr-status p { margin: 0 0 6px; }
.bar { height: 8px; border-radius: 99px; background: #ece3d2; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.25s ease; }
textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fffefb; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; resize: vertical; }
.msg { margin: 8px 0 0; font-size: 0.92rem; color: var(--muted); }
.msg.err { color: #a3321d; }
.add-person { display: flex; gap: 8px; }
.add-person input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fffefb; }
.people { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.person { display: inline-flex; align-items: center; gap: 6px; padding: 4px 4px 4px 10px; border-radius: 99px; background: color-mix(in srgb, var(--c) 16%, white); border: 1px solid color-mix(in srgb, var(--c) 45%, white); font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.person button { min-height: 28px; width: 28px; padding: 0; border-radius: 50%; background: transparent; color: var(--muted); }
.person button:hover { background: rgba(0,0,0,0.06); }
.items, .adjs { list-style: none; padding: 0; margin: 0; }
.item { border-top: 1px solid var(--line); padding: 10px 0; }
.item:first-child { border-top: 0; }
.item.unclaimed .item-main { box-shadow: inset 3px 0 0 var(--warn); padding-left: 8px; }
.item-main { display: grid; grid-template-columns: 54px 1fr 104px 36px; gap: 8px; align-items: center; }
.item input, .adj input, .adj select { border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; background: transparent; min-width: 0; width: 100%; }
.item input:hover, .adj input:hover, .adj select:hover { border-color: var(--line); }
.item input:focus, .adj input:focus, .adj select:focus { border-color: var(--accent); background: #fff; outline: none; }
.qty { text-align: center; }
.price { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.icon-btn { min-height: 32px; width: 32px; padding: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 1.1rem; }
.icon-btn:hover { background: #f1eadc; color: #a3321d; }
.who { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: center; }
.who .tag {
  min-height: 32px; padding: 3px 10px; border-radius: 99px; font-size: 0.86rem; font-weight: 600;
  background: transparent; border: 1px dashed #c9bda7; color: var(--muted);
}
.who .tag[aria-pressed="true"] { background: color-mix(in srgb, var(--c) 20%, white); border: 1px solid var(--c); color: var(--ink); }
.who .all { border-style: solid; }
.who .note { color: var(--muted); font-size: 0.82rem; margin-left: 4px; }
.minor { font-size: 0.98rem; margin: 18px 0 6px; }
.minor span { color: var(--muted); font-weight: 400; font-size: 0.86rem; margin-left: 6px; }
.adj { display: grid; grid-template-columns: 1fr 76px 96px 36px; gap: 8px; align-items: center; padding: 4px 0; }
.adj .val { text-align: right; font-variant-numeric: tabular-nums; }
.chips-row { margin-top: 6px; }
.chip-btn { min-height: 34px; padding: 4px 12px; border-radius: 99px; background: #efe7d7; border: 0; font-size: 0.88rem; font-weight: 600; }
.chip-btn:hover { background: #e7dcc7; }
.check { margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: #f3efe6; font-size: 0.93rem; }
.check:empty { display: none; }
.check.ok { background: #e8f3ec; color: #1f5a37; }
.check.warn { background: #fbeee3; color: #7a3a12; }
.check strong { font-variant-numeric: tabular-nums; }
.payer { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.payer select { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fffefb; min-height: 42px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.pcard { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fffefb; border-top: 5px solid var(--c); }
.pcard h3 { margin: 0; font-size: 1rem; display: flex; justify-content: space-between; gap: 8px; }
.pcard .amt { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; margin: 2px 0; }
.pcard .owes { margin: 0 0 6px; font-size: 0.9rem; color: var(--green); font-weight: 600; }
.pcard .owes.payer-note { color: var(--muted); }
.pcard details { font-size: 0.88rem; color: var(--muted); }
.pcard summary { cursor: pointer; }
.pcard ul { list-style: none; margin: 6px 0 0; padding: 0; }
.pcard li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.pcard li span:last-child { font-variant-numeric: tabular-nums; }
.totalbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center; align-items: center; gap: 16px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); background: var(--green); color: #fff; font-size: 0.95rem;
}
.totalbar strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
#tb-flag { color: #ffd9c9; }
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 16px; width: min(520px, calc(100vw - 24px)); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(20, 26, 24, 0.45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; font-size: 1.15rem; }
.bills { list-style: none; padding: 0; margin: 0; max-height: 60vh; overflow: auto; }
.bill { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding: 8px 0; }
.bill:first-child { border-top: 0; }
.bill button.open { flex: 1; text-align: left; background: transparent; border: 0; padding: 6px 4px; }
.bill .meta { display: block; color: var(--muted); font-size: 0.84rem; }
.bill.current { background: #f6efe1; border-radius: 10px; }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 10; font-size: 0.92rem; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.foot { max-width: 860px; margin: 0 auto; padding: 0 18px 24px; color: var(--muted); font-size: 0.85rem; }
@media (max-width: 560px) {
  .top { padding-top: 14px; }
  .brand h1 { font-size: 1.25rem; }
  .sub { font-size: 0.84rem; }
  .item-main { grid-template-columns: 44px 1fr 86px 32px; gap: 4px; }
  .adj { grid-template-columns: 1fr 64px 80px 32px; gap: 4px; }
  .step { padding: 14px 12px 16px; }
  .totalbar { gap: 10px; font-size: 0.88rem; }
}
@media (min-width: 1100px) {
  .top, .foot { max-width: 1220px; }
  main {
    max-width: 1220px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    column-gap: 22px;
    align-items: start;
  }
  .titlebar { grid-column: 1 / -1; }
  #step-receipt, #step-people, #step-items { grid-column: 1; }
  #step-settle { grid-column: 2; grid-row: 2 / span 3; position: sticky; top: 16px; max-height: calc(100vh - 100px); overflow: auto; }
  #step-settle .cards { grid-template-columns: 1fr; }
  .totalbar { justify-content: flex-end; padding-right: max(18px, calc((100vw - 1220px) / 2 + 18px)); }
}
