/* Racha: papel de recibo, tinta preta e um verde-limão de marca-texto.
   Raios: campos 14px, botões e chips em pílula, recibo reto com picote. */

:root {
  --bg: #ecece7;
  --surface: #f7f7f3;
  --paper: #fcfcfa;
  --ink: #161615;
  --muted: #5c5c56;
  --line: #d2d2ca;
  --accent: #c9f24d;
  --accent-ink: #161615;
  --accent-deep: #3f5a00;
  --danger: #b3261e;
  --shadow: 32 32 20;
  --r-field: 14px;
  --font: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --dock-h: 76px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --surface: #1a1a18;
    --paper: #1f1f1d;
    --ink: #efefe8;
    --muted: #a3a39a;
    --line: #34342f;
    --accent-deep: #c9f24d;
    --danger: #ff8a80;
    --shadow: 0 0 0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2.5px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- topo ---------- */

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 22px; letter-spacing: -0.04em;
}
.brand-mark {
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--mono); font-weight: 700; font-size: 20px; line-height: 1;
}
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; min-width: 40px; padding: 0 10px;
  border: 0; border-radius: 999px; background: transparent;
  transition: transform 0.15s var(--ease), background-color 0.2s;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn i { font-size: 20px; }
.top .icon-btn { background: var(--surface); border: 1px solid var(--line); padding: 0 14px 0 10px; }
.pix-state { font-size: 14px; font-weight: 700; max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pix-state.is-empty { color: var(--muted); }

/* ---------- painéis ---------- */

main {
  max-width: 560px; margin: 0 auto;
  padding: 4px 16px calc(var(--dock-h) + env(safe-area-inset-bottom) + 24px);
}
.panel { display: grid; gap: 22px; animation: rise 0.45s var(--ease) both; }
.title {
  margin: 10px 0 0;
  font-size: clamp(40px, 12vw, 58px);
  font-weight: 800; line-height: 0.95; letter-spacing: -0.05em;
}

.seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 4px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
}
.seg-opt {
  min-height: 42px; border: 0; border-radius: 999px; background: transparent;
  font-size: 14px; font-weight: 700; color: var(--muted);
  transition: background-color 0.25s var(--ease), color 0.25s;
}
.seg-opt[aria-checked="true"] { background: var(--ink); color: var(--bg); }

/* ---------- campos ---------- */

.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: grid; gap: 8px; align-content: start; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field label:not(.check), .label { font-size: 14px; font-weight: 700; }
.input-wrap {
  display: flex; align-items: center; gap: 6px;
  height: 58px; padding: 0 16px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r-field);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrap:focus-within { border-color: var(--ink); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 70%, transparent); }
.input-wrap input {
  flex: 1; min-width: 0; width: 100%; height: 100%;
  border: 0; outline: 0; background: transparent;
  font-family: var(--mono); font-size: 22px; font-weight: 700; letter-spacing: -0.02em;
}
.input-wrap input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
.input-big { height: 72px; }
.input-big input { font-size: 32px; }
.input-sm { height: 46px; padding: 0 12px; }
.input-sm input { font-size: 16px; }
.unit { font-family: var(--mono); font-size: 14px; font-weight: 500; color: var(--muted); }
.unit-pre { font-size: 18px; }

.field > input, .field > select {
  height: 52px; padding: 0 14px; width: 100%;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r-field);
  font-size: 16px; outline: 0;
}
.field > input:focus, .field > select:focus { border-color: var(--ink); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 70%, transparent); }
.field-error { margin: 0; font-size: 14px; color: var(--danger); font-weight: 600; }

