/*
 * One stylesheet for both directions.
 *
 * RTL rule: never use left/right. Use the logical properties
 * (margin-inline-start, padding-inline, inset-inline, border-inline-start,
 * text-align: start/end) and the browser mirrors the whole layout when
 * <html dir> flips to rtl. Flexbox and grid follow `dir` automatically.
 */

:root {
  --bg: #12100e;
  --surface: #1d1a17;
  --surface-2: #262220;
  --line: #3a332e;
  --text: #f6f1ea;
  --muted: #a89c90;
  --brand: #e3562a;
  --brand-dim: #b53f1c;
  --green: #4caf7d;
  --amber: #e0a33a;
  --red: #d9533f;
  --radius: 14px;
  --radius-sm: 9px;
  --pad: 16px;
  --font: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', sans-serif;
  --font-ar: 'Noto Kufi Arabic', 'Dubai', 'Tahoma', 'Segoe UI', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

html[dir='rtl'] body {
  font-family: var(--font-ar);
}

body {
  min-height: 100vh;
  padding-bottom: 96px; /* room for the sticky bar */
  line-height: 1.55;
}

/*
 * Figures line up in columns. Note what this does NOT do: it never forces
 * `direction: ltr`. Strings like "45 ريال" are mixed bidi text and the browser
 * already orders them correctly; overriding direction here reverses them.
 * Only genuinely LTR tokens - order codes, phone numbers - get .ltr / .code.
 */
.num {
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- layout */

.wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 var(--pad);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-block-end: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px var(--pad);
  max-width: 680px;
  margin: 0 auto;
}

.brand {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.brand strong {
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand span {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

section {
  margin-block: 20px;
}

h1 {
  font-size: 1.35rem;
  margin-block: 0 10px;
}

h2 {
  font-size: 1.05rem;
  margin-block: 0 10px;
}

p {
  margin-block: 0 10px;
}

.muted {
  color: var(--muted);
  font-size: 0.86rem;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.grow {
  flex: 1;
  min-width: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hidden {
  display: none !important;
}

/* ---------------------------------------------------------------- controls */

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  min-height: 44px; /* one-handed thumb target */
  transition: filter 0.15s ease, opacity 0.15s ease;
}

button:active {
  filter: brightness(1.25);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}

button.ghost {
  background: transparent;
}

button.danger {
  background: transparent;
  border-color: var(--red);
  color: var(--red);
}

button.small {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

button.block {
  width: 100%;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-block-end: 4px;
}

input,
textarea,
select {
  font: inherit;
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  min-height: 44px;
}

input:focus,
textarea:focus,
select:focus,
button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

textarea {
  min-height: 70px;
  resize: vertical;
}

/* Phone/code fields stay LTR even in an RTL page. */
input[inputmode='tel'],
input.ltr {
  direction: ltr;
  text-align: start;
}

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
}

.card + .card {
  margin-block-start: 10px;
}

.menu-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.menu-card .emoji {
  font-size: 2rem;
  line-height: 1;
}

/*
 * Photo and emoji occupy the same box, so a menu where only some pizzas have a
 * photo still lines up. object-fit keeps a portrait phone shot from stretching.
 */
.photo {
  inline-size: 76px;
  block-size: 76px;
  flex: none;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.photo.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}

.photo-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border-block-start: 1px solid var(--line);
  padding-block-start: 12px;
}

.stack-tight {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row.wrap {
  flex-wrap: wrap;
}

.menu-card.is-unavailable {
  opacity: 0.55;
}

.price {
  font-weight: 700;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge.open {
  background: rgba(76, 175, 125, 0.16);
  color: var(--green);
  border-color: rgba(76, 175, 125, 0.4);
}

.badge.closed {
  background: rgba(217, 83, 63, 0.16);
  color: var(--red);
  border-color: rgba(217, 83, 63, 0.4);
}

.badge.warn {
  background: rgba(224, 163, 58, 0.16);
  color: var(--amber);
  border-color: rgba(224, 163, 58, 0.4);
}

.badge.neutral {
  background: var(--surface-2);
  color: var(--muted);
  border-color: var(--line);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.banner {
  border-radius: var(--radius);
  padding: 12px var(--pad);
  border: 1px solid var(--line);
  background: var(--surface);
  /* A coloured edge that mirrors with direction. */
  border-inline-start: 4px solid var(--brand);
}

.banner.closed {
  border-inline-start-color: var(--red);
}

.banner.warn {
  border-inline-start-color: var(--amber);
}

.banner.ok {
  border-inline-start-color: var(--green);
}

/* ---------------------------------------------------------------- chips */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.85rem;
  min-height: 40px;
  cursor: pointer;
}

.chip[aria-pressed='true'] {
  border-color: var(--brand);
  background: rgba(227, 86, 42, 0.18);
  color: #ffd9c9;
}

.chip.removed[aria-pressed='true'] {
  border-color: var(--red);
  background: rgba(217, 83, 63, 0.16);
  color: #ffc9c0;
  text-decoration: line-through;
}

.chip .chip-price {
  color: var(--muted);
  font-size: 0.78rem;
}

/* ---------------------------------------------------------------- qty */

.qty {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.qty button {
  border: 0;
  border-radius: 0;
  min-width: 44px;
  background: var(--surface-2);
}

.qty output {
  min-width: 44px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- sheet */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet {
  background: var(--surface);
  border-start-start-radius: 20px;
  border-start-end-radius: 20px;
  border-block-start: 1px solid var(--line);
  width: 100%;
  max-width: 680px;
  max-height: 88vh;
  overflow-y: auto;
  padding: var(--pad);
  padding-block-end: calc(var(--pad) + env(safe-area-inset-bottom, 0px));
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-block-end: 12px;
}

/* ---------------------------------------------------------------- sticky bar */

.stickybar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border-block-start: 1px solid var(--line);
  padding: 10px var(--pad);
  padding-block-end: calc(10px + env(safe-area-inset-bottom, 0px));
}

.stickybar-inner {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ---------------------------------------------------------------- totals */

.totals {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  font-size: 0.92rem;
}

.totals .grand {
  font-size: 1.1rem;
  font-weight: 700;
  padding-block-start: 8px;
  border-block-start: 1px solid var(--line);
}

.totals .discount {
  color: var(--green);
}

/* ---------------------------------------------------------------- code */

.code-box {
  text-align: center;
  padding: 22px;
  border: 2px dashed var(--brand);
  border-radius: var(--radius);
  background: rgba(227, 86, 42, 0.08);
}

.code-box .code {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  direction: ltr;
  unicode-bidi: isolate;
}

/* ---------------------------------------------------------------- switch */

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 54px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: 0;
  min-height: 32px;
}

.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--muted);
  transition: inset-inline-start 0.16s ease, background 0.16s ease;
}

.switch[aria-pressed='true'] {
  background: rgba(76, 175, 125, 0.25);
  border-color: var(--green);
}

.switch[aria-pressed='true']::after {
  inset-inline-start: 27px;
  background: var(--green);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-block: 10px;
  border-block-end: 1px solid var(--line);
}

.toggle-row:last-child {
  border-block-end: 0;
}

.toggle-row .label {
  flex: 1;
  min-width: 0;
}

.toggle-row .label strong {
  display: block;
  font-weight: 600;
}

/* ---------------------------------------------------------------- segmented */

.segmented {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.segmented button {
  flex: 1;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.segmented button + button {
  border-inline-start: 1px solid var(--line);
}

.segmented button[aria-pressed='true'] {
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}

/* ---------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-block: 8px;
}

.tabs button {
  white-space: nowrap;
  min-height: 40px;
}

.tabs button[aria-selected='true'] {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}

/* ---------------------------------------------------------------- order rows */

.order {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px;
}

.order + .order {
  margin-block-start: 10px;
}

.order.status-new {
  border-inline-start: 4px solid var(--amber);
}

.order.status-preparing {
  border-inline-start: 4px solid var(--brand);
}

.order.status-ready {
  border-inline-start: 4px solid var(--green);
}

.order.status-collected,
.order.status-cancelled {
  opacity: 0.6;
}

.order .ocode {
  font-weight: 700;
  direction: ltr;
  unicode-bidi: isolate;
}

.order ul {
  margin: 8px 0;
  padding-inline-start: 18px;
  font-size: 0.9rem;
}

.mods {
  font-size: 0.8rem;
  color: var(--muted);
}

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

.toast {
  position: fixed;
  inset-inline: 16px;
  bottom: 100px;
  z-index: 60;
  margin: 0 auto;
  max-width: 420px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.toast.err {
  border-color: var(--red);
  color: #ffc9c0;
}

.toast.ok {
  border-color: var(--green);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

@media (min-width: 560px) {
  .menu-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .menu-grid .card + .card {
    margin-block-start: 0;
  }
}
