/* Turkana Hot Sales — tokens first; components only use tokens. Light, high-contrast
   by default because reps use it outdoors on phones. */
:root {
  /* colour */
  --navy-900: #100641;
  --navy-700: #2a2172;
  --navy-100: #e9e7f5;
  --red-600: #d4211b;
  --red-700: #b01a15;
  --red-50: #fdecea;
  --green-700: #17693a;
  --green-50: #e7f5ec;
  --amber-700: #8a5a00;
  --amber-50: #fff5dc;
  --ink: #16132b;
  --ink-2: #4c4866;      /* 7.9:1 on white */
  --ink-3: #6b6785;      /* 5.2:1 on white */
  --line: #dddbe8;
  --surface: #ffffff;
  --canvas: #f4f3f8;
  --focus: #2a63ff;

  /* type */
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
  --fs-xs: .75rem; --fs-sm: .875rem; --fs-md: 1rem; --fs-lg: 1.1875rem;
  --fs-xl: 1.5rem; --fs-2xl: 2rem;

  /* space / shape */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --r-sm: 8px; --r-md: 12px; --r-lg: 18px; --r-pill: 999px;
  --shadow-1: 0 1px 2px rgba(16, 6, 65, .06), 0 1px 1px rgba(16, 6, 65, .04);
  --shadow-2: 0 10px 30px rgba(16, 6, 65, .14);
  --tap: 44px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: var(--fs-md); color: var(--ink);
  background: var(--canvas); line-height: 1.4;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---- header ---- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--navy-900); color: #fff;
  display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s4);
  padding-top: max(var(--s2), env(safe-area-inset-top));
}
.topbar img { width: 40px; height: auto; }
.topbar .title { font-weight: 800; letter-spacing: .01em; line-height: 1.1; }
.topbar .sub { font-size: var(--fs-xs); opacity: .8; }
.topbar .spacer { flex: 1; }
.topbar .btn { white-space: nowrap; padding: 0 var(--s2); }
.sandbox-flag {
  background: #ffd84d; color: #3a2a00; font-weight: 800; font-size: var(--fs-xs);
  padding: 2px var(--s2); border-radius: var(--r-pill); letter-spacing: .04em;
}

/* ---- tabs (bottom on phones, top row on desktop) ---- */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; min-height: 56px; border: 0; background: none; font-weight: 700;
  font-size: var(--fs-sm); color: var(--ink-3); display: grid; place-items: center; gap: 2px;
}
.tabs button svg { width: 22px; height: 22px; }
.tabs button[aria-selected="true"] { color: var(--red-600); }

main { max-width: 760px; margin: 0 auto; padding: var(--s4) var(--s4) 140px; }
@media (min-width: 900px) {
  .tabs { position: static; justify-content: center; border: 0; background: none; gap: var(--s2);
          max-width: 760px; margin: var(--s4) auto 0; padding: 0 var(--s4); }
  .tabs button { flex: 0 0 auto; grid-auto-flow: column; padding: 0 var(--s4); min-height: var(--tap);
                 border-radius: var(--r-pill); }
  .tabs button[aria-selected="true"] { background: var(--navy-100); color: var(--navy-900); }
  main { padding-bottom: 128px; }
}

/* ---- building blocks ---- */
h1 { font-size: var(--fs-xl); margin: var(--s2) 0 var(--s4); letter-spacing: -.01em; }
h2 { font-size: var(--fs-lg); margin: var(--s5) 0 var(--s3); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1); padding: var(--s4);
}
.stack > * + * { margin-top: var(--s3); }
.row { display: flex; gap: var(--s3); align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.btn {
  min-height: var(--tap); padding: 0 var(--s4); border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--surface); font-weight: 700; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; gap: var(--s2);
  transition: transform .12s var(--ease), background .12s var(--ease);
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--red-600); border-color: var(--red-600); color: #fff; }
.btn-primary:hover { background: var(--red-700); }
.btn-navy { background: var(--navy-900); border-color: var(--navy-900); color: #fff; }
.btn-ghost { background: none; border-color: transparent; color: var(--navy-700); }
.btn-block { width: 100%; min-height: 52px; font-size: var(--fs-lg); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

label.field { display: block; font-size: var(--fs-sm); font-weight: 700; color: var(--ink-2); }
label.field .req { color: var(--red-600); }
.input {
  width: 100%; min-height: var(--tap); margin-top: var(--s1); padding: 0 var(--s3);
  border: 1.5px solid var(--line); border-radius: var(--r-md); background: var(--surface);
  font-size: 16px; /* no iOS zoom */
}
textarea.input { padding: var(--s3); min-height: 72px; resize: vertical; }
.input::placeholder { color: #a8a4bd; font-style: italic; }
.input.invalid { border-color: var(--red-600); background: var(--red-50); }
.input:focus { border-color: var(--navy-700); outline: none; box-shadow: 0 0 0 3px rgba(42, 33, 114, .18); }
.grid-2 { display: grid; gap: var(--s3); grid-template-columns: 1fr 1fr; }
.grid-3 { display: grid; gap: var(--s3); grid-template-columns: 2fr 1fr 1fr; }
@media (max-width: 420px) { .grid-3 { grid-template-columns: 1fr 1fr; } .grid-3 > :first-child { grid-column: 1 / -1; } }

.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 20px; color: var(--ink-3); }
.search .input { padding-left: 40px; margin: 0; min-height: 50px; border-radius: var(--r-pill); }

/* list rows */
.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--line); }
.pick {
  width: 100%; text-align: left; background: none; border: 0; padding: var(--s3) var(--s1);
  min-height: 60px; display: flex; gap: var(--s3); align-items: center; cursor: pointer;
}
.pick:hover { background: var(--canvas); }
.pick .name { font-weight: 700; }
.pick .meta { font-size: var(--fs-sm); color: var(--ink-3); }
.chip {
  display: inline-block; font-size: var(--fs-xs); font-weight: 800; padding: 2px var(--s2);
  border-radius: var(--r-pill); background: var(--navy-100); color: var(--navy-900); white-space: nowrap;
}
.chip.ok { background: var(--green-50); color: var(--green-700); }
.chip.warn { background: var(--amber-50); color: var(--amber-700); }
.chip.bad { background: var(--red-50); color: var(--red-700); }

