:root {
  --bg: #f3f5fa; --card: #fff; --ink: #0f1a33; --ink2: #4a5672; --mute: #8a94ab; --line: #e3e8f2;
  --pri: #0b2a6f; --pri2: #1746b8; --ok: #0f9d63; --okbg: #e6f6ee; --nc: #d43a3a; --ncbg: #fdecec;
  --wait: #b7791f; --waitbg: #fdf4e3; --r: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent }
html { background: var(--bg) }
body { margin: 0; font-family: Almarai, system-ui, sans-serif; color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.6; -webkit-text-size-adjust: 100% }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none }
button, input, select, textarea { font: inherit; color: inherit }
a { color: inherit; text-decoration: none }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate }
[hidden] { display: none !important }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--pri); color: #fff }
.top .ttl { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3 }
.top .ttl b { font-size: 17px; font-weight: 800 }
.top .ttl small { opacity: .7; font-size: 12px }
.ib { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 0; background: rgba(255,255,255,.12); color: inherit; cursor: pointer }
.ib.sm { width: 34px; height: 34px; background: var(--bg); color: var(--ink2) }
.logo { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: rgba(255,255,255,.14); color: #3ddc97 }
.logo svg { stroke-width: 3 }
.logo.lg { width: 64px; height: 64px; border-radius: 18px; background: var(--pri) }
.logo.lg svg { width: 32px; height: 32px }

.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(40px + env(safe-area-inset-bottom)) }
.wrap.wide { max-width: 980px }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r) }
.pad { padding: 16px }
.sec { font-size: 15px; margin: 24px 2px 10px; color: var(--ink2) }
.empty { text-align: center; color: var(--mute); padding: 28px 0 }
.hint { text-align: center; color: var(--mute); font-size: 13px; margin: 10px 0 0 }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 700; cursor: pointer }
.btn.pri { background: var(--pri); border-color: var(--pri); color: #fff }
.btn.pri:active { background: var(--pri2) }
.btn.ghost { background: var(--card); color: var(--pri) }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: 13.5px }
.btn.wide { width: 100% }
.btn.big { min-height: 56px; font-size: 17px }
.btn:disabled { opacity: .6 }

.lbl { display: block; font-size: 13px; color: var(--ink2); margin: 0 0 6px; font-weight: 700 }
.in { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; outline: none }
.in:focus { border-color: var(--pri2); box-shadow: 0 0 0 3px rgba(23,70,184,.12) }
.in.sm { min-height: 40px; padding: 7px 10px; font-size: 14px }
.in.ro { display: flex; align-items: center; background: var(--bg); color: var(--ink2) }
textarea.in { resize: vertical; min-height: 64px; line-height: 1.6 }
textarea.need { border-color: var(--nc); background: #fffafa }
input[type=date].in { direction: ltr; text-align: right }

/* الدخول */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; max-width: 400px; margin: 0 auto; padding: 24px 16px }
.brand { text-align: center; margin-bottom: 20px }
.brand .logo { margin: 0 auto 12px }
.brand h1 { margin: 0; font-size: 24px; font-weight: 800 }
.brand p { margin: 2px 0 0; color: var(--mute) }
.login form .in { margin-bottom: 14px }
.login .btn { margin-top: 4px }
.err { color: var(--nc); text-align: center; margin: 12px 0 0; font-size: 14px }

