:root {
  --green: #5b9330;
  --green-hover: #457026;
  --green-dark: #304c19;
  --green-light: #dde8cf;
  --bg: #121512;
  --surface: #1c201c;
  --surface-2: #242a24;
  --line: #2f362f;
  --text: #f2f5f0;
  --muted: #a3aca0;
  --danger: #e2564a;
  --warn: #d8a13a;
  --r: 14px;
  --pad: 18px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Satoshi', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior-y: contain;
}

.tabular { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum' 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) var(--pad) 12px;
  background: rgba(18, 21, 18, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { height: 38px; width: auto; display: block; }
.wordmark {
  margin-left: auto;
  font-size: 12px; font-weight: 700; letter-spacing: 0.16em;
  color: var(--muted);
}
.back {
  display: grid; place-items: center;
  width: 40px; height: 40px; margin-left: -8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); cursor: pointer;
}
.back:active { background: var(--surface-2); }

.offline-badge {
  position: sticky; top: 0; z-index: 25;
  margin: 0; padding: 7px var(--pad);
  background: var(--warn); color: #201a06;
  font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-align: center;
}

/* ---------- screens ---------- */
main { max-width: 620px; margin: 0 auto; }
.screen { display: none; padding: 20px var(--pad) 120px; }
.screen.active { display: block; animation: slide 0.26s var(--ease); }
@keyframes slide { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .screen.active { animation: none; } }

.screen-title { font-size: 26px; font-weight: 900; line-height: 1.15; margin: 4px 0 6px; letter-spacing: -0.01em; }
.hint { color: var(--muted); font-size: 15px; margin: 0 0 20px; }

/* ---------- tiles ---------- */
.tile {
  display: flex; align-items: center; gap: 14px; width: 100%;
  margin-bottom: 12px; padding: 18px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  color: var(--text); text-align: left; font: inherit;
}
.tile-active {
  background: linear-gradient(160deg, #23331a, var(--surface) 70%);
  border-color: var(--green); cursor: pointer;
  box-shadow: 0 8px 24px -14px rgba(91, 147, 48, 0.7);
  transition: transform 0.12s var(--ease), background 0.2s var(--ease);
}
.tile-active:active { transform: scale(0.985); background: #263a1c; }
.tile-soon { opacity: 0.5; }
.tile-icon { flex: 0 0 46px; height: 46px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); color: var(--green); }
.tile-active .tile-icon { background: var(--green); color: #0f1a08; }
.tile-icon svg { width: 26px; height: 26px; }
.tile-body { display: flex; flex-direction: column; min-width: 0; }
.tile-label { font-size: 18px; font-weight: 700; }
.tile-sub { font-size: 14px; color: var(--muted); }
.tile-go { margin-left: auto; color: var(--green); }
.chip {
  margin-left: auto; padding: 4px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 11px; font-weight: 700; letter-spacing: 0.1em; color: var(--muted);
}

.queue-banner {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 18px; padding: 14px;
  background: #33290c; border: 1px solid var(--warn); border-radius: var(--r);
}
.queue-banner strong { display: block; font-size: 15px; }
.queue-banner span { font-size: 13px; color: #e6d3a5; }

.home-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line);
  font-size: 14px; color: var(--muted);
}
.link { background: none; border: 0; padding: 6px 0; color: var(--green); font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 54px; padding: 14px 18px;
  border: 1px solid transparent; border-radius: var(--r);
  font: inherit; font-weight: 700; font-size: 17px; cursor: pointer;
  transition: transform 0.1s var(--ease), background 0.16s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: scale(0.985); }
.btn-primary { background: var(--green); color: #0d1607; }
.btn-primary:hover:not(:disabled) { background: var(--green-hover); }
.btn-primary:disabled { background: var(--surface-2); color: #6d766c; cursor: not-allowed; border-color: var(--line); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface); }
.btn-xl { min-height: 68px; font-size: 19px; }
.btn-lg { min-height: 60px; font-size: 18px; }
.btn-sm { width: auto; min-height: 44px; font-size: 15px; padding: 10px 16px; flex: 0 0 auto; }
.btn-warn { background: var(--warn); color: #201a06; }

/* Outlook hand-off. Deliberately NOT green: green means "the app sent it".
   This button means "your own mail app is sending it", and the crew should be
   able to tell those two apart at a glance. */
.btn-outlook { background: #0f6cbd; color: #ffffff; }
.btn-outlook:hover:not(:disabled) { background: #0d5aa0; }
.btn-outlook svg { width: 22px; height: 22px; flex: 0 0 auto; }
.btn-outlook.secondary {
  background: transparent; color: #7cb8e8; border-color: #2c4a63;
  min-height: 48px; font-size: 15px; margin-top: 8px;
}
.btn-outlook.secondary:hover { background: rgba(15,108,189,0.12); }
.btn-outlook.secondary svg { width: 18px; height: 18px; }
.handoff-note {
  margin: 8px 0 0; font-size: 13px; line-height: 1.4; color: var(--muted);
  text-align: center;
}
.btn + .btn { margin-top: 10px; }
:focus-visible { outline: 3px solid var(--green-light); outline-offset: 2px; }

.spinner { display: none; width: 20px; height: 20px; border: 3px solid rgba(0,0,0,0.25); border-top-color: #0d1607; border-radius: 50%; animation: spin 0.7s linear infinite; }
.btn.sending .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.sticky-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px var(--pad) calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 62%, rgba(18,21,18,0));
}
.sticky-bar { display: flex; flex-direction: column; align-items: center; }
.sticky-bar > * { width: 100%; max-width: 620px; }

/* ---------- capture ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin-top: 22px; padding: 30px 16px;
  border: 1px dashed var(--line); border-radius: var(--r);
  color: var(--muted); font-size: 15px;
}
.empty-mark { color: #4c554a; }

.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; margin-top: 20px; }
.shot { position: relative; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); }
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shot .x {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px;
  display: grid; place-items: center; border: 0; border-radius: 50%;
  background: rgba(10,12,10,0.82); color: #fff; font-size: 17px; line-height: 1; cursor: pointer;
}
.shot .sz { position: absolute; bottom: 0; left: 0; right: 0; padding: 5px 7px; background: rgba(10,12,10,0.78); font-size: 11px; color: var(--green-light); font-variant-numeric: tabular-nums; }
.shots-review .x { display: none; }
.compress-note { margin-top: 12px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- form ---------- */
.field { margin-bottom: 18px; }
.field label, .toggle-row label { display: block; margin-bottom: 7px; font-size: 15px; font-weight: 700; }
.field label em { margin-left: 6px; font-style: normal; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; color: var(--green); text-transform: uppercase; }
input[type="text"], input[type="date"], select {
  width: 100%; min-height: 56px; padding: 12px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  font: inherit; font-size: 17px;
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a3aca0' stroke-width='2.4'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 20px;
  padding-right: 44px;
}
input:focus, select:focus { border-color: var(--green); outline: none; }
input::placeholder { color: #707a6e; }
.other-input { margin-top: 10px; }
.row .field label { white-space: nowrap; }
.field label em.star { font-size: 17px; color: var(--green); letter-spacing: 0; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.money { position: relative; }
.money span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 700; }
.money input { padding-left: 32px; font-size: 20px; font-weight: 700; }

.suggests { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.suggests button {
  padding: 9px 13px; min-height: 40px;
  background: var(--surface-2); color: var(--green-light);
  border: 1px solid var(--line); border-radius: 999px;
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
}
.suggests button:active { background: var(--green-dark); }

.optional { margin: 4px 0 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.optional > summary { padding: 17px 16px; font-weight: 700; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; }
.optional > summary::-webkit-details-marker { display: none; }
.optional > summary::after { content: '+'; margin-left: auto; font-size: 22px; color: var(--green); }
.optional[open] > summary::after { content: '–'; }
.sum-hint { font-size: 13px; font-weight: 400; color: var(--muted); }
.optional > .field, .optional > .toggle-row { margin: 0 16px 18px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toggle-row label { margin: 0; }
.switch { flex: 0 0 auto; width: 62px; height: 36px; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); cursor: pointer; }
.switch span { display: block; width: 28px; height: 28px; border-radius: 50%; background: #7d867b; transition: transform 0.18s var(--ease), background 0.18s var(--ease); }
.switch[aria-checked="true"] { background: var(--green-dark); border-color: var(--green); }
.switch[aria-checked="true"] span { transform: translateX(26px); background: var(--green); }

.form-error.queued { background: #33290c; border-color: var(--warn); color: #f0d69b; }
.form-error {
  display: flex; gap: 8px; margin: 4px 0 18px; padding: 13px 14px;
  background: #331916; border: 1px solid var(--danger); border-radius: 12px;
  color: #ffc9c3; font-size: 15px;
}

/* ---------- review ---------- */
.subject-card { padding: 14px; margin-bottom: 18px; background: var(--surface); border: 1px solid var(--green-dark); border-left: 4px solid var(--green); border-radius: 12px; }
.subject-label { display: block; margin-bottom: 7px; font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.subject-card code { display: block; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 13.5px; line-height: 1.55; color: var(--green-light); word-break: break-word; }

.summary { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.sumrow { display: flex; gap: 14px; padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 16px; }
.sumrow:last-child { border-bottom: 0; }
.sumrow span { flex: 0 0 44%; color: var(--muted); font-size: 15px; }
.sumrow strong { flex: 1; font-weight: 700; word-break: break-word; }
.sumrow.big strong { font-size: 20px; color: var(--green); font-variant-numeric: tabular-nums; }
.dest-note { margin: 16px 0 0; font-size: 14px; color: var(--muted); }
.dest-note strong { color: var(--text); }

/* ---------- success ---------- */
.screen-success { text-align: center; padding-top: 44px; }
.screen-success h1 { font-size: 27px; font-weight: 900; margin: 20px 0 6px; }
.success-sub { color: var(--muted); margin: 0 0 22px; }
.tick { width: 104px; height: 104px; margin: 0 auto; }
.tick svg { width: 100%; height: 100%; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.tick-c { stroke: var(--green); stroke-width: 2.5; opacity: 0.45; }
.tick-p { stroke: var(--green); stroke-width: 4.5; stroke-dasharray: 48; stroke-dashoffset: 48; animation: draw 0.5s 0.1s var(--ease) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
/* Hand-off destination. Blue, matching the Outlook button, so the crew learn that
   blue = "you are finishing this in your own mail app". */
.to-box {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  max-width: 420px; margin: 0 auto 22px; padding: 16px 18px;
  background: rgba(15,108,189,0.10); border: 1px solid #2c6fa8; border-radius: 12px;
}
.to-box .to-label { font-size: 12px; letter-spacing: 0.09em; text-transform: uppercase; color: #9fd0f5; }
.to-box code {
  font-family: ui-monospace, Menlo, monospace; font-size: 16px; color: #e6f2fb;
  word-break: break-all; line-height: 1.35;
}
.to-box .btn { width: auto; }
/* When the receipt was handed to the crew member's mail app the app cannot prove
   it was sent, so the tick is blue, not the green "confirmed sent" tick. */
.screen-success.handoff .tick-c { stroke: #2c6fa8; }
.screen-success.handoff .tick-p { stroke: #4a9de0; }

.ref-box { display: inline-flex; flex-direction: column; gap: 4px; padding: 12px 20px; margin-bottom: 26px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.ref-box span { font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.ref-box code { font-family: ui-monospace, Menlo, monospace; font-size: 16px; color: var(--green-light); }
.stack { max-width: 380px; margin: 0 auto; }

/* ---------- recent ---------- */
.rec { display: flex; align-items: center; gap: 12px; padding: 15px 14px; margin-bottom: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.rec-main { min-width: 0; flex: 1; }
.rec-vendor { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-meta { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rec-amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.status { padding: 4px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; }
.status.sent { background: #1f3312; color: #b6e08d; border: 1px solid var(--green-dark); }
.status.failed { background: #331916; color: #ffc9c3; border: 1px solid var(--danger); }
.status.queued { background: #33290c; color: #f0d69b; border: 1px solid var(--warn); }
/* Handed to the crew member's own mail app. The app cannot prove it left the
   phone, so it is styled distinctly from a confirmed SENT. */
.status.handoff { background: #10283b; color: #9fd0f5; border: 1px solid #2c6fa8; }

@media (min-width: 700px) {
  .screen { padding-bottom: 130px; }
  .screen-title { font-size: 30px; }
}

/* ---------- pickers (chip rows) ---------- */
.picker { margin: 0 0 20px; }
.picker-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 9px; }
.picker-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: 0.01em; }
.picker-head em { font-style: normal; font-size: 11px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
.picker-head em.req { color: var(--green); }
.picker-head em.opt { color: #7d867b; }
.picker-head .clear { margin-left: auto; background: none; border: 0; padding: 4px 0; color: var(--muted); font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  min-height: 48px; padding: 11px 16px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  font: inherit; font-size: 15.5px; font-weight: 500; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s var(--ease), background 0.14s var(--ease), border-color 0.14s var(--ease);
}
.pill:active { transform: scale(0.97); }
.pill.on { background: var(--green); border-color: var(--green); color: #0d1607; font-weight: 700; }
.pill.ghost { background: transparent; color: var(--muted); border-style: dashed; }
.pill.ghost.on { background: var(--green-dark); border-style: solid; border-color: var(--green); color: var(--green-light); }
.picker.unset .chips { padding: 6px; margin: -6px; border-radius: 16px; }
.picker.unset.flash .chips { box-shadow: 0 0 0 2px var(--danger); }

/* ---------- bottom sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet-scrim { position: absolute; inset: 0; background: rgba(6, 8, 6, 0.72); }
.sheet {
  position: relative; max-height: 78vh; display: flex; flex-direction: column;
  background: var(--surface); border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise 0.24s var(--ease);
  max-width: 620px; width: 100%; margin: 0 auto;
}
@keyframes rise { from { transform: translateY(28px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 16px var(--pad); border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 18px; font-weight: 900; }
.sheet-head .back { margin-left: auto; }
.sheet-list { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px var(--pad) 20px; }
.sheet-item {
  display: block; width: 100%; min-height: 56px; padding: 15px 16px;
  margin-top: 8px; text-align: left;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  font: inherit; font-size: 17px; cursor: pointer;
}
.sheet-item.on { background: var(--green-dark); border-color: var(--green); color: var(--green-light); font-weight: 700; }
.sheet-item:active { background: var(--green-dark); }


/* ---- long QuickBooks names: truncate in chips, never in the sheet -------- */
.pill {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 430px) {
  .pill { max-width: calc(100vw - 60px); }
}

/* ---- searchable bottom sheet -------------------------------------------- */
.sheet-search {
  padding: 10px 16px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.sheet-search input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  font: inherit;
  font-size: 16px;                /* 16px stops iOS Safari zooming on focus */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  -webkit-appearance: none;
}
.sheet-search input:focus { outline: none; border-color: var(--brand); }
.sheet-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  text-align: left;
}
.sheet-item .sheet-name { white-space: normal; overflow-wrap: anywhere; }
.sheet-item .sheet-num {
  flex: none;
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 0.82rem;
  color: var(--muted);
}
.sheet-item.on .sheet-num { color: inherit; }
.sheet-empty { padding: 22px 4px; color: var(--muted); }
