/* ============================================================
   ORDERS SYSTEM — tokens and primitives

   The world: quiet surfaces, generous air, one accent, and type
   doing the work that borders used to do. Nothing is decorated.
   A control looks pressable because of its shape and its fill,
   not because something was drawn around it.

   Rules the rest of the stylesheet obeys:
     · One accent. Colour means state, never brand mood.
     · Hairlines, not borders. A rule is 1px of near-nothing.
     · Elevation is one soft shadow, used on things that float.
     · Radius is consistent: 8 for controls, 14 for surfaces.
     · Figures are tabular, always. Money that shifts width as
       its digits change is software that does not respect money.
   ============================================================ */

:root {
  /* ── Surfaces ───────────────────────────────────────────── */
  /* The page is a shade below the cards on it, so a card reads
     as raised without a border or a shadow doing the telling. */
  --bg:          #f5f5f7;
  --surface:     #ffffff;
  --surface-2:   #fbfbfd;
  --surface-3:   #f0f0f3;

  /* Translucent fills, the way the platform tints a control:
     they sit correctly on any surface underneath them. */
  --fill:        rgba(120, 120, 128, 0.10);
  --fill-strong: rgba(120, 120, 128, 0.18);

  /* ── Ink ────────────────────────────────────────────────── */
  --text:   #1d1d1f;    /* headings, figures, body            */
  --text-2: #55555c;    /* secondary — 7.3:1 on --bg          */
  --text-3: #6e6e76;    /* tertiary: hints, disabled — 5.3:1  */

  --hairline:        rgba(0, 0, 0, 0.10);
  --hairline-strong: rgba(0, 0, 0, 0.16);

  /* ── Accent and status ──────────────────────────────────── */
  /* One accent. It marks where you are, what has focus, and the
     single key that finishes the task on screen. */
  --accent:       #0062cc;
  --accent-hover: #0071e3;
  --accent-soft:  rgba(0, 113, 227, 0.10);
  --on-accent:    #ffffff;
  /* Accent text sitting ON --accent-soft. The accent itself is tuned for a
     white ground and drops under 4.5:1 once the tint is behind it. */
  --accent-ink:   #084b9e;
  /* The ground under white text on a filled key. Separate from --accent
     because the two are measured against opposite things. */
  --accent-fill:  #0062cc;

  --red:       #c9161f;   /* money leaving, destructive acts  */
  --red-soft:  rgba(201, 22, 31, 0.10);
  --green:     #12703c;   /* settled, positive figures        */
  --green-soft: rgba(18, 112, 60, 0.10);
  --amber:     #9a5b00;   /* waiting, low stock               */
  --amber-soft: rgba(154, 91, 0, 0.10);

  /* ── Type ───────────────────────────────────────────────── */
  /* System stacks only. This machine is offline: a webfont host
     is a request that will never resolve and a CSP directive we
     refuse to open. -apple-system first, so a Mac or an iPad
     counter tablet gets the real thing. */
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui,
             "Segoe UI", Roboto, "Noto Sans Arabic", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono",
               Menlo, Consolas, "DejaVu Sans Mono", monospace;

  --t-micro: 0.75rem;    /* 12px — labels, meta               */
  --t-small: 0.8125rem;  /* 13px                              */
  --t-body:  1rem;       /* 16px — never smaller for body     */
  --t-lead:  1.0625rem;
  --t-fig:   1.375rem;
  --t-total: 2rem;
  --t-hero:  2.125rem;

  /* Optical tightening, the way large type is set on a good
     page: the bigger it is, the closer it wants to sit. */
  --track-head:  0.005em;
  --track-tight: -0.015em;
  --track-hero:  -0.028em;

  /* ── Rhythm ─────────────────────────────────────────────── */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  --tap: 44px;

  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-xl:   22px;
  --r-pill: 980px;
  --radius: var(--r-sm);   /* the default a control inherits  */

  /* Elevation. Two shadows only: one for a resting surface,
     one for something genuinely floating over the page. */
  --lift:   0 1px 2px rgba(0, 0, 0, .05), 0 0 0 .5px rgba(0, 0, 0, .04);
  --lift-2: 0 12px 40px rgba(0, 0, 0, .14), 0 2px 8px rgba(0, 0, 0, .06);

  --dur:   200ms;
  --dur-2: 320ms;
  --ease:  cubic-bezier(.25, .1, .25, 1);

  --z-sticky: 20; --z-nav: 40; --z-sheet: 60; --z-toast: 80;
}

