/* Musaadiya PPM — practical, high-contrast, works on phones and desktops. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#eef1f4, #0f1419);
  --surface: light-dark(#ffffff, #171e26);
  --surface2: light-dark(#f6f8fa, #1e2731);
  --ink: light-dark(#111b26, #e6ebf0);
  --muted: light-dark(#5b6876, #93a1af);
  --line: light-dark(#d9dfe5, #2b3641);
  --primary: light-dark(#1f4e79, #6aa7dc);
  --primary-ink: light-dark(#ffffff, #0b1520);
  --ok: light-dark(#137a3e, #4cc27f);
  --ok-bg: light-dark(#e2f4e8, #12321f);
  --warn: light-dark(#9a5a00, #f0b357);
  --warn-bg: light-dark(#fdf0d8, #3a2a10);
  --bad: light-dark(#b42318, #ff8a80);
  --bad-bg: light-dark(#fde7e5, #3d1714);
  --radius: 10px;
  --side: 232px;
  --font: "Tajawal", "Segoe UI", Tahoma, Arial, sans-serif;
}
* { box-sizing: border-box; min-width: 0; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); -webkit-text-size-adjust: 100%; overflow-x: clip; }
a { color: var(--primary); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
h1 { font-size: clamp(22px, 2.6vw, 30px); line-height: 1.2; margin: 0; font-weight: 800; }
h2 { font-size: 18px; margin: 0; font-weight: 700; }
small { font-size: 13px; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; letter-spacing: .02em; direction: ltr; unicode-bidi: isolate; overflow-wrap: anywhere; }
[dir=rtl] .mono { text-align: right; }
.boot { display: grid; place-items: center; height: 100vh; font-weight: 800; font-size: 28px; color: var(--primary); }

/* ---------- shell ---------- */
#app { min-height: 100%; }
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; }
.mark { display: inline-grid; place-items: center; height: 32px; padding: 0 8px; border-radius: 6px; background: var(--primary); color: var(--primary-ink); font: 800 14px/1 var(--font); letter-spacing: .04em; }
.top-actions { display: flex; align-items: center; gap: 14px; }
.who { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.link { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 6px 2px; font-weight: 700; }

.side { display: none; }
main { padding: 18px max(16px, env(safe-area-inset-right, 0px)) calc(96px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); max-width: 1240px; margin: 0 auto; outline: none; }
.bottom { position: fixed; inset-inline: 0; bottom: 0; z-index: 20; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); }
.bottom a { display: grid; justify-items: center; gap: 2px; padding: 8px 2px 7px; color: var(--muted); font-size: 12px; font-weight: 500; }
.bottom svg, .side svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bottom a.on { color: var(--primary); font-weight: 700; }
.bottom a.scan-tab svg { background: var(--primary); color: var(--primary-ink); border-radius: 50%; width: 40px; height: 40px; padding: 9px; margin-top: -16px; border: 3px solid var(--surface); box-sizing: content-box; }

@media (min-width: 960px) {
  #app:has(.side) { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .top { grid-column: 1 / -1; }
  .side { display: flex; flex-direction: column; gap: 2px; padding: 16px 12px; border-inline-end: 1px solid var(--line); background: var(--surface); position: sticky; top: 57px; height: calc(100vh - 57px); }
  .side a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--ink); font-weight: 500; }
  .side a:hover { background: var(--surface2); }
  .side a.on { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 700; }
  .bottom { display: none; }
  main { padding: 24px 28px 48px; width: 100%; }
  .scan-cta { display: none; }
}

