:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1c2733;
  --muted: #66788c;
  --line: #e3e9ef;
  --accent: #0e9f6e;
  --accent-ink: #ffffff;
  --warn: #f39c12;
  --warn-bg: #fff5e5;
  --done: #8aa0b4;
  --done-bg: #f0f4f7;
  --danger: #e04f4f;
  --shadow: 0 1px 3px rgba(20, 40, 60, .08);
  --radius: 14px;
  --tabbar-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Heebo", "Arial Hebrew", sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior-y: contain;
}
button { font: inherit; border: 0; background: none; color: inherit; cursor: pointer; padding: 0; }
input, select { font: inherit; }
.num { unicode-bidi: plaintext; font-variant-numeric: tabular-nums; }

/* ---------- app bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; gap: 10px;
}
#topbar h1 { font-size: 1.1rem; margin: 0; flex: 1; font-weight: 700; }
#syncdot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); transition: background .3s; }
#syncdot.offline { background: var(--warn); }
#queue-badge {
  font-size: .75rem; background: var(--warn-bg); color: var(--warn);
  border-radius: 999px; padding: 2px 8px; font-weight: 700;
}
#queue-badge[hidden] { display: none !important; }
.iconbtn { font-size: 1.25rem; padding: 6px; border-radius: 8px; }
.iconbtn:active { background: var(--bg); }

/* ---------- screens & tab bar ---------- */
.screen { padding: 12px 12px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
#tabbar {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 30;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
#tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .7rem; color: var(--muted); font-weight: 600;
}
#tabbar button .ico { font-size: 1.35rem; }
#tabbar button.active { color: var(--accent); }
#tabbar .tabcount {
  position: absolute; transform: translate(-14px, -22px);
  background: var(--danger); color: #fff; font-size: .65rem; font-weight: 700;
  border-radius: 999px; min-width: 17px; height: 17px; line-height: 17px; padding: 0 4px;
}

/* ---------- generic cards & rows ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden; }
.cat-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 12px 14px; font-weight: 700; font-size: .95rem; text-align: start;
  border-bottom: 1px solid var(--line);
}
.cat-head .count { color: var(--muted); font-weight: 500; font-size: .8rem; margin-inline-start: auto; }
.row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-bottom: 1px solid var(--line);
  user-select: none; -webkit-user-select: none;
}
.row:last-child { border-bottom: 0; }
.row .name { flex: 1; min-width: 0; }
.row .name .t { font-weight: 600; }
.row .name .sub { font-size: .75rem; color: var(--muted); margin-top: 1px; }
.row.missing { background: var(--warn-bg); }
.row.bought .name .t { text-decoration: line-through; color: var(--done); font-weight: 500; }
.row.bought { background: var(--done-bg); }

/* stepper */
.stepper { display: flex; align-items: center; gap: 2px; background: var(--bg); border-radius: 999px; padding: 2px; }
.stepper button { width: 32px; height: 32px; border-radius: 50%; font-size: 1.1rem; font-weight: 700; background: var(--card); box-shadow: var(--shadow); }
.stepper .qv { min-width: 44px; text-align: center; font-weight: 700; font-size: .9rem; }

/* pill buttons */
.pill {
  border-radius: 999px; padding: 7px 14px; font-weight: 700; font-size: .85rem;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.pill.on { background: var(--warn); color: #fff; border-color: var(--warn); }
.pill.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.checkring {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 1rem; color: transparent; flex: none;
}
.row.bought .checkring { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- search & toolbars ---------- */
.searchwrap { position: sticky; top: calc(52px + env(safe-area-inset-top)); z-index: 15; padding: 4px 0 10px; background: var(--bg); }
.searchwrap input {
  width: 100%; padding: 11px 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--card); font-size: 1rem;
}
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar select {
  border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  padding: 7px 12px; font-weight: 600; font-size: .85rem; max-width: 46vw;
}

/* ---------- FAB & sticky finish ---------- */
.fab {
  position: fixed; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); inset-inline-start: 16px;
  width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 1.7rem; box-shadow: 0 4px 14px rgba(14, 159, 110, .45); z-index: 25;
  display: flex; align-items: center; justify-content: center;
}
.finishbar {
  position: fixed; bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom));
  inset-inline: 12px; z-index: 25; max-width: 616px; margin: 0 auto;
}
.finishbar button {
  width: 100%; padding: 14px; border-radius: var(--radius); background: var(--accent);
  color: #fff; font-weight: 800; font-size: 1rem; box-shadow: 0 4px 14px rgba(14, 159, 110, .45);
}

/* ---------- bottom sheet / dialog ---------- */
#sheet-backdrop {
  position: fixed; inset: 0; background: rgba(15, 25, 35, .45); z-index: 40;
  opacity: 0; transition: opacity .18s; pointer-events: none;
}
#sheet-backdrop.open { opacity: 1; pointer-events: auto; }
#sheet {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 41; background: var(--card);
  border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .22s ease-out;
  max-width: 640px; margin: 0 auto; max-height: 82vh; overflow-y: auto;
}
#sheet.open { transform: translateY(0); }
#sheet h2 { margin: 0 0 14px; font-size: 1.05rem; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .8rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field input[type=text], .field input[type=number], .field input[type=tel], .field select {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 1rem;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .pill.sel { background: var(--accent); color: #fff; border-color: var(--accent); }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 8px 4px; border-radius: 8px; font-weight: 700; font-size: .85rem; color: var(--muted); }
.seg button.sel { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn { flex: 1; padding: 13px; border-radius: 12px; font-weight: 800; font-size: .95rem; text-align: center; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: var(--bg); color: var(--ink); }
.btn.danger { background: #fdecec; color: var(--danger); }

/* ---------- store editor ---------- */
.drag-item {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); background: var(--card);
}
.drag-item .handle { font-size: 1.2rem; color: var(--muted); touch-action: none; padding: 4px 8px; cursor: grab; }
.drag-item.dragging { opacity: .35; }
.drag-item .pos { color: var(--muted); font-size: .8rem; min-width: 22px; text-align: center; font-weight: 700; }

/* ---------- history ---------- */
.trip-head { display: flex; align-items: center; gap: 8px; padding: 13px 14px; width: 100%; text-align: start; }
.trip-head .when { font-weight: 700; }
.trip-head .meta { color: var(--muted); font-size: .8rem; margin-inline-start: auto; }
.trip-items .row { padding: 8px 14px; }
.skipped { color: var(--danger); font-size: .75rem; font-weight: 700; }

/* ---------- auth screens ---------- */
.auth { max-width: 380px; margin: 8vh auto 0; padding: 24px; text-align: center; }
.auth .logo { font-size: 3.2rem; }
.auth h1 { font-size: 1.4rem; margin: 8px 0 4px; }
.auth p { color: var(--muted); margin: 0 0 22px; }
.auth .field { text-align: start; }
.auth .btn { width: 100%; margin-top: 6px; }

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty .big { font-size: 2.6rem; margin-bottom: 10px; }
#toast {
  position: fixed; bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom));
  inset-inline: 0; margin: 0 auto; width: fit-content; max-width: 88vw;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: .85rem; font-weight: 600; z-index: 60; opacity: 0; transition: opacity .25s;
  pointer-events: none;
}
#toast.show { opacity: .95; }
.cart-section-title { padding: 10px 14px 4px; color: var(--muted); font-size: .8rem; font-weight: 800; }
[hidden] { display: none !important; }
