/* RTL, mobile-first. Big touch targets (gloves!), high contrast, light + dark. */
:root {
  --bg: #f1f4f9;
  --card: #ffffff;
  --text: #111827;
  --muted: #5b6475;
  --line: #dfe4ec;
  --brand: #1e3a8a;
  --brand-ink: #ffffff;
  --accent: #2563eb;

  --ok: #15803d;      --ok-bg: #dcfce7;   --ok-ink: #14532d;
  --bad: #dc2626;     --bad-bg: #fee2e2;  --bad-ink: #7f1d1d;
  --warn: #b45309;    --warn-bg: #fef3c7; --warn-ink: #78350f;
  --na: #475569;      --na-bg: #e5e7eb;   --na-ink: #1f2937;
  --info: #1d4ed8;    --info-bg: #dbeafe; --info-ink: #1e3a8a;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 6px 18px rgba(15, 23, 42, .06);
  --appbar-h: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", "Geeza Pro", "Droid Arabic Kufi", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #141d30;
    --text: #e8edf6;
    --muted: #a0abbd;
    --line: #26324b;
    --brand: #2b4bb8;
    --accent: #6b9bff;
    --ok: #22c55e;   --ok-bg: #12351f;   --ok-ink: #bbf7d0;
    --bad: #f87171;  --bad-bg: #3b1518;  --bad-ink: #fecaca;
    --warn: #f59e0b; --warn-bg: #3a2a0b; --warn-ink: #fde68a;
    --na: #94a3b8;   --na-bg: #263247;   --na-ink: #e2e8f0;
    --info: #60a5fa; --info-bg: #14264d; --info-ink: #bfdbfe;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.3; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6em; }
a { color: var(--accent); }
bdi { unicode-bidi: isolate; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.err-text, .bad-text { color: var(--bad); }
.danger-text { color: var(--bad); }
.stack { display: grid; gap: 12px; }
.stack-sm { display: grid; gap: 8px; }

/* ---------------------------------------------------------------- layout */
.view { max-width: 720px; margin: 0 auto; padding: 0 12px calc(100px + env(safe-area-inset-bottom)); }
.view.narrow { padding-top: 12vh; }
.content { display: grid; gap: 12px; padding-top: 12px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.section-title { margin: 18px 4px 8px; color: var(--muted); font-size: .95rem; }

.appbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--appbar-h);
  margin: 0 -12px;
  padding: 0 10px;
  display: flex; align-items: center; gap: 8px;
  background: var(--brand); color: var(--brand-ink);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}
.appbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.appbar-title strong { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-title small { opacity: .8; font-size: .75rem; }
.appbar-actions { display: flex; gap: 4px; }
.appbar .logo { font-size: 1.5rem; padding-inline: 6px; }
.icon-btn {
  width: 48px; height: 48px; display: inline-grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent; color: inherit;
  font-size: 1.4rem; cursor: pointer;
}
.icon-btn:hover, .icon-btn:active { background: rgba(255, 255, 255, .15); }
.icon-btn.on-dark { color: #fff; }
.icon-btn.active { background: rgba(255, 255, 255, .28); }
.view > :not(.appbar):not(.content) { margin-top: 12px; }

/* ---------------------------------------------------------------- buttons / inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  border: 2px solid transparent; border-radius: 12px;
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  background: var(--card); color: var(--text);
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-small { min-height: 40px; padding: 6px 12px; font-size: .9rem; }
.btn-lg { min-height: 56px; font-size: 1.05rem; }
.btn-xl { min-height: 72px; font-size: 1.2rem; }
.btn-block { width: 100%; }
.grow { flex: 1; }
.on-dark.btn-ghost { color: #fff; border-color: rgba(255, 255, 255, .35); }

.input {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 2px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text); font: inherit;
}
textarea.input { min-height: 72px; resize: vertical; }
.input.invalid { border-color: var(--bad); background: var(--bad-bg); }
.field-label { display: block; margin: 4px 0 2px; font-weight: 700; font-size: .92rem; }
.row-form { display: flex; gap: 8px; align-items: center; }
.row-form .input { flex: 1; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }
.check.disabled { opacity: .55; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; white-space: nowrap;
  background: var(--na-bg); color: var(--na-ink);
}
.chip-ok { background: var(--ok-bg); color: var(--ok-ink); }
.chip-bad { background: var(--bad-bg); color: var(--bad-ink); }
.chip-warn { background: var(--warn-bg); color: var(--warn-ink); }
.chip-info { background: var(--info-bg); color: var(--info-ink); }
.chip-muted { background: var(--na-bg); color: var(--na-ink); }
.chip.as-btn { border: 0; cursor: pointer; min-height: 32px; font: inherit; font-weight: 700; font-size: .85rem; }

.notice { padding: 12px 14px; border-radius: var(--radius); border: 1px solid transparent; }
.notice ul { margin: 6px 0 0; padding-inline-start: 20px; }
.notice-ok { background: var(--ok-bg); color: var(--ok-ink); border-color: var(--ok); }
.notice-bad { background: var(--bad-bg); color: var(--bad-ink); border-color: var(--bad); }
.notice-warn { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn); }
.notice-info { background: var(--info-bg); color: var(--info-ink); border-color: var(--info); }
.prev-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }

.counts { display: flex; flex-wrap: wrap; gap: 6px; }
.count {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
  background: var(--na-bg); color: var(--na-ink); font-size: .85rem;
}
.count-ok { background: var(--ok-bg); color: var(--ok-ink); }
.count-bad { background: var(--bad-bg); color: var(--bad-ink); }
.count-warn { background: var(--warn-bg); color: var(--warn-ink); }
.count-info { background: var(--info-bg); color: var(--info-ink); }
.counts.big .count { font-size: 1.05rem; padding: 6px 14px; }
.count.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .55); } 50% { box-shadow: 0 0 0 7px rgba(220, 38, 38, 0); } }

/* ---------------------------------------------------------------- home */
.hero { display: flex; align-items: center; gap: 14px; padding: 22px 4px 8px; }
.hero h1 { margin: 0; }
.hero p { margin: 0; font-size: .8rem; direction: ltr; text-align: right; }
.hero-logo { font-size: 2.6rem; }
a.apparatus { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; min-height: 72px; }
.apparatus-ico { font-size: 2rem; }
.apparatus-main { flex: 1; display: grid; gap: 2px; }
.apparatus-main strong { font-size: 1.15rem; }
.draft-line { color: var(--warn); font-weight: 700; }
.go { font-size: 1.8rem; color: var(--muted); }
.links { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.outbox h2 { margin-bottom: 8px; }
.outbox-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.outbox-row small { grid-column: 1; }
.outbox-row button { grid-row: 1 / span 2; grid-column: 2; }
.login-card { display: grid; gap: 12px; text-align: center; }
.login-logo { font-size: 3rem; }

/* ---------------------------------------------------------------- shift banner */
.shift-banner {
  display: flex; align-items: center; gap: 14px; padding: 16px;
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.shift-morning { background: linear-gradient(135deg, #fde68a, #fb923c); color: #3b1d03; }
.shift-night { background: linear-gradient(135deg, #1e1b4b, #3730a3); color: #fff; }
.shift-icon { font-size: 2.8rem; line-height: 1; }
.shift-main { flex: 1; min-width: 0; }
.shift-name { font-size: 1.45rem; font-weight: 800; line-height: 1.2; }
.shift-en { font-size: .85rem; opacity: .85; }
.shift-day { margin-top: 4px; font-size: 1.15rem; font-weight: 700; }
.shift-week { font-size: .85rem; opacity: .85; }
.shift-side { display: grid; gap: 8px; justify-items: end; }
.shift-banner .btn-small { background: rgba(255, 255, 255, .92); color: #111827; }
.shift-edit { display: grid; gap: 8px; }
.seg { display: flex; gap: 6px; }
.seg-btn, .day {
  flex: 1; min-height: 48px; padding: 6px 8px; border: 2px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text); font: inherit; font-weight: 700; cursor: pointer;
}
.seg-btn.on, .day.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.days { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.days .day { font-size: .9rem; padding-inline: 2px; }

/* ---------------------------------------------------------------- inspection page */
.setup > summary, .comp > summary {
  list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 52px; cursor: pointer;
}
.setup > summary { flex-wrap: wrap; }
summary::-webkit-details-marker { display: none; }
.setup[open] > summary { margin-bottom: 10px; }

.progress {
  position: sticky; top: var(--appbar-h); z-index: 20;
  margin: 0 -12px; padding: 8px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.meter { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--ok); transition: width .25s; }
.progress.has-missing .meter-fill { background: linear-gradient(90deg, var(--ok), var(--bad)); }
.prog-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.prog-text { font-weight: 800; }

.comp { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.comp > summary { padding: 6px 14px; background: color-mix(in srgb, var(--brand) 12%, var(--card)); }
.comp-names { display: grid; }
.comp-names small { direction: ltr; text-align: right; }
.comp-badge { padding: 3px 12px; border-radius: 99px; background: var(--na-bg); color: var(--na-ink); font-weight: 800; font-size: .85rem; white-space: nowrap; }
.comp-badge.done { background: var(--ok-bg); color: var(--ok-ink); }
.issue-dot { color: var(--bad); }
.comp-body { display: grid; gap: 10px; padding: 10px; }

.item {
  display: grid; gap: 8px; padding: 10px;
  border: 1px solid var(--line); border-inline-start: 6px solid var(--line);
  border-radius: 12px; background: var(--card);
}
.item.s-present { border-inline-start-color: var(--ok); }
.item.s-corrected { border-inline-start-color: var(--info); }
.item.s-missing { border-inline-start-color: var(--bad); background: var(--bad-bg); }
.item.s-repair { border-inline-start-color: var(--warn); background: var(--warn-bg); }
.item.s-na { border-inline-start-color: var(--na); opacity: .9; }
.item.flash { animation: flash 1.2s ease 1; }
@keyframes flash { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 30% { box-shadow: 0 0 0 5px var(--accent); } }
.item-head { display: flex; align-items: flex-start; gap: 10px; }
.item-no {
  min-width: 36px; height: 36px; padding: 0 6px; display: inline-grid; place-items: center;
  border-radius: 10px; background: var(--brand); color: #fff; font-weight: 800; font-size: .9rem;
}
.item-names { flex: 1; min-width: 0; }
.item-en { direction: ltr; text-align: right; unicode-bidi: isolate; font-weight: 700; word-break: break-word; }
.item-ar { color: var(--muted); font-size: .88rem; }
.qty-tag { padding: 2px 10px; border-radius: 99px; background: var(--info-bg); color: var(--info-ink); font-weight: 800; white-space: nowrap; direction: ltr; }
.prev-issue { padding: 6px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-ink); font-size: .88rem; font-weight: 700; }

.statuses { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.statuses.one { grid-template-columns: 1fr; }
.st {
  min-height: 60px; padding: 6px 2px; display: grid; place-items: center; align-content: center; gap: 2px;
  border: 2px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text);
  font: inherit; cursor: pointer; line-height: 1.2;
}
.statuses.one .st { grid-auto-flow: column; min-height: 48px; gap: 8px; }
.st-ico { font-size: 1.35rem; }
.st-txt { font-size: .78rem; font-weight: 700; text-align: center; }
.st:active { transform: scale(.97); }
.st.on { color: #fff; border-color: transparent; }
.st.on.st-present { background: var(--ok); }
.st.on.st-missing { background: var(--bad); }
.st.on.st-repair { background: var(--warn); }
.st.on.st-na { background: var(--na); }
.st.on.st-corrected { background: var(--info); }
@media (prefers-color-scheme: dark) { .st.on { color: #0b1220; } }

.qty-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 700; }
.step { width: 48px; height: 48px; border: 2px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); font-size: 1.5rem; font-weight: 800; cursor: pointer; }
.step:disabled { opacity: .4; }
.qty-val { min-width: 76px; text-align: center; font-size: 1.15rem; font-weight: 800; }
.alert-banner {
  padding: 8px 12px; border-radius: 10px; background: var(--bad); color: #fff; font-weight: 800;
  animation: pulse 1.6s ease-in-out infinite;
}
@media (prefers-color-scheme: dark) { .alert-banner { color: #1f0507; } }
.note label { display: block; margin-bottom: 4px; font-size: .88rem; font-weight: 700; }

.actionbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 40;
  display: flex; gap: 8px; align-items: stretch;
  max-width: 720px; margin-inline: auto; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(0, 0, 0, .12);
}

/* ---------------------------------------------------------------- dialogs / toasts */
dialog.dlg {
  width: calc(100% - 24px); max-width: 520px; max-height: calc(100dvh - 24px);
  padding: 0; border: 0; border-radius: 18px; background: var(--card); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35); overflow: auto;
}
dialog.dlg::backdrop { background: rgba(2, 6, 23, .6); }
dialog.sheet { width: 100%; max-width: 640px; margin: auto auto 0; border-radius: 22px 22px 0 0; max-height: 92dvh; }
.dlg-body { padding: 18px; display: grid; gap: 12px; }
.dlg-title { margin: 0; }
.dlg-text { margin: 0; white-space: pre-line; }
.dlg-actions { display: grid; gap: 8px; }
.sheet-grip { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: -6px auto 0; }
.review ul { margin: 4px 0 0; padding-inline-start: 20px; }

#toasts { position: fixed; z-index: 100; inset-inline: 12px; top: calc(var(--appbar-h) + 8px); display: grid; gap: 8px; pointer-events: none; max-width: 520px; margin-inline: auto; }
.toast {
  padding: 12px 16px; border-radius: 12px; font-weight: 700; box-shadow: var(--shadow);
  background: var(--brand); color: #fff; animation: slide-in .2s ease-out;
}
.toast-ok { background: var(--ok); }
.toast-err { background: var(--bad); }
.toast-warn { background: var(--warn); }
@media (prefers-color-scheme: dark) { .toast-ok, .toast-err, .toast-warn { color: #0b1220; } }
.toast.out { opacity: 0; transform: translateY(-8px); transition: .25s; }
@keyframes slide-in { from { opacity: 0; transform: translateY(-10px); } }

.center-msg { display: grid; place-items: center; gap: 12px; padding: 60px 12px; text-align: center; }
.spin { width: 38px; height: 38px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--brand); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- report + history */
.ready-banner { padding: 14px; border-radius: var(--radius); font-size: 1.2rem; font-weight: 800; text-align: center; }
.ready-banner.ok { background: var(--ok-bg); color: var(--ok-ink); border: 2px solid var(--ok); }
.ready-banner.bad { background: var(--bad-bg); color: var(--bad-ink); border: 2px solid var(--bad); }
.fact { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.fact-k { color: var(--muted); }
.fact-v { font-weight: 700; text-align: end; }
.card > .counts { margin-top: 10px; }
.alert-row { padding: 10px; border-radius: 10px; border-inline-start: 5px solid var(--bad); background: var(--bad-bg); display: grid; gap: 2px; }
.alert-row.alert-repair { border-inline-start-color: var(--warn); background: var(--warn-bg); }
.alert-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.alert-note { margin: 4px 0 0; font-weight: 700; white-space: pre-line; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions .btn { flex: 1; }
.resend { display: grid; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
a.history-row { display: grid; gap: 4px; color: inherit; text-decoration: none; }
a.history-row.has-alert { border-inline-start: 6px solid var(--bad); }
.history-top { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.history-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- scanner overlay */
.scan-overlay {
  position: fixed; inset: 0; z-index: 90; display: flex; flex-direction: column; gap: 10px;
  padding: env(safe-area-inset-top) 12px calc(12px + env(safe-area-inset-bottom));
  background: #05070d; color: #fff;
}
.scan-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 56px; }
.scan-top strong { flex: 1; text-align: center; }
.scan-viewport { position: relative; flex: 1; min-height: 220px; border-radius: 16px; overflow: hidden; background: #000; }
.scan-region { position: absolute; inset: 0; }
.scan-region video { width: 100% !important; height: 100% !important; object-fit: cover; }
.scan-msg { margin: 0; min-height: 3em; text-align: center; color: #cbd5e1; }
.scan-msg.scan-err { color: #fca5a5; font-weight: 700; }
.scan-msg.scan-warn { color: #fde68a; }
.scan-manual { display: flex; gap: 8px; }
.scan-manual .input { background: #111827; color: #fff; border-color: #374151; }
.scan-file { cursor: pointer; }

@media (min-width: 720px) {
  .view { padding-inline: 20px; }
  .appbar { margin-inline: -20px; padding-inline: 20px; border-radius: 0 0 14px 14px; }
  .progress { margin-inline: -20px; padding-inline: 20px; }
  .st { min-height: 64px; }
  .st-txt { font-size: .85rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
