/* The desk around the paper: rich black, white type, hairlines. Phone first. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--desk); color: var(--pearl); font: 300 var(--text-m)/1.5 var(--ui); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) var(--gap) 10px; background: var(--desk); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; text-decoration: none; }
.brand img { width: clamp(104px, 26vw, 132px); height: auto; }
.tabs { display: flex; gap: clamp(14px, 3vw, 30px); }
.tabs a { position: relative; padding: 10px 0; text-decoration: none; font: 400 .9375rem/1 var(--ui); color: var(--muted); transition: color var(--fast) var(--ease); }
.tabs a:hover, .tabs a[aria-current="page"] { color: var(--pearl); }
.tabs a[aria-current="page"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: 2px; height: 1px; background: var(--pearl); }

main { padding: var(--gap); padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px)); }
.view { max-width: 1480px; margin: 0 auto; }
.view-new { display: grid; gap: var(--gap); }
@media (min-width: 1040px) { .view-new { grid-template-columns: minmax(380px, 460px) 1fr; align-items: start; } .preview-wrap { position: sticky; top: 84px; } }

.form { display: grid; gap: 30px; }
fieldset { margin: 0; padding: 0; border: 0; display: grid; gap: 14px; min-width: 0; }
legend, .h { padding: 0 0 2px; font: 500 1rem/1.2 var(--ui); color: var(--pearl); }
.row { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 12px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > span { font-size: var(--text-s); color: var(--muted); }
input, select, textarea { width: 100%; min-height: 46px; padding: 11px 12px; background: var(--field); border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 1rem; font-weight: 400; transition: border-color var(--fast) var(--ease); }
textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
input:hover, select:hover, textarea:hover { border-color: var(--line-2); }
:focus-visible { outline: 1px solid var(--pearl); outline-offset: 2px; }
input:focus, select:focus, textarea:focus { border-color: var(--pearl); }
input[aria-invalid="true"] { border-color: var(--danger); }

.seg { display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { min-height: 46px; border: 0; background: transparent; color: var(--muted); font-size: .9375rem; cursor: pointer; transition: background var(--fast) var(--ease), color var(--fast) var(--ease); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { color: var(--pearl); }
.seg button[aria-pressed="true"] { background: var(--pearl); color: var(--desk); font-weight: 500; }
.seg button:active { transform: scale(.98); }

.item { display: grid; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.item-head { display: flex; justify-content: space-between; align-items: center; font-size: var(--text-s); color: var(--faint); }
.link { padding: 6px 0; border: 0; background: none; color: var(--muted); font-size: var(--text-s); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link:hover { color: var(--pearl); }
.link.is-armed, .bill-who.is-armed { color: var(--danger); }
.add { min-height: 46px; border: 1px dashed var(--line-2); border-radius: var(--radius); background: transparent; color: var(--pearl); font-size: .9375rem; cursor: pointer; }
.add:hover { border-color: var(--pearl); }
.hint { margin: 0; font-size: var(--text-s); color: var(--danger); }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 22px; border: 1px solid var(--pearl); border-radius: var(--radius);
  background: transparent; color: var(--pearl); font-size: .9375rem; font-weight: 500; cursor: pointer; transition: transform var(--fast) var(--ease), background var(--fast) var(--ease); }
.btn:active { transform: scale(.97); }
.btn:focus-within { outline: 1px solid var(--pearl); outline-offset: 2px; }
.btn.primary { background: var(--pearl); color: var(--desk); }
.btn.quiet { border-color: transparent; color: var(--muted); }
.btn.quiet:hover { color: var(--pearl); }
.btn.is-armed { border-color: var(--danger); color: var(--danger); }

.actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; gap: 10px; justify-content: flex-end; align-items: center;
  padding: 12px var(--gap) calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--desk); border-top: 1px solid var(--line); }
.actions .status { margin: 0 auto 0 0; font-size: var(--text-s); color: var(--muted); }
.actions .status:empty { display: none; }
.actions .status.is-error { color: var(--danger); }
.act-btns { display: flex; gap: 10px; }
@media (max-width: 520px) {
  .actions { flex-wrap: wrap; }
  .actions .status { flex-basis: 100%; text-align: center; }
  .act-btns { flex: 1; } .act-btns .btn { flex: 1; padding: 0 8px; }
}

.preview-wrap { display: grid; justify-items: center; }
.preview-label { justify-self: stretch; margin: 0 0 10px; font: 500 1rem/1.2 var(--ui); }
.preview { position: relative; overflow: hidden; border-radius: 1px; box-shadow: 0 30px 80px -30px rgb(0 0 0 / .9), 0 0 0 1px rgb(255 255 255 / .04); }
.preview .sheet { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
/* where a long bill turns to page 2 */
.preview::after { content: ""; position: absolute; left: 0; right: 0; top: var(--page-break, -10px); border-top: 1px dashed #9a968f; pointer-events: none; }

/* bills */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 18px; }
.toolbar .field { flex: 1 1 240px; }
.list { display: grid; list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.bill { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; padding: 16px 4px; border-bottom: 1px solid var(--line); }
.bill-main { display: grid; gap: 2px; text-align: left; padding: 0; border: 0; background: none; cursor: pointer; }
.bill-main:hover .bill-who { text-decoration: underline; text-underline-offset: 4px; }
.bill-who { font: 400 1.25rem/1.2 var(--serif); }
.bill-sub { font-size: var(--text-s); color: var(--muted); }
.bill-side { display: grid; justify-items: end; gap: 4px; }
.bill-total { font-weight: 400; font-variant-numeric: tabular-nums; }
.chip { font-size: var(--text-s); color: var(--muted); }
.chip.due { color: var(--pearl); }
.bill-acts { grid-column: 1 / -1; display: flex; gap: 18px; }
.empty { padding: 40px 0; color: var(--muted); font-size: var(--text-s); }
.panel { margin-top: 36px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); display: grid; gap: 12px; }
.panel p { margin: 0; color: var(--muted); font-size: var(--text-s); }
.panel .h { color: var(--pearl); font-size: 1rem; }
.panel .row-btns { display: flex; flex-wrap: wrap; gap: 10px; }

/* details */
.details { max-width: 720px; display: grid; gap: 32px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.toggle input { flex: none; width: 46px; min-height: 26px; height: 26px; appearance: none; border-radius: 13px; padding: 0; position: relative; background: var(--field); cursor: pointer; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: transform var(--fast) var(--ease), background var(--fast) var(--ease); }
.toggle input:checked { background: var(--pearl); }
.toggle input:checked::after { transform: translateX(20px); background: var(--desk); }

#print-root { display: none; }
/* measured off screen before printing (see print.js) */
#print-root.measuring { display: block; position: absolute; left: -10000px; top: 0; visibility: hidden; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }

/* one margin on every page, so Chrome and Safari agree; the sheet itself has no top or bottom padding in print */
@page { size: A4; margin: 10mm 0 11mm; }
@media print {
  :root { color-scheme: light; }
  html, body { background: #fff !important; }
  #app { display: none !important; }
  #print-root { display: block !important; position: static; visibility: visible; }
}