/* 12px Latin labels are legible; 12px Arabic is not, and the status pills,
   the table headers and the analytics labels all sit at that step. */
:root:lang(ar) { --t-micro: 0.8125rem; }

/* Dark is the same world with the light behind it turned off:
   the page goes to true black, surfaces lift out of it in grey,
   and the accent brightens to hold its contrast. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #000000;
    --surface:   #1c1c1e;
    --surface-2: #232325;
    --surface-3: #2c2c2e;
    --fill:        rgba(120, 120, 128, 0.24);
    --fill-strong: rgba(120, 120, 128, 0.36);
    --text:   #f5f5f7;
    --text-2: #b0b0b8;
    --text-3: #9a9aa2;
    --hairline:        rgba(255, 255, 255, 0.12);
    --hairline-strong: rgba(255, 255, 255, 0.20);
    --accent:       #0a84ff;
    --accent-hover: #3f9dff;
    --accent-soft:  rgba(10, 132, 255, 0.18);
    --on-accent:    #ffffff;
    --accent-ink:   #8ac6ff;
    --accent-fill:  #1668d0;
    --red:        #ff6961;
    --red-soft:   rgba(255, 105, 97, 0.16);
    --green:      #40d472;
    --green-soft: rgba(64, 212, 114, 0.16);
    --amber:      #ffb340;
    --amber-soft: rgba(255, 179, 64, 0.16);
    --lift:   0 1px 2px rgba(0, 0, 0, .5), 0 0 0 .5px rgba(255, 255, 255, .06);
    --lift-2: 0 16px 44px rgba(0, 0, 0, .7), 0 2px 8px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  --bg:        #000000;
  --surface:   #1c1c1e;
  --surface-2: #232325;
  --surface-3: #2c2c2e;
  --fill:        rgba(120, 120, 128, 0.24);
  --fill-strong: rgba(120, 120, 128, 0.36);
  --text:   #f5f5f7;
  --text-2: #b0b0b8;
  --text-3: #9a9aa2;
  --hairline:        rgba(255, 255, 255, 0.12);
  --hairline-strong: rgba(255, 255, 255, 0.20);
  --accent:       #0a84ff;
  --accent-hover: #3f9dff;
  --accent-soft:  rgba(10, 132, 255, 0.18);
  --on-accent:    #ffffff;
  --accent-ink:   #8ac6ff;
  --accent-fill:  #1668d0;
  --red:        #ff6961;
  --red-soft:   rgba(255, 105, 97, 0.16);
  --green:      #40d472;
  --green-soft: rgba(64, 212, 114, 0.16);
  --amber:      #ffb340;
  --amber-soft: rgba(255, 179, 64, 0.16);
  --lift:   0 1px 2px rgba(0, 0, 0, .5), 0 0 0 .5px rgba(255, 255, 255, .06);
  --lift-2: 0 16px 44px rgba(0, 0, 0, .7), 0 2px 8px rgba(0, 0, 0, .5);
}

/* Compatibility aliases. The receipt-roll world named its tokens
   after paper and ink; a handful of older rules and the printed
   slip still reach for those names. They resolve here rather
   than being renamed in eight files at once. */
