:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-ink: #06263a;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }

/* dvh keeps the bottom row clear of a phone browser's collapsing chrome. */
.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
/* Every screen mounts as <div>[topbar, content]. That wrapper has to be a
   flex column that fills .app, or the content's `flex: 1` resolves against an
   auto height: panes stop scrolling internally and a long cart scrolls the
   whole page instead, carrying Pay off the bottom of the screen. */
.app > div { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* Generic buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-weight: 600;
  transition: transform .05s ease, background .1s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.green { background: var(--green); color: #04240f; border-color: transparent; }
.btn.red { background: var(--red); color: #2b0606; border-color: transparent; }
.btn.ghost { background: transparent; }
/* A required choice the cashier hasn't made yet (the order's customer). */
.btn.needed { border-color: var(--amber); color: var(--amber); }
.btn.big { padding: 20px; font-size: 18px; }

/* RTL: the shell flips to dir="rtl" for Arabic (set on <html> by js/i18n.js).
   Layout uses logical properties (inline-start/end, text-align start/end) so it
   mirrors automatically; the rules below cover the few spots that can't. */
.btn:disabled { opacity: .45; }

/* Pill toggles. Generic, not scoped to the category strip: the kitchen-note tag
   modal uses them too, and a bare <button> falls back to the browser's white
   ButtonFace while inheriting our light --text — invisible on invisible. */
.chip {
  padding: 10px 14px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); font-weight: 600;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .title { font-weight: 700; font-size: 18px; }
.topbar .spacer { flex: 1; }
.pill { padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.pill.online { background: rgba(34,197,94,.15); color: var(--green); }
.pill.offline { background: rgba(245,158,11,.15); color: var(--amber); }
.pill.queue { background: rgba(56,189,248,.15); color: var(--accent); }
.pill.failed { background: rgba(239,68,68,.15); color: var(--red); }

/* Centered card screens (activation / login / shift) */
.center { flex: 1; display: grid; place-items: center; padding: 24px; }
.card {
  width: min(460px, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px; text-align: center;
}
.card h1 { margin: 0 0 6px; font-size: 24px; }
.card p.sub { margin: 0 0 20px; color: var(--muted); }
.field { width: 100%; padding: 14px; margin: 8px 0; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); }
.pindisplay { font-size: 34px; letter-spacing: 12px; height: 46px; margin: 6px 0 14px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad .btn { padding: 22px; font-size: 22px; }

/* Order screen layout */
.order { flex: 1; display: grid; grid-template-columns: 1fr 380px; min-height: 0; }
/* min-width: 0 — without it the grid item's automatic minimum size is the
   category strip's min-content (every chip on one line), so a long category
   list widens the column past the screen instead of scrolling inside .cats. */
.catalog { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.cats { display: flex; gap: 8px; padding: 10px 12px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.cats .chip { white-space: nowrap; }
.grid { flex: 1; overflow-y: auto; display: grid; gap: 12px; padding: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); align-content: start; }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; text-align: start; display: flex; flex-direction: column; min-height: 120px;
}
/* A combo tile reads as a deal, not another product. `position: relative` on the
   tile so the badge pins to its corner. */
.tile.combo { position: relative; border-color: var(--accent); }
.tile .combobadge {
  position: absolute; top: 6px; inset-inline-start: 6px; padding: 2px 8px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700;
  letter-spacing: .04em;
}
.line.comboline { border-inline-start: 3px solid var(--accent); padding-inline-start: 9px; }
.tile .thumb { height: 78px; background: var(--panel-2) center/cover no-repeat; display: grid; place-items: center;
  color: var(--muted); font-size: 26px; }
.tile .meta { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.tile .name { font-weight: 600; font-size: 14px; line-height: 1.2; }
.tile .price { color: var(--accent); font-weight: 700; font-size: 13px; }

/* Cart */
.cart { background: var(--panel); border-inline-start: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.cart .ordertypes { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.cart .ordertypes .btn { flex: 1; padding: 10px; font-size: 13px; }
.cart .ordertypes .btn.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
/* Table + customer pickers share a row; min-width lets a long customer name
   ellipsize instead of widening the button past its half. */
.pickrow { display: flex; gap: 8px; padding: 0 10px; margin-bottom: 6px; }
.pickrow > .btn { flex: 1; min-width: 0; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
/* The order's allergy / customer info. Loud on purpose and full-width: it is
   the one note that must not need a tap to discover. Wraps rather than
   ellipsizes — half an allergy is worse than none. */
.allergy { display: block; width: calc(100% - 20px); margin: 0 10px 6px;
  padding: 8px 10px; border: 1px solid var(--amber); border-radius: 8px;
  background: #78350f; color: #fde68a; font: inherit; font-weight: 600;
  font-size: 14px; text-align: start; white-space: normal; cursor: pointer; }
/* Split bill: the "N checks — tap to switch" bar and the split modal's list. */
.checksbar { display: block; width: calc(100% - 20px); margin: 0 10px 6px;
  padding: 8px 10px; border: 1px solid var(--accent); border-radius: 8px;
  background: var(--panel-2); color: var(--text); font: inherit; font-weight: 700;
  font-size: 14px; text-align: start; cursor: pointer; }
/* Open tab: the "Tab #12 · Table 5 — round 3" banner above the cart, tapped to
   go back to the bill. Green rather than accent — the cart is composing for a
   bill that already exists on the server, not one it owns. */
.tabbar { display: block; width: calc(100% - 20px); margin: 0 10px 6px;
  padding: 8px 10px; border: 1px solid var(--green); border-radius: 8px;
  background: var(--panel-2); color: var(--text); font: inherit; font-weight: 700;
  font-size: 14px; text-align: start; cursor: pointer; }
.splitlist { max-height: 46vh; overflow-y: auto; margin: 6px 0; }
.splitrow { display: flex; align-items: center; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--line); }
.splitname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-weight: 600; }
.splittotals { display: flex; justify-content: space-between; gap: 10px;
  padding: 8px 2px 0; }
.splitamt { font-weight: 800; }
/* A checkbox + its label on one line inside a modal. The box is enlarged: at
   arm's length on a tablet a default 13px checkbox is not a reliable target. */
.checkrow { display: flex; align-items: center; gap: 10px; margin-top: 10px;
  font-size: 15px; cursor: pointer; }
.checkrow input { width: 22px; height: 22px; accent-color: var(--accent); }
.lines { flex: 1; overflow-y: auto; padding: 6px 10px; }
.line { padding: 10px 6px; border-bottom: 1px solid var(--line); }
.line .top { display: flex; justify-content: space-between; gap: 8px; }
.line .name { font-weight: 600; }
.line .mods { color: var(--muted); font-size: 13px; margin-top: 2px; }
.line .qtyrow { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.qtybtn { width: 38px; height: 38px; border-radius: 10px; font-size: 20px; font-weight: 700;
  background: var(--panel-2); border: 1px solid var(--line); }
.line .amt { margin-inline-start: auto; font-weight: 700; }
.totals { padding: 10px 14px; border-top: 1px solid var(--line); }
.totals .row { display: flex; justify-content: space-between; padding: 3px 0; color: var(--muted); }
.totals .row.grand { color: var(--text); font-size: 22px; font-weight: 800; padding-top: 8px; }
.cart .actions { padding: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cart .actions .pay { grid-column: 1 / -1; }
/* The cart's phone chrome: on a tablet the summary bar is absent and .cartbody
   dissolves into its parent, so .cart's children lay out as if neither
   existed. The phone media query turns the pair into a bottom sheet. */
.cartbar { display: none; }
.cartbody { display: contents; }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(2,6,23,.72); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { width: min(560px, 96vw); max-height: 90vh; overflow-y: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 20px; padding: 20px; }
.modal h2 { margin: 0 0 12px; }
.optgroup { margin-bottom: 14px; }
.optgroup h3 { margin: 0 0 8px; font-size: 15px; }
.opt { display: flex; justify-content: space-between; align-items: center; padding: 12px; margin: 6px 0;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); }
.opt.sel { border-color: var(--accent); background: rgba(56,189,248,.12); }
/* The app-wide `user-select: none` would otherwise make the QR URL uncopyable. */
.qrlink { display: block; margin: 8px 0; color: var(--accent); word-break: break-all;
  user-select: text; -webkit-user-select: text; }

/* Payment */
.pay-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tenders { display: flex; flex-direction: column; gap: 10px; }
.amount-display { font-size: 40px; font-weight: 800; text-align: right; padding: 10px 6px; }
.change { font-size: 20px; text-align: right; color: var(--green); font-weight: 700; min-height: 28px; }
.paykeys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.paykeys .btn { padding: 20px; font-size: 22px; }

/* Report / list */
.scroll { flex: 1; overflow-y: auto; padding: 16px; }
.stat { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.stat .k { color: var(--muted); }
.stat .v { font-weight: 700; }
/* A `.stat` row that is also a control — the editable details of an open bill.
   Full-width and left-aligned so it reads as a row, not a button in a row. */
.statrow { width: 100%; background: none; border: none; border-bottom: 1px solid var(--line);
  color: inherit; font: inherit; text-align: start; cursor: pointer; }
.statrow:hover { background: var(--panel-2); }
.section-title { margin: 18px 0 6px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); padding: 12px 18px; border-radius: 12px;
  font-weight: 600; z-index: 100; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.toast.err { border-color: var(--red); color: #fecaca; }

.muted { color: var(--muted); }
.center-msg { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; }

/* Cashier sign-in roster */
.cashierlist { display: flex; flex-direction: column; gap: 8px; margin-top: 12px;
  max-height: 46vh; overflow-y: auto; }
.cashiertile { width: 100%; text-align: center; }

/* Tables (floors + editor) */
.tablesview { display: flex; flex-direction: column; padding: 0; }
.tablesbar { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tgrid { flex: 1; display: grid; gap: 6px; padding: 14px; min-height: 420px; }
.tcell { border: 1px dashed var(--line); border-radius: 10px; min-height: 46px; cursor: pointer; }
.tcell:hover { background: var(--panel-2); }
.ttable { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 2px solid var(--line); border-radius: 12px; background: var(--panel-2); cursor: pointer;
  min-height: 46px; position: relative; color: var(--ink, inherit); }
.ttable.circle { border-radius: 50%; }
.ttable .tnum { font-weight: 800; font-size: 16px; }
.ttable .tseats { font-size: 10px; color: var(--muted); }
.ttable.booked { border-color: var(--amber); background: rgba(245,158,11,.14); }
.ttable.haspending { border-color: var(--red); }
.ttable.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56,189,248,.3); }
.ttable .tdot { position: absolute; top: -6px; inset-inline-end: -6px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--red); color: #fff; font-weight: 800; font-size: 12px; display: grid; place-items: center; }

/* Action menu entries + pending badge */
.actionitem { width: 100%; margin: 4px 0; justify-content: flex-start; text-align: start; }
.btn.attn { border-color: var(--red); color: var(--red); font-weight: 800; }

/* Kitchen Display System — read across a kitchen, so bigger type and status
   colour. Wider cards than the product grid; the whole card leans on urgency. */
.kdsgrid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); align-content: start; }
.kdscard { background: var(--panel); border: 1px solid var(--line); border-inline-start: 5px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.kdscard.warn { border-inline-start-color: var(--amber); }
.kdscard.late { border-inline-start-color: var(--red); }
.kdscard.ready { border-inline-start-color: var(--green); background: rgba(34,197,94,.06); }
.kdshead { display: flex; justify-content: space-between; align-items: baseline; }
.kdsno { font-weight: 800; font-size: 16px; }
.kdstime { font-weight: 700; color: var(--muted); }
.kdscard.warn .kdstime { color: var(--amber); }
.kdscard.late .kdstime { color: var(--red); }
.kdssub { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
/* Which fire this card is, on a tab that orders in rounds. Loud enough to read
   at a glance: mistaking round 3 for a reprint of round 1 costs a remake. */
.kdsround { background: var(--accent); color: var(--accent-ink); font-weight: 800;
  font-size: 12px; padding: 1px 8px; border-radius: 999px; }
.kdslines { display: flex; flex-direction: column; gap: 4px; margin: 4px 0; }
.kdsqty { font-weight: 700; font-size: 15px; }
.kdsmod { color: var(--muted); font-size: 13px; padding-inline-start: 14px; }
.kdsalert { border: 1px solid var(--amber); background: #78350f; color: #fde68a;
  border-radius: 8px; padding: 6px 8px; font-weight: 600; font-size: 14px; }
.kdsnote { font-weight: 700; font-size: 14px; }
.kdsbtn { margin-top: 4px; }

/* ---- Phone support (demo only; the till is a landscape tablet) ------------
   Both queries are scoped so a tablet can never match them: 700px is under
   every tablet width (iPad portrait is 768), and no tablet is 500px tall.

   Phones in EITHER orientation. A dine-in cart stacks ~530px of fixed rows
   (order types, table, customer, totals, discount, actions), so sharing the
   screen with the product grid leaves neither one usable: the grid takes the
   whole screen and the cart becomes a bottom sheet, collapsed to a summary
   bar the cashier taps to expand. */
@media (max-width: 700px), (max-height: 500px) {
  .order { grid-template-columns: 1fr; }

  .cart { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    max-height: 85vh; border-left: none; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.45); }
  .cartbar { display: flex; align-items: center; gap: 12px; width: 100%;
    padding: 14px 18px; background: var(--panel-2); border: 0;
    border-radius: 16px 16px 0 0; font-weight: 700; }
  .cartbar .bartotal { margin-left: auto; font-size: 18px; }
  .cartbar .barchev { color: var(--muted); }
  .cartbody { display: none; }
  /* Half a phone row is tight for "👤 Select customer" — buy it back in padding
     rather than letting the label ellipsize. */
  .pickrow > .btn { padding-left: 10px; padding-right: 10px; }
  .cart.open .cartbody { display: flex; flex-direction: column;
    overflow-y: auto; border-top: 1px solid var(--line); }
  /* Pay stays on screen however long the order gets. */
  .cart.open .actions { position: sticky; bottom: 0; background: var(--panel);
    border-top: 1px solid var(--line); }
  /* The sheet scrolls as one piece, so .lines drops its own scroller rather
     than collapsing to nothing and trapping the rows below it. */
  .lines { flex: none; min-height: 0; overflow: visible; }
  /* Clear the collapsed bar so the last row of products stays tappable. */
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 8px; padding: 10px 10px 76px; }

  /* Trim the catalog chrome — on a 360px screen the stock paddings cost more
     height than a row of products. */
  .tile { min-height: 96px; }
  .tile .thumb { height: 56px; font-size: 20px; }
  .catalog > .field { padding: 10px 12px; font-size: 15px; }
  .cats { padding: 8px 10px; gap: 6px; }
  .cats .chip { padding: 8px 12px; font-size: 14px; }

  /* Six nav buttons are ~713px wide — unwrapped they'd scroll off the screen. */
  .topbar { flex-wrap: wrap; gap: 6px; padding: 8px 10px; }
  .topbar .title { font-size: 15px; }
  .topbar .btn { padding: 8px 12px; font-size: 14px; }
  .pay-grid { grid-template-columns: 1fr; }
  .amount-display { font-size: 28px; }
  .tgrid { min-height: 260px; }
}

/* Phone landscape — ~390px of height total. Stacked, the top bar, search and
   category strip cost 150px of it and a tile row another 129, so barely one
   row of products showed. Search and the chips share a row (a grid over the
   same markup — search left, chips scrolling right), the chrome loses its
   tablet padding, and the tiles halve: ~88px of chrome and ~3 rows visible. */
@media (max-height: 500px) {
  .catalog { display: grid; grid-template-columns: 150px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "search cats" "grid grid"; }
  .catalog > .field { grid-area: search; margin-block: 6px; margin-inline: 8px 0; padding: 8px 10px; }
  .cats { grid-area: cats; min-width: 0; border-bottom: none; padding: 6px 8px; }
  .cats .chip { padding: 6px 12px; font-size: 13px; }
  .grid { grid-area: grid; border-top: 1px solid var(--line);
    padding: 8px 8px 56px; }
  .tile { min-height: 84px; }
  .tile .thumb { height: 40px; font-size: 16px; }
  .tile .meta { padding: 6px 8px; }
  .tile .name { font-size: 13px; }

  .topbar { padding: 6px 10px; }
  /* The device name is the first thing a 390px-tall screen can spare. */
  .topbar .title { display: none; }
  .topbar .btn { padding: 6px 10px; font-size: 13px; }

  /* The sheet can't spend 130px on a stacked Clear/Pay either. */
  .cart .actions { grid-template-columns: 1fr 2fr; padding: 8px; }
  .cart .actions .pay { grid-column: auto; }
  .cartbar { padding: 10px 16px; }
  .cartbody .btn { padding: 10px 12px; }
  .btn.big { padding: 12px; font-size: 16px; }
  .totals { padding: 6px 14px; }
}

/* The receipt only exists to be printed — never shown on the cashier screen.
   This base rule MUST stay above the @media print block: media queries add no
   specificity, so a later `display:none` would win over the print rule and
   print a blank page. */
#receipt { display: none; }

/* Print: only the receipt shows, formatted for an 80mm roll. `size: 80mm auto`
   + `margin: 0` also suppress the browser's default page headers/footers (page
   title, URL, date) that would otherwise be all a receipt printer emits. */
@page { size: 80mm auto; margin: 0; }
@media print {
  html, body { height: auto; background: #fff; overscroll-behavior: auto; }
  /* Remove the app shell from layout rather than hiding it: a 100vh shell left
     in flow pushes the receipt onto a second page / emits blank pages. */
  body > *:not(#receipt) { display: none !important; }
  /* direction: ltr keeps the 80mm layout stable when the app is in Arabic (the
     shell sets <html dir="rtl">, which #receipt would otherwise inherit and
     mirror). Labels are bilingual; the amount stays on the right. */
  #receipt { display: block; direction: ltr; width: 72mm; color: #000; background: #fff;
    font-family: "Courier New", monospace; font-size: 12px; padding: 4mm; }
}