/* ---------- building blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); align-items: start; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head p { margin: 4px 0 0; }
.back { display: inline-block; font-size: 14px; font-weight: 700; margin-bottom: 4px; }
[dir=rtl] .back::before { content: "→ "; } [dir=ltr] .back::before { content: "← "; }
.sec { margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.count { display: inline-block; font-size: 13px; font-weight: 700; background: var(--surface2); border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; color: var(--muted); }
.note { background: var(--surface2); border-inline-start: 3px solid var(--primary); padding: 8px 12px; border-radius: 6px; margin: 0 0 12px; }
.empty { color: var(--muted); padding: 18px 4px; margin: 0; }
.err { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; font-weight: 500; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 700; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface2); }
.btn:focus-visible, .chip:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 36px; padding: 0 10px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn.on { background: var(--warn-bg); border-color: var(--warn); }
.seg { display: flex; gap: 6px; }
.seg .btn { min-width: 44px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }

.fld { display: grid; gap: 6px; margin-bottom: 12px; }
.fld > span { font-size: 14px; font-weight: 700; color: var(--muted); }
.fld input, .fld select, .search, .pwrow input { width: 100%; min-height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 16px; }
.fld.sm { margin: 0; min-width: 150px; flex: 1; }
.search { max-width: 420px; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.b-done { background: var(--ok-bg); color: var(--ok); }
.b-due { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); }
.b-overdue { background: var(--bad-bg); color: var(--bad); }
.b-notdue { background: var(--surface2); color: var(--muted); }
.warn { color: var(--bad); font-weight: 700; }

.bar { height: 8px; background: var(--surface2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.bar span { display: block; height: 100%; background: var(--ok); }
.bar.big { height: 12px; margin-bottom: 14px; }
.scan-cta { width: 100%; min-height: 54px; font-size: 18px; margin-bottom: 14px; }

.toast { position: fixed; z-index: 50; inset-inline: 16px; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); max-width: 480px; margin: 0 auto;
  padding: 12px 16px; border-radius: 8px; background: var(--ink); color: var(--surface); font-weight: 700; text-align: center;
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .15s, transform .15s; }
.toast.show { opacity: 1; transform: none; }
.toast.bad { background: var(--bad); color: #fff; }
@media (min-width: 960px) { .toast { bottom: 24px; } }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(100%, 420px); }
.auth-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.auth-head > div { flex: 1; }
.auth-head h1 { font-size: 22px; }
.auth-head p { margin: 0; font-size: 14px; }

/* ---------- month ---------- */
.depts { grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); margin-bottom: 14px; }
.dept { display: grid; gap: 10px; color: var(--ink); }
.dept:hover { border-color: var(--primary); }
.dept-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.num { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.num small { font-size: 16px; color: var(--muted); font-weight: 500; }
.dept-foot { display: flex; justify-content: space-between; font-size: 14px; gap: 8px; }

/* ---------- device lists ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.toolbar.card { align-items: end; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; }
.chip.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.dlist { display: grid; }
.dl-head { display: none; }
.dl-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "nm st" "sn st"; gap: 2px 10px; align-items: center;
  padding: 12px 4px; border-bottom: 1px solid var(--line); color: var(--ink); text-align: start; background: none; border-inline: 0; border-top: 0; width: 100%; cursor: pointer; }
.dl-row:last-child { border-bottom: 0; }
.dl-row:hover { background: var(--surface2); }
.dl-row .nm { grid-area: nm; font-weight: 700; display: grid; }
.dl-row .nm small { font-weight: 400; color: var(--muted); }
.dl-row > .mono:not(.d-only) { grid-area: sn; color: var(--muted); font-size: 14px; }
.dl-row > span:last-child { grid-area: st; }
.d-only { display: none; }
.dlist.rep .dl-row { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "ck nm dt"; }
.dlist.rep .dl-row > span:first-child { grid-area: ck; }
.dlist.rep .dl-row > span:nth-child(5) { grid-area: dt; font-size: 14px; }
.dlist.adm .dl-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "nm st" "dp mo"; }
.dlist.adm .dl-row > span:nth-child(5) { grid-area: dp; color: var(--muted); font-size: 14px; }
.dlist.adm .dl-row > span:nth-child(6) { grid-area: mo; font-size: 14px; color: var(--muted); }
.dlist.adm .dl-row > span:last-child { grid-area: st; }
@media (min-width: 760px) {
  .m-only { display: none !important; }
  .d-only { display: block; }
  .dl-head { display: grid; grid-template-columns: 2fr 1.6fr 1.2fr 1.3fr 1fr 110px; gap: 12px; padding: 6px 4px 10px; font-size: 13px; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--line); }
  .dl-row { grid-template-columns: 2fr 1.6fr 1.2fr 1.3fr 1fr 110px; grid-template-areas: none; gap: 12px; }
  .dl-row > * { grid-area: auto !important; }
  .dl-row > .mono:not(.d-only) { color: var(--ink); font-size: 15px; }
  .dlist.rep .dl-row { grid-template-columns: 32px 2fr 1.2fr 1fr 110px 1fr; grid-template-areas: none; }
  .dlist.adm .dl-row { grid-template-columns: 2fr 1.2fr 1.2fr 1.3fr 1fr 1.4fr 90px; grid-template-areas: none; }
  .dlist.adm .dl-row > span { color: var(--ink) !important; font-size: 15px !important; }
}

/* ---------- scan ---------- */
.scan-wrap { display: grid; gap: 12px; }
.viewport { position: relative; background: #000; border-radius: 8px; overflow: hidden; aspect-ratio: 4 / 3; max-height: 62vh; }
.viewport video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.frame { position: absolute; inset: 18% 12%; border: 3px solid rgba(255, 255, 255, .9); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .28); }
.cam-msg { position: absolute; inset: auto 12px 12px; margin: 0; padding: 10px 12px; background: rgba(0, 0, 0, .7); color: #fff; border-radius: 8px; font-weight: 500; }
.hint { color: var(--muted); margin: 10px 0; font-size: 14px; }
.status { min-height: 1.4em; margin: 10px 0 0; font-weight: 700; overflow-wrap: anywhere; }
.cand-list { display: grid; gap: 8px; }
.cand { display: grid; gap: 2px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); }
.cand:hover { border-color: var(--primary); }
.cand .nm { font-weight: 800; }
.cand .mono { font-size: 14px; }
.cand .why { font-size: 13px; color: var(--primary); font-weight: 700; }
@media (min-width: 960px) {
  .scan-wrap { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); align-items: start; }
  .viewport { max-height: 58vh; }
}

