:root {
  --bg: #f2f2f7;
  --card: #fff;
  --text: #111;
  --muted: #6b6b73;
  --line: #dcdce2;
  --accent: #0a5bd8;
  --accent-ink: #fff;
  --green: #1f8a3b;
  --green-bg: #e3f5e8;
  --red: #c62828;
  --red-bg: #fdecec;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 17px/1.35 -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea, select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff;
  font-size: 17px; /* 16px+ stops iOS zooming on focus */
  -webkit-appearance: none; appearance: none;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
button { cursor: pointer; border: 0; background: none; touch-action: manipulation; }
.hidden { display: none !important; }

#view { padding: calc(var(--safe-t) + 8px) 12px calc(var(--nav-h) + var(--safe-b) + 90px); max-width: 720px; margin: 0 auto; }
body.nonav #view { padding-bottom: 40px; }

/* Bottom navigation */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
  background: rgba(250, 250, 252, 0.97); border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
#tabs button { flex: 1; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); }
#tabs button svg { width: 26px; height: 26px; }
#tabs button.on { color: var(--accent); }
body.nonav #tabs { display: none; }

/* Generic pieces */
h1 { font-size: 26px; margin: 8px 4px 12px; }
.top { display: flex; align-items: center; gap: 8px; min-height: 52px; margin-bottom: 8px; }
.top h1 { flex: 1; margin: 0 4px; font-size: 22px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .sub { display: block; font-size: 14px; color: var(--muted); font-weight: 400; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 0 18px;
  border-radius: 12px; background: var(--card); border: 1px solid var(--line); font-weight: 600; font-size: 17px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--red); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.card { background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 14px; color: var(--muted); margin: 0 4px 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.err { color: var(--red); margin: 8px 4px; min-height: 1em; }

/* Home */
.home { display: flex; flex-direction: column; gap: 16px; padding-top: 12vh; }
.home .big { min-height: 120px; border-radius: 20px; font-size: 26px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 12px; }
.home .big.primary { background: var(--accent); color: #fff; }
.home .big.second { background: #fff; color: var(--text); border: 2px solid var(--line); }
.home .big .count { font-size: 18px; background: var(--bg); color: var(--text); border-radius: 20px; padding: 2px 12px; }

/* Lists */
.list { background: var(--card); border-radius: 14px; overflow: hidden; }
.list > .item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 13px 14px; min-height: 58px; border-bottom: 1px solid var(--line); }
.list > .item:last-child { border-bottom: 0; }
.list > .item:active { background: #eef3fd; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: 14px; color: var(--muted); }
.item .right { text-align: right; white-space: nowrap; font-weight: 600; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 10px; background: var(--bg); color: var(--muted); }
.badge.inv { background: #e6eefc; color: var(--accent); }
.badge.paid { background: var(--green-bg); color: var(--green); }
.badge.unpaid { background: var(--red-bg); color: var(--red); }
.badge.qty { background: var(--accent); color: #fff; font-size: 14px; min-width: 28px; text-align: center; }
.more { text-align: center; color: var(--muted); font-size: 14px; padding: 12px; }

/* Search bar (sticky) */
.searchbar { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: calc(var(--safe-t) + 6px) 0 8px; margin-top: calc(-1 * var(--safe-t) - 8px); display: flex; gap: 8px; }
.searchbar .box { position: relative; flex: 1; }
.searchbar input { height: 52px; padding-right: 44px; font-size: 18px; }
.searchbar .clear { position: absolute; right: 4px; top: 4px; width: 44px; height: 44px; font-size: 22px; color: var(--muted); }
.iconbtn { width: 52px; height: 52px; flex: none; border-radius: 12px; background: var(--card); border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; }
.iconbtn svg { width: 26px; height: 26px; }
.iconbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Estimate / fulfillment lines */
.lines { display: flex; flex-direction: column; gap: 8px; }
.line { background: var(--card); border-radius: 14px; padding: 10px 10px 10px 14px; }
.line .name { font-weight: 600; }
.line .sub { font-size: 14px; color: var(--muted); }
.line .ctl { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.line .ctl .lt { flex: 1; font-weight: 600; }
.line.flash { animation: flash 1s; }
@keyframes flash { from { background: #dce8ff; } to { background: var(--card); } }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.stepper button { width: 48px; height: 46px; font-size: 24px; font-weight: 600; color: var(--accent); }
.stepper input { width: 58px; height: 46px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); border-radius: 0; text-align: center; padding: 0; font-weight: 700; }
.del { width: 46px; height: 46px; border-radius: 12px; color: var(--red); font-size: 22px; }
.acts { display: flex; gap: 8px; margin-top: 8px; }
.acts button { flex: 1; min-height: 48px; border-radius: 12px; font-weight: 700; border: 1px solid var(--line); background: #fff; }
.acts .got.on { background: var(--green); color: #fff; border-color: var(--green); }
.acts .na { color: var(--red); }
.line.got { background: var(--green-bg); }
.line.got .name::before { content: "✓ "; color: var(--green); font-weight: 800; }
.line.na { background: #ececf0; }
.line.na .name, .line.na .sub, .line.na .lt { text-decoration: line-through; color: var(--muted); }
.notefield { margin-top: 12px; }

/* Bottom action / total bar */
.totalbar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b)); z-index: 15;
  background: #fff; border-top: 1px solid var(--line); padding: 8px 12px; display: flex; align-items: center; gap: 10px;
}
.totalbar .sum { flex: 1; }
.totalbar .sum b { font-size: 22px; display: block; }
.totalbar .sum span { font-size: 13px; color: var(--muted); }

/* Search results */
.results .item .price { color: var(--muted); font-size: 14px; }
.notfound { text-align: center; padding: 20px 10px; }
.notfound p { color: var(--muted); margin: 0 0 12px; }

/* Segmented controls (Documents filters) */
.seg { display: flex; background: #e3e3e8; border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 8px; }
.seg button { flex: 1; min-height: 40px; border-radius: 10px; font-weight: 600; font-size: 15px; color: var(--text); }
.seg button.on { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.period { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.period .label { flex: 1; text-align: center; font-weight: 700; }
.toggle { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 4px; font-weight: 600; }
.toggle input { width: 24px; height: 24px; -webkit-appearance: checkbox; appearance: auto; }
.sumline { display: flex; justify-content: space-between; padding: 6px 6px 10px; color: var(--muted); font-size: 15px; }

/* Paid toggle */
.paidbtn { width: 100%; min-height: 60px; border-radius: 14px; font-size: 20px; font-weight: 800; border: 2px solid var(--red); color: var(--red); background: var(--red-bg); margin-bottom: 12px; }
.paidbtn.on { border-color: var(--green); color: var(--green); background: var(--green-bg); }

/* Modal sheet */
.sheet-bg { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 720px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px 14px calc(16px + var(--safe-b)); }
.sheet h2 { margin: 0 0 12px; font-size: 20px; }
.sheet .btns { display: flex; gap: 10px; margin-top: 8px; }
.sheet .btns .btn { flex: 1; }

/* Camera scanner */
.scan-bg { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; flex-direction: column; }
.scan-bg #reader { flex: 1; width: 100%; }
.scan-bg #reader video { object-fit: cover; }
.scan-bg .scan-bar { padding: 12px 12px calc(12px + var(--safe-b)); display: flex; gap: 10px; }
.scan-bg .scan-msg { color: #fff; text-align: center; padding: calc(var(--safe-t) + 12px) 12px 8px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 84px); z-index: 70; background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; max-width: 90vw; }

.logo-prev { max-width: 200px; max-height: 80px; display: block; margin-bottom: 8px; }
.filebtn { position: relative; overflow: hidden; }
.filebtn input { position: absolute; inset: 0; opacity: 0; }
input[type=search]::-webkit-search-cancel-button, input[type=search]::-webkit-search-decoration { -webkit-appearance: none; display: none; }
