:root {
  --brand: #714B67; --brand-ink: #fff; --bg: #f3f2f5; --card: #fff; --ink: #1d1b20;
  --muted: #6b6670; --line: #e2dfe6; --ok: #1e7a46; --warn: #a15c00; --danger: #b3261e;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141216; --card: #211e24; --ink: #ece9ef; --muted: #a29ca8; --line: #36323a; --brand: #b483a8; --brand-ink: #1b1219; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 17px; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }

.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--brand); color: var(--brand-ink);
}
.bar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; }
.bar .link-btn { color: var(--brand-ink); }
.icon-btn { background: none; border: 0; color: inherit; font-size: 30px; line-height: 1; padding: 0 6px 0 0; }

main { padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px); max-width: 640px; margin: 0 auto; }
.view { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; border: 1px solid var(--line); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.muted { color: var(--muted); font-size: 14px; font-weight: 400; }
.center { text-align: center; }
.section-label { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 8px 0 -4px; }

label, .field-label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, select {
  font: inherit; font-size: 17px; color: var(--ink); background: var(--card); width: 100%;
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 46px;
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

button { font: inherit; cursor: pointer; }
.primary, .secondary {
  border-radius: 12px; padding: 13px 16px; font-weight: 600; min-height: 48px; border: 0;
}
.primary { background: var(--brand); color: var(--brand-ink); }
.secondary { background: var(--card); color: var(--brand); border: 1px solid var(--line); }
.big { font-size: 18px; min-height: 56px; }
.primary:disabled { opacity: .6; }
.link-btn { background: none; border: 0; color: var(--brand); font-size: 15px; padding: 6px; cursor: pointer; }
.link-btn.danger { color: var(--danger); }

.target {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: var(--ink);
}
.target:active { transform: scale(.99); }
.target:disabled { opacity: .5; }
.target-name { font-weight: 600; }
.target.general { border: 2px dashed var(--brand); }
.target-banner { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; }

.camera-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  min-height: 220px; border-radius: 20px; background: var(--brand); color: var(--brand-ink);
  font-size: 19px; font-weight: 600; text-align: center; padding: 20px; cursor: pointer;
}
.camera-icon { font-size: 56px; }
.reading { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.reading img { max-height: 220px; max-width: 100%; border-radius: 8px; }
.spinner {
  display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.notice { background: #fff4e0; color: #6a4300; border-radius: 10px; padding: 10px 12px; font-size: 15px; }
@media (prefers-color-scheme: dark) { .notice { background: #3a2b10; color: #ffd89a; } }

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 10px; padding: 3px; }
.segmented button { border: 0; background: none; padding: 9px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 15px; }
.segmented button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

.vendor { display: flex; flex-direction: column; gap: 6px; }
.chip { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--bg); border-radius: 10px; padding: 8px 8px 8px 12px; font-weight: 600; }
.results { display: flex; flex-direction: column; }
.results button { text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 11px 4px; color: var(--ink); }
.new-vendor { margin-top: 6px; }

.line { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.line-nums { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 8px; }
.line-foot { display: flex; justify-content: space-between; align-items: center; }

.totals { display: flex; flex-direction: column; gap: 6px; }
.totals > div { display: flex; justify-content: space-between; }
.totals .grand { font-weight: 700; font-size: 19px; border-top: 1px solid var(--line); padding-top: 6px; }
.totals .ok { color: var(--ok); }
.totals .warn { color: var(--warn); }
#t-check { display: block; font-size: 14px; }

.photo-details summary { cursor: pointer; color: var(--brand); }
.photo-details img { width: 100%; margin-top: 10px; border-radius: 8px; }

.done { align-items: center; text-align: center; }
.done h2 { margin: 0; font-size: 20px; }
.done p { margin: 0; }
.done a { color: var(--brand); font-weight: 600; }
.tick { width: 64px; height: 64px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 36px; display: grid; place-items: center; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px); z-index: 10;
  background: #2b2730; color: #fff; padding: 12px 14px; border-radius: 12px; font-size: 15px; max-width: 600px; margin: 0 auto;
}
.segmented.pay { grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); }
.done .notice { text-align: left; }
button.camera-btn { border: 0; width: 100%; }
.l-product { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; background: var(--bg); border-radius: 8px; padding: 4px 4px 4px 10px; }
.l-product.new .l-prod-name { color: var(--warn); }
.l-product.matched .l-prod-name { color: var(--ok); }
#ocr-text { white-space: pre-wrap; font-size: 13px; max-height: 260px; overflow: auto; margin: 8px 0 0; }
