/* Split a receipt (tools.runemic.com/split-receipt). Class names start with tsp- (tools.css rule: t…).
   Four steps (Items, People, Who had what, Who owes) with a bar at the bottom of the screen; phone first. */
.tsplit { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
#sp-editor { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
#sp-editor[hidden] { display: none; }
.tsp-alt { text-align: center; margin: 10px 0 0; }

/* the steps, and Share / ⋯ */
.tsp-top { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.tsp-steps { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2, rgba(0,0,0,.05)); overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; min-width: 0; }
.tsp-steps::-webkit-scrollbar { display: none; }
.tsp-steps button { display: inline-flex; align-items: center; gap: 8px; flex: 1 0 auto; justify-content: center; font: inherit; font-size: .92rem; padding: 8px 12px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.tsp-steps button[aria-selected="true"] { background: var(--bg); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.tsp-steps__n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--line); font-size: .78rem; font-weight: 600; color: var(--ink-2); }
.tsp-steps button[aria-selected="true"] .tsp-steps__n { background: var(--ink); color: var(--bg); }
.tsp-steps__mark { font-size: .75rem; color: var(--ink-3, #999); font-variant-numeric: tabular-nums; }
.tsp-steps__mark:empty { display: none; }
.tsp-top__acts { display: flex; gap: 6px; align-items: center; }
.tsp-menuwrap { position: relative; }
.tsp-menu { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 30; display: grid; min-width: 190px; padding: 6px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); box-shadow: 0 10px 30px rgba(0,0,0,.14); }
.tsp-menu button { font: inherit; text-align: start; padding: 9px 12px; border: 0; border-radius: 8px; background: none; color: var(--ink); cursor: pointer; }
.tsp-menu .tsp-menu__share { display: none; }
.tsp-menu button:hover { background: var(--surface-2, rgba(0,0,0,.05)); }
.tsp-state { margin: -4px 0 0; color: var(--ink-3, #888); }
.tsp-state[data-kind="shared"] { color: #15803d; }
.tsp-state[data-kind="shared"]::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #16a34a; margin-inline-end: 6px; vertical-align: middle; }
.tsp-note { margin: 0; padding: 10px 14px; border-radius: 12px; background: color-mix(in srgb, #16a34a 10%, var(--bg)); color: var(--ink); font-size: .92rem; }
.tsp-note[data-kind="warn"] { background: color-mix(in srgb, #d97706 12%, var(--bg)); }
.tsp-panel { display: grid; gap: 12px; padding-bottom: 8px; }
.tsp-h { font-size: 1.15rem; margin: 4px 0 0; }
.tsp-empty { color: var(--ink-2); padding: 18px; border: 1px dashed var(--line); border-radius: 12px; text-align: center; margin: 0; }
.tsplit input, .tsplit select { font: inherit; font-size: 1rem; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); min-width: 0; }
.tsplit input:focus, .tsplit select:focus { outline: 2px solid color-mix(in srgb, var(--ink) 25%, transparent); outline-offset: 0; border-color: var(--ink-3, #999); }

/* step 1: the photo beside the items */
.tsp-items { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 18px; align-items: start; }
.tsp-photo { margin: 0; position: sticky; top: 72px; display: grid; gap: 10px; }
.tsp-photo__btn { position: relative; display: block; width: 100%; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2, #f4f4f5); cursor: zoom-in; overflow: hidden; }
.tsp-photo img { display: block; width: 100%; max-height: 70vh; object-fit: contain; }
.tsp-photo.is-reading { grid-column: 1 / -1; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 18px; align-items: start; position: static; }
.tsp-photo.is-reading .tsp-photo__btn { cursor: default; }
.tsp-photo.is-reading .tscan { display: block; animation: tscan 1.8s ease-in-out infinite; }
.tsp-photo .tscan { display: none; }
.tsp-reading { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.tsp-reading__steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.tsp-reading__steps li { display: flex; gap: 10px; align-items: center; color: var(--ink-3, #999); }
.tsp-reading__steps li::before { content: ""; width: 9px; height: 9px; border-radius: 50%; border: 2px solid currentColor; flex: none; }
.tsp-reading__steps li.is-now { color: var(--ink); font-weight: 600; }
.tsp-reading__steps li.is-now::before { background: var(--brand, #0f766e); border-color: var(--brand, #0f766e); animation: tsppulse 1s ease-in-out infinite; }
.tsp-reading__steps li.is-done { color: var(--ink-2); }
.tsp-reading__steps li.is-done::before { content: "✓"; width: auto; height: auto; border: 0; color: #16a34a; font-weight: 700; }
.tsp-reading__secs { font-variant-numeric: tabular-nums; }
.tsp-reading__text { grid-column: 1 / -1; margin: 0; max-height: 200px; min-height: 3em; overflow: auto; font: .78rem/1.5 var(--mono, ui-monospace, monospace); white-space: pre-wrap; color: var(--ink-2); }
.tsp-reading__text:empty::before { content: "The text appears here as it is read…"; color: var(--ink-3, #999); }
@keyframes tsppulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .tsp-photo.is-reading .tscan, .tsp-reading__steps li.is-now::before { animation: none; } }
.tsp-items__main { display: grid; gap: 10px; min-width: 0; }
.tsp-meta { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.3fr) minmax(0, 1fr); gap: 6px; }
.tsp-check { margin: 0; padding: 8px 12px; border-radius: 10px; background: var(--surface-2, rgba(0,0,0,.04)); color: var(--ink-2); }
.tsp-check[data-kind="ok"] { color: #15803d; background: color-mix(in srgb, #16a34a 9%, var(--bg)); }
.tsp-check[data-kind="warn"] { color: #92400e; background: color-mix(in srgb, #d97706 11%, var(--bg)); }
.tsp-lines { display: grid; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.tsp-line { display: grid; grid-template-columns: minmax(0, 1fr) auto 104px 30px; align-items: center; gap: 6px; padding: 6px 6px 6px 10px; border-bottom: 1px solid var(--line); }
.tsp-line:last-child { border-bottom: 0; }
.tsp-lines:empty { display: none; }
.tsplit .tsp-line input { border-color: transparent; background: transparent; padding: 7px 8px; }
.tsplit .tsp-line input:hover { border-color: var(--line); }
.tsplit .tsp-line input:focus { background: var(--bg); border-color: var(--ink-3, #999); }
.tsp-line__qty { display: inline-flex; align-items: center; color: var(--ink-3, #999); font-size: .9rem; }
.tsplit .tsp-line__qty input { width: 50px; text-align: center; padding-inline: 4px; }
.tsplit .tsp-line__amt { text-align: end; font-variant-numeric: tabular-nums; font-weight: 500; }
.tsp-x { border: 0; background: none; color: var(--ink-3, #999); font-size: 1.25rem; line-height: 1; cursor: pointer; padding: 6px; border-radius: 8px; }
.tsp-x:hover { color: var(--ink); background: var(--surface-2, rgba(0,0,0,.05)); }
.tsp-add { justify-self: start; padding: 4px 0; }
.tsp-totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tsp-totals label { display: grid; gap: 4px; font-size: .82rem; color: var(--ink-2); }
.tsp-totals input { text-align: end; font-variant-numeric: tabular-nums; }
.tsp-totals__total { font-weight: 600; color: var(--ink) !important; }

/* step 2: people */
.tsp-addp { display: flex; gap: 8px; }
.tsp-addp input { flex: 1; }
.tsp-people { display: flex; flex-wrap: wrap; gap: 8px; }
.tsp-person { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 4px 3px 4px; background: var(--bg); }
.tsplit .tsp-person__name { border: 0; padding: 5px 6px; border-radius: 999px; width: auto; font-weight: 500; }
.tsp-av { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: var(--bg); font-size: .8rem; font-weight: 600; flex: none; }

/* step 3: who had what */
.tsp-splithead { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.tseg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--surface-2, rgba(0,0,0,.05)); }
.tseg button { font: inherit; font-size: .9rem; padding: 6px 14px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); cursor: pointer; }
.tseg button[aria-selected="true"] { background: var(--bg); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.tsp-progress { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.tsp-progress i { display: block; height: 100%; width: 0; background: #16a34a; border-radius: 99px; transition: width .25s; }
.tsp-progress__text { margin: -6px 0 0; }
.tsp-had { display: grid; gap: 0; }
.tsp-item { display: grid; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.tsp-item__head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.tsp-item__name { font-weight: 500; overflow-wrap: anywhere; }
.tsp-item__foot { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.tsp-money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tsp-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tsp-chip { font: inherit; font-size: .9rem; min-height: 36px; padding: 6px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); color: var(--ink-2); cursor: pointer; }
.tsp-chip:hover { border-color: var(--ink-3, #999); }
.tsp-chip.is-on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tsp-chip--all { border-style: dashed; }
.tsp-chip--all.is-on { border-style: solid; }
.tsp-left { font-size: .82rem; color: #b45309; }
.tsp-mode { color: var(--ink-3, #888); }
.tsp-whotabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.tsp-whotabs .tsp-chip { flex: none; }
.tsp-hint { margin: 4px 0; }
.tsp-pick { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 12px; align-items: center; width: 100%; padding: 12px 6px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--ink); font: inherit; text-align: start; cursor: pointer; }
.tsp-pick:hover { background: var(--surface-2, rgba(0,0,0,.03)); }
.tsp-pick__box { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--line); font-size: .72rem; font-weight: 700; }
.tsp-pick.is-on .tsp-pick__box { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.tsp-pick__name { overflow-wrap: anywhere; }

/* step 4: who owes whom */
.tsp-sum { display: grid; gap: 8px; }
.tsp-owe { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.tsp-owe.is-payer { background: var(--surface-2, rgba(0,0,0,.03)); }
.tsp-owe__who { display: grid; }
.tsp-owe__amt { font-size: 1.1rem; }
.tsp-open { margin: 0; color: #92400e; }
.tsp-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* the bar at the bottom of the screen */
.tsp-bar { position: sticky; bottom: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 6px -12px 0; padding: 12px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-top: 1px solid var(--line); }
.tsp-bar__text { font-size: .92rem; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tsp-bar__btns { display: flex; gap: 6px; flex: none; }

/* sharing */
.tsp-dlg { border: 1px solid var(--line); border-radius: 18px; padding: 0; width: min(92vw, 540px); background: var(--bg); color: var(--ink); }
.tsp-dlg::backdrop { background: rgb(0 0 0 / .45); }
.tsp-dlg__body { display: grid; gap: 12px; padding: 22px; }
.tsp-dlg h2 { margin: 0; font-size: 1.2rem; }
.tsp-dlg p { margin: 0; }
.tsp-linkrow { display: flex; gap: 6px; }
.tsp-linkrow input { flex: 1; font-size: .85rem; }
.tsp-dlg__acts { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

@media (max-width: 820px) {
  .tsp-items { grid-template-columns: 1fr; }
  .tsp-photo { position: static; }
  .tsp-photo.is-reading { grid-template-columns: 1fr; }
  .tsp-photo:not(.is-reading):not(.is-big) img { max-height: 150px; }
  .tsp-photo.is-reading img { max-height: 38vh; }
}
@media (max-width: 560px) {
  .tsp-top { flex-wrap: nowrap; }
  #sp-share { display: none; } .tsp-menu .tsp-menu__share { display: block; }
  .tsp-bar__text { white-space: normal; font-size: .85rem; line-height: 1.3; }
  .tsp-steps button { padding: 8px 9px; gap: 6px; }
  .tsp-steps button:not([aria-selected="true"]) .tsp-steps__t { display: none; }
  .tsp-meta { grid-template-columns: 1fr 1fr; } .tsp-meta #sp-shop { grid-column: 1 / -1; }
  .tsp-line { grid-template-columns: minmax(0, 1fr) auto 30px; grid-template-areas: "name name x" "qty amt amt"; padding: 6px; row-gap: 0; }
  .tsp-line__name { grid-area: name; } .tsp-line__qty { grid-area: qty; } .tsp-line__amt { grid-area: amt; } .tsp-line .tsp-x { grid-area: x; }
  .tsp-totals { grid-template-columns: 1fr 1fr; } .tsp-totals__total { grid-column: 1 / -1; }
  .tsp-bar { margin-inline: -16px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
  .tsp-bar__btns .btn { padding-inline: 14px; }
}
