/* ==========================================================================
   Stampi — portal design system
   Light: apple.com white — pure white, near-black text, generous whitespace.
   Dark:  luxury — near-black surfaces, warm gold accent.

   Contrast verified (WCAG AA):
     light  text 16.83:1  muted 5.07:1  accent 6.45:1
     dark   text 18.18:1  muted 7.69:1  gold   9.41:1

   Direction-agnostic: every inline offset uses logical properties, so the
   same sheet serves LTR English and RTL Arabic with no overrides.
   ========================================================================== */

:root {
  --bg:          #ffffff;
  --surface:     #f5f5f7;
  --elevated:    #ffffff;
  --text:        #1d1d1f;
  --muted:       #6e6e73;
  --hairline:    #d2d2d7;   /* decorative only */
  --control:     #86868b;   /* 3.62:1 — form borders */
  --accent:      #146c43;   /* overridden per tenant */
  --on-accent:   #ffffff;
  --danger:      #b3261e;
  --warn:        #8a6100;
  --ok:          #146c43;
  --shadow:      0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --shadow-lift: 0 2px 6px rgba(0,0,0,.06), 0 18px 48px rgba(0,0,0,.10);
  --radius:      14px;
  --radius-lg:   22px;

  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
          system-ui, "Noto Sans Arabic", "Geeza Pro", Tahoma, sans-serif;
}

:root[data-theme="dark"] {
  --bg:        #0a0a0b;
  --surface:   #141416;
  --elevated:  #1c1c1f;
  --text:      #f5f5f7;
  --muted:     #a1a1a6;
  --hairline:  #2c2c2e;
  --control:   #7a7a80;
  --accent:    #d4af37;     /* gold — 9.41:1 on bg */
  --on-accent: #0a0a0b;
  --danger:    #ff6961;
  --warn:      #e8b931;
  --ok:        #4ade80;
  --shadow:      0 1px 2px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.45);
  --shadow-lift: 0 2px 6px rgba(0,0,0,.55), 0 18px 48px rgba(0,0,0,.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#0a0a0b; --surface:#141416; --elevated:#1c1c1f;
    --text:#f5f5f7; --muted:#a1a1a6; --hairline:#2c2c2e; --control:#7a7a80;
    --accent:#d4af37; --on-accent:#0a0a0b;
    --danger:#ff6961; --warn:#e8b931; --ok:#4ade80;
    --shadow:0 1px 2px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.45);
    --shadow-lift:0 2px 6px rgba(0,0,0,.55), 0 18px 48px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 17px/1.5 var(--font);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}

/* ── Type scale ─────────────────────────────────────────────────────── */
h1 { font-size: clamp(28px, 4vw, 40px); line-height: 1.1; letter-spacing:-.025em;
     font-weight: 600; margin: 0 0 var(--s2); }
h2 { font-size: 22px; line-height: 1.25; letter-spacing:-.02em; font-weight: 600;
     margin: 0 0 var(--s3); }
h3 { font-size: 17px; font-weight: 600; margin: 0 0 var(--s2); }
p  { margin: 0 0 var(--s3); }
small, .small { font-size: 13px; }
.muted { color: var(--muted); }
.mono  { font-variant-numeric: tabular-nums; }

/* ── Layout ─────────────────────────────────────────────────────────── */
.shell   { min-height: 100dvh; display: flex; flex-direction: column; }
.wrap    { width: min(1120px, 100%); margin-inline: auto; padding-inline: var(--s5); }
.wrap-sm { width: min(460px, 100%);  margin-inline: auto; padding-inline: var(--s5); }
.stack > * + * { margin-block-start: var(--s5); }
.grid { display: grid; gap: var(--s4); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.center { text-align: center; }

/* ── Top bar ────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  border-block-end: 1px solid var(--hairline);
}
.topbar .wrap { display: flex; align-items: center; gap: var(--s4);
                min-height: 52px; }
.brand { font-weight: 600; letter-spacing: -.02em; display: flex;
         align-items: center; gap: var(--s2); text-decoration: none; color: var(--text); }
.brand .dot { width: 18px; height: 18px; border-radius: 6px; background: var(--accent);
               object-fit: cover; display: block; }
img.dot { background: none !important; }
.nav { display: flex; gap: var(--s1); margin-inline-start: auto; flex-wrap: wrap; }
.nav a {
  color: var(--muted); text-decoration: none; font-size: 14px;
  padding: 7px 12px; border-radius: 980px; transition: color .18s, background .18s;
}
.nav a:hover { color: var(--text); background: var(--surface); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface); font-weight: 500; }

/* ── Cards ──────────────────────────────────────────────────────────── */
.card {
  background: var(--elevated);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: var(--s5);
  box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; background: var(--surface); }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .n { font-size: 34px; font-weight: 600; letter-spacing: -.03em; line-height: 1.05; }
.stat .l { font-size: 13px; color: var(--muted); }

/* ── Controls ───────────────────────────────────────────────────────── */
label { display: block; font-size: 13px; color: var(--muted); margin-block-end: 6px; }

/* Bare `input` too: an <input> with no type attribute defaults to text but
   does NOT match input[type=text]. */
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=hidden]):not([type=file]),
select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg);
  border: 1px solid var(--control);
  border-radius: 11px; padding: 11px 13px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}