.check {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 15px; font-weight: 600; cursor: pointer; user-select: none;
  min-height: 32px;
}
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check-box {
  width: 24px; height: 24px; border-radius: 8px;
  border: 1.5px solid var(--ink); background: var(--surface);
  display: grid; place-items: center;
  transition: background-color 0.2s var(--ease);
}
.check-box::after {
  content: ""; width: 10px; height: 6px; margin-top: -3px;
  border-left: 2.5px solid var(--accent-ink); border-bottom: 2.5px solid var(--accent-ink);
  transform: rotate(-45deg) scale(0); transition: transform 0.2s var(--ease);
}
.check input:checked + .check-box { background: var(--accent); }
.check input:checked + .check-box::after { transform: rotate(-45deg) scale(1); }
.check input:focus-visible + .check-box { outline: 2.5px solid var(--ink); outline-offset: 2px; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mode-equal, .mode-km { display: grid; gap: 14px; }
.hint { margin: 0; font-size: 14px; color: var(--muted); max-width: 52ch; }

.stepper {
  display: flex; align-items: center;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 999px; padding: 4px;
}
.stepper input {
  width: 52px; text-align: center; border: 0; outline: 0; background: transparent;
  font-family: var(--mono); font-size: 22px; font-weight: 700;
}
.step {
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--ink); color: var(--bg); display: grid; place-items: center;
  transition: transform 0.15s var(--ease);
}
.step:active { transform: scale(0.9); }
.step i { font-size: 18px; }

/* ---------- pessoas (modo por km) ---------- */

.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.person {
  display: grid; grid-template-columns: minmax(0, 1fr) 116px auto 36px; gap: 8px; align-items: center;
  animation: rise 0.35s var(--ease) both;
}
.person-name {
  height: 46px; min-width: 0; padding: 0 12px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r-field);
  font-weight: 700; outline: 0;
}
.person-name:focus { border-color: var(--ink); }
.toggle { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track {
  position: relative; width: 44px; height: 26px; border-radius: 999px;
  background: var(--line); transition: background-color 0.2s var(--ease);
}
.toggle-track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: var(--paper);
  box-shadow: 0 1px 3px rgb(var(--shadow) / 0.3);
  transition: transform 0.25s var(--ease);
}
.toggle input:checked + .toggle-track { background: var(--ink); }
.toggle input:checked + .toggle-track::after { transform: translateX(18px); background: var(--accent); }
.toggle input:focus-visible + .toggle-track { outline: 2.5px solid var(--ink); outline-offset: 2px; }
.toggle-label { font-size: 11px; font-weight: 700; color: var(--muted); }

.ghost-btn, .solid-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 999px;
  font-weight: 700; font-size: 15px;
  transition: transform 0.15s var(--ease), background-color 0.2s;
}
.ghost-btn { background: transparent; border: 1.5px dashed var(--ink); }
.solid-btn { background: var(--ink); color: var(--bg); border: 0; }
.ghost-btn:active, .solid-btn:active { transform: scale(0.97); }

/* ---------- recibo ---------- */

