:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --card: #ffffff;
  --fill: rgba(118, 118, 128, 0.12);
  --segment: #ffffff;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #a1a1a6;
  --line: rgba(60, 60, 67, 0.16);
  --accent: #0038b8;
  --accent-press: #002c91;
  --on-accent: #ffffff;
  --red: #d92d27;
  --blush: #f8e6e3;
  --bar: rgba(245, 245, 247, 0.78);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 8px 28px rgba(0, 0, 0, 0.05);
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --segment: #636366;
    --text: #f5f5f7;
    --text-2: #98989d;
    --text-3: #636366;
    --line: rgba(84, 84, 88, 0.55);
    --accent: #4d7cf5;
    --accent-press: #3a68dd;
    --red: #ff5a52;
    --blush: #2a1413;
    --bar: rgba(0, 0, 0, 0.72);
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 17px; line-height: 1.35; letter-spacing: -0.012em; -webkit-font-smoothing: antialiased; }
h1, h2, p { margin: 0; }
button, input, select, textarea { font: inherit; letter-spacing: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
label { cursor: pointer; }
img { display: block; }

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

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.row-input:focus-visible, .amount-input:focus-visible { outline: none; }

.demo-flag {
  text-align: center; font-size: 12px; font-weight: 500; color: var(--text-2);
  padding: calc(env(safe-area-inset-top) + 6px) 16px 6px; background: var(--fill);
}

/* Screens */
.screen {
  min-height: 100dvh;
  animation: rise 0.34s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.demo-flag:not([hidden]) ~ .screen { min-height: calc(100dvh - 30px); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.screen-center, .screen-home {
  display: flex; flex-direction: column; align-items: center;
  padding: calc(env(safe-area-inset-top) + 40px) 24px calc(env(safe-area-inset-bottom) + 24px);
  text-align: center;
}
.screen-center { justify-content: center; gap: 44px; }
.screen-home {
  justify-content: space-between; gap: 32px;
  background: radial-gradient(130% 55% at 50% 0%, var(--blush) 0%, transparent 100%);
}

.brand { display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: 420px; }
.brand-logo { width: 116px; height: 116px; margin-bottom: 18px; }
.screen-home .brand { margin-top: 5vh; }
.display { font-size: 34px; line-height: 1.12; font-weight: 700; letter-spacing: -0.028em; }
.lede { color: var(--text-2); font-size: 17px; }

/* Capture */
.capture { display: flex; flex-direction: column; align-items: center; gap: 24px; width: 100%; }
.shutter { display: flex; flex-direction: column; align-items: center; gap: 14px; user-select: none; -webkit-user-select: none; }
.shutter-disc {
  display: grid; place-items: center; width: 112px; height: 112px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 0 0 5px var(--bg), 0 0 0 8px var(--accent), 0 14px 34px rgba(0, 56, 184, 0.26);
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.18s;
}
.shutter:active .shutter-disc { transform: scale(0.94); background: var(--accent-press); }
.shutter-label { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; margin-top: 8px; }
input:focus-visible + .shutter .shutter-disc { outline: 2px solid var(--accent); outline-offset: 12px; }

.text-button {
  display: inline-block; padding: 10px 14px; font-size: 16px; font-weight: 500; color: var(--accent);
  border-radius: 10px; transition: opacity 0.15s;
}
.text-button:active { opacity: 0.55; }
input:focus-visible + .text-button { outline: 2px solid var(--accent); }

.account { display: flex; gap: 10px; align-items: baseline; justify-content: center; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.link { color: var(--text-2); font-size: 13px; text-decoration: underline; text-underline-offset: 2px; }

.error-text { color: var(--red); font-size: 15px; }
.google-button { display: flex; justify-content: center; width: 100%; min-height: 44px; color-scheme: light; }
.signin-action { display: flex; flex-direction: column; gap: 14px; align-items: center; width: 100%; max-width: 340px; }
.demo-google {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 48px;
  border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-weight: 500; font-size: 16px;
}
.demo-google:active { opacity: 0.6; }

/* Scan */
.scan-frame {
  position: relative; width: min(66vw, 280px); aspect-ratio: 3 / 4; border-radius: 20px; overflow: hidden;
  background: var(--card); box-shadow: var(--shadow), 0 20px 50px rgba(0, 0, 0, 0.1);
}
.scan-frame img { width: 100%; height: 100%; object-fit: cover; }
.scan-doc { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-3); }
.scan-sweep {
  position: absolute; left: 0; right: 0; top: 0; height: 42%;
  background: linear-gradient(180deg, transparent, rgba(77, 124, 245, 0.34) 88%, rgba(255, 255, 255, 0.9) 100%);
  animation: sweep 1.9s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;
}
@keyframes sweep { from { transform: translateY(-85%); } to { transform: translateY(190%); } }
.scan-title { font-size: 19px; font-weight: 600; letter-spacing: -0.018em; animation: breathe 1.9s ease-in-out infinite alternate; }
@keyframes breathe { from { opacity: 1; } to { opacity: 0.5; } }

/* Review */
.navbar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: var(--bar); border-bottom: 0.5px solid var(--line);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.nav-title { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; text-align: center; }
.nav-button { justify-self: start; color: var(--accent); font-size: 17px; min-height: 36px; }
.nav-button:active { opacity: 0.5; }
.nav-button-strong { justify-self: end; font-weight: 600; }
.nav-spacer { display: block; }

.sheet {
  display: flex; flex-direction: column; gap: 22px; max-width: 560px; margin: 0 auto;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 28px);
}

.pages { display: flex; gap: 10px; overflow-x: auto; padding: 2px; margin: -2px; scrollbar-width: none; justify-content: safe center; }
.pages::-webkit-scrollbar { display: none; }
.page {
  position: relative; flex: none; width: 66px; height: 88px; border-radius: 10px; overflow: hidden;
  background: var(--card); box-shadow: var(--shadow), 0 0 0 0.5px var(--line);
}
.page-open { display: block; width: 100%; height: 100%; }
.page img { width: 100%; height: 100%; object-fit: cover; }
.page-doc { display: grid; place-items: center; height: 100%; font-size: 12px; font-weight: 600; color: var(--text-2); }
.page-remove {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 13px; line-height: 1;
}
.page-add {
  flex: none; width: 66px; height: 88px; border-radius: 10px; display: grid; place-items: center;
  color: var(--accent); background: var(--fill); font-size: 26px; font-weight: 300;
}
.page-add:active { opacity: 0.55; }

.scan-note { text-align: center; text-wrap: balance; color: var(--text-2); font-size: 14px; margin-top: -8px; }
.scan-note:empty { display: none; }

.amount { display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 2px; }
.amount-line {
  display: flex; align-items: baseline; justify-content: center; max-width: 100%;
  font-size: 54px; line-height: 1.1; font-weight: 700; letter-spacing: -0.035em; font-variant-numeric: tabular-nums;
}
.amount-symbol { margin-right: 2px; }
.amount-input {
  width: 4.5ch; min-width: 2ch; max-width: 100%; padding: 0; border: 0; background: none; outline: 0;
  font-weight: 700; letter-spacing: -0.035em; font-variant-numeric: tabular-nums; caret-color: var(--accent);
}
.amount-input::placeholder { color: var(--text-3); }
.is-missing .amount-symbol, .is-missing .amount-input::placeholder { color: var(--red); }

.group { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.group-title { font-size: 13px; font-weight: 400; color: var(--text-2); letter-spacing: 0; margin: 0 0 -14px 16px; }

.row {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 50px;
  padding: 8px 16px; text-align: left;
}
.row + .row::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 0.5px; background: var(--line);
}
.row-top { align-items: flex-start; padding-top: 14px; padding-bottom: 14px; }
.row-label { flex: none; width: 96px; font-weight: 400; }
.row-label-wide { width: auto; flex: 1; }
.row-input {
  flex: 1; min-width: 0; width: 100%; border: 0; background: none; padding: 0; outline: 0;
  -webkit-appearance: none; appearance: none; color: var(--text); min-height: 22px;
}
.row-input::placeholder { color: var(--text-3); }
.row-input-end { flex: 0 1 45%; text-align: right; font-weight: 600; }
.row-input-end::placeholder { font-weight: 400; }
input[type="date"].row-input { display: block; text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
textarea.row-input { resize: none; overflow: hidden; line-height: 1.32; display: block; field-sizing: content; }
.is-missing .row-label { color: var(--red); }

.select-wrap { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; }
.select-wrap select { padding-right: 18px; text-overflow: ellipsis; }
.chevron-updown { position: absolute; right: 0; color: var(--text-3); pointer-events: none; }

.row-button { color: var(--text); }
.row-button:active { background: var(--fill); }
.row-value { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: right; color: var(--text-2); }
.row-value.has-value { color: var(--text); }
.chevron { flex: none; color: var(--text-3); }

.switch {
  -webkit-appearance: none; appearance: none; flex: none; position: relative; width: 51px; height: 31px; margin: 0;
  border-radius: 999px; background: var(--fill); cursor: pointer; transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
  transition: transform 0.22s cubic-bezier(0.3, 1.2, 0.5, 1);
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

/* Segmented control */
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 2px;
  border-radius: 10px; background: var(--fill);
}
.segmented label { display: block; text-align: center; position: relative; }
.segmented input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: block; padding: 7px 8px; border-radius: 8px; font-size: 15px; font-weight: 500;
  transition: background 0.18s, box-shadow 0.18s;
}
.segmented input:checked + span {
  background: var(--segment); font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
}
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.segmented-small { width: 188px; border-radius: 9px; }
.segmented-small span { padding: 5px 8px; font-size: 14px; border-radius: 7px; }
.segmented.is-missing { box-shadow: 0 0 0 1px var(--red); }

/* Send */
.primary {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 54px;
  border-radius: 14px; background: var(--accent); color: var(--on-accent); font-size: 17px; font-weight: 600;
  transition: transform 0.15s, background 0.15s, opacity 0.15s; user-select: none; -webkit-user-select: none;
}
.primary:active { transform: scale(0.98); background: var(--accent-press); }
.primary[aria-disabled="true"] { opacity: 0.38; }
.primary.is-busy { opacity: 0.8; pointer-events: none; }
.spinner { width: 17px; height: 17px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35); border-top-color: #fff; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.send-hint, .send-as { text-align: center; font-size: 13px; color: var(--text-2); margin-top: -12px; }
.send-hint:empty, .send-as:empty { display: none; }
.error-block { text-align: center; margin-bottom: -8px; }

/* Sent */
.done { margin-bottom: 18px; }
.done-ring, .done-check { fill: none; stroke: var(--accent); stroke-linecap: round; stroke-linejoin: round; }
.done-ring { stroke-width: 3; stroke-dasharray: 183; stroke-dashoffset: 183; transform: rotate(-90deg); transform-origin: center; animation: draw 0.55s cubic-bezier(0.6, 0, 0.3, 1) forwards; }
.done-check { stroke-width: 4; stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw 0.28s 0.42s ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.sent-amount { font-size: 28px; font-weight: 600; letter-spacing: -0.024em; font-variant-numeric: tabular-nums; margin-top: 6px; }
.sent-note { font-size: 14px; color: var(--text-2); margin-top: 14px; max-width: 300px; }
.sent-actions { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; max-width: 340px; }

/* Session picker */
.bottom-sheet {
  width: 100%; max-width: 560px; max-height: 78dvh; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 16px 16px 0 0; background: var(--bg); color: var(--text); overflow: hidden;
}
.bottom-sheet[open] { display: flex; flex-direction: column; animation: slide-up 0.3s cubic-bezier(0.2, 0.85, 0.25, 1); }
.bottom-sheet::backdrop, .viewer::backdrop { background: rgba(0, 0, 0, 0.42); animation: fade 0.25s; }
@keyframes slide-up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.sheet-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 12px 16px;
  background: var(--bar); border-bottom: 0.5px solid var(--line);
}
.sheet-list { overflow-y: auto; margin: 14px 16px calc(env(safe-area-inset-bottom) + 18px); border-radius: var(--radius); background: var(--card); flex: 1; }
.check-row { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 16px; position: relative; }
.check-row + .check-row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 0.5px; background: var(--line); }
.check-row:active { background: var(--fill); }
.check-row input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.check-row span { flex: 1; }
.check-row svg { flex: none; color: var(--accent); visibility: hidden; }
.check-row input:checked ~ svg { visibility: visible; }
.check-row input:focus-visible ~ span { text-decoration: underline; }

/* Photo viewer */
.viewer { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #000; }
.viewer[open] { display: flex; align-items: center; justify-content: center; animation: fade 0.2s; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-close { position: absolute; top: calc(env(safe-area-inset-top) + 12px); right: 16px; color: #fff; font-weight: 600; z-index: 1; padding: 8px; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7); }

@media (min-width: 700px) {
  .sheet { padding-top: 28px; }
  .bottom-sheet { margin: auto; border-radius: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .scan-title { animation: none; }
}
