/* Bill splitter (แชร์บิล) */
.bs-banner { display: flex; gap: 8px; align-items: flex-start; }
.bs-mode { display: inline-flex; gap: 4px; padding: 4px; margin: 4px 0 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; }
.bs-mode button { border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; padding: 7px 16px; border-radius: 999px; cursor: pointer; }
.bs-mode button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.bs-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); gap: 16px; align-items: start; }
.bs-main { display: grid; gap: 14px; min-width: 0; }
.bs-card { padding: 18px; }
.bs-h { display: flex; align-items: center; gap: 10px; font-size: 1.02rem; margin: 0 0 12px; }
.bs-h span { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: .85rem; }

/* :where() keeps these base styles weak, so the sized inputs below (price, qty, parts …) win */
:where(#bs) input:not([type="checkbox"]):not([type="file"]), :where(#bs) select {
  width: 100%; min-width: 0; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 12px;
}
:where(#bs) input:focus, :where(#bs) select:focus, .bs-ocr-row input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
:where(#bs) input[readonly] { background: transparent; }
.bs-title { margin-bottom: 12px; font-weight: 600; }
.bs-linkbtn { border: 0; background: none; padding: 2px 4px; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.bs-people { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; margin-bottom: 10px; }
.bs-person { display: flex; align-items: center; gap: 8px; }
.bs-dot { flex: none; display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; color: #141312; font-weight: 700; font-size: .9rem; }
.bs-free { flex: none; border: 1px solid var(--line); background: none; color: var(--muted); font: inherit; font-size: .8rem; padding: 4px 9px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.bs-free[aria-pressed="true"] { background: var(--gold-soft); border-color: var(--gold); color: var(--gold); font-weight: 600; }
.bs-free[aria-pressed="true"]::before { content: "🎂 "; }
.bs-readonly .bs-free[aria-pressed="false"] { display: none; }
.bs-x { flex: none; width: 30px; height: 30px; border: 0; border-radius: 50%; background: none; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.bs-x:hover { background: var(--bad-soft); color: var(--bad); }
.bs-add { display: inline-flex; align-items: center; gap: 6px; border: 1px dashed var(--line); background: none; color: var(--text); font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 999px; cursor: pointer; }
.bs-add:hover { border-color: var(--accent); color: var(--accent); }
.bs-add svg { width: 16px; height: 16px; }
.bs-photo { border-style: solid; background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.bs-photo[hidden] { display: none; }
.bs-friends { display: grid; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.bs-friends[hidden] { display: none; }
.bs-friend-list { display: flex; flex-wrap: wrap; gap: 6px; }
.bs-friends .bs-linkbtn { justify-self: start; color: var(--muted); font-weight: 400; }

.bs-items { display: grid; gap: 10px; margin-bottom: 10px; }
.bs-item { padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.bs-item-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#bs .bs-item-name { flex: 1 1 180px; width: auto; }
.bs-item-money { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
#bs .bs-item-price { width: 104px; text-align: right; font-variant-numeric: tabular-nums; }
#bs .bs-item-qty { width: 56px; text-align: center; }
.bs-baht { color: var(--muted); }
.bs-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.bs-chip { --c: var(--accent); border: 1px solid var(--line); background: none; color: var(--muted); font: inherit; font-size: .85rem; padding: 4px 11px; border-radius: 999px; cursor: pointer; }
.bs-chip[aria-pressed="true"] { background: color-mix(in srgb, var(--c) 22%, transparent); border-color: var(--c); color: var(--text); font-weight: 600; }
.bs-chip:disabled { cursor: default; }
.bs-part { --c: var(--accent); display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 11px; border: 1px solid var(--c); border-radius: 999px; font-size: .85rem; }
#bs .bs-part input { width: 42px; padding: 3px 4px; text-align: center; border-radius: 999px; }
.bs-treat { font-size: .88rem; color: var(--gold); font-weight: 600; }
.bs-treat::before { content: "🎁 "; }
.bs-each { margin-left: auto; }
.bs-more { border: 0; background: var(--surface-2); color: var(--muted); width: 30px; height: 26px; border-radius: 999px; font: inherit; font-weight: 700; cursor: pointer; }
.bs-more[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); }
.bs-item-opts { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.bs-treat-pick { display: inline-flex; align-items: center; gap: 6px; }
#bs .bs-treat-pick select { width: auto; padding: 5px 10px; }
.bs-item-btns { display: flex; flex-wrap: wrap; gap: 8px; }

.bs-set { display: grid; gap: 12px; }
.bs-set-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.bs-label { min-width: 52px; font-weight: 600; }
.bs-num { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
#bs .bs-num input { width: 86px; text-align: right; }
#bs .bs-set select { width: auto; }
.bs-tg, .bs-seg button { border: 1px solid var(--line); background: none; color: var(--muted); font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 999px; cursor: pointer; }
.bs-tg[aria-pressed="true"], .bs-seg button[aria-pressed="true"] { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.bs-tg[aria-pressed="true"]::before { content: "✓ "; }
.bs-tg:disabled, .bs-seg button:disabled { cursor: default; }
.bs-seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.bs-payers { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.bs-payer { font-size: .95rem; padding: 7px 14px; }

.bs-result { position: sticky; top: 84px; padding: 18px; }
.bs-me-pick { display: grid; gap: 8px; padding: 14px; margin-bottom: 14px; border-radius: var(--radius-sm); background: var(--info-soft); }
.bs-me-pick[hidden] { display: none; }
.bs-me-names { display: flex; flex-wrap: wrap; gap: 8px; }
.bs-me-names .bs-chip { font-size: 1rem; padding: 8px 16px; color: var(--text); border-color: var(--c); }
.bs-me { padding: 16px; margin-bottom: 14px; border-radius: var(--radius-sm); border: 2px solid var(--accent); background: var(--surface-2); }
.bs-me[hidden] { display: none; }
.bs-me-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.bs-me-amt { font-size: 2.2rem; font-weight: 700; margin: 4px 0 0; color: var(--accent); font-variant-numeric: tabular-nums; }
.bs-me-amt + p { margin: 0 0 10px; }
.bs-me-qr img { display: block; width: 100%; max-width: 240px; padding: 12px; margin: 0 auto 10px; background: #fff; border-radius: 14px; cursor: zoom-in; }
.bs-me-qr img:not([src]) { visibility: hidden; }
.bs-me-sub { margin: 12px 0 4px; }
.bs-me-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: .9rem; }
.bs-me-items li { display: flex; justify-content: space-between; gap: 10px; }
.bs-me-items li span:last-child { font-variant-numeric: tabular-nums; color: var(--muted); }

.bs-total { display: grid; gap: 2px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.bs-total b { font-size: 2.3rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.bs-rows { display: grid; gap: 8px; margin: 14px 0 8px; }
.bs-row { display: grid; grid-template-columns: 32px 1fr auto; gap: 4px 10px; align-items: center; padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.bs-row.payer { background: var(--ok-soft); }
.bs-row.payer .bs-amt, .bs-row.payer .bs-who span { color: var(--ok); }
.bs-row.done .bs-amt { text-decoration: line-through; color: var(--muted); }
.bs-row.mine { outline: 2px solid var(--accent); }
.bs-who { display: grid; min-width: 0; }
.bs-who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bs-who span { color: var(--muted); }
.bs-row.done .bs-who span { color: var(--ok); }
.bs-amt { font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.bs-qr { grid-column: 2 / 4; }
.bs-qr img { display: block; width: 132px; height: 132px; padding: 8px; background: #fff; border-radius: 10px; cursor: zoom-in; }
.bs-qr img:not([src]) { visibility: hidden; }
.bs-row.done .bs-qr { display: none; }
.bs-pay { grid-column: 2 / 4; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: .9rem; }
.bs-paid { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.bs-paid input { width: 18px; height: 18px; accent-color: var(--ok); }
.bs-slip-note { flex-basis: 100%; font-size: .85rem; }
.bs-slip-note.ok { color: var(--ok); }
.bs-slip-note.warn { color: var(--gold); }
#bs-extra { margin: 4px 0 0; }
.bs-actions { display: grid; gap: 8px; margin-top: 14px; }
.bs-actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bs-actions .btn svg { width: 18px; height: 18px; }
.bs-actions [hidden] { display: none; }
.bs-line { background: #06c755; color: #fff; border-color: #06c755; font-weight: 700; }
.bs-line:hover { background: #05b04b; color: #fff; }

.bs-history { margin-top: 16px; }
.bs-history[hidden] { display: none; }
.bs-history-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.bs-hist { display: grid; gap: 2px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--text); text-decoration: none; }
.bs-hist:hover { border-color: var(--accent); }
.bs-hist.current { border-color: var(--accent); background: var(--accent-soft); }
.bs-hist-note { font-weight: 600; color: var(--gold); font-size: .9rem; }
.bs-hist-note.ok { color: var(--ok); }

.bs-readonly .bs-add, .bs-readonly .bs-x, .bs-readonly #bs-new, .bs-readonly .bs-mode { display: none; }

.bs-dialog { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; }
.bs-dialog::backdrop { background: rgb(0 0 0 / .55); }
.bs-dialog h3 { margin: 0 0 6px; }
.bs-ocr-list { display: grid; gap: 6px; margin: 12px 0; max-height: 50vh; overflow: auto; }
.bs-ocr-row { display: grid; grid-template-columns: 20px 1fr 100px; gap: 8px; align-items: center; }
.bs-ocr-row input { width: 100%; min-width: 0; font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 12px; }
.bs-ocr-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.bs-ocr-row input:last-child { text-align: right; }
.bs-ocr-flags { display: grid; gap: 6px; }
.bs-qr-big { width: min(380px, calc(100vw - 32px)); text-align: center; }
.bs-qr-big img { width: 100%; max-width: 300px; padding: 12px; background: #fff; border-radius: 14px; }
.bs-big-amt { font-size: 2rem; font-weight: 700; margin: 0 0 10px; color: var(--accent); }
.bs-slip-img { display: block; width: 100%; max-height: 60vh; object-fit: contain; margin: 8px 0; border-radius: 10px; background: #fff; }

@media (max-width: 900px) {
  .bs-layout { grid-template-columns: 1fr; }
  .bs-result { position: static; }
  .bs-readonly .bs-result { order: -1; }            /* a friend opening the link wants their QR first */
}
@media (max-width: 520px) {
  .bs-card, .bs-result { padding: 14px; }
  .bs-people { grid-template-columns: 1fr; }
  #bs .bs-item-name { flex-basis: calc(100% - 38px); }      /* name + delete on one line, price × qty below */
  .bs-item-money { flex: 1 1 100%; order: 2; }
  #bs .bs-item-price { flex: 1 1 auto; width: auto; }
  .bs-mode { display: flex; }
  .bs-mode button { flex: 1; }
  .bs-label { min-width: 0; }
}
