:root {
  --bg: #fffdf6;
  --fg: #111;
  --muted: #777;
  --line: #ddd;
  --bar: #3b78c4;
  --bar-fg: #fff;
  --btn-bg: #fff;
  --sel: #3b78c4;
  --sel-bg: #dce8f7;
  --danger: #b3261e;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --fg: #eee;
    --muted: #999;
    --line: #333;
    --bar: #2a5a96;
    --btn-bg: #1e1e1e;
    --sel: #4a8ad8;
    --sel-bg: #1f3350;
    --danger: #ff6b60;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bar);
  color: var(--bar-fg);
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
}
.bar h1 { margin: 0; font-size: 20px; }
.bar select {
  background: transparent;
  color: var(--bar-fg);
  border: 1px solid rgba(255,255,255,.6);
  border-radius: 6px;
  padding: 4px 8px;
  max-width: 55%;
}
.bar select option { color: #000; }

.filters {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.filters label { font-weight: 600; white-space: nowrap; }
.filters select, .filters input, .dlg-body input, .dlg-body select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--btn-bg);
  font-size: 16px; /* avoid iOS zoom on focus */
}
.filters input { flex: 1; min-width: 0; }

main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#list { list-style: none; margin: 0; padding: 0; }
#list li {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  min-height: 46px;
}
#list .cb {
  width: 48px; height: 46px;
  display: grid; place-items: center;
  flex: none;
}
#list .cb input { width: 22px; height: 22px; margin: 0; accent-color: var(--sel); }
#list li { cursor: pointer; user-select: none; -webkit-user-select: none; }
#list li.sel { background: var(--sel-bg); }
#list .name {
  flex: 1;
  padding: 10px 4px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#list .name small { color: var(--muted); margin-left: 6px; }
#list .qty {
  flex: none;
  min-width: 56px;
  height: 46px;
  padding: 0 14px;
  border: 0;
  background: none;
  appearance: none;
  -webkit-appearance: none;
  text-align: right;
  text-align-last: right;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
#list li.have .name { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 24px; }

.bottom {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
  border-top: 1px solid var(--line);
}
.btn {
  border: 1px solid var(--line);
  background: var(--btn-bg);
  border-radius: 999px;
  padding: 7px 16px;
}
.btn.primary { border-color: var(--sel); color: var(--sel); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .4; }
.bottom { gap: 6px; padding-left: 8px; padding-right: 8px; }
.bottom .btn { padding: 7px 10px; }
.seg button { padding: 7px 4px; }
.seg { flex: 1; display: flex; border: 1px solid var(--sel); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: none; padding: 7px 0; }
.seg button + button { border-left: 1px solid var(--sel); }
.seg button.on { background: var(--sel); color: #fff; }

dialog {
  border: 0;
  padding: 0;
  width: min(100vw - 24px, 480px);
  max-height: calc(100dvh - 24px - env(safe-area-inset-top));
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { display: flex; flex-direction: column; max-height: inherit; }
.dlg-title {
  margin: 0;
  background: var(--bar);
  color: var(--bar-fg);
  font-size: 18px;
  text-align: center;
  padding: 10px;
}
.dlg-body { padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.dlg-body .row { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.dlg-body .row > input:not([type=checkbox]), .dlg-body .row > select { flex: 1; min-width: 0; font-weight: normal; }
.dlg-body .check input { width: 22px; height: 22px; accent-color: var(--sel); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 40px; height: 36px; border: 1px solid var(--line); border-radius: 6px; background: var(--btn-bg); }
.stepper input { width: 64px; text-align: center; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0; padding: 4px 10px 8px; }
legend { font-weight: 600; padding: 0 4px; }
#fStores label { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
#fStores input { width: 22px; height: 22px; accent-color: var(--sel); }
.dlg-actions { display: flex; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.dlg-actions .btn { flex: 1; }

.menu .btn { border-radius: 8px; text-align: left; padding: 12px; }

.names { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.names li { display: flex; gap: 4px; align-items: center; }
.names input { flex: 1; min-width: 0; }
.names button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 6px; background: var(--btn-bg); flex: none; }
.names .del { color: var(--danger); }
#fStores .hint { color: var(--muted); margin: 6px 0; font-size: 15px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
.menu label.btn { display: block; cursor: pointer; }
