/*
 * The sale screen (POS-UX1): TWO PANELS and no page scroll — the products on one side, the order on the other —
 * in the layout the shop chose for this till, `data-layout` on `.sale`:
 *
 *   classic  category tabs over coloured tiles                    (cafés, restaurants)
 *   photo    a category rail beside photo cards (an initial when a card has no picture)
 *   quick    a scan field, a list cart and a keypad                (retail, barcode first)
 *
 * The page does not scroll: the stage is as tall as the window, the panels fill it and only a LIST inside a
 * panel scrolls (the product grid, the cart's lines). At 480 px or less one panel shows at a time, switched by
 * two tabs. Every colour is a token (tokens.css); every control is at least 44 px (`--tap-sm`), the cart's
 * − and + at least 48 px (`--tap-qty`), the pay button at least 60 px (`--tap-pay`) — sizes that grow with the
 * terminal's «button size» setting (`data-size`).
 */

body[data-screen='sale'] {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
body[data-screen='sale'] .stage {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: var(--gap);
  overflow: hidden;
}

/* The wrappers the screen paints into take no box of their own. */
#r-tabs,
#r-msg,
#r-sheet {
  display: contents;
}

.sale {
  position: relative;
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--order-w);
  gap: var(--gap);
}
.sale__tabs {
  display: none;
}
.sale__products,
.sale__order {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.sale__products {
  gap: var(--gap);
}
.sale__catalogue {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ---------------------------------------------------------------- the toolbar */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.toolbar .btn {
  margin: 0;
}
.search {
  flex: 1 1 14rem;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--tap);
  padding: 0 0.75rem;
  background: var(--surface);
  color: var(--ink);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
}
.search input {
  flex: 1;
  min-width: 0;
  min-height: calc(var(--tap) - 0.25rem);
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 1.1rem;
}
.search input:focus-visible {
  outline: none;
}
.search:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.search__icon {
  flex: none;
}
.more {
  position: relative;
}
.menu {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 0.25rem);
  z-index: 40;
  min-width: 16rem;
  max-width: calc(100vw - 1.5rem);
  display: flex;
  flex-direction: column;
  padding: 0.35rem;
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 0.5rem 1.5rem var(--shadow);
}
.menu__item {
  min-height: var(--tap);
  padding: 0 0.85rem;
  border: 0;
  border-radius: 0.5rem;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
}
.menu__item:hover,
.menu__item:focus-visible {
  background: var(--accent-soft);
}

/* ---------------------------------------------------------------- categories */

.cats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: 0.5rem;
}
.cat {
  min-height: var(--tap);
  padding: 0.25rem 0.75rem;
  border: 2px solid var(--h, var(--hue-none));
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--h, var(--hue-none));
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  overflow-wrap: anywhere;
}
.cat--on {
  background: var(--h, var(--hue-none));
  color: var(--on-hue);
}
[data-theme='dark'] .cat:not(.cat--on) {
  color: var(--ink);
}

/* one hue per section: a class sets --h, the tokens draw it */
.hue-0 {
  --h: var(--hue-0);
}
.hue-1 {
  --h: var(--hue-1);
}
.hue-2 {
  --h: var(--hue-2);
}
.hue-3 {
  --h: var(--hue-3);
}
.hue-4 {
  --h: var(--hue-4);
}
.hue-5 {
  --h: var(--hue-5);
}
.hue-6 {
  --h: var(--hue-6);
}
.hue-7 {
  --h: var(--hue-7);
}
.hue-none {
  --h: var(--hue-none);
}

/* ---------------------------------------------------------------- the product grid */

