/* ═══════════════════════════════════════════════════════════════════
   PlateDiary — the split bill calculator (/tools/split-bill-calculator).
   Loaded after css/pages.css, whose tokens, type and components it uses
   (.pd-menu lines for the receipt, .pill for the copy button).

   The form sits on sheets; the answer is a paper receipt with dotted
   leaders that stays in view on wide screens. Flat fills, no outlines;
   transitions use the app's springs sampled into linear() (--snap), never
   an easing curve. Script-only parts hide until the head marks
   <html class="js">, so a visitor without JavaScript gets the note and the
   by-hand steps, not dead inputs.
   ═══════════════════════════════════════════════════════════════════ */

html:not(.js) .sb-needs-js {
  display: none !important;
}

.js .sb-nojs {
  display: none;
}

.sb-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── the hero is the tool ── */

.sb-app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 400px);
  grid-template-areas:
    'copy copy'
    'tool receipt'
    'nojs nojs';
  column-gap: clamp(24px, 4vw, 56px);
  align-items: start;
  padding-bottom: 48px;
}

.sb-copy { grid-area: copy; }
.sb-tool { grid-area: tool; min-width: 0; }
.sb-receipt { grid-area: receipt; }
.sb-nojs { grid-area: nojs; }

.sb-copy .pd-h1 {
  font-size: clamp(40px, 5.4vw, 72px);
}

.sb-copy .pd-lede {
  max-width: 34em;
}

/* ── even split / by item ── */

.sb-modes {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  margin: 26px 0 14px;
  padding: 4px;
  border-radius: 999px;
  background: var(--sunken);
}

.sb-mode {
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-muted);
  font: 600 15px/1 var(--font-ui);
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--t-snap) var(--snap), color var(--t-snap) var(--snap);
}

.sb-mode[aria-pressed='true'] {
  background: var(--accent);
  color: var(--on-accent);
}

/* ── the sheets ── */

.sb-card {
  display: grid;
  gap: 18px;
  min-width: 0;
  margin: 0 0 14px;
  padding: 22px clamp(16px, 3vw, 26px);
  border: 0;
  border-radius: 24px;
  background: var(--sheet);
  box-shadow: var(--shadow-float);
}

.sb-card[hidden] {
  display: none;
}

.sb-field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.sb-label {
  margin: 0;
  padding: 0;
  font: 500 18px/1.25 var(--font-display);
  color: var(--ink);
}