:root, :root[data-theme="dark"] {
  --paper: var(--bg);
  --paper-raised: var(--surface);
  --paper-band: var(--surface-3);
  --paper-sunk: var(--surface-3);
  --ink: var(--text);
  --ink-2: var(--text-2);
  --ink-3: var(--text-3);
  --ink-hair: var(--hairline);
  --stamp: var(--accent);
  --stamp-soft: var(--accent-soft);
  --good: var(--green);
  --good-soft: var(--green-soft);
}

/* ── Reset ────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--t-body);
  line-height: 1.47;
  letter-spacing: var(--track-head);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, p, figure { margin: 0; }
h1, h2, h3, h4 { letter-spacing: var(--track-tight); }
ul, ol { margin: 0; padding: 0; list-style: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }

input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

/* Focus is a ring in the accent, and it is never removed — the
   back office runs this on a laptop with a keyboard. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--accent-soft); color: var(--text); }

/* ── Figures ──────────────────────────────────────────────── */

.fig, .money, td.num, .stat-value, .figure {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: var(--track-tight);
}

/* Amounts stay left-to-right even when the page is Arabic: a
   minus sign or a currency code on the wrong side of the digits
   is a misread number, not a style choice.
   No display change here — this class also lands on <td>, and
   inline-block takes a cell out of table layout and collapses
   the column it belongs to. */
.money { unicode-bidi: isolate; direction: ltr; }

.figure { font-weight: 600; font-size: var(--t-fig); }
.figure--lg { font-size: var(--t-total); letter-spacing: var(--track-hero); }

/* A quiet label above a thing. Sentence case: shouting a word in
   caps was the old world's way of marking a heading, and it made
   every screen look like a form. */
.head {
  font-size: var(--t-micro);
  font-weight: 600;
  letter-spacing: var(--track-head);
  color: var(--text-3);
}

/* ── Rules ────────────────────────────────────────────────── */

.rule, .rule-dash, .rule-solid {
  border: 0;
  border-top: 1px solid var(--hairline);
  margin: var(--s4) 0;
}

/* The receipt world's torn paper edge. Kept as an inert hook so
   the markup that still names it lays out correctly; there is
   nothing to tear off a surface that is not paper. */
.torn { box-shadow: none; -webkit-mask: none; mask: none; }
.tear { display: none; }

/* label ......... value, without the dots. Space does the
   separating now; the eye tracks a gap as well as it tracks a
   row of periods, and the row of periods was ink for nothing. */
.leader {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s4);
  min-width: 0;
  padding: var(--s1) 0;
}
.leader > :first-child { flex: 0 1 auto; min-width: 0; color: var(--text-2); }
.leader > :last-child { flex: none; white-space: nowrap; font-variant-numeric: tabular-nums; }
.leader--strong > * { color: var(--text); font-weight: 600; }
/* A row whose value is words, not a figure — a customer, a date, a state.
   It may wrap rather than push the page sideways on a phone: a money value
   never breaks, but "3 تشرين الأول 2027" at 320 px has to. */
.leader--text > :last-child { flex: 0 1 auto; min-width: 0; white-space: normal; overflow-wrap: anywhere; text-align: end; }

/* The total, ruled off from what fed into it. */
.reverse {
  padding-top: var(--s3);
  border-top: 1px solid var(--hairline-strong);
}

/* ── Status ───────────────────────────────────────────────── */

/* A soft tint carrying a word. Colour is never the only signal:
   the pill always says its status out loud. */
.stamp, .tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--fill);
  color: var(--text-2);
  font-size: var(--t-micro);
  font-weight: 590;
  letter-spacing: var(--track-head);
  white-space: nowrap;
}
.stamp--live  { background: var(--accent-soft); color: var(--accent-ink); }
.stamp--done,
.tag--done    { background: var(--green-soft);  color: var(--green); }
.stamp--void  { background: var(--red-soft);    color: var(--red); }
.stamp--muted { background: var(--fill);        color: var(--text-3); }
.tag--warn    { background: var(--amber-soft);  color: var(--amber); }