.receipt-shadow { filter: drop-shadow(0 14px 22px rgb(var(--shadow) / 0.14)) drop-shadow(0 2px 3px rgb(var(--shadow) / 0.08)); margin-top: 4px; }
.receipt {
  --z: 9px;
  position: relative;
  background: var(--paper);
  padding: 18px 20px calc(22px + var(--z));
  font-family: var(--mono); font-size: 14px;
  -webkit-mask:
    conic-gradient(from 135deg at top, #0000, #000 1deg 89deg, #0000 90deg) top / calc(2 * var(--z)) var(--z) repeat-x,
    linear-gradient(#000 0 0) center / 100% calc(100% - 2 * var(--z)) no-repeat,
    conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) bottom / calc(2 * var(--z)) var(--z) repeat-x;
  mask:
    conic-gradient(from 135deg at top, #0000, #000 1deg 89deg, #0000 90deg) top / calc(2 * var(--z)) var(--z) repeat-x,
    linear-gradient(#000 0 0) center / 100% calc(100% - 2 * var(--z)) no-repeat,
    conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) bottom / calc(2 * var(--z)) var(--z) repeat-x;
}
.r-head {
  display: flex; justify-content: space-between;
  padding: var(--z) 0 12px; margin-bottom: 4px;
  border-bottom: 1.5px dashed var(--line);
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
}
.r-empty { margin: 14px 0 4px; color: var(--muted); font-family: var(--font); font-size: 15px; }
.r-lines { margin: 0; display: grid; gap: 8px; padding: 12px 0 14px; }
.r-lines div { display: flex; justify-content: space-between; gap: 12px; }
.r-lines dt { color: var(--muted); }
.r-lines dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.r-total {
  display: grid; gap: 2px; padding: 16px 0 6px;
  border-top: 1.5px dashed var(--line);
}
.r-total-label { font-family: var(--font); font-weight: 700; font-size: 15px; }
.r-total-value {
  font-size: clamp(42px, 13vw, 60px); font-weight: 700; letter-spacing: -0.05em; line-height: 1.05;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(transparent 58%, var(--accent) 58% 92%, transparent 92%);
  width: fit-content; padding: 0 4px; margin-left: -4px;
  animation: tick 0.35s var(--ease);
}
@media (prefers-color-scheme: dark) {
  .r-total-value { background: none; color: var(--accent); }
}
.r-total-sub { color: var(--muted); font-size: 13px; }

.r-people { list-style: none; margin: 0; padding: 8px 0 0; border-top: 1.5px dashed var(--line); display: grid; }
.r-people li { display: grid; grid-template-columns: 1fr auto 40px; gap: 8px; align-items: center; min-height: 52px; }
.r-people li + li { border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.r-name { display: grid; font-family: var(--font); font-weight: 700; font-size: 16px; min-width: 0; overflow-wrap: anywhere; }
.r-name small { font-family: var(--mono); font-weight: 500; font-size: 12px; color: var(--muted); }
.r-amount { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.r-people li.is-out .r-amount { font-size: 13px; color: var(--muted); font-weight: 500; }
.r-send { background: var(--accent); color: var(--accent-ink); padding: 0; }
.r-pix {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  margin-top: 14px; min-height: 46px; border-radius: 999px;
  background: transparent; border: 1.5px solid var(--ink);
  font-family: var(--font); font-weight: 700; font-size: 14px;
  transition: transform 0.15s var(--ease);
}
.r-pix:active { transform: scale(0.98); }
.r-pix-add { border-style: dashed; }

/* ---------- foto / OCR ---------- */

.photo { display: grid; gap: 10px; }
.photo-btn {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 14px 16px; border: 0; border-radius: var(--r-field);
  background: var(--ink); color: var(--bg); cursor: pointer;
  transition: transform 0.15s var(--ease);
}
.photo-btn:active { transform: scale(0.98); }
.photo-btn i {
  display: grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 22px;
}
.photo-btn span { display: grid; }
.photo-btn small { opacity: 0.72; font-size: 13px; }
.photo-alt {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; border-radius: 999px; border: 1.5px dashed var(--ink);
  font-weight: 700; font-size: 15px; cursor: pointer;
  transition: transform 0.15s var(--ease);
}
.photo-alt:active { transform: scale(0.98); }
.photo-alt i { font-size: 19px; }
.photo:has(#billPhoto:focus-visible) .photo-alt { outline: 2.5px solid var(--ink); outline-offset: 2px; }

/* câmera ao vivo (computador ou navegador sem câmera nativa) */
.camera {
  width: 100%; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0;
  border: 0; background: #0d0d0c; color: #efefe8;
}
.camera[open] { display: grid; grid-template-rows: 1fr auto auto; }
.camera::backdrop { background: #0d0d0c; }
.camera video { width: 100%; height: 100%; min-height: 0; object-fit: contain; background: #0d0d0c; }
.camera-tip { margin: 0; padding: 10px 16px 0; text-align: center; font-size: 14px; color: #a3a39a; }
.camera-bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 20px);
}
.camera-cancel { justify-self: start; border-color: #efefe8; color: #efefe8; }
.shutter {
  width: 76px; height: 76px; border-radius: 50%;
  background: var(--accent); border: 5px solid #0d0d0c; box-shadow: 0 0 0 3px var(--accent);
  transition: transform 0.15s var(--ease);
}
.shutter:active { transform: scale(0.92); }
.ocr { display: grid; gap: 10px; }
.ocr-bar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.ocr-bar span {
  display: block; height: 100%; background: var(--ink);
  transform-origin: left; transform: scaleX(0); transition: transform 0.3s var(--ease);
}
.ocr:not(.is-busy) .ocr-bar { display: none; }
.ocr-status { margin: 0; font-size: 14px; font-weight: 600; }
.ocr-picks { display: flex; flex-wrap: wrap; gap: 8px; }

.chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  min-height: 44px; padding: 0 16px; border-radius: 999px;
  background: var(--surface); border: 1.5px solid var(--line);
  font-family: var(--mono); font-weight: 700; font-size: 15px;
  transition: background-color 0.2s var(--ease), border-color 0.2s, transform 0.15s var(--ease);
}
.chip:active { transform: scale(0.95); }
.chip[aria-checked="true"], .chip-input.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chips .chip { padding: 0 8px; }
.chips .chip-input { padding: 0 12px; }
.chip-input input { width: 5.5ch; border: 0; outline: 0; background: transparent; font: inherit; text-align: right; }
.chip-input input::placeholder { color: var(--muted); font-weight: 500; }
.chip-input.is-on input::placeholder { color: var(--accent-ink); }
.chip-input:focus-within { border-color: var(--ink); }

/* ---------- compartilhar ---------- */

.share-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; margin-top: 22px;
  min-height: 58px; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 800; font-size: 17px; letter-spacing: -0.01em;
  box-shadow: 0 8px 20px -8px rgb(var(--shadow) / 0.35), inset 0 -2px 0 rgb(0 0 0 / 0.12);
  transition: transform 0.15s var(--ease), opacity 0.2s;
}
.share-btn i { font-size: 24px; }
.share-btn:active { transform: scale(0.97); }
.share-btn:disabled { opacity: 0.4; cursor: default; box-shadow: none; }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid;
  padding: 14px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(to top, var(--bg) 70%, color-mix(in srgb, var(--bg) 0%, transparent));
}
.dock > * { width: 100%; max-width: 528px; margin: 0 auto; }
/* Selo do Netlify (plano grátis) oculto a pedido do dono do site. */
#nl-badge-frame { display: none !important; }

.tabs {
  position: relative; display: grid; grid-template-columns: 1fr 1fr;
  padding: 4px; border-radius: 999px; background: var(--ink);
}
.tab {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; border: 0; background: transparent; border-radius: 999px;
  color: color-mix(in srgb, var(--bg) 65%, transparent); font-weight: 700; font-size: 15px;
  transition: color 0.3s var(--ease);
}
.tab[aria-selected="true"] { color: var(--ink); }
.tab i { font-size: 19px; }
.tab-pill {
  position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc(50% - 4px);
  border-radius: 999px; background: var(--bg);
  transition: transform 0.4s var(--ease);
}
body[data-tab="bill"] .tab-pill { transform: translateX(100%); }
.tab:focus-visible { outline-color: var(--accent); }

/* ---------- folha de configurações ---------- */

.sheet {
  width: 100%; max-width: 560px; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 28px 28px 0 0;
  background: var(--bg); color: var(--ink);
  max-height: 92dvh;
}
.sheet[open] { animation: sheet-up 0.4s var(--ease); }
.sheet::backdrop { background: rgb(10 10 9 / 0.5); backdrop-filter: blur(3px); }
.sheet-body { display: grid; gap: 16px; padding: 10px 20px calc(env(safe-area-inset-bottom) + 20px); }
.sheet-grip { width: 44px; height: 5px; border-radius: 999px; background: var(--line); margin: 0 auto 4px; }
.sheet h2 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -0.04em; line-height: 1.05; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 6px; }
@media (min-width: 640px) {
  .sheet { margin: auto; border-radius: 28px; }
}

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 14px); z-index: 30;
  padding: 10px 18px; border-radius: 999px;
  background: var(--ink); color: var(--bg); font-weight: 700; font-size: 14px;
  transform: translate(-50%, -140%); opacity: 0;
  transition: transform 0.35s var(--ease), opacity 0.35s;
  pointer-events: none; white-space: nowrap;
}
.toast.is-on { transform: translate(-50%, 0); opacity: 1; }

/* ---------- telas pequenas ---------- */

@media (max-width: 380px) {
  .person { grid-template-columns: minmax(0, 1fr) 100px auto 32px; gap: 6px; }
  .fields { gap: 10px; }
  .input-wrap { padding: 0 12px; }
}

/* ---------- movimento ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes tick { from { opacity: 0.4; transform: translateY(4px); } }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }

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