:root {
  --bg: #0e1116;
  --surface: #171b22;
  --line: #262c36;
  --text: #e8ecf1;
  --muted: #8a94a3;
  --accent: #3ddc97;
  --warn: #f5b942;
  --bad: #ff6b6b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body { -webkit-user-select: none; user-select: none; }
input, select { -webkit-user-select: text; user-select: text; }

[hidden] { display: none !important; }

.app {
  min-height: 100vh;
  padding: calc(var(--safe-top) + 8px) 16px calc(var(--safe-bottom) + 32px);
  max-width: 640px;
  margin: 0 auto;
}
.app.with-fab { padding-bottom: calc(var(--safe-bottom) + 110px); }

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
}
.bar h1 { font-size: 28px; letter-spacing: -0.02em; margin: 0; flex: 1; }
.bar .title { font-size: 22px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button { font: inherit; color: inherit; border: 0; cursor: pointer; }
button:disabled { opacity: 0.55; cursor: default; }

.ghost {
  background: none;
  color: var(--muted);
  padding: 8px 4px;
  font-size: 16px;
}

.back {
  background: none;
  width: 40px;
  height: 40px;
  margin-left: -10px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--text);
}
.back:active { background: var(--line); }

.badge {
  font: 600 14px/1 ui-monospace, "SF Mono", Menlo, monospace;
  padding: 7px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  white-space: nowrap;
}

/* ---- login ---- */
.login { padding-top: 14vh; }
.brand { font-size: 38px; letter-spacing: -0.03em; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 28px; }

/* ---- forms ---- */
.field { display: block; color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.field input, .field select, .sheet input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 13px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 17px;   /* 16px+ keeps iOS from zooming in */
  appearance: none;
  -webkit-appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238a94a3' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}
.field input:focus, .field select:focus, .sheet input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field input.money { font: 600 22px/1.2 ui-monospace, "SF Mono", Menlo, monospace; text-align: right; }
.stack > * { margin-bottom: 0; }
.stack .field { margin-bottom: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.err { color: var(--bad); margin: 0 0 12px; font-size: 15px; }
.hint { color: var(--muted); font-size: 14px; margin: -6px 0 14px; }
.note {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-size: 15px;
}
.note.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.code-line { font: 600 22px/1.2 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.04em; margin: 6px 0 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 15px 22px;
  border-radius: 14px;
  font-weight: 650;
  font-size: 17px;
}
.btn.block { display: flex; width: 100%; margin-top: 10px; }
.btn.primary { background: var(--accent); color: #06281a; }
.btn.secondary { background: var(--surface); border: 1px solid var(--line); color: var(--text); }
.btn:active { filter: brightness(0.92); }

.more { margin: 0 0 14px; }
.more summary { color: var(--muted); font-size: 15px; padding: 6px 0 12px; cursor: pointer; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font: 600 16px/1 ui-monospace, "SF Mono", Menlo, monospace;
}
.chip:active { border-color: var(--accent); }
#chips-wrap .hint { margin-bottom: 8px; }

/* ---- cards ---- */
.greeting { color: var(--muted); margin: 0 0 14px; font-size: 18px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
}
.card .field:last-of-type { margin-bottom: 4px; }
.row-btn {
  width: 100%;
  background: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 0;
  font-size: 17px;
  text-align: left;
}
.card form { margin-top: 14px; }

.empty {
  color: var(--muted);
  text-align: center;
  margin: 18vh 24px 0;
  line-height: 1.6;
}
.empty b { color: var(--text); font-weight: 600; }

/* ---- list ---- */
.list { list-style: none; margin: 8px 0 0; padding: 0; }

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.item.tap:active { background: #1c212a; }

.code { flex: 1; min-width: 0; }
.code .name { font-weight: 600; font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; }
.code .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.code .mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.03em; }
.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--line);
  font-size: 18px;
  line-height: 1;
}
.qty button:active { background: #323a47; }
.qty span { min-width: 22px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.line-total { font: 600 15px/1 ui-monospace, "SF Mono", Menlo, monospace; white-space: nowrap; }

.del {
  background: none;
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin-right: -8px;
}
.del:active { background: var(--line); }

.summary { margin-top: 6px; }
.sum-row { display: flex; justify-content: space-between; color: var(--muted); padding: 3px 0; }
.sum-row.big { color: var(--text); font-size: 22px; font-weight: 700; padding-top: 8px; }

.fab {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 20px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 28px;
  border-radius: 999px;
  background: var(--accent);
  color: #06281a;
  font-weight: 650;
  font-size: 17px;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.45);
}
.fab:active { transform: translateX(-50%) scale(0.97); }

/* ---- busy / toast ---- */
.busy {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.busy-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 24px 28px; min-width: 240px; text-align: center; }
.busy-card p { margin: 14px 0 12px; }
.spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.bar-track { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.25s; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--safe-bottom) + 96px);
  z-index: 40;
  margin: 0 auto;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: 14px;
  background: #232a35;
  border: 1px solid var(--line);
  text-align: center;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.45);
}

/* ---- camera ---- */
.scanner {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #000;
  overflow: hidden;
}

.scanner video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.box {
  position: absolute;
  border: 3px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgb(0 0 0 / 0.35);
  transition: left 0.12s, top 0.12s, width 0.12s, height 0.12s;
  pointer-events: none;
}

/* Frame the label here: this part of the picture is what gets read. */
.guide {
  position: absolute;
  left: 4%;
  right: 4%;
  top: 22%;
  aspect-ratio: 1.7 / 1;
  border: 3px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 0 0 9999px rgb(0 0 0 / 0.45);
  pointer-events: none;
}

.scanner-top {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: row-reverse;
}
.scan-title {
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgb(20 24 31 / 0.65);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-weight: 600;
  font-size: 15px;
}
.scan-title:empty { display: none; }

.round {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgb(20 24 31 / 0.65);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #fff;
}
.round[aria-pressed="true"] { background: var(--warn); color: #261b00; }

.scanner-bottom {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(var(--safe-bottom) + 24px);
  text-align: center;
  text-shadow: 0 1px 8px rgb(0 0 0 / 0.8);
}
.status { margin: 0; font-size: 18px; font-weight: 600; }
.detail {
  margin: 6px 0 14px;
  min-height: 1.4em;
  font: 15px/1.4 ui-monospace, "SF Mono", Menlo, monospace;
  color: #d4dae3;
}

.scan-actions { display: flex; align-items: center; justify-content: center; gap: 18px; min-height: 54px; }
.pill {
  padding: 13px 18px;
  border-radius: 999px;
  background: rgb(20 24 31 / 0.7);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  text-shadow: none;
}
.shutter {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: none;
  border: 4px solid #fff;
  padding: 4px;
}
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; }
.shutter:active span { background: var(--accent); }

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px 16px calc(var(--safe-bottom) + 18px);
  background: var(--bg);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  text-shadow: none;
}
.sheet-title { margin: 0 0 4px; font-weight: 600; font-size: 17px; }
.sheet input { margin: 8px 0 14px; font: 600 22px/1.2 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.06em; text-align: center; }
.sheet .err { margin-top: -6px; }

@media (prefers-reduced-motion: reduce) {
  .box, .bar-fill { transition: none; }
  .spinner { animation-duration: 2s; }
}
