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

/* Quick taps on + must not double-tap zoom the page (iOS). */
button { touch-action: manipulation; }

/* Hover styles below sit inside @media (hover: hover): iOS keeps :hover
   applied after a tap, so a tapped button would stay highlighted. */

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  padding-bottom: 120px;          /* room for the cart bar */
}

/* Background picture from the admin panel. A fixed layer rather than
   background-attachment: fixed, which iOS ignores. The veil keeps group
   titles and empty-state text readable over any picture. */
body.has-bg::before {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background:
    linear-gradient(color-mix(in srgb, var(--bg) 55%, transparent),
                    color-mix(in srgb, var(--bg) 55%, transparent)),
    var(--app-bg-image) center / cover no-repeat;
}

/* One centred column. On a phone it is the whole screen; on a desktop it
   keeps the price and the stepper within a glance of the item name instead
   of throwing them to opposite edges. */
.wrap { width: 100%; max-width: 560px; margin: 0 auto; padding: 0 16px; }

/* ── centred states (login, waiting, errors) ─────────────────── */
.center { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.center__box { width: 100%; max-width: 340px; text-align: center; }
.mark {
  width: 56px; height: 56px; margin: 0 auto 14px; border-radius: var(--r-lg);
  background: var(--brand); color: #fff; display: grid; place-items: center;
  font-weight: 800; font-size: 20px;
}
.center h1 { font-size: 20px; margin: 0 0 6px; }
.center p { color: var(--ink-3); margin: 0 0 20px; font-size: 14px; line-height: 1.5; }

input, textarea {
  width: 100%; padding: 13px; font: inherit; color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface);
}
input:focus, textarea:focus {
  outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.code-input { text-align: center; font-weight: 700; letter-spacing: 2px; }

.btn {
  width: 100%; padding: 14px; border: 0; border-radius: var(--r-md);
  background: var(--brand); color: #fff; font-weight: 800; font-size: 15px;
  cursor: pointer; font-family: inherit;
}
@media (hover: hover) { .btn:hover { background: var(--brand-hover); } }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--ghost { background: var(--surface-2); color: var(--ink-2); }
@media (hover: hover) { .btn--ghost:hover { background: var(--line); } }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ── header ──────────────────────────────────────────────────── */
.head {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding-top: 14px;
}
.head__row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.head__id { flex: 1 1 auto; min-width: 0; }
.head__name {
  font-weight: 800; font-size: 17px; letter-spacing: -.2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.head__who { font-size: 12px; color: var(--ink-3); }
.head__contact {
  flex: 0 0 auto; padding: 6px 11px; border: 1px solid var(--brand); border-radius: var(--r-pill);
  background: none; color: var(--brand); cursor: pointer; white-space: nowrap;
  font-family: inherit; font-size: 12px; font-weight: 700;
  transition: background var(--speed);
}
@media (hover: hover) { .head__contact:hover { background: var(--brand-soft); } }
/* Owner only, and deliberately quiet: it is not an everyday button. */
.head__key {
  border: 0; background: none; cursor: pointer; padding: 2px 4px;
  font-size: 15px; line-height: 1; opacity: .55;
  transition: opacity var(--speed);
}
.head__key:focus-visible { opacity: 1; }
@media (hover: hover) { .head__key:hover { opacity: 1; } }

.tabs { display: flex; gap: 2px; }
.tab {
  flex: 1 1 0; padding: 10px 6px; border: 0; background: none; cursor: pointer;
  font-family: inherit; font-weight: 700; font-size: 14px; color: var(--ink-3);
  border-bottom: 2px solid transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: color var(--speed), border-color var(--speed);
}
@media (hover: hover) { .tab:hover { color: var(--ink-2); } }
.tab[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }
/* locked while an already-sent order of the other kind is being edited */
.tab:disabled { opacity: .4; cursor: not-allowed; }
.tab__count {
  min-width: 18px; padding: 1px 6px; border-radius: var(--r-pill);
  background: var(--brand); color: #fff; font-size: 11px; font-weight: 800;
}

/* ── catalog ─────────────────────────────────────────────────── */

/* Three image sizes, chosen in the admin panel. Everything that scales with
   the choice reads these two variables, so a size is one line to change and
   nothing can drift out of step with the rest. */
:root { --img: 60px; --img-group: 34px; }
:root[data-imgsize="sm"] { --img: 40px; --img-group: 26px; }
:root[data-imgsize="lg"] { --img: 80px; --img-group: 44px; }

.group__title {
  padding: 22px 2px 8px; font-size: 12px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .6px; color: var(--ink-3);
  display: flex; align-items: center; gap: 10px;
}
.group__img {
  width: var(--img-group); height: var(--img-group);
  border-radius: var(--r-sm); object-fit: cover; display: block;
}
.item__img {
  width: var(--img); height: var(--img); flex: 0 0 var(--img);
  border-radius: var(--r-md);
  object-fit: cover; display: block; background: var(--surface-2);
}
.item__img--none { border: 1px dashed var(--line-strong); background: none; }
.list {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); overflow: hidden; margin-top: 14px;
}
.group__title + .list { margin-top: 0; }

.item {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: 0; }
.item__body { flex: 1 1 auto; min-width: 0; }
.item__name {
  font-weight: 700; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.item__cost { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.item--picked { background: var(--brand-soft); }

.stepper { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.stepper button {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font-size: 18px; font-weight: 700;
  cursor: pointer; display: grid; place-items: center; line-height: 1; font-family: inherit;
  transition: border-color var(--speed), color var(--speed), background var(--speed);
}
@media (hover: hover) { .stepper button:hover { border-color: var(--brand); color: var(--brand); } }
.stepper__qty { min-width: 26px; text-align: center; font-weight: 800; }
.stepper--empty .stepper__qty, .stepper--empty .stepper__minus { visibility: hidden; }
.stepper__plus { border-color: var(--brand); color: var(--brand); }
@media (hover: hover) { .stepper__plus:hover { background: var(--brand); color: #fff; } }

/* ── cart bar ────────────────────────────────────────────────── */
.cart {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
}
/* Tall carts scroll rather than swallow the catalog. */
/* contain: reaching the end of the cart list must not scroll the page (iOS). */
.cart__list { max-height: 38vh; overflow-y: auto; overscroll-behavior: contain; margin-bottom: 10px; }
.cart__group + .cart__group { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }

.cart__ghead { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.cart__gname {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px;
  color: var(--ink-3); flex: 1 1 auto;
}
.cart__gname.is-replacement { color: var(--brand); }
.cart__gsum { font-weight: 800; font-size: 15px; }
.cart__clear {
  width: 22px; height: 22px; flex: 0 0 auto; border: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--ink-3); font-size: 15px; line-height: 1;
  cursor: pointer; font-family: inherit; display: grid; place-items: center;
}
@media (hover: hover) { .cart__clear:hover { background: var(--brand-soft); color: var(--brand); } }

.cart__line {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 13px; color: var(--ink-2); padding: 2px 0;
}
.cart__lname { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart__lqty { color: var(--ink-3); font-weight: 700; flex: 0 0 auto; }
.cart__lsum { font-weight: 700; flex: 0 0 auto; min-width: 56px; text-align: right; }

/* ── history ─────────────────────────────────────────────────── */
.order {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 14px 16px; margin-top: 12px;
}
.order__head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.order__id { font-weight: 800; flex: 1 1 auto; }
.order__lines { font-size: 13px; color: var(--ink-2); line-height: 1.6; }
.order__total { margin-top: 8px; font-weight: 800; }

.badge {
  font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.badge--new  { background: #fff3cd; color: #8a6100; }
.badge--ok   { background: #e7f6e9; color: #256d2b; }
.badge--no   { background: var(--brand-soft); color: var(--brand); }
[data-theme="dark"] .badge--new { background: #3d3417; color: #ffd479; }
[data-theme="dark"] .badge--ok  { background: #17351b; color: #86e18f; }

.empty { padding: 48px 24px; text-align: center; color: var(--ink-3); font-size: 14px; }
.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--r-pill);
  font-size: 13px; font-weight: 700; z-index: 20; max-width: 90vw; text-align: center;
}
.toast--err { background: var(--danger); color: #fff; }

/* Edge to edge on a phone: the rounded list would waste horizontal room. */
@media (max-width: 560px) {
  .wrap { padding: 0 12px; }
  .list { border-radius: var(--r-md); }
}

/* ── editing a sent order ───────────────────────────────────── */
.editbar {
  display: flex; align-items: center; gap: 10px;
  margin: 12px 0 0; padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--brand-soft); color: var(--brand);
  font-size: 13px; font-weight: 700;
}
.editbar span { flex: 1 1 auto; }
.editbar__cancel {
  flex: 0 0 auto; border: 0; background: none; cursor: pointer;
  color: var(--brand); font: inherit; text-decoration: underline;
}

.order__note { margin-top: 8px; font-size: 12px; color: var(--ink-3); }
.order__acts {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  margin-top: 10px;
}

.notice {
  margin: 12px 0 0; padding: 10px 12px; border-radius: var(--r-md);
  background: var(--surface-2); color: var(--ink-2);
  font-size: 13px; line-height: 1.45;
}
.cart__note { font-size: 12px; color: var(--ink-3); margin-bottom: 8px; }
.btn--sm { width: auto; padding: 7px 12px; font-size: 13px; }

/* ── confirmation before sending ─────────────────────────────── */
.sheet {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .45);
}
.sheet__box {
  width: 100%; max-width: 560px; max-height: 88vh;
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); color: var(--ink);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
}
.sheet__title { margin: 0 0 12px; font-size: 17px; font-weight: 800; }
.sheet__hint { margin: 10px 0 0; font-size: 12px; line-height: 1.45; color: var(--ink-3); }
.sheet__acts { display: flex; gap: 8px; margin-top: 16px; }
.sheet__acts .btn { flex: 1 1 0; }

.sum { width: 100%; border-collapse: collapse; font-size: 13px; }
.sum th {
  padding: 0 0 6px 8px; text-align: right; color: var(--ink-3);
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px;
}
.sum td {
  padding: 8px 0 8px 8px; text-align: right; border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.sum th:first-child, .sum td:first-child { padding-left: 0; text-align: left; }
.sum td:first-child { font-weight: 700; white-space: normal; word-break: break-word; }
.sum__deliver { font-weight: 800; color: var(--brand); }
.sum__zero { color: var(--ink-3); }

.totals {
  margin-top: 14px; padding: 10px 12px; border-radius: var(--r-md);
  background: var(--surface-2); font-size: 14px;
}
.totals__row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.totals__row b { white-space: nowrap; }
.totals__row--main {
  margin-top: 6px; padding-top: 9px; border-top: 1px solid var(--line);
  font-size: 15px; font-weight: 800;
}