.sb-label--small {
  font: 600 13px/1.2 var(--font-ui);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* a legend floats over the fieldset's edge unless it is taken out of flow */
.sb-charges > legend {
  float: left;
  width: 100%;
}

.sb-charges > legend + * {
  clear: both;
}

.sb-help {
  margin: 0;
  font-size: 14px;
  color: var(--ink-muted);
}

.sb-input,
.sb-select {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: 14px;
  background: var(--sunken);
  color: var(--ink);
  font: 400 17px/1 var(--font-ui);
}

.sb-input::placeholder {
  color: var(--ink-faint);
}

.sb-input:focus-visible,
.sb-select:focus-visible,
.sb-mode:focus-visible,
.sb-chip:focus-visible,
.sb-step:focus-visible,
.sb-add:focus-visible,
.sb-x:focus-visible,
.sb-check input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sb-input--big {
  height: 60px;
  font: 600 28px/1 var(--font-display);
  font-variant-numeric: tabular-nums;
}

.sb-select {
  appearance: none;
  padding-right: 36px;
  background-image: linear-gradient(45deg, #0000 50%, var(--ink-muted) 50%), linear-gradient(-45deg, #0000 50%, var(--ink-muted) 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  font-size: 16px;
  cursor: pointer;
}

/* ── the people stepper ── */

.sb-stepper {
  display: grid;
  grid-template-columns: 48px minmax(0, 120px) 48px;
  gap: 8px;
}

.sb-input--people {
  text-align: center;
  font: 600 22px/1 var(--font-display);
}

.sb-step,
.sb-x {
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font: 600 22px/1 var(--font-display);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sb-step {
  height: 48px;
}

.sb-x {
  width: 40px;
  height: 40px;
  flex: none;
  background: var(--sunken);
  color: var(--ink-muted);
}

.sb-x:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── people and dishes (by item) ── */

.sb-people,
.sb-items {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sb-person {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sb-item {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 18px;
  background: color-mix(in oklab, var(--sunken) 55%, var(--sheet));
}

.sb-item.is-new {
  animation: sb-in var(--t-snap) var(--snap);
}

@keyframes sb-in {
  from {
    opacity: 0;
    translate: 0 10px;
  }
}

.sb-item__top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 120px) 40px;
  align-items: center;
  gap: 8px;
}

.sb-item .sb-input {
  background: var(--sheet);
}

.sb-input--price {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sb-item__who {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.sb-item__label {
  margin: 0;
  font: 400 16px/1 var(--font-hand);
  color: var(--ink-muted);
}

.sb-add {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font: 600 15px/1 var(--font-ui);
  cursor: pointer;
}

.sb-add:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ── chips: presets, tips, who shared ── */

.sb-chips,
.sb-presets,
.sb-tips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sb-chip {
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--sunken);
  color: var(--ink);
  font: 600 14px/1 var(--font-ui);
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--t-snap) var(--snap), color var(--t-snap) var(--snap), translate var(--t-snap) var(--snap);
}

.sb-chip:active {
  translate: 0 1px;
}

.sb-chip[aria-pressed='true'] {
  background: var(--accent);
  color: var(--on-accent);
}

.sb-chip[aria-pressed='false'] {
  background: var(--sheet);
  color: var(--ink-muted);
}

.sb-chip--small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

/* ── service, tax, tip ── */

.sb-trio {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.sb-pct {
  position: relative;
}

.sb-pct .sb-input {
  padding-right: 32px;
  font: 600 20px/1 var(--font-display);
  font-variant-numeric: tabular-nums;
}

.sb-pct span {
  position: absolute;
  top: 50%;
  right: 14px;
  translate: 0 -50%;
  color: var(--ink-muted);
  font: 500 16px/1 var(--font-display);
  pointer-events: none;
}

.sb-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 16px;
  cursor: pointer;
}

.sb-check input {
  flex: none;
  width: 22px;
  height: 22px;
  margin: 1px 0 0;
  accent-color: var(--accent);
}

.sb-check small {
  color: var(--ink-muted);
}

.sb-selects {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

/* ── the receipt ── */

.sb-receipt {
  position: sticky;
  top: 84px;
  max-width: none;
  margin-top: 26px;
  padding: 26px clamp(18px, 3vw, 26px) 22px;
  background: var(--paper);
  color: #131A2E;
  /* torn edges, top and bottom, punched in the surface colour */
  -webkit-mask: radial-gradient(circle 6px at 50% 0, #0000 98%, #000) 0 0 / 22px 51% repeat-x, radial-gradient(circle 6px at 50% 100%, #0000 98%, #000) 0 100% / 22px 51% repeat-x;
  mask: radial-gradient(circle 6px at 50% 0, #0000 98%, #000) 0 0 / 22px 51% repeat-x, radial-gradient(circle 6px at 50% 100%, #0000 98%, #000) 0 100% / 22px 51% repeat-x;
  border-radius: 6px;
}

/* the receipt is paper in both themes: its ink is fixed, like the dish saves */
.sb-receipt .pd-menu__line > span,
.sb-receipt .pd-menu__line > b {
  color: #131A2E;
}

.sb-receipt .pd-menu__line > i {
  background: radial-gradient(circle 1.5px, #131A2E66 96%, #0000) 0 50% / 8px 4px repeat-x;
}

.sb-receipt .pd-menu__line > small {
  color: #131A2EB3;
}

.sb-receipt__head {
  margin: 0;
  font: 600 13px/1.2 var(--font-ui);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #131A2EB3;
}

.sb-receipt__each {
  margin: 4px 0 6px;
  font: 600 clamp(40px, 7vw, 54px)/1.05 var(--font-display);
  color: #2F4FA0;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.sb-receipt__each:empty {
  display: none;
}

.sb-receipt__rows,
.sb-receipt__lines {
  margin: 0;
}

.sb-receipt__rows:empty {
  display: none;
}

.sb-receipt__rows .pd-menu__line > b {
  font-size: 22px;
  color: #2F4FA0;
}

.sb-receipt__note {
  margin: 6px 0 14px;
  font: 400 17px/1.35 var(--font-hand);
  color: #131A2EB3;
}

.sb-receipt__lines {
  padding-top: 12px;
  border-top: 2px dashed #131A2E26;
}

.sb-receipt__lines .pd-menu__line > span {
  font-size: 18px;
}

.sb-receipt__lines .pd-menu__line > b {
  font-size: 16px;
}

.sb-receipt .sb-total > b {
  font-size: 20px;
}

.sb-copy-btn {
  width: 100%;
  margin-top: 16px;
  box-shadow: none;
}

.sb-copy-btn:disabled {
  opacity: 0.45;
  translate: none;
}

.sb-text {
  margin-top: 10px;
}

.sb-text summary {
  font: 400 17px/1.4 var(--font-hand);
  color: #2F4FA0;
  cursor: pointer;
}

.sb-text textarea {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border: 0;
  border-radius: 12px;
  background: #131A2E0F;
  color: #131A2E;
  font: 400 14px/1.45 ui-monospace, 'SF Mono', Menlo, monospace;
  resize: vertical;
}

.sb-receipt__small {
  margin: 12px 0 0;
  font-size: 13px;
  color: #131A2EB3;
}

.sb-nojs {
  margin: 24px 0 0;
  padding: 18px 20px;
  border-radius: 18px;
  background: var(--accent-soft);
}

/* ── below the tool ── */

.sb-sample {
  margin: 14px 0;
  padding: 18px 20px;
  overflow-x: auto;
  border-radius: 6px;
  background: var(--paper);
  color: #131A2E;
  font: 400 14px/1.5 ui-monospace, 'SF Mono', Menlo, monospace;
  white-space: pre;
}

@media (max-width: 959px) {
  .sb-app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      'copy'
      'tool'
      'receipt'
      'nojs';
  }

  .sb-receipt {
    position: static;
    margin-top: 6px;
  }
}

@media (max-width: 599px) {
  .sb-copy .pd-h1 {
    margin: 14px 0 12px;
  }

  .sb-copy .pd-lede {
    font-size: 17px;
  }

  .sb-modes {
    display: grid;
    width: 100%;
  }

  .sb-trio {
    gap: 8px;
  }

  .sb-pct .sb-input {
    padding: 0 26px 0 12px;
    font-size: 18px;
  }

  .sb-pct span {
    right: 10px;
  }

  .sb-selects {
    grid-template-columns: minmax(0, 1fr);
  }

  .sb-item__top {
    grid-template-columns: minmax(0, 1fr) minmax(0, 104px) 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sb-mode,
  .sb-chip {
    transition: none;
  }

  .sb-item.is-new {
    animation: none;
  }
}
