/* ============================================================================
   billsplit.css  -  the "split the bill" screen
   ----------------------------------------------------------------------------
   Every class here starts with "bs-" so nothing in this file can accidentally
   restyle another screen.

   The colours, corner sizes and the bouncy --spring timing all come from the
   variables defined on :root in style.css. Writing var(--lime) instead of
   #C6FF4F everywhere means the whole app changes together if a colour is
   ever changed.

   Sizes to remember:
     - anything you tap is at least 48px tall (a comfortable thumb target)
     - the screen is designed at 390px wide first; wider screens just get air

   Why some selectors are written ".bs-wrap .bs-chip" and not just ".bs-chip":
   style.css has general rules for every <button> and <input> in the app.
   Naming the wrapper as well makes our rule the more specific one, so ours
   wins without needing !important.
   ========================================================================== */

.bs-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
  color: var(--ink);
}

/* Buttons and inputs do not use the page font unless told to. This makes
   every control on this screen match the text around it. */
.bs-wrap button,
.bs-wrap input,
.bs-pad button {
  font-family: inherit;
  color: inherit;
  margin: 0;
}

.bs-wrap button,
.bs-pad button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* A clear outline for anyone moving around with a keyboard. */
.bs-wrap button:focus-visible,
.bs-wrap input:focus-visible,
.bs-pad button:focus-visible,
.bs-wrap .bs-photo-btn:focus-within {
  outline: 3px solid var(--violet);
  outline-offset: 2px;
}

/* --- headings ------------------------------------------------------------- */

.bs-title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.1;
  margin: 0;
  /* A very long place name wraps instead of pushing the screen sideways. */
  overflow-wrap: anywhere;
}

.bs-when {
  margin: -8px 0 0;
  font-size: 13px;
  color: var(--ink-2);
}

/* --- cards ---------------------------------------------------------------- */

.bs-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* Lets the card shrink to the screen instead of growing to fit its widest
     child - the thing that causes sideways scrolling. */
  min-width: 0;
}

.bs-card-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.01em;
  margin: 0;
}

.bs-hint {
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-2);
  margin: 0;
}

.bs-hint-centre { text-align: center; }

/* --- text inputs ---------------------------------------------------------- */

.bs-wrap .bs-input {
  flex: 1;
  min-width: 0;            /* lets the box shrink inside a row */
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink);
  /* 16px or more stops iPhones zooming the page in when the box is tapped. */
  font-size: 16px;
  font-weight: 500;
}

.bs-wrap .bs-input::placeholder { color: var(--ink-3); }

/* --- photo + place -------------------------------------------------------- */

.bs-top-row,
.bs-add-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bs-photo-btn {
  flex: 0 0 56px;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px dashed var(--ink-3);
  border-radius: var(--r-sm);
  overflow: hidden;
  cursor: pointer;
  /* The hidden file input is positioned inside this box. */
  position: relative;
  transition: transform .18s var(--spring);
}

.bs-photo-btn:active { transform: scale(.92); }
.bs-photo-btn.bs-has-photo { border: 2px solid var(--lime); }
.bs-photo-icon { font-size: 24px; line-height: 1; }

.bs-photo-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;       /* fill the square, cropping rather than squashing */
  display: block;
}

/* The real file input: invisible, but still there for keyboards and screen
   readers. (display:none would remove it for them as well.) */
.bs-wrap .bs-file {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.bs-photo-full {
  display: block;
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: var(--r);
  border: 1px solid var(--line);
  cursor: zoom-in;
}

/* Tapped: show the whole photo, uncropped. */
.bs-photo-full.bs-is-big {
  max-height: none;
  object-fit: contain;
  cursor: zoom-out;
}

/* --- small text buttons --------------------------------------------------- */

.bs-wrap .bs-link {
  align-self: flex-start;
  min-height: 48px;
  padding: 0 4px;
  background: none;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.bs-wrap .bs-link-centre { align-self: center; }

/* --- who's in: the chips -------------------------------------------------- */

.bs-chips {
  display: flex;
  flex-wrap: wrap;         /* names flow onto a new line instead of scrolling */
  gap: 8px;
}

.bs-wrap .bs-chip {
  min-height: 48px;
  max-width: 100%;
  padding: 0 18px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: transform .18s var(--spring), background .15s, color .15s;
}

.bs-wrap .bs-chip:active { transform: scale(.94); }

.bs-wrap .bs-chip.bs-is-on {
  background: var(--lime);
  border-color: var(--lime);
  color: var(--bg);        /* near-black text on lime */
}

/* --- one line of the form: name ... controls ... amount ------------------- */

.bs-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
}

.bs-row-name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  /* A long name wraps onto a second line rather than being cut off. */
  overflow-wrap: anywhere;
}

.bs-row-sub {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}

/* The "me" pill on a person's row. */
.bs-wrap .bs-me {
  flex: 0 0 auto;
  min-width: 48px;
  min-height: 48px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-3);
  transition: transform .18s var(--spring);
}

.bs-wrap .bs-me:active { transform: scale(.92); }

.bs-wrap .bs-me.bs-is-on {
  background: var(--violet);
  border-color: var(--violet);
  color: var(--ink);
}

/* The amount button: looks like a number, behaves like a button. */
.bs-wrap .bs-amount {
  flex: 0 0 auto;
  min-width: 104px;
  max-width: 50%;
  min-height: 52px;
  padding: 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 19px;
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
  /* tabular-nums gives every digit the same width, so columns of numbers
     line up instead of wobbling. */
  font-variant-numeric: tabular-nums;
  transition: transform .18s var(--spring);
}

