:root {
  --green: #2f6b3a;
  --green-dark: #24522d;
  --bg: #f4f6f4;
  --card: #ffffff;
  --text: #1f2a22;
  --muted: #6b7570;
  --line: #e1e6e2;
  --warn: #b7411c;
  --ok: #2f6b3a;
  --chip: #e6eee8;
  --chip-on: var(--green);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; }
[hidden] { display: none !important; }
.view { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--warn); margin: 8px 0 0; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  background: var(--green); color: #fff; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; }
.topbar .title { flex: 1; font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: #fff; font-size: 24px; width: 40px; height: 40px; border-radius: 20px; }
.icon-btn:active { background: rgba(255,255,255,.2); }

/* login */
#view-login { display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 16px; padding: 24px 20px; box-shadow: 0 4px 20px rgba(0,0,0,.06); }
.brand { font-size: 28px; font-weight: 700; margin-bottom: 20px; }
.brand-equi { color: var(--green); } .brand-connect { color: #b4322b; } .brand-m { font-weight: 400; color: var(--muted); font-size: 16px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input, label select { display: block; width: 100%; margin-top: 4px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 16px; }
.btn { width: 100%; padding: 14px; border-radius: 12px; border: 0; font-weight: 600; font-size: 16px; }
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:active { background: var(--green-dark); }

/* search + lists */
.searchbar { padding: 10px 12px; background: var(--bg); position: sticky; top: 56px; z-index: 4; }
.searchbar input { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; font-size: 16px; background: #fff; }
.list { padding: 0 12px 24px; display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--card); border-radius: 12px; padding: 12px 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card:active { background: #f1f4f1; }
.card .h { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card .name { font-weight: 600; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card .price { font-weight: 700; color: var(--green); white-space: nowrap; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--chip); color: var(--green-dark); }
.badge.warn { background: #fbe3dc; color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

/* tabs */
.tabs { display: flex; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 56px; z-index: 4; }
.tab { flex: 1; padding: 12px 4px; border: 0; background: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; }
.tab.active { color: var(--green); border-bottom-color: var(--green); }

/* inventory controls */
.controls { padding: 10px 12px 0; }
.controls .row { display: flex; gap: 8px; }
.controls label.inline { flex: 1; margin-bottom: 0; }
.controls .searchbar { position: static; padding: 8px 0; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; padding: 8px 14px; border-radius: 999px; border: 0; background: var(--chip); color: var(--green-dark); font-weight: 600; font-size: 14px; }
.chip.on { background: var(--chip-on); color: #fff; }
#inv-summary { padding: 0 14px 8px; }

/* bottom sheet */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.sheet-body { position: absolute; left: 0; right: 0; bottom: 0; background: #fff; border-radius: 18px 18px 0 0;
  padding: 8px 18px calc(24px + env(safe-area-inset-bottom));
  max-height: 80vh; max-height: 80dvh;            /* dvh: iOS Safari's visible area, excluding its toolbar */
  overflow-y: auto; overscroll-behavior: contain; /* scroll stays inside the sheet, never the page behind */
  -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.sheet-handle { width: 40px; height: 4px; background: var(--line); border-radius: 2px; margin: 4px auto 14px; }
.sheet-close { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border: 0; border-radius: 18px;
  background: var(--chip); color: var(--green-dark); font-size: 20px; line-height: 36px; }
.sheet h3 { padding-right: 40px; }
body.sheet-open { position: fixed; left: 0; right: 0; overflow: hidden; } /* iOS: block page scroll under the sheet */
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-top: 10px; }
.kv div span { display: block; font-size: 12px; color: var(--muted); }
.kv div b { font-size: 15px; }
.sheet h3 { margin: 0 0 4px; font-size: 18px; }

/* cart (Phase 2a) */
.tab .count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--green); color: #fff; font-size: 11px; line-height: 18px; margin-left: 2px; }
.qty { display: flex; align-items: center; gap: 10px; margin: 16px 0 8px; }
.qty button { width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--line); background: #fff; font-size: 22px; }
.qty input { width: 70px; text-align: center; font-size: 18px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
.qty .hint { color: var(--muted); font-size: 13px; }
.price-row { margin-top: 4px; }
.price-row input { width: 90px; }
.card .sub.warn { color: var(--warn); }
.card .sub.ok { color: var(--ok); }
.sheet .btn { margin-top: 8px; }
.card .inv-cart { background: var(--green); color: #fff; }
.totals { margin: 0 12px 10px; padding: 12px 14px; background: #fff; border-radius: 12px; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 15px; }
.totals b { text-align: right; }
.cart-actions { display: flex; gap: 10px; padding: 0 12px 24px; }
.cart-actions .btn { flex: 1; }
.btn:not(.primary) { background: var(--chip); color: var(--green-dark); }
.card .line-qty { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.card .line-qty button { width: 36px; height: 36px; border-radius: 18px; border: 1px solid var(--line); background: #fff; font-size: 18px; }
.card .line-qty .del { margin-left: auto; color: var(--warn); border-color: #fbe3dc; background: #fbe3dc; font-size: 14px; width: auto; padding: 0 12px; }
.confirm .kv { margin-top: 6px; }
.confirm .warn { color: var(--warn); }

/* toast + loader */
.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); background: #222; color: #fff;
  padding: 10px 16px; border-radius: 10px; z-index: 30; font-size: 14px; max-width: 90vw; }
.loader { position: fixed; inset: 0; z-index: 25; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,.4); }
.spinner { width: 36px; height: 36px; border: 4px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* filter bar + filter sheet (Phase 2b) */
.chip.filters-btn { background: var(--green-dark); color: #fff; }
.chip.x { padding-right: 10px; }
.filters .fgroup { border-top: 1px solid var(--line); padding: 6px 0; }
.filters summary { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; font-weight: 600; cursor: pointer; list-style: none; }
.filters summary::-webkit-details-marker { display: none; }
.filters summary .muted { font-weight: 400; font-size: 13px; }
.fopts { display: flex; flex-direction: column; gap: 2px; padding-bottom: 6px; max-height: 40dvh; overflow-y: auto; }
.fopt { display: flex; align-items: center; gap: 10px; padding: 9px 4px; margin: 0; font-size: 15px; color: var(--ink, #222); }
.fopt input { width: 20px; height: 20px; margin: 0; display: inline-block; padding: 0; }
.fopt span { flex: 1; }
.fopt em { font-style: normal; color: var(--muted); font-size: 13px; }

.badge.ok { background: #e1f1e4; color: var(--ok); }

/* card payment (Phase 2c) */
.cards { margin: 10px 0 4px; border-top: 1px solid var(--line); }
.cards .fopt { border-bottom: 1px solid var(--line); }
.bt-field { height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; margin-top: 4px; }
.bt-field iframe { height: 100%; }
#new-card .row { display: flex; gap: 8px; }
#new-card .row label.inline { flex: 1; }