/* ---------- device ---------- */
.dev-title { overflow-wrap: anywhere; }
.dev-grid { display: grid; gap: 12px; }
.action { display: grid; gap: 12px; }
.cyc { margin: 0; color: var(--muted); font-weight: 700; }
.done-btn { min-height: 84px; font-size: 26px; font-weight: 800; background: var(--ok); border-color: var(--ok); color: #fff; letter-spacing: .02em; }
.done-btn:hover { filter: brightness(1.08); background: var(--ok); }
.done-box { display: grid; gap: 4px; padding: 16px; border-radius: 8px; background: var(--ok-bg); color: var(--ok); }
.done-box strong { font-size: 20px; }
.info { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 12px 18px; margin: 0; }
.info dt { font-size: 13px; color: var(--muted); font-weight: 700; }
.info dd { margin: 2px 0 0; font-weight: 500; overflow-wrap: anywhere; }
.hist { list-style: none; margin: 0; padding: 0; display: grid; }
.hist li { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); color: var(--ink); }
@media (min-width: 960px) {
  .dev-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); }
  .dev-grid .action { grid-row: span 2; align-self: start; position: sticky; top: 80px; }
}

/* ---------- reports / admin ---------- */
.rep-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.chk { display: inline-flex; gap: 8px; align-items: center; font-weight: 700; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--primary); }
.ulist { display: grid; }
.urow { display: grid; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.urow.off { opacity: .6; }
.urow > div:first-child { display: grid; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.pwrow { display: flex; gap: 8px; }
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(10, 16, 22, .45); display: grid; place-items: end center; padding: 0; }
.sheet-card { width: min(100%, 760px); max-height: 92vh; overflow: auto; border-radius: 14px 14px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (min-width: 760px) { .sheet { place-items: center; padding: 24px; } .sheet-card { border-radius: 14px; } }

@media (min-width: 960px) { .btn.scan-cta { display: none; } }