input[type=color] {
  inline-size: 52px; block-size: 40px; padding: 3px; cursor: pointer;
  border: 1px solid var(--control); border-radius: 10px; background: var(--bg);
}
input[type=range] { inline-size: 100%; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 11px 20px;            /* 44px touch target */
  font: inherit; font-size: 15px; font-weight: 500;
  border-radius: 980px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none;
  transition: transform .15s ease, opacity .15s, background .15s, border-color .15s;
}
.btn:active { transform: scale(.975); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { opacity: .88; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--control); }
.btn-ghost:hover { background: var(--surface); }
.btn-quiet { background: transparent; color: var(--muted); padding-inline: 10px; }
.btn-quiet:hover { color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border-color: currentColor; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ── Tables ─────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 12px 14px; text-align: start; border-block-end: 1px solid var(--hairline); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
     color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--surface); }

/* ── Pills & notices ────────────────────────────────────────────────── */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
        font-weight: 500; padding: 4px 10px; border-radius: 980px;
        background: var(--surface); color: var(--muted);
        border: 1px solid var(--hairline); }
.pill.ok    { color: var(--ok);    border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.warn  { color: var(--warn);  border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.pill.bad   { color: var(--danger);border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

.notice { padding: 12px 14px; border-radius: 12px; font-size: 14px;
          border: 1px solid var(--hairline); background: var(--surface); }
.notice.bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent);
              background: color-mix(in srgb, var(--danger) 8%, transparent); }
.notice.ok  { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent);
              background: color-mix(in srgb, var(--ok) 8%, transparent); }

/* ── Live pass preview (card designer) ──────────────────────────────── */
.pass-preview {
  --pc: #146c43;
  inline-size: 320px; max-inline-size: 100%;
  border-radius: 18px; overflow: hidden;
  background: var(--elevated);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-lift);
  font-size: 14px;
}
.pass-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; }
.pass-mark { inline-size: 30px; block-size: 30px; border-radius: 9px; background: var(--pc);
             display: grid; place-items: center; flex: none; }
