:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f4f7f4;
  --card: #ffffff;
  --text: #17211b;
  --muted: #66736b;
  --line: #dfe7e1;
  --green: #2f6f4e;
  --green-dark: #24593e;
  --green-soft: #e6f2eb;
  --danger: #a64242;
  --warning: #fff6d9;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  font-size: 16px;
  background: #fff;
  color: var(--text);
}
input:focus, button:focus-visible { outline: 3px solid rgba(47,111,78,.22); outline-offset: 2px; }

.app-shell {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(26px, env(safe-area-inset-bottom));
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 2px; font-size: 1.65rem; }
h2 { margin-bottom: 8px; }
.subtle { color: var(--muted); }
.hidden { display: none !important; }

.welcome-card, .choice-card, .manual-card, .scan-card, .modal-card, .list-heading, .notice {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.welcome-card { text-align: center; padding: 24px 20px; margin-bottom: 14px; }
.big-icon { font-size: 52px; margin-bottom: 6px; }
.choice-card, .manual-card, .modal-card { padding: 18px; }
.choice-card label, .manual-card label { display: block; font-weight: 700; margin: 8px 0 7px; }
.choice-card button, .manual-card button { width: 100%; margin-top: 12px; }

.primary-button, .secondary-button, .scan-button, .icon-button, .check-button {
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 800;
}
.primary-button, .scan-button { background: var(--green); color: white; }
.primary-button:hover, .scan-button:hover { background: var(--green-dark); }
.secondary-button { background: white; border-color: var(--line); color: var(--text); }
.icon-button { min-width: 48px; padding: 0 12px; background: white; border-color: var(--line); font-size: 1.25rem; }
.check-button { min-width: 48px; padding: 0; background: var(--green-soft); color: var(--green-dark); font-size: 1.2rem; }

.divider { display: flex; align-items: center; gap: 12px; margin: 18px 0 8px; color: var(--muted); }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.status { min-height: 24px; color: var(--muted); margin: 12px 0 0; }
.notice { padding: 12px 14px; margin-bottom: 14px; }
.notice.warning { background: var(--warning); }

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: #e8eee9;
  border-radius: 14px;
  padding: 5px;
  margin-bottom: 14px;
}
.tab {
  min-height: 46px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-weight: 800;
  color: var(--muted);
}
.tab.active { background: white; color: var(--text); }
.badge { display: inline-grid; place-items: center; min-width: 22px; height: 22px; border-radius: 999px; padding: 0 6px; background: var(--green-soft); color: var(--green-dark); font-size: .82rem; }

.scan-card { padding: 22px 18px; text-align: center; }
.scan-button { width: 100%; min-height: 72px; display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 1.02rem; }
.camera-icon { font-size: 1.6rem; }
.scan-help { color: var(--muted); margin: 12px 6px 0; }
.scanner-panel { position: relative; margin-top: 14px; overflow: hidden; border-radius: 18px; background: #111; padding-bottom: 12px; }
.scanner-panel video { width: 100%; max-height: 62vh; display: block; object-fit: cover; }
.scan-frame { position: absolute; left: 12%; right: 12%; top: 28%; height: 28%; border: 3px solid white; border-radius: 14px; box-shadow: 0 0 0 2000px rgba(0,0,0,.22); pointer-events: none; }
.scanner-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 12px 0;
}
.scanner-actions .primary-button,
.scanner-actions .secondary-button { margin: 0; width: 100%; }

.modal-card { margin-top: 14px; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

.list-heading { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; margin-bottom: 10px; }
.list-heading h2, .list-heading p { margin-bottom: 0; }
.grocery-list { display: grid; gap: 9px; }
.grocery-item { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 15px; padding: 12px; }
.grocery-info { flex: 1; min-width: 0; }
.grocery-name { font-weight: 800; word-break: break-word; }
.grocery-meta { color: var(--muted); font-size: .88rem; margin-top: 2px; }
.quantity { flex: 0 0 auto; min-width: 38px; font-weight: 800; text-align: center; }
.empty-state { text-align: center; color: var(--muted); padding: 44px 18px; }
.empty-state > div { font-size: 2rem; }

.toast {
  position: sticky;
  bottom: max(10px, env(safe-area-inset-bottom));
  margin: 14px auto 0;
  width: fit-content;
  max-width: 95%;
  background: #17211b;
  color: white;
  padding: 11px 14px;
  border-radius: 12px;
  text-align: center;
  z-index: 20;
}

.household-dialog { border: 0; border-radius: 18px; padding: 0; width: min(92vw, 430px); }
.household-dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-content { padding: 22px; text-align: center; }
.invite-code { font-size: 2rem; font-weight: 900; letter-spacing: .16em; background: var(--green-soft); border-radius: 14px; padding: 14px; margin: 10px 0 14px; }

@media (max-width: 420px) {
  .app-shell { padding-left: 12px; padding-right: 12px; }
  .button-row { grid-template-columns: 1fr; }
  .scanner-actions { grid-template-columns: 1fr; }
}

/* v3 scanner */
.scanner-reader {
  width: 100%;
  min-height: 280px;
  overflow: hidden;
  border-radius: 16px;
  background: #111;
}
.scanner-reader video {
  width: 100% !important;
  height: auto !important;
  max-height: 52vh;
  object-fit: cover;
}
.scanner-reader canvas { display: none !important; }
#scannerReader__scan_region { background: #111 !important; }
#scannerReader__dashboard { display: none !important; }

.barcode-video {
  display: block;
  width: 100%;
  max-height: 62vh;
  object-fit: cover;
  background: #111;
  border-radius: 14px;
}
#scannerReader video, #scannerReader canvas {
  width: 100% !important;
  height: auto !important;
  border-radius: 14px;
}

/* Out To Buy brand accents */
.brand-kicker {
  display: inline-block;
  margin-top: 5px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-weight: 800;
  font-size: .78rem;
  letter-spacing: .02em;
}