.grid {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  grid-auto-rows: max-content;
  gap: 0.625rem;
  align-content: start;
}
.grid--photo {
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
}
.item {
  min-width: 0;
  min-height: 6rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
  touch-action: manipulation;
}
.item:active {
  filter: brightness(0.92);
}
.item--off {
  opacity: 0.5;
  cursor: not-allowed;
}
.item__name {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.item__price {
  margin-top: auto;
  font-weight: 700;
}
.item__warn {
  align-self: flex-start;
  padding: 0.1rem 0.4rem;
  border-radius: 0.4rem;
  background: var(--stop-bg);
  color: var(--stop);
  font-size: 0.8rem;
}

/* classic: a coloured tile per section */
.sale--classic .item {
  min-height: 7.25rem;
  border: 0;
  background: var(--h, var(--hue-none));
  color: var(--on-hue);
}
.sale--classic .item__warn {
  background: var(--on-hue);
}

/* photo: a card — the picture, or the section's colour with the item's initial */
.sale--photo .item {
  padding: 0;
  overflow: hidden;
}
.sale--photo .item > :not(.item__media) {
  margin-inline: 0.75rem;
}
.sale--photo .item__name {
  margin-top: 0.6rem;
}
.sale--photo .item__price {
  margin-bottom: 0.65rem;
  color: var(--accent);
}
.sale--photo .grid--compact .item {
  min-height: 6.5rem;
  border-top: 4px solid var(--h, var(--hue-none));
  padding-top: 0.25rem;
}
.item__media {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 6.5rem;
  background: color-mix(in srgb, var(--h, var(--hue-none)) 16%, var(--surface));
  border-bottom: 3px solid var(--h, var(--hue-none));
}
.item__initial {
  display: grid;
  place-items: center;
  width: 4rem;
  height: 4rem;
  border-radius: 1.1rem;
  background: var(--h, var(--hue-none));
  color: var(--on-hue);
  font-size: 1.9rem;
  font-weight: 700;
}
.item__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* the photo layout puts the categories in a rail beside the cards */
.sale--photo .sale__catalogue {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: var(--gap);
}
.sale--photo .sale__catalogue > :not(.cats) {
  grid-column: 2;
}
.sale--photo .cats {
  grid-column: 1;
  grid-row: 1 / -1;
  display: flex;
  flex-direction: column;
  width: 6.75rem;
  overflow-y: auto;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.sale--photo .cat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  min-height: 4.5rem;
  padding: 0.5rem 0.25rem;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.85rem;
}
.sale--photo .cat::before {
  content: '';
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 0.6rem;
  background: var(--h, var(--hue-none));
}
.sale--photo .cat--on {
  background: var(--surface-2);
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.pager {
  display: flex;
  gap: 0.5rem;
}
.pager .btn {
  margin: 0;
}

/* ---------------------------------------------------------------- the order panel */

/*
 * THE LIVE SLIP (POS-UX2, the signature of the Mizan language): the order panel is the receipt being printed — warm
 * paper, a perforated top edge, square top corners, tabular figures. What it shows is what prints.
 */
.cart {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--slip);
  border: 1px solid var(--line);
  border-radius: 0 0 var(--r-card) var(--r-card);
  border-start-start-radius: 0;
  border-start-end-radius: 0;
  box-shadow: var(--e1);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}
.cart::before {
  content: '';
  flex: none;
  block-size: 0.55rem;
  background: radial-gradient(circle at 50% 0, var(--bg) 0.26rem, transparent 0.28rem) 0 0 / 0.95rem
    0.55rem repeat-x;
}
.cart__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--line);
}
.cart__head h2 {
  margin: 0;
  font-size: 1.1rem;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
}
.seg__btn {
  min-width: 4.25rem;
  min-height: var(--tap-sm);
  padding: 0 0.85rem;
  border: 0;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.seg__btn--on {
  background: var(--accent);
  color: var(--accent-ink);
}
.cart__alerts {
  max-height: 40%;
  overflow: auto;
  padding: 0 1rem;
}
.cart__alerts:empty {
  display: none;
}
.cart__alerts .notice {
  margin: 0.5rem 0;
}
.cart__empty {
  margin: auto;
  padding: 1rem;
  color: var(--ink-soft);
  text-align: center;
}
.cart__lines {
  flex: 1;
  min-height: 0;
  overflow: auto;
  list-style: none;
  margin: 0;
  padding: 0 1rem;
}
.line {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.55rem 0;
  border-bottom: 1px dashed var(--line);
}
.line__main {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-weight: 600;
}
.cart__name {
  min-width: 0;
  overflow-wrap: anywhere;
}
.line__ctl {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.line__unit {
  color: var(--ink-soft);
  font-size: 0.9rem;
}
.qty {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.qty__btn {
  min-width: var(--tap-qty);
  min-height: var(--tap-qty);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.qty__btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.qty__n {
  min-width: 2.25rem;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
}
.cart__discount,
.cart__basket {
  color: var(--accent);
  font-weight: 600;
}
.cart__discount .btn,
.line__ctl .btn {
  margin: 0;
}
.cart__basket {
  margin: 0;
  padding: 0.5rem 1rem;
}
.totals {
  margin: 0;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.totals > div {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}
.totals dt {
  color: var(--ink-soft);
}
.totals dd {
  margin: 0;
}
.totals__grand {
  margin-top: 0.25rem;
  font-size: 1.4rem;
  font-weight: 700;
}
.totals__grand dt {
  color: var(--ink);
}
.cart__actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0 1rem 1rem;
}
.cart__row {
  display: flex;
  gap: 0.5rem;
}
.cart__row .btn {
  flex: 1;
  margin: 0;
  padding: 0 0.5rem;
}

/* the big button: pay, confirm, apply — never smaller than 60 px */
.btn--pay {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  margin: 0;
  min-height: var(--tap-pay);
  padding: 0 1rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.btn--pay:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------------------------------------------------------------- a discount waiting for a manager (r42a M2) */

.badge--pending {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--warn);
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.8125rem;
  font-weight: 700;
  white-space: nowrap;
}
.totals__grand--pending dd {
  opacity: 0.7;
}
.btn--pay:disabled {
  font-size: 1rem;
}

/* ---------------------------------------------------------------- the toast */

.sale__msg {
  position: absolute;
  bottom: 0.5rem;
  inset-inline: 0;
  margin-inline: auto;
  width: min(100%, 40rem);
  z-index: 90;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  pointer-events: none;
}
/* r42a H1: at the bottom of the product side, clear of the toolbar (بحث / استرجاع / السلال المعلّقة / المزيد) and
   of the order panel's pay button; it ends by itself and has a close button. */
.sale:not(.sale--quick) .sale__msg {
  inset-inline: 0 auto;
  margin-inline: 0;
  width: min(calc(100% - var(--order-w) - var(--gap)), 40rem);
}
.sale__msg:empty {
  display: none;
}
.sale__msg > * {
  pointer-events: auto;
}
.sale__msg-body {
  flex: 1;
  min-width: 0;
}
.sale__msg-close {
  flex: none;
  min-width: var(--tap);
  min-height: var(--tap);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 0.25rem 1rem var(--shadow);
}
.sale__msg .notice {
  margin: 0;
  box-shadow: 0 0.25rem 1rem var(--shadow);
}

/* ---------------------------------------------------------------- the phone: one panel at a time */

@media (max-width: 30rem) {
  body[data-screen='sale'] .stage {
    padding: 0.5rem;
  }
  .sale:not(.sale--quick) .sale__msg {
    inset-inline: 0;
    margin-inline: auto;
    width: 100%;
  }
  .sale {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 0.5rem;
  }
  .sale__tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }
  .sale-tab {
    min-height: var(--tap);
    padding: 0 0.5rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
  }
  .sale-tab--on {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
  }
  .sale[data-tab='products'] .sale__order {
    display: none;
  }
  .sale[data-tab='order'] .sale__products {
    display: none;
  }
  .search {
    flex-basis: 100%;
  }
  .toolbar__go {
    display: none;
  }
  .toolbar__tool {
    flex: 1;
    padding: 0 0.5rem;
  }
  .more {
    flex: 1;
    display: flex;
  }
  .more .toolbar__tool {
    width: 100%;
  }
  .cats {
    display: flex;
    overflow-x: auto;
    padding-bottom: 0.25rem;
  }
  .cat {
    flex: none;
  }
  .grid,
  .grid--photo {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .sale--photo .sale__catalogue {
    display: flex;
    flex-direction: column;
  }
  .sale--photo .cats {
    flex-direction: row;
    width: auto;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.35rem;
  }
  .sale--photo .cat {
    flex: none;
    min-width: 5.5rem;
  }
}