/* الرئيسية */
.hello { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 2px 16px }
.hello small { display: block; color: var(--mute); font-size: 13px }
.hello b { font-size: 20px; font-weight: 800 }
.list { display: flex; flex-direction: column; gap: 10px }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r) }
.row__main { min-width: 0; display: flex; flex-direction: column }
.row__main b { font-weight: 800 }
.row__main small { color: var(--mute); font-size: 13px }
.row__side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none }
.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--bg); color: var(--ink2) }
.pill.ok { background: var(--okbg); color: var(--ok) }
.pill.nc { background: var(--ncbg); color: var(--nc) }
.pill.wait { background: var(--waitbg); color: var(--wait) }
.pill.sent { background: #e9eefb; color: var(--pri) }
.pill.draft { background: var(--bg); color: var(--ink2) }

/* الجولة */
.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 14px }
.meta .full { grid-column: 1 / -1 }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px }
.seg.seg4 { grid-template-columns: repeat(4, 1fr) }
.seg button { min-height: 44px; border: 1px solid var(--line); background: #fff; border-radius: 10px; font-weight: 700; cursor: pointer }
.seg button.on { background: var(--pri); border-color: var(--pri); color: #fff }
.prog { display: flex; align-items: center; gap: 12px; margin: 16px 2px 12px; font-size: 13px; color: var(--ink2); position: sticky; top: calc(60px + env(safe-area-inset-top)); z-index: 10; background: var(--bg); padding: 8px 0 }
.prog span { flex: none; font-weight: 700 }
.prog i { flex: 1; height: 6px; background: var(--line); border-radius: 9px; overflow: hidden }
.prog b { display: block; height: 100%; width: 0; background: var(--ok); transition: width .3s }

.item { padding: 16px; margin-bottom: 12px; border-inline-start: 4px solid var(--line) }
.item.is-ok { border-inline-start-color: var(--ok) }
.item.is-nc { border-inline-start-color: var(--nc) }
.item__head { display: flex; gap: 12px; align-items: flex-start }
.item__head > div { flex: 1; min-width: 0 }
.item__head b { font-size: 16px; font-weight: 800 }
.item__head p { margin: 2px 0 0; color: var(--ink2); font-size: 13.5px }
.no { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--bg); font-weight: 800; font-size: 14px; flex: none; color: var(--ink2) }
.st { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0 10px }
.st button { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 50px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; font-weight: 800; cursor: pointer; color: var(--ink2) }
.st button.ok.on { background: var(--ok); border-color: var(--ok); color: #fff }
.st button.nc.on { background: var(--nc); border-color: var(--nc); color: #fff }
.loc { display: flex; align-items: center; gap: 8px; color: var(--mute); margin-bottom: 8px }
.loc.ro { color: var(--ink2); font-size: 14px }
.note { display: flex; gap: 6px; align-items: flex-start; margin-bottom: 8px }
.warn { color: var(--nc); font-size: 13px; margin: -2px 2px 8px; font-weight: 700 }
.acts { display: flex; flex-wrap: wrap; gap: 8px }
.phs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin: 4px 0 10px }
.ph { position: relative; display: block; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--bg) }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block }
.phx { position: absolute; top: 4px; inset-inline-end: 4px; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; border: 0; background: rgba(15,26,51,.7); color: #fff; cursor: pointer }
.phx svg { width: 15px; height: 15px }
.item.ro .item__head .pill { margin-top: 2px }
.nt { margin: 6px 0; padding: 10px 12px; background: var(--bg); border-radius: 10px; white-space: pre-wrap }
.item.is-nc .nt { background: var(--ncbg) }

.sum { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 12px }
.sum small { display: block; color: var(--mute); font-size: 12px }
.sum b { font-weight: 800 }
.red { color: var(--nc) }
.banner { padding: 12px 14px; border-radius: 12px; margin: 0 0 12px; font-weight: 700 }
.banner.wait { background: var(--waitbg); color: var(--wait) }

/* المشرف */
.filters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; align-items: end }
.filters .dt small { display: block; font-size: 12px; color: var(--mute) }
.chk { display: flex; align-items: center; gap: 8px; min-height: 40px; font-size: 14px }
.chk input { width: 18px; height: 18px; accent-color: var(--pri) }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0 }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px }
.stat small { display: block; color: var(--mute); font-size: 12px }
.stat b { font-size: 24px; font-weight: 800 }
.stat.wide { grid-column: 1 / -1 }
.bars { display: flex; flex-direction: column; gap: 8px; margin-top: 8px }
.bar { display: grid; grid-template-columns: 110px 1fr 28px; gap: 10px; align-items: center; font-size: 13.5px }
.bar i { height: 8px; background: var(--bg); border-radius: 9px; overflow: hidden }
.bar i b { display: block; height: 100%; background: var(--nc); border-radius: 9px }
.bar em { font-style: normal; font-weight: 800; text-align: left }