/* ── Controls ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: var(--tap);
  padding: 0 var(--s4);
  border: 0;
  border-radius: var(--r-sm);
  background: var(--fill);
  color: var(--text);
  font-size: var(--t-small);
  font-weight: 590;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
              transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:hover { background: var(--fill-strong); }
.btn:active { transform: scale(.97); }

/* The key: the one filled accent shape on a screen, and it is
   the thing that finishes what you came to do. */
.btn--key {
  background: var(--accent-fill);
  color: var(--on-accent);
  font-weight: 600;
}
.btn--key:hover { background: var(--accent-hover); }
/* A pressed option's price ("Oat +1.000") is muted grey on a plain key; on the
   accent it was grey on blue, the one figure the cashier reads off the key. */
.btn--key .muted { color: inherit; }

.btn--danger { background: transparent; color: var(--red); }
.btn--danger:hover { background: var(--red-soft); }
.btn--ghost { background: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--fill); color: var(--text); }
.btn--small { min-height: 36px; padding: 0 var(--s3); }
.btn--icon { min-width: 36px; padding: 0 var(--s2); }
/* Small enough to sit inside a receipt line without shouting,
   but still a real target: 32px tall inside a 44px row. */
.btn--tiny {
  min-height: 32px;
  padding: 0 var(--s3);
  font-size: var(--t-micro);
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn--tiny:hover { background: var(--accent); color: var(--on-accent); }

.btn[disabled], .btn[aria-disabled="true"] {
  opacity: .38;
  cursor: not-allowed;
  transform: none;
}

/* ── Fields ───────────────────────────────────────────────── */

.field { display: block; margin-bottom: var(--s4); }
.field > .label {
  display: block;
  margin-bottom: var(--s2);
  font-size: var(--t-small);
  font-weight: 590;
  color: var(--text-2);
}
.field .req { color: var(--red); }

/* Filled, not outlined. An outline is a border around every
   field on the page, and a settings form has thirty of them. */
.input, .select, .textarea {
  width: 100%;
  min-height: var(--tap);
  padding: var(--s2) var(--s3);
  background: var(--fill);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--text);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.input:hover, .select:hover, .textarea:hover { background: var(--fill-strong); }
.input:focus, .select:focus, .textarea:focus {
  background: var(--surface);
  border-color: var(--accent);
}
.input::placeholder { color: var(--text-3); }
.input[aria-invalid="true"] { border-color: var(--red); }
.textarea { min-height: 84px; resize: vertical; }

.hint { display: block; margin-top: var(--s2); font-size: var(--t-small); color: var(--text-3); }
.error-text {
  display: flex; align-items: center; gap: 6px;
  margin-top: var(--s2); font-size: var(--t-small); color: var(--red); font-weight: 590;
}

.chk { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; min-height: var(--tap); }
.chk input { width: 22px; height: 22px; }

/* A short piece of guidance inside a surface — not an alert. */
.notice {
  padding: var(--s3);
  margin-bottom: var(--s3);
  border-radius: var(--r-md);
  background: var(--fill);
  color: var(--text-2);
  font-size: var(--t-small);
}

/* ── Utility ──────────────────────────────────────────────── */

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; inset-inline-start: var(--s3); top: -100px;
  z-index: var(--z-toast); padding: var(--s3) var(--s4);
  background: var(--accent-fill); color: var(--on-accent); border-radius: var(--r-sm);
}
.skip-link:focus { top: var(--s3); }

.row { display: flex; align-items: center; gap: var(--s3); }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.row--tight { gap: var(--s2); }
.grow { flex: 1 1 auto; min-width: 0; }
.stack > * + * { margin-top: var(--s3); }
.muted { color: var(--text-3); }
.neg { color: var(--red); }
.pos { color: var(--green); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
/* A `display` rule of our own outranks the UA stylesheet's
   [hidden], so any element we lay out has to be told again. */
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
