:root {
  --bg: #fff8f1;
  --surface: #ffffff;
  --text: #1f1a17;
  --muted: #6b625c;
  --line: #ece3da;
  --brand: #e8590c;
  --brand-ink: #ffffff;
  --ready: #2b8a3e;
  --ready-bg: #ebfbee;
  --warn-bg: #fff4e6;
  --warn: #a14a00;
  --danger: #c92a2a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 6px 24px rgba(0, 0, 0, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", "Noto Sans", Tahoma, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171412;
    --surface: #221e1b;
    --text: #f4eee9;
    --muted: #a99f97;
    --line: #362f2a;
    --ready-bg: #13321b;
    --warn-bg: #3a2610;
    --warn: #ffb870;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

h1, h2 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  display: grid;
  gap: 16px;
}

/* --- Top bar ---------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.brand { font-size: 1.05rem; }

.conn { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }
.conn .dot { width: 10px; height: 10px; border-radius: 50%; background: #f59f00; }
.conn.ok .dot { background: var(--ready); }

/* --- Buttons ------------------------------------------------------------ */
.btn, .btn-ghost {
  font: inherit;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn {
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn-lg { min-height: 52px; }
.btn-xl { min-height: 64px; width: 100%; font-size: 1.15rem; border-radius: 14px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary.is-on { background: var(--ready); border-color: var(--ready); opacity: 1; }
.btn-ready { background: var(--ready); border-color: var(--ready); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-light { background: #fff; color: var(--ready); border-color: #fff; }
.btn-ghost {
  min-height: 44px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}
.btn:focus-visible, .btn-ghost:focus-visible, input:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* --- Cards / forms -------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.eyebrow { margin: 0; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }
.note { margin: 12px 0 0; color: var(--muted); font-size: .95rem; }
.note.warn { background: var(--warn-bg); color: var(--warn); padding: 12px 14px; border-radius: 12px; }
.error { color: var(--danger); margin: 8px 0; }
.empty { color: var(--muted); }

.field { display: grid; gap: 8px; margin-bottom: 12px; }
input[type="text"], input[type="password"] {
  font: inherit;
  font-size: 1.1rem;
  min-height: 52px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
.create-form { display: grid; gap: 10px; }
@media (min-width: 560px) { .create-form { grid-template-columns: 1fr auto; } }

/* --- Customer order page -------------------------------------------------- */
.customer .wrap { padding-top: 24px; }
.order-label { font-size: clamp(2.6rem, 14vw, 4.5rem); margin: 4px 0 16px; word-break: break-word; }
.status-hint { font-size: 1.05rem; margin: 16px 0 20px; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.steps li {
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
  font-size: .95rem;
  color: var(--muted);
  position: relative;
}
.step-dot { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); background: var(--surface); }
.steps li.done .step-dot { background: var(--muted); border-color: var(--muted); }
.steps li.current { color: var(--text); font-weight: 700; }
.steps li.current .step-dot { border-color: var(--brand); background: var(--brand); box-shadow: 0 0 0 6px rgba(232, 89, 12, .18); }
[data-status="ready"] .steps li.current .step-dot { border-color: var(--ready); background: var(--ready); box-shadow: 0 0 0 6px rgba(43, 138, 62, .2); }
[data-status="preparing"] .steps li.current .step-dot { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 12px rgba(232, 89, 12, 0); } }

/* "Enable alerts" prompt shown right after scanning */
.enable-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, .55);
}
.enable-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 28px 22px 18px;
  width: min(100%, 440px);
  display: grid;
  gap: 12px;
  text-align: center;
  justify-items: center;
}
.enable-card p { margin: 0 0 6px; color: var(--muted); font-size: 1.05rem; }
.enable-icon {
  width: 84px; height: 84px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 2.6rem;
  background: var(--warn-bg);
  animation: bounce 1.2s ease-in-out infinite;
}
.btn-later { border: 0; color: var(--muted); width: 100%; }

/* iPhone "Add to Home Screen" guide */
.ios-install {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: rgba(0, 0, 0, .55);
}
.ios-install.arrow-top { justify-content: flex-start; }
.ios-sheet {
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 22px 18px calc(18px + env(safe-area-inset-bottom));
  display: grid;
  gap: 14px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}
.ios-install.arrow-top .ios-sheet { border-radius: 0 0 22px 22px; padding-top: calc(22px + env(safe-area-inset-top)); order: 2; }
.ios-app { display: flex; align-items: center; gap: 14px; }
.ios-app img { border-radius: 14px; flex: none; }
.ios-app h1 { font-size: 1.25rem; margin: 0 0 4px; }
.ios-app p { margin: 0; color: var(--muted); }
.ios-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ios-steps li {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg); border-radius: 14px; padding: 12px 14px;
}
.step-num {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 700;
}
.step-text { flex: 1; }
.step-icon { flex: none; display: grid; place-items: center; width: 36px; height: 36px; }
.step-icon svg { width: 30px; height: 30px; fill: none; stroke: #0a84ff; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.step-icon img { border-radius: 7px; }
.ios-arrow {
  text-align: center; font-size: 2.6rem; color: #fff; line-height: 1;
  padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
  animation: nudge 1s ease-in-out infinite;
}
.ios-install.arrow-top .ios-arrow { order: 1; padding: calc(4px + env(safe-area-inset-top)) 0 4px; }
@keyframes nudge { 50% { transform: translateY(8px); } }
.ios-install.arrow-top .ios-arrow { animation-name: nudge-up; }
@keyframes nudge-up { 50% { transform: translateY(-8px); } }

/* Full-screen pager alert */
.ready-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--ready);
  color: #fff;
  text-align: center;
  animation: flash 1s steps(2, jump-none) infinite;
}
@keyframes flash { 0% { background: var(--ready); } 100% { background: #1f6f30; } }
.ready-inner { max-width: 480px; display: grid; gap: 12px; justify-items: center; }
.ready-inner h1 { font-size: clamp(2rem, 9vw, 3rem); }
.ready-icon {
  width: 120px; height: 120px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 4rem; font-weight: 700;
  background: rgba(255, 255, 255, .18);
  animation: bounce 1s ease-in-out infinite;
}
@keyframes bounce { 50% { transform: scale(1.08); } }
.ready-label { font-size: clamp(3rem, 18vw, 6rem); font-weight: 800; margin: 0; line-height: 1; word-break: break-word; }
.is-ready { overflow: hidden; }
@media (prefers-reduced-motion: reduce) {
  .ready-overlay, .ready-icon, .enable-icon, .ios-arrow, .steps li .step-dot { animation: none !important; }
}

/* --- Staff dashboard ------------------------------------------------------ */
.section-title { margin: 8px 4px 12px; }
.orders { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.order {
  background: var(--surface);
  border: 1px solid var(--line);
  border-inline-start: 6px solid var(--brand);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow);
}
.order[data-status="ready"] { border-inline-start-color: var(--ready); background: var(--ready-bg); }
.order[data-status="collected"] { border-inline-start-color: var(--line); opacity: .7; }
.order-main { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.order-label-sm { font-size: 1.6rem; font-weight: 800; word-break: break-word; }
.pill {
  padding: 4px 12px; border-radius: 999px; font-size: .9rem; font-weight: 700;
  background: var(--warn-bg); color: var(--warn); white-space: nowrap;
}
.pill[data-status="ready"] { background: var(--ready); color: #fff; }
.pill[data-status="collected"] { background: var(--line); color: var(--muted); }
.order-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: .9rem; }
.order-meta .on { color: var(--ready); font-weight: 600; }
.order-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.order-actions .btn-ready { flex: 1 1 140px; font-size: 1.1rem; }

.toast {
  position: fixed;
  inset-inline: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  margin: 0 auto;
  max-width: 480px;
  background: var(--text);
  color: var(--bg);
  padding: 14px 18px;
  border-radius: 12px;
  z-index: 60;
  text-align: center;
}

/* QR modal */
.modal {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, .5);
  display: grid; place-items: center;
  padding: 16px;
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: min(100%, 520px);
  max-height: 100%;
  overflow: auto;
  text-align: center;
  display: grid;
  gap: 12px;
}
.qr-label { font-size: 2.4rem; margin: 0; }
.qr { background: #fff; border-radius: 12px; padding: 8px; aspect-ratio: 1; width: 100%; max-width: 420px; margin: 0 auto; }
.qr svg { width: 100%; height: 100%; display: block; }
.qr-url { font-size: .85rem; color: var(--muted); word-break: break-all; margin: 0; direction: ltr; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.modal-actions .btn { flex: 1 1 120px; }
.modal-open { overflow: hidden; }
.print-only { display: none; }

@media print {
  body.staff > *:not(#qrModal) { display: none !important; }
  .modal { position: static; background: none; padding: 0; }
  .modal-card { box-shadow: none; width: 100%; max-width: none; color: #000; background: #fff; }
  .print-only { display: block; font-size: 1.2rem; color: #000; }
  .no-print { display: none !important; }
  .qr { max-width: 12cm; }
  .qr-label { font-size: 3rem; }
  .qr-url { color: #333; }
}
