/* نداء — نظام التصميم
   الفكرة: جهاز النداء نفسه — قرص بحلقة أضواء.
   ألوان هادئة: رملي = بالانتظار، أخضر مريمي = جاهز، تركوازي هادئ للأزرار.
   الخط: IBM Plex Sans Arabic للعربي، Roboto للإنجليزي والأرقام اللاتينية. */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@300;400;500;600;700&family=Roboto:wght@400;500;700&display=swap');

:root {
  --paper: #f5f6f4;
  --surface: #ffffff;
  --sunken: #eef1ee;
  --ink: #2f3a3d;
  --ink-2: #56636a;
  --muted: #8b969b;
  --line: #e2e6e3;

  --primary: #3e7c76;
  --primary-ink: #ffffff;
  --primary-soft: #e3efed;
  --wait: #c99a4b;
  --wait-ink: #8c6a2e;
  --wait-soft: #f7efe0;
  --go: #5e9c7f;
  --go-ink: #3f7259;
  --go-soft: #e4f0e9;
  --danger: #b5605a;
  --danger-soft: #f5e5e3;

  --brand: var(--primary); /* يتغير حسب لون المنشأة في صفحات العميل */

  /* Roboto أولاً: يأخذ الحروف اللاتينية، والعربي يرجع تلقائيًا لـ IBM Plex Sans Arabic */
  --font: 'Roboto', 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --font-display: var(--font);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 20px;
  --shadow-lift: 0 1px 0 rgb(47 58 61 / 0.03), 0 10px 28px -14px rgb(47 58 61 / 0.18);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #171c1e;
    --surface: #1f2629;
    --sunken: #1a2023;
    --ink: #e4e9e7;
    --ink-2: #b3bdba;
    --muted: #85918f;
    --line: #2e383b;
    --primary: #6eaaa3;
    --primary-ink: #102220;
    --primary-soft: #22383a;
    --wait-ink: #e2bf83;
    --wait-soft: #3a3122;
    --go-ink: #8cc7ab;
    --go-soft: #213a2f;
    --danger-soft: #3d2422;
    --shadow-lift: 0 10px 28px -14px rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --paper: #171c1e;
  --surface: #1f2629;
  --sunken: #1a2023;
  --ink: #e4e9e7;
  --ink-2: #b3bdba;
  --muted: #85918f;
  --line: #2e383b;
  --primary: #6eaaa3;
  --primary-ink: #102220;
  --primary-soft: #22383a;
  --wait-ink: #e2bf83;
  --wait-soft: #3a3122;
  --go-ink: #8cc7ab;
  --go-soft: #213a2f;
  --danger-soft: #3d2422;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; line-height: 1.3; margin: 0; letter-spacing: 0; }
p { margin: 0; }
a { color: inherit; }
img { max-width: 100%; }
.num { font-family: var(--font); font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

/* ---------- العلامة: قرص البيجر ---------- */
.mark { width: 36px; height: 36px; display: block; flex: none; }
.wordmark { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; }

/* ---------- الأزرار ---------- */
.btn {
  --bg: var(--sunken);
  --fg: var(--ink);
  font: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.08s ease, background-color 0.15s, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary { --bg: var(--primary); --fg: var(--primary-ink); }
.btn-dark { --bg: var(--ink); --fg: var(--paper); }
.btn-go { --bg: var(--go); --fg: #fff; }
.btn-wait { --bg: var(--wait); --fg: #fff; }
.btn-ghost { --bg: transparent; border-color: var(--line); }
.btn-ghost:hover { --bg: var(--sunken); }
.btn-danger { --bg: var(--danger-soft); --fg: var(--danger); }
.btn-quiet { --bg: transparent; padding-inline: 10px; color: var(--ink-2); }
.btn-quiet:hover { --bg: var(--sunken); }
.btn-lg { min-height: 56px; font-size: 1.1rem; padding: 14px 24px; border-radius: 16px; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; border-radius: 10px; }

/* ---------- الحقول ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-weight: 500; font-size: 0.92rem; color: var(--ink-2); }
.field small { color: var(--muted); font-size: 0.82rem; }
input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  padding: 11px 14px;
  min-height: 46px;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[dir='ltr'] { text-align: left; }

/* ---------- حالات الطلب ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.waiting { background: var(--wait-soft); color: var(--wait-ink); }
.status.ready { background: var(--go-soft); color: var(--go-ink); }
.status.done { background: var(--sunken); color: var(--muted); }

/* ---------- عام ---------- */
.toast {
  position: fixed;
  inset-inline: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: 420px;
  margin: 0 auto;
  background: var(--ink);
  color: var(--paper);
  padding: 12px 18px;
  border-radius: var(--r-md);
  text-align: center;
  font-weight: 500;
  opacity: 0;
  transform: translateY(12px);
  transition: 0.22s ease;
  pointer-events: none;
  z-index: 1000;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #d32f2f; color: #fff; font-weight: 700; }

/* حقل الرقم عند إدخال رقم مكرر */
input.dup { outline: 2px solid #d32f2f; outline-offset: 2px; animation: dup-shake 0.35s; }
@keyframes dup-shake {
  0%, 100% { transform: none; }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
@media (prefers-reduced-motion: reduce) { input.dup { animation: none; } }

dialog {
  border: 0;
  padding: 0;
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  box-shadow: 0 30px 80px -20px rgb(0 0 0 / 0.45);
}
dialog::backdrop { background: rgb(23 28 30 / 0.55); backdrop-filter: blur(2px); }

.qr-frame { background: #fff; padding: 14px; border-radius: 18px; display: block; }
.qr-frame img { display: block; width: 100%; height: auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* =========================================================
   مكوّنات لوحات التحكم (الموظف + المدير)
   ========================================================= */
.i { width: 20px; height: 20px; flex: none; display: inline-block; vertical-align: middle; }
.i-sm { width: 16px; height: 16px; }
.i-lg { width: 24px; height: 24px; }

.icon-btn {
  width: 40px; height: 40px; flex: none; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); display: inline-grid; place-items: center; cursor: pointer;
  transition: background-color .15s, color .15s, transform .08s;
}
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
.icon-btn:active { transform: scale(.95); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

.avatar {
  --c: var(--primary);
  width: 38px; height: 38px; border-radius: 12px; flex: none; display: grid; place-items: center;
  background: color-mix(in srgb, var(--c) 14%, var(--surface)); color: var(--c);
  font-weight: 600; font-size: .95rem; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; min-height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: background-color .2s; }
.switch span::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .2); transition: inset-inline-start .2s; }
.switch input:checked + span { background: var(--go); }
.switch input:checked + span::after { inset-inline-start: 21px; }
.switch input:focus-visible + span { outline: 3px solid var(--primary); outline-offset: 2px; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 99px; white-space: nowrap; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.trial, .pill.waiting { background: var(--wait-soft); color: var(--wait-ink); }
.pill.active, .pill.ready, .pill.on { background: var(--go-soft); color: var(--go-ink); }
.pill.expired, .pill.suspended { background: var(--danger-soft); color: var(--danger); }
.pill.off, .pill.done { background: var(--sunken); color: var(--muted); }
.pill.plain::before { display: none; }

/* تلميح الرسوم البيانية */
.chart-tip {
  position: fixed; z-index: 2000; pointer-events: none; background: var(--ink); color: var(--paper);
  padding: 6px 10px; border-radius: 8px; font-size: .82rem; line-height: 1.4; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px)); opacity: 0; transition: opacity .1s;
}
.chart-tip.show { opacity: 1; }
.chart-tip b { font-family: Roboto, var(--font); font-size: .95rem; }

/* رسم الأعمدة (SVG) */
.colchart { width: 100%; height: auto; display: block; overflow: visible; }
.colchart .grid { stroke: var(--line); stroke-width: 1; }
.colchart .base { stroke: color-mix(in srgb, var(--muted) 55%, var(--line)); stroke-width: 1; }
.colchart .tick { fill: var(--muted); font-size: 11px; font-family: Roboto, var(--font); }
.colchart .bar { fill: var(--primary); }
.colchart .bar.dim { fill: color-mix(in srgb, var(--primary) 30%, var(--surface)); }
.colchart .hit { fill: transparent; cursor: default; }
.colchart .hit:hover + .bar, .colchart g:hover .bar { fill: color-mix(in srgb, var(--primary) 80%, var(--ink)); }
.colchart .val { fill: var(--ink-2); font-size: 11px; font-weight: 600; font-family: Roboto, var(--font); }

/* درج جانبي */
dialog.drawer {
  margin: 0; margin-inline-start: auto; height: 100dvh; max-height: 100dvh; width: min(560px, 100vw);
  border-radius: 0; border-start-start-radius: 22px; border-end-start-radius: 22px;
}
dialog.drawer[open] { animation: drawer-in .22s cubic-bezier(.2, .8, .3, 1); }
@keyframes drawer-in { from { transform: translateX(-24px); opacity: 0; } }