.bs-wrap .bs-amount:active { transform: scale(.95); }
.bs-wrap .bs-amount.bs-is-zero { color: var(--ink-3); }

/* The little rupee / percent switch on each charge. */
.bs-unit {
  flex: 0 0 auto;
  display: flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 3px;
}

.bs-wrap .bs-unit button {
  width: 38px;
  min-height: 48px;        /* each half is its own tap target, so 48 tall */
  padding: 0;
  background: transparent;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 800;
  color: var(--ink-3);
}

.bs-wrap .bs-unit button.bs-is-on {
  background: var(--surface-2);
  color: var(--lime);
}

/* The two-way "split equally / by what they ate" switch. */
.bs-seg {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 4px;
}

.bs-wrap .bs-seg button {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 0 6px;
  background: transparent;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-2);
}

.bs-wrap .bs-seg button.bs-is-on {
  background: var(--lime);
  color: var(--bg);
}

/* --- the running total above the big button ------------------------------- */

.bs-total-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 6px 0;
}

.bs-total-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-2);
}

.bs-total-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

/* --- buttons -------------------------------------------------------------- */

.bs-wrap .bs-btn,
.bs-pad .bs-btn {
  width: 100%;
  min-height: 52px;
  padding: 10px 18px;
  border-radius: var(--r);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
  transition: transform .18s var(--spring);
}

.bs-wrap .bs-btn:active,
.bs-pad .bs-btn:active { transform: scale(.96); }

.bs-wrap .bs-btn-primary,
.bs-pad .bs-btn-primary {
  background: var(--lime);
  color: var(--bg);
}

.bs-wrap .bs-btn-big {
  min-height: 60px;
  font-size: 18px;
}

.bs-wrap .bs-btn-quiet {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
}

.bs-wrap .bs-btn-small {
  width: auto;
  flex: 0 0 auto;
  border-radius: var(--r-sm);
  white-space: nowrap;
}

.bs-wrap .bs-btn-danger {
  background: transparent;
  border: 1px solid var(--bad);
  color: var(--bad);
}

.bs-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* --- THE ANSWER ----------------------------------------------------------- */

.bs-answer {
  border-color: var(--lime);
  gap: 14px;
}

.bs-answer-total {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bs-answer-total-value {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.bs-shares {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bs-share {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: var(--r);
  animation: bs-rise .35s var(--spring) both;
}

/* Each row arrives a beat after the one above it. */
.bs-share:nth-child(2) { animation-delay: .05s; }
.bs-share:nth-child(3) { animation-delay: .10s; }
.bs-share:nth-child(4) { animation-delay: .15s; }
.bs-share:nth-child(n+5) { animation-delay: .20s; }

/* The rows only MOVE into place - they never start invisible. If an animation
   ever fails to run, the worst case is a row that did not slide, not an
   answer nobody can read. */
@keyframes bs-rise {
  from { transform: translateY(10px); }
  to   { transform: none; }
}

/* Your own row stands out, so you can find it at a glance. */
.bs-share-me {
  background: var(--lime);
  color: var(--bg);
}

.bs-share-who {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bs-share-name {
  font-size: 19px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bs-share-sub {
  font-size: 12px;
  color: var(--ink-2);
}

.bs-share-me .bs-share-sub {
  color: var(--bg);
  opacity: .75;
}

.bs-share-pays {
  flex: 0 0 auto;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

/* The "it adds up" line. */
.bs-check {
  padding: 12px 14px;
  border: 1px solid var(--good);
  border-radius: var(--r-sm);
  color: var(--good);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

.bs-check-bad {
  border-color: var(--bad);
  color: var(--bad);
}

.bs-detail {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

/* --- past bills ----------------------------------------------------------- */

.bs-wrap .bs-past {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  color: var(--ink);
  text-align: left;
  transition: transform .18s var(--spring);
}

.bs-wrap .bs-past:active { transform: scale(.98); }

.bs-past-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bs-past-place {
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bs-past-meta {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}

.bs-past-total {
  flex: 0 0 auto;
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* --- the number pad ------------------------------------------------------- */

/* The dark layer over the whole screen. z-index 70 puts it above the tab bar
   but below the app's popups and toasts, so error messages still show. */
.bs-pad {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, .6);
  animation: bs-fade .15s ease-out;
}

.bs-pad-sheet {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* env(safe-area-inset-bottom) is the strip at the bottom of newer phones
     where the home bar sits. This keeps the Done button clear of it. */
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  color: var(--ink);
  animation: bs-slide-up .28s var(--spring);
}

.bs-pad-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bs-pad-display {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.bs-pad-display.bs-is-zero { color: var(--ink-3); }

.bs-pad-keys {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.bs-pad .bs-pad-key {
  min-height: 56px;
  padding: 0;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  color: var(--ink);
  font-size: 22px;
  font-weight: 700;
  transition: transform .12s var(--spring), background .1s;
}

.bs-pad .bs-pad-key:active {
  transform: scale(.94);
  background: var(--lime);
  color: var(--bg);
}

.bs-pad .bs-pad-del { color: var(--ink-2); }

@keyframes bs-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes bs-slide-up {
  from { transform: translateY(100%); }
  to   { transform: none; }
}

/* --- for people who have asked their phone for less movement ---------------
   Some people get dizzy or distracted by things sliding and bouncing. Phones
   have a "reduce motion" setting for this, and this block respects it: every
   animation and transition on this screen is switched off. Nothing is lost -
   the same things appear, they just appear straight away. */
@media (prefers-reduced-motion: reduce) {
  .bs-wrap *,
  .bs-pad,
  .bs-pad * {
    animation: none !important;
    transition: none !important;
  }
}
