:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --panel-2: #f4f6f9;
  --line: #d7dde4;
  --text: #14202b;
  --muted: #5c6b7a;
  --red: #e31837;       /* Costco logo red */
  --red-dk: #c1122f;
  --blue: #005daa;      /* Costco logo blue */
  --blue-dk: #004a88;
  --danger: #c1122f;
  --chip: #eef2f6;
  --radius: 10px;
  --tap: 48px;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

/* Header — white with the Costco red rule on top */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #fff;
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  border-top: 5px solid var(--red);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(20, 32, 43, 0.06);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-size: 24px;
  width: 44px; height: 44px;
  display: grid; place-content: center;
  background: var(--blue); border-radius: 10px;
  flex: 0 0 auto;
}
.topbar h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.4px; font-style: italic; }
.c-red { color: var(--red); }
.c-blue { color: var(--blue); }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; font-style: normal; }

.view { padding: 12px 12px 0; max-width: 640px; margin: 0 auto; }
.hidden { display: none !important; }

/* Tabs */
.tabs {
  display: flex; gap: 6px;
  background: #e3e8ee; border-radius: 12px; padding: 4px;
  margin: 4px 4px 12px;
  position: sticky; top: calc(72px + env(safe-area-inset-top)); z-index: 4;
}
.tab {
  flex: 1; border: none; background: transparent;
  color: var(--muted); font-size: 15px; font-weight: 700;
  padding: 10px 8px; border-radius: 9px;
}
.tab.active { background: #fff; color: var(--blue); box-shadow: 0 1px 3px rgba(20,32,43,0.12); }

/* List */
.cat { margin: 18px 4px 8px; color: var(--blue); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; }
.list { display: flex; flex-direction: column; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  min-height: var(--tap);
  box-shadow: 0 1px 2px rgba(20, 32, 43, 0.04);
  touch-action: pan-y;               /* let vertical scroll through; we own horizontal swipe */
  -webkit-user-select: none; user-select: none;
}
.row.off { opacity: 0.55; }

.check {
  appearance: none;
  width: 26px; height: 26px;
  border-radius: 6px;
  border: 2px solid #b9c3ce;
  background: #fff;
  flex: 0 0 auto;
  display: grid;
  place-content: center;
}
.check:checked { background: var(--blue); border-color: var(--blue); }
.check:checked::after { content: "✓"; color: #fff; font-size: 16px; font-weight: 700; }

.row-main { flex: 1 1 auto; min-width: 0; }
.row-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { display: flex; gap: 6px; align-items: center; margin-top: 3px; }
.chip { font-size: 11px; color: var(--muted); background: var(--chip); border-radius: 4px; padding: 2px 8px; font-weight: 600; }
.chip.staple { color: #fff; background: var(--blue); }
.chip.due { color: #8a5a00; background: #fdeecb; }

.stepper { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.step-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--blue);
  font-size: 20px; line-height: 1; font-weight: 700;
}
.step-btn:active { background: var(--panel-2); }
.qty { min-width: 22px; text-align: center; font-variant-numeric: tabular-nums; font-size: 16px; font-weight: 700; }

/* Add form */
.add-form { display: flex; gap: 8px; margin: 14px 4px 6px; }
.add-input {
  flex: 1 1 auto;
  height: var(--tap);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 0 14px;
  font-size: 16px;
}
.add-input::placeholder { color: #9aa7b4; }
.save-state { text-align: center; color: var(--muted); font-size: 12px; min-height: 16px; margin: 4px 0 0; }

/* Buttons */
.btn {
  border: none; border-radius: var(--radius);
  font-size: 16px; font-weight: 700;
  padding: 0 16px; min-height: var(--tap);
  color: #fff;
}
.btn-primary { background: var(--red); box-shadow: 0 2px 6px rgba(227, 24, 55, 0.3); }
.btn-primary:active { background: var(--red-dk); }
.btn-ghost { background: #fff; border: 1px solid var(--line); color: var(--blue); font-weight: 700; }
.btn-block { width: 100%; }

/* Action bar */
.action-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(238, 241, 244, 0), var(--bg) 32%);
  max-width: 640px; margin: 0 auto;
}

/* Summary */
#summary h2 { font-size: 16px; margin: 0; }
.sum-total { font-size: 30px; font-weight: 800; margin: 8px 4px 2px; color: var(--blue); }
.sum-section { margin-bottom: 14px; }
.sum-head { display: flex; align-items: center; gap: 8px; margin: 16px 4px 8px; }
.sum-head .dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.good { background: #1a8a3a; }
.dot.new { background: #f0a017; }
.dot.miss { background: var(--danger); }
.dot.info { background: var(--blue); }
.sum-item {
  display: flex; justify-content: space-between; gap: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 6px;
  box-shadow: 0 1px 2px rgba(20, 32, 43, 0.04);
}
.sum-item .price { color: var(--muted); font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: 14px; margin: 2px 4px 0; }
.note { color: var(--muted); font-size: 13px; margin: 2px 4px 10px; }

/* Overlay */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  display: grid; place-content: center; justify-items: center; gap: 16px;
  padding: 24px; text-align: center;
}
.overlay p { color: var(--text); font-size: 20px; font-weight: 700; margin: 0; }
.overlay-sub { color: var(--muted) !important; font-size: 14px !important; font-weight: 500 !important; max-width: 320px; }
.big-check {
  width: 96px; height: 96px; border-radius: 50%;
  background: #e7f0f9; color: var(--blue);
  display: grid; place-content: center;
  font-size: 56px; font-weight: 800;
}
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid #d7dde4; border-top-color: var(--red);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #14202b; border: none;
  color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; z-index: 30; box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