/* customer banner in the invoice step */
.cust-banner { background: var(--navy-900); color: #fff; border: 0; }
.cust-banner .muted { color: #c9c5e6; }
.cust-banner .btn-ghost { color: #fff; }

/* cart */
.line { display: grid; grid-template-columns: 1fr auto; gap: var(--s2) var(--s3); padding: var(--s3) 0; }
.line + .line { border-top: 1px solid var(--line); }
.line .name { font-weight: 700; }
.line .controls { grid-column: 1 / -1; display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; }
.stepper { display: inline-flex; border: 1.5px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.stepper button { width: var(--tap); height: var(--tap); border: 0; background: var(--canvas); font-size: 1.25rem; font-weight: 800; cursor: pointer; }
.stepper input { width: 64px; border: 0; text-align: center; font-weight: 800; font-size: 16px; }
.price-in { width: 110px; min-height: var(--tap); border: 1.5px solid var(--line); border-radius: var(--r-md); padding: 0 var(--s2); font-size: 16px; text-align: right; }
.price-in.below { border-color: var(--amber-700); background: var(--amber-50); }
.linetotal { font-weight: 800; text-align: right; }

.checkout {
  position: fixed; left: 0; right: 0; bottom: calc(56px + env(safe-area-inset-bottom)); z-index: 15;
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 24px rgba(16, 6, 65, .08);
  padding: var(--s3) var(--s4);
}
.checkout .inner { max-width: 760px; margin: 0 auto; display: flex; align-items: center; gap: var(--s4); }
.checkout .total { font-size: var(--fs-xl); font-weight: 800; }
@media (min-width: 900px) { .checkout { bottom: 0; } }

/* result */
.success { text-align: center; padding: var(--s5) var(--s4); }
.success .tick {
  width: 72px; height: 72px; border-radius: 50%; background: var(--green-50); color: var(--green-700);
  display: grid; place-items: center; margin: 0 auto var(--s3);
}
.success .docnum { font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -.02em; }
table.slip { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.slip th { text-align: left; color: var(--ink-3); font-weight: 700; padding: var(--s2) var(--s1); border-bottom: 1px solid var(--line); }
table.slip td { padding: var(--s2) var(--s1); border-bottom: 1px solid var(--line); vertical-align: top; }
table.slip .r { text-align: right; }

/* toast + sheet */
.toast {
  position: fixed; left: 50%; top: calc(72px + env(safe-area-inset-top)); transform: translate(-50%, -12px); opacity: 0;
  background: var(--ink); color: #fff; padding: var(--s3) var(--s4); border-radius: var(--r-md);
  max-width: min(92vw, 520px); box-shadow: var(--shadow-2); z-index: 50; font-weight: 600;
  transition: opacity .2s var(--ease), transform .2s var(--ease); pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red-700); }
.scrim { position: fixed; inset: 0; background: rgba(16, 6, 65, .45); z-index: 40; display: grid; align-items: end; }
.sheet {
  background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0; padding: var(--s5) var(--s4);
  padding-bottom: max(var(--s5), env(safe-area-inset-bottom)); max-height: 90vh; overflow: auto;
  width: 100%; max-width: 760px; margin: 0 auto; animation: up .22s var(--ease);
}
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.spinner { width: 20px; height: 20px; border: 3px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.dark { border-color: var(--line); border-top-color: var(--navy-700); }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--ink-3); padding: var(--s6) var(--s4); }
.alert { border-radius: var(--r-md); padding: var(--s3); font-size: var(--fs-sm); }
.alert.warn { background: var(--amber-50); color: var(--amber-700); }
.alert.bad { background: var(--red-50); color: var(--red-700); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---- browse tiles (Brand / Category) ---- */
.browse { margin-top: var(--s4); }
.browse-head { display: flex; align-items: center; justify-content: space-between; margin: var(--s4) 0 var(--s2); min-height: 36px; }
.browse h3 { margin: 0; font-size: var(--fs-xs); font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.btn-sm { min-height: var(--tap); padding: 0 var(--s2); font-size: var(--fs-sm); }
.tiles { display: grid; gap: var(--s2); }
.tiles-brand { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.tiles-cat { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.tile {
  min-height: 64px; padding: var(--s3); text-align: left; cursor: pointer;
  display: flex; flex-direction: column; justify-content: space-between; gap: var(--s1);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  transition: border-color .15s var(--ease), background .15s var(--ease), transform .12s var(--ease);
}
.tile:hover { border-color: var(--navy-700); }
.tile:active { transform: scale(.98); }
.tile-name { font-weight: 800; line-height: 1.2; }
.tile-count { font-size: var(--fs-xs); color: var(--ink-3); font-weight: 700; }
.tiles-brand .tile { min-height: 76px; background: var(--navy-900); border-color: var(--navy-900); color: #fff; }
.tiles-brand .tile .tile-name { font-size: var(--fs-lg); letter-spacing: .02em; }
.tiles-brand .tile .tile-count { color: #c9c5e6; }
.tile[aria-pressed="true"] { border-color: var(--red-600); background: var(--red-50); box-shadow: inset 0 0 0 1px var(--red-600); }
.tiles-brand .tile[aria-pressed="true"] { background: var(--red-600); border-color: var(--red-600); box-shadow: none; }
.tiles-brand .tile[aria-pressed="true"] .tile-count { color: #ffe3e1; }

/* ---- customer bar (optional until checkout) ---- */
.cust-bar { display: flex; align-items: center; gap: var(--s3); border-style: dashed; border-width: 1.5px; }
.cust-bar.chosen { background: var(--navy-900); color: #fff; border: 0; }
.cust-bar.chosen .btn-ghost { color: #fff; }
.cust-label { font-size: var(--fs-xs); font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.cust-bar.chosen .cust-label { color: #c9c5e6; }
.cust-none { color: var(--ink-2); font-size: var(--fs-sm); margin-top: 2px; }
.cust-name { font-weight: 800; font-size: var(--fs-lg); line-height: 1.2; margin-top: 2px; }
.cust-meta { font-size: var(--fs-sm); color: #c9c5e6; }
@media (max-width: 420px) { .cust-bar { flex-wrap: wrap; } .cust-bar .btn { width: 100%; } }

/* ---- product cards ---- */
.pgrid { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
@media (min-width: 640px) { .pgrid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.pcard {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1);
  transition: box-shadow .15s var(--ease), opacity .15s var(--ease);
}
.pcard:hover { box-shadow: var(--shadow-2); }
.pcard.busy { opacity: .5; pointer-events: none; }
.pimg { aspect-ratio: 1 / 1; background: #fff; border-bottom: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; }
.pimg img { width: 100%; height: 100%; object-fit: contain; padding: var(--s2); }
.pimg-ph {
  width: 100%; height: 100%; display: grid; place-items: center; background: var(--navy-100);
  color: var(--navy-700); font-weight: 800; font-size: var(--fs-xl); letter-spacing: .06em; text-transform: uppercase;
}
.pbody { padding: var(--s3); display: flex; flex-direction: column; gap: var(--s1); flex: 1; }
.pmeta { font-size: var(--fs-xs); font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--red-700); }
.pname {
  margin: 0; font-size: var(--fs-sm); font-weight: 800; line-height: 1.25; min-height: 2.5em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pcode { font-size: var(--fs-xs); color: var(--ink-3); display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.pfoot { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-top: auto; padding-top: var(--s1); }
.pprice { font-weight: 800; font-size: var(--fs-lg); }
.pctl { margin-top: var(--s2); }
.padd { width: 100%; min-height: var(--tap); margin-top: var(--s1); }
.pstep { display: flex; width: 100%; }
.pstep input { flex: 1; width: 0; }

/* cart thumbnail + tappable checkout summary */
.line-img { width: 48px; height: 48px; object-fit: contain; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; flex: none; }
.co-sum { background: none; border: 0; text-align: left; padding: 0; cursor: pointer; min-height: var(--tap); }

/* Wide screens: the product grids get room; forms and lists stay at a readable width. */
@media (min-width: 1100px) {
  main { max-width: 1160px; }
  .tabs { max-width: 1160px; }
  #tab-customer, #tab-history, #tab-admin { max-width: 760px; margin: 0 auto; }
  .checkout .inner { max-width: 1160px; }
}

/* piece price + expiry line on product cards */
.pinfo { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); flex-wrap: wrap;
         font-size: var(--fs-xs); color: var(--ink-2); }
.pinfo strong { color: var(--ink); font-size: var(--fs-sm); }
.pexp { font-weight: 800; white-space: nowrap; color: var(--green-700); }   /* 6.6:1 on white */
.pexp.soon { color: var(--amber-700); background: var(--amber-50); padding: 1px var(--s2); border-radius: var(--r-pill); }
.pexp.expired { color: var(--red-700); background: var(--red-50); padding: 1px var(--s2); border-radius: var(--r-pill); }
