:root {
  --ink: #263238;
  --muted: #78909c;
  --bg: #eceff1;
  --card: #ffffff;
  --accent: #1e88e5;
  --produce: #43a047;
  --dairy: #1e88e5;
  --meat: #e53935;
  --pantry: #f57f17;
  --household: #8e24aa;
}

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

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  /* clear the notch / status bar in standalone (black-translucent) mode */
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--ink);
  color: #fff;
}
.app-header .logo { width: 28px; height: 28px; }
.app-header h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 700; }

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, .15); }

.add-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
}

.panel {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.panel h2 { margin: 0 0 12px; font-size: 16px; }
.count {
  display: inline-block;
  min-width: 24px;
  text-align: center;
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  font-size: 13px;
  padding: 1px 7px;
  vertical-align: 2px;
}
.purchased h2 { color: var(--muted); }

.items { list-style: none; margin: 0; padding: 0; }

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid #eceff1;
  min-height: 56px;
}
.item:last-child { border-bottom: none; }
.item img { width: 40px; height: 40px; flex-shrink: 0; }
.item .name { flex: 1; font-size: 17px; font-weight: 600; }
.item .cat-dot {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block; margin-right: 6px; vertical-align: 1px;
}
.item .name small { color: var(--muted); font-weight: 400; font-size: 12px; }

.item button {
  min-width: 48px;
  min-height: 48px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.got-btn { background: #e8f5e9; color: #2e7d32; }
.back-btn { background: #fff3e0; color: #e65100; }

.purchased .name { text-decoration: line-through; color: var(--muted); }

.empty { color: var(--muted); text-align: center; padding: 24px 0; margin: 0; }

.ghost {
  border: 1px solid #cfd8dc;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(38, 50, 56, .5);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: var(--bg);
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 16px;
  padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px));
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.sheet-head h2 { margin: 0; font-size: 18px; }

.catalog h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 16px 0 8px;
}
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}
.catalog-grid button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border: none;
  border-radius: 12px;
  background: var(--card);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.catalog-grid button img { width: 40px; height: 40px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 15px;
  font-weight: 600;
  z-index: 60;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}

.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 16px calc(20px + env(safe-area-inset-bottom, 0px));
}

.scanner {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #000;
}
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 62vmin; height: 62vmin;
  max-width: 320px; max-height: 320px;
  border: 3px solid rgba(255, 255, 255, .9);
  border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35);
}
.scan-hint {
  position: absolute;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  left: 0; right: 0;
  text-align: center;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .7);
}
.scan-close {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: 16px;
  width: 44px; height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}

.hidden { display: none !important; }
