:root {
  --green: #16a34a;
  --green-dark: #15803d;
  --red: #dc2626;
  --amber: #d97706;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --radius: 14px;
  --bottombar-h: calc(60px + env(safe-area-inset-bottom));
}

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

[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
}

/* ---------- top & bottom bars ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 1.25rem; }

.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.icon-btn-ghost {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--muted);
  font-size: 1.1rem;
  text-decoration: none;
}

.bottombar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.72rem;
  cursor: pointer;
}
.nav-btn.active { color: var(--green-dark); font-weight: 600; }
.nav-icon { font-size: 1.35rem; }
.badge {
  position: absolute;
  top: 4px;
  left: calc(50% + 8px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 18px;
}

.tab { padding: 12px 12px calc(var(--bottombar-h) + 16px); }

/* ---------- search + filter chips ---------- */
.searchbar input,
#picker-search {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  font-size: 1rem;
  outline: none;
}
.searchbar input:focus { border-color: var(--green); }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 2px 2px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips-sub { padding-top: 6px; }
.chip {
  flex: 0 0 auto;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}
.chip.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-weight: 600;
}
.chips-sub .chip.active { background: var(--text); border-color: var(--text); }

/* ---------- item cards ---------- */
.list { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; }

.card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.thumb {
  flex: 0 0 56px;
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}
.card-main { flex: 1; min-width: 0; }
.card-name { font-weight: 600; font-size: 0.95rem; }
.card-sub {
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-tags { margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
}
.tag.out { background: #fee2e2; color: var(--red); font-weight: 700; }
.tag.low { background: #fef3c7; color: var(--amber); font-weight: 700; }

.card-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.stepper {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.stepper button {
  width: 38px;
  height: 36px;
  border: none;
  background: none;
  font-size: 1.2rem;
  color: var(--green-dark);
  cursor: pointer;
}
.stepper button:active { background: var(--bg); }
.stepper .qty {
  min-width: 28px;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stepper .qty.zero { color: var(--red); }

.cart-btn {
  border: none;
  background: none;
  font-size: 1.05rem;
  cursor: pointer;
  color: var(--muted);
  padding: 2px 6px;
}
.cart-btn.on { color: var(--green-dark); }

/* ---------- shopping list ---------- */
.shop-actions { display: flex; gap: 8px; padding-bottom: 4px; }
.shop-actions .btn { flex: 1; }

.store-group { margin-top: 14px; }
.store-title {
  margin: 0 4px 6px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.shop-row { padding: 8px 10px; }
.shop-row.done { opacity: 0.55; }
.shop-row.done .card-name { text-decoration: line-through; }

.checkbox {
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  font-size: 0.9rem;
}
.shop-row.done .checkbox {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.remove-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 4px 6px;
  cursor: pointer;
}

/* ---------- buttons ---------- */
.btn {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-outline { background: var(--card); border: 1px solid var(--line); color: var(--text); }
.btn-danger { background: #fee2e2; color: var(--red); }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 48px 24px; color: var(--text); }
.empty-icon { font-size: 3rem; }
.empty .muted { color: var(--muted); font-size: 0.85rem; }

/* ---------- bottom sheets ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
}
.sheet {
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: slide-up 0.2s ease-out;
}
@keyframes slide-up {
  from { transform: translateY(40px); opacity: 0.5; }
  to   { transform: translateY(0);    opacity: 1; }
}
.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 6px auto 10px;
}
.sheet h2 { margin: 0 0 12px; font-size: 1.1rem; }

.picker-list { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; }
.picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: none;
  border-radius: 12px;
  background: var(--bg);
  text-align: left;
  font-size: 0.95rem;
  cursor: pointer;
}
.picker-row .thumb { flex: 0 0 44px; width: 44px; height: 44px; }
.picker-row .in-list { margin-left: auto; color: var(--green-dark); font-weight: 700; font-size: 0.8rem; }
.picker-row .stock-hint { margin-left: auto; color: var(--muted); font-size: 0.78rem; white-space: nowrap; }

/* ---------- editor form ---------- */
#editor-form label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}
#editor-form input:not([type="file"]) {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 1rem;
  outline: none;
  background: var(--card);
  color: var(--text);
}
#editor-form input:focus { border-color: var(--green); }
.form-row { display: flex; gap: 10px; }
.form-row label { flex: 1; }

.photo-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 110px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--muted);
  overflow: hidden;
}
.photo-pick img { max-width: 100%; max-height: 180px; object-fit: contain; }

.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.form-actions .btn { flex: 1; }

/* ---------- login page ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
.login-wrap { width: 100%; max-width: 380px; text-align: center; }
.login-logo { font-size: 3rem; }
.login-app { margin: 4px 0 20px; font-size: 1.5rem; }
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 20px;
  text-align: left;
}
.login-card h2 { margin: 0 0 12px; font-size: 1.1rem; }
.login-card label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}
.login-card input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 1rem;
  outline: none;
}
.login-card input:focus { border-color: var(--green); }
.login-btn { width: 100%; margin-top: 4px; }
.login-hint { font-size: 0.85rem; color: var(--muted); }
.login-error {
  background: #fee2e2;
  color: var(--red);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
}
.login-notice {
  background: #dcfce7;
  color: var(--green-dark);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
}

/* ---------- toast ---------- */
#toast {
  position: fixed;
  bottom: calc(var(--bottombar-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}
