:root {
  --accent: #9f1d4f;
  --accent-soft: #fbe7ef;
  --bg: #f8f5f3;
  --card: #ffffff;
  --text: #1f1a1c;
  --muted: #7a7074;
  --line: #ebe4e6;
  --low: #c2410c;
  --out: #b91c1c;
  --ok: #15803d;
  color-scheme: light;
}

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

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
}

button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }

/* ---------- Header ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
}
.title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
h1 { margin: 0 0 10px; font-size: 22px; color: var(--accent); }
.summary { font-size: 13px; color: var(--muted); }

#search {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  font-size: 17px;
  outline: none;
}
#search:focus { border-color: var(--accent); }

/* ---------- List ---------- */
.list { padding: 4px 16px 110px; display: flex; flex-direction: column; gap: 10px; }

.card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.card.out { opacity: .6; }
.thumb {
  width: 60px; height: 60px; flex: none;
  border-radius: 12px;
  object-fit: cover;
  background: var(--accent-soft);
  display: grid; place-items: center;
  font-size: 28px;
}
.info { flex: 1; min-width: 0; }
.name { font-weight: 600; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.price { color: var(--muted); font-size: 14px; }
.base { color: var(--muted); font-size: 13px; }
.stock { font-size: 14px; font-weight: 600; color: var(--ok); }
.stock.low { color: var(--low); }
.stock.out { color: var(--out); }

.del {
  flex: none;
  width: 40px; height: 48px;
  border: 0; border-radius: 12px;
  background: #fdecec;
  font-size: 18px;
}
.del:active { transform: scale(.94); }

.sell {
  flex: none;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 14px 10px;
  min-width: 0;
}
.sell:active { transform: scale(.96); }
.sell:disabled { background: #d8cfd2; color: #fff; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty b { display: block; font-size: 40px; margin-bottom: 8px; }

/* ---------- Floating add button ---------- */
.fab {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  padding: 16px 28px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  z-index: 6;
}

/* ---------- Sheets ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  transform: translateY(100%);
  transition: transform .22s ease;
  visibility: hidden;
}
.sheet.open { transform: none; visibility: visible; }
#detailSheet { z-index: 10; }
#formSheet { z-index: 11; }

.sheet-bar {
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.sheet-bar h2 { margin: 0; font-size: 17px; text-align: center; }
.icon-btn, .text-btn {
  border: 0; background: none; height: 44px; font-size: 18px;
}
.text-btn { color: var(--accent); font-weight: 600; font-size: 16px; }

.sheet-body { flex: 1; overflow-y: auto; padding: 16px; }
.sheet-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }

/* ---------- Form ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.photo-grid:empty { display: none; }
.ph { position: relative; aspect-ratio: 1; }
.ph img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; display: block; }
.ph button {
  position: absolute; top: 4px; right: 4px;
  width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 1;
}
.ph.busy { border-radius: 12px; background: var(--accent-soft); display: grid; place-items: center; color: var(--muted); font-size: 13px; }

.photo-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 14px; padding: 14px; font-weight: 600; text-align: center;
}
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; width: 100%; }
.btn.primary:disabled { opacity: .5; }
.btn.big { font-size: 18px; padding: 16px; }
.btn.danger-soft { background: #fdecec; color: var(--out); width: 100%; margin-top: 28px; }

.field { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 14px; flex: 1; }
.field input {
  display: block; width: 100%; margin-top: 6px;
  padding: 14px; border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text); font-size: 17px; font-weight: 400; outline: none;
}
.field input:focus { border-color: var(--accent); }
.field-row { display: flex; gap: 12px; }
.hint { font-size: 13px; color: var(--muted); margin: -4px 0 0; }

/* ---------- Detail ---------- */
.carousel {
  display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory;
  margin: -16px -16px 14px; padding: 0;
}
.carousel img, .carousel .noimg {
  flex: none; width: 100%; aspect-ratio: 3/4; object-fit: cover; scroll-snap-align: center; background: var(--accent-soft);
}
.carousel .noimg { display: grid; place-items: center; font-size: 64px; }
.carousel.multi img { width: 85%; }
.d-name { margin: 0; font-size: 22px; }
.d-price { margin: 4px 0 18px; color: var(--muted); font-size: 18px; }
.d-base { margin: -12px 0 18px; color: var(--muted); font-size: 14px; }
.d-base:empty { display: none; }

.stepper {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border-radius: 18px; padding: 10px;
}
.step {
  width: 64px; height: 64px; border-radius: 16px; border: 0;
  background: var(--accent-soft); color: var(--accent); font-size: 32px; font-weight: 700;
}
.step:active { transform: scale(.95); }
.step-val { text-align: center; }
.step-val span { display: block; font-size: 36px; font-weight: 800; }
.step-val small { color: var(--muted); }

/* ---------- Login ---------- */
.login { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.login[hidden] { display: none; }
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-logo { font-size: 56px; }
.login-box h2 { color: var(--accent); margin: 4px 0 20px; }
.login-box input {
  width: 100%; padding: 16px; border: 1.5px solid var(--line); border-radius: 14px;
  background: var(--card); font-size: 18px; outline: none; text-align: center;
}
.login-box input:focus { border-color: var(--accent); }
.login-err { color: var(--out); min-height: 20px; font-size: 14px; margin: 8px 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 16px; right: 16px;
  bottom: calc(84px + env(safe-area-inset-bottom));
  max-width: 528px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  background: var(--text); color: #fff;
  padding: 12px 12px 12px 16px; border-radius: 14px;
  font-size: 15px;
  z-index: 20;
  opacity: 0; transform: translateY(10px); pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; pointer-events: auto; }
#toastMsg { flex: 1; }
#toastUndo { border: 0; background: none; color: #f9a8c9; font-weight: 800; padding: 8px; }
#toastUndo[hidden] { display: none; }