.pass-mark i { inline-size: 12px; block-size: 12px; border-radius: 50%;
               border: 3px solid #fff; display: block; }
.pass-org { font-weight: 600; font-size: 14px; }
.pass-count { margin-inline-start: auto; font-variant-numeric: tabular-nums;
              font-weight: 600; font-size: 15px; }
.pass-strip { block-size: 96px; display: flex; align-items: center; justify-content: center;
              gap: 8px; background: linear-gradient(160deg, var(--pc), color-mix(in srgb, var(--pc) 62%, #000)); }
.pass-strip span { inline-size: 20px; block-size: 20px; border-radius: 50%;
                   border: 2px solid rgba(255,255,255,.75); }
.pass-strip span.on { background: #fff; border-color: #fff;
                      box-shadow: inset 0 0 0 4px var(--pc); }
.pass-body { padding: 14px 16px; display: grid; gap: 3px; }
.pass-label { font-size: 10px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.pass-reward { font-weight: 600; }
.pass-qr { padding: 0 16px 16px; }
.pass-qr div {
  block-size: 62px; border-radius: 9px; display: grid; place-items: center;
  background: var(--surface); border: 1px dashed var(--hairline);
  color: var(--muted); font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
}
.pass-qr div::after { content: "QR"; }

/* ── Theme + language switch ────────────────────────────────────────── */
.switch { display: inline-flex; background: var(--surface); border: 1px solid var(--hairline);
          border-radius: 980px; padding: 2px; }
.switch a, .switch button {
  font: inherit; font-size: 12px; font-weight: 500; padding: 5px 11px;
  border-radius: 980px; border: 0; background: transparent; color: var(--muted);
  cursor: pointer; text-decoration: none; min-height: 30px; display: inline-flex;
  align-items: center;
}
.switch .on { background: var(--elevated); color: var(--text); box-shadow: var(--shadow); }

/* ── Motion: subtle (dial 3/10), and honour reduced-motion ──────────── */
@media (prefers-reduced-motion: no-preference) {
  .reveal { animation: rise .35s cubic-bezier(.22,.61,.36,1) both; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── RTL: mirror only what logical properties cannot ────────────────── */
[dir="rtl"] .pass-count { margin-inline-start: auto; }
[dir="rtl"] .nav { margin-inline-start: auto; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .wrap { padding-inline: var(--s4); }
  .card { padding: var(--s4); border-radius: var(--radius); }
  .topbar .wrap { flex-wrap: wrap; padding-block: var(--s2); }
}

/* ── Print: the counter card, and nothing else ──────────────────────────
   Everything outside .poster is hidden explicitly. Relying on .no-print
   alone left the sticky topbar and page padding on the sheet. */
@media print {
  @page { size: A5 portrait; margin: 0; }

  html, body {
    background: #fff !important; color: #000 !important;
    margin: 0 !important; padding: 0 !important;
    width: 148mm; height: 210mm;
  }
  .topbar, .foot, .no-print, nav, script { display: none !important; }

  /* Lift the poster out of the page flow so wrappers cannot offset it. */
  body * { visibility: hidden; }
  .poster, .poster * { visibility: visible; }
  .poster {
    position: absolute; inset-block-start: 0; inset-inline-start: 0;
    inline-size: 148mm !important; block-size: 210mm !important;
    margin: 0 !important; border: 0 !important; border-radius: 0 !important;
    box-shadow: none !important; background: #fff !important;
    break-inside: avoid; page-break-inside: avoid;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  /* Brand colour must survive the printer's default of dropping backgrounds. */
  .poster * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Visually hidden without creating layout.
   The usual `left:-9999px` trick is direction-unsafe: in RTL the scroll
   origin flips and that offset becomes ~10000px of real horizontal
   overflow, which blanks the page. Clip instead of moving. */
.vh {
  position: absolute !important;
  inline-size: 1px; block-size: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; white-space: nowrap;
  clip-path: inset(50%);
}

/* Stamp counters are always "done / total".
   In RTL, bidi treats the slash as neutral and flips it to "6 / 4", which
   misreads as progress going backwards. Pin these runs to LTR. */
.pass-n, .pass-count, .dots { direction: ltr; unicode-bidi: isolate; }

/* ── Counter card (A5, printed and stood on the counter) ────────────────
   Fixed proportions in mm so screen preview and print match exactly. */
.poster {
  inline-size: 148mm; max-inline-size: 100%; aspect-ratio: 148/210;
  margin-inline: auto; background: #fff; color: #111;
  border: 1px solid var(--hairline); border-radius: var(--radius-lg);
  overflow: hidden; display: grid; grid-template-rows: auto 1fr auto;
  box-shadow: var(--shadow-lift);
}
.poster-top {
  background: linear-gradient(158deg, var(--accent),
              color-mix(in srgb, var(--accent) 62%, #000));
  color: #fff; padding: 12mm 10mm 9mm; text-align: center;
}
.poster-mark { inline-size: 22mm; block-size: 22mm; margin: 0 auto 5mm;
               border-radius: 26%; overflow: hidden; background: rgba(255,255,255,.16);
               display: grid; place-items: center; }
.poster-mark img { inline-size: 100%; block-size: 100%; object-fit: cover; display: block; }
.poster-name { font-size: 7.5mm; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }
.poster-branch { font-size: 3.6mm; opacity: .85; margin-block-start: 1.5mm; }

.poster-mid { display: grid; place-content: center; justify-items: center;
              gap: 4mm; padding: 8mm; }
.poster-qr { inline-size: 55mm; block-size: 55mm; }
.poster-qr svg { inline-size: 100%; block-size: 100%; display: block; }
.poster-cta { font-size: 6mm; font-weight: 600; letter-spacing: -.02em; }
.poster-sub { font-size: 3.6mm; color: #5b5b60; text-align: center; max-inline-size: 90mm; }

.poster-bot { padding: 0 10mm 9mm; text-align: center; display: grid; gap: 3.5mm;
              justify-items: center; }
.poster-dots { display: flex; gap: 2.4mm; }
.poster-dots span { inline-size: 4.6mm; block-size: 4.6mm; border-radius: 50%;
                    border: .7mm solid var(--accent); }
.poster-dots span.last { background: var(--accent); }
.poster-reward { font-size: 4.2mm; }
.poster-foot { font-size: 2.8mm; color: #8a8a8f; letter-spacing: .08em; }

/* ==========================================================================
   App shell — sidebar layout for the merchant and admin portals.
   The top nav was wrapping to two rows once there were seven destinations;
   a rail scales and gives buttons a place to live.
   Mobile keeps a top bar and a slide-over drawer, so no viewport is asked
   to render a permanent sidebar it cannot afford.
   ========================================================================== */
.app { min-height: 100dvh; display: grid; grid-template-columns: 1fr; }

.side {
  position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 60;
  inline-size: 248px; padding: var(--s4);
  background: var(--elevated); border-inline-end: 1px solid var(--hairline);
  display: flex; flex-direction: column; gap: var(--s2);
  transform: translateX(-102%); transition: transform .24s cubic-bezier(.22,.61,.36,1);
  overflow-y: auto;
}
[dir="rtl"] .side { transform: translateX(102%); }
.side.open { transform: none; }

.side-brand { display: flex; align-items: center; gap: 10px; font-weight: 600;
              letter-spacing: -.02em; text-decoration: none; color: var(--text);
              padding: 6px 10px var(--s4); }
.side-brand .dot, .side-brand img { inline-size: 26px; block-size: 26px;
              border-radius: 8px; background: var(--accent); object-fit: cover; }

.side-group { font-size: 11px; text-transform: uppercase; letter-spacing: .1em;
              color: var(--muted); padding: var(--s4) 10px 6px; font-weight: 600; }

.side a.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 11px; min-height: 44px;
  color: var(--muted); text-decoration: none; font-size: 15px;
  transition: background .15s, color .15s;
}
.side a.nav-item:hover { background: var(--surface); color: var(--text); }
.side a.nav-item[aria-current="page"] {
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  color: var(--accent); font-weight: 600;
}
.side a.nav-item svg { inline-size: 19px; block-size: 19px; flex: none; }
.side .spacer { flex: 1; }
.side .side-foot { border-block-start: 1px solid var(--hairline); padding-block-start: var(--s3);
                   display: grid; gap: var(--s2); }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 55;
         opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.on { opacity: 1; pointer-events: auto; }

/* Content column */
.appbar {
  position: sticky; inset-block-start: 0; z-index: 40;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4); min-height: 56px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  border-block-end: 1px solid var(--hairline);
}
.appbar h1 { font-size: 19px; margin: 0; letter-spacing: -.02em; }
.appbar .grow { flex: 1; }
.burger { display: inline-flex; align-items: center; justify-content: center;
          inline-size: 40px; block-size: 40px; border-radius: 11px;
          border: 1px solid var(--hairline); background: var(--elevated);
          color: var(--text); cursor: pointer; }
.burger svg { inline-size: 20px; block-size: 20px; }

.content { padding: var(--s5) var(--s4) var(--s8); }
.content > * + * { margin-block-start: var(--s5); }

/* Page-level action row: primary action first, everything else quiet. */
.actions { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }
.actions .btn { min-height: 40px; padding: 9px 16px; font-size: 14px; }

@media (min-width: 1000px) {
  .app { grid-template-columns: 248px 1fr; }
  .side { position: sticky; inset-block-start: 0; block-size: 100dvh; transform: none; }
  [dir="rtl"] .side { transform: none; }
  .burger, .scrim { display: none; }
  .appbar { padding-inline: var(--s6); }
  .content { padding-inline: var(--s6); }
}