.net { position: sticky; top: 0; z-index: 30; padding: 8px 16px; text-align: center; font-size: 13px; font-weight: 700 }
.net.off { background: #2b2f3a; color: #fff }
.net.wait { background: var(--waitbg); color: var(--wait) }
.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 50; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px; background: var(--ink); color: #fff; font-weight: 700; font-size: 14px; text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,.2) }
.toast.bad { background: var(--nc) }
.spin { width: 28px; height: 28px; margin: 30px auto; border: 3px solid var(--line); border-top-color: var(--pri); border-radius: 50%; animation: sp 1s linear infinite }
@keyframes sp { to { transform: rotate(360deg) } }

@media (max-width: 560px) {
  .filters { grid-template-columns: 1fr 1fr }
  .filters .chk { grid-column: 1 / -1 }
  .stats { grid-template-columns: repeat(3, 1fr) }
  .stat b { font-size: 20px }
  .bar { grid-template-columns: 90px 1fr 24px }
}

/* تقرير PDF */
.top .ib + .ib { margin-inline-start: -4px }
#print { display: none }
@media print {
  @page { size: A4; margin: 12mm 10mm }
  html, body { background: #fff !important }
  body.printing > *:not(#print) { display: none !important }
  body.printing #print { display: block }
  #print { color: #0f1a33; font-size: 10.5pt; line-height: 1.5; -webkit-print-color-adjust: exact; print-color-adjust: exact }
  .rep { break-after: page }
  .rep:last-child { break-after: auto }
  .rh { display: flex; justify-content: space-between; align-items: center; border-bottom: 3px solid #0b2a6f; padding-bottom: 8px; margin-bottom: 10px }
  .rh h1 { margin: 0; font-size: 17pt; color: #0b2a6f }
  .rh p { margin: 0; color: #4a5672 }
  .rref { font-size: 14pt; font-weight: 800; color: #0b2a6f; direction: ltr }
  .rm { width: 100%; border-collapse: separate; border-spacing: 6px 0; margin: 0 -6px 12px }
  .rm td { background: #f3f5fa; border-radius: 6px; padding: 6px 10px; width: 25% }
  .rm small { display: block; color: #8a94ab; font-size: 8.5pt }
  .rm b { font-size: 10pt }
  .rt { width: 100%; border-collapse: collapse }
  .rt th { background: #0b2a6f; color: #fff; font-size: 9.5pt; padding: 6px; text-align: right }
  .rt td { border-bottom: 1px solid #e3e8f2; padding: 7px 6px; vertical-align: top }
  .rt tr { break-inside: avoid }
  .rt td.c { text-align: center; white-space: nowrap }
  .rt th:nth-child(1) { width: 26px } .rt th:nth-child(3) { width: 70px } .rt th:nth-child(4) { width: 90px } .rt th:nth-child(5) { width: 34% }
  .rt tr.nc > td { background: #fff6f6 }
  .crit { color: #4a5672; font-size: 8.5pt; margin-top: 2px }
  .st { display: inline-block; padding: 2px 8px; border-radius: 99px; font-weight: 800; font-size: 9pt }
  .st.ok { background: #e6f6ee; color: #0f9d63 }
  .st.nc { background: #fdecec; color: #d43a3a }
  .pn { margin-bottom: 3px }
  .pn + .pn { border-top: 1px dashed #e3e8f2; padding-top: 3px }
  .phr td { border-bottom: 1px solid #e3e8f2; padding-top: 0 }
  .pg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px }
  .pg img { width: 100%; height: 52mm; object-fit: cover; border-radius: 4px; break-inside: avoid }
  .rf { margin-top: 10px; color: #8a94ab; font-size: 8pt; text-align: left }
  .red { color: #d43a3a }
}
