:root {
  --brand: #0f5c4d;
  --brand-2: #e8f2ef;
  --ink: #1d2523;
  --muted: #5f6b68;
  --line: #d9e0de;
  --bg: #f5f7f6;
  --card: #ffffff;
  --ok: #1d7a46;
  --ok-bg: #e3f4ea;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --err: #a32020;
  --radius: 14px;
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Geeza Pro", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; line-height: 1.6; }
main { max-width: 760px; margin: 0 auto; padding: 0 16px 48px; }

.top { background: var(--brand); color: #fff; padding: 28px 16px 56px; text-align: center; }
.top h1 { margin: 0 0 4px; font-size: 1.6rem; }
.top p { margin: 0; opacity: .9; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-top: 16px; }
#scan { margin-top: -36px; box-shadow: 0 6px 24px rgba(0,0,0,.06); }
h2 { font-size: 1.15rem; margin: 0 0 16px; display: flex; align-items: center; gap: 8px; }
.num { background: var(--brand); color: #fff; width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; font-size: .95rem; }

.shots { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.shot { border: 2px dashed var(--line); background: var(--bg); border-radius: var(--radius); padding: 14px 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; font: inherit; color: inherit; }
.shot:hover { border-color: var(--brand); }
.shot .thumb { width: 100%; max-width: 170px; aspect-ratio: 86/54; display: grid; place-items: center; border-radius: 8px; overflow: hidden; }
.shot svg { width: 80%; fill: none; stroke: var(--muted); stroke-width: 2; }
.shot img { width: 100%; height: 100%; object-fit: cover; }
.shot .label { font-weight: 700; }
.shot .state { font-size: .85rem; color: var(--muted); }
.shot.done { border-style: solid; border-color: var(--ok); background: var(--ok-bg); }
.shot.done .state { color: var(--ok); }

.tips { color: var(--muted); font-size: .9rem; padding-inline-start: 20px; margin: 14px 0; }
.consent { display: flex; gap: 10px; align-items: flex-start; font-size: .9rem; margin: 8px 0 14px; }
.consent input { margin-top: 5px; width: 18px; height: 18px; accent-color: var(--brand); }

button.primary { width: 100%; background: var(--brand); color: #fff; border: 0; border-radius: 12px; padding: 14px; font: inherit; font-weight: 700; font-size: 1.05rem; cursor: pointer; }
button.primary:disabled { opacity: .45; cursor: not-allowed; }

.status { margin-top: 12px; font-size: .95rem; min-height: 1.5em; }
.status.loading::before { content: ""; display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; margin-inline-end: 8px; vertical-align: -3px; }
.status.error { color: var(--err); }
.status.success { color: var(--ok); }
@keyframes spin { to { transform: rotate(360deg); } }

fieldset { border: 0; padding: 0; margin: 0 0 18px; }
legend { font-weight: 700; margin-bottom: 10px; color: var(--brand); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); position: relative; }
.grid .wide { grid-column: 1 / -1; }
input, select, textarea { font: inherit; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
input[dir="ltr"] { text-align: left; }

.filled-ok input, .filled-ok select { border-color: var(--ok); background: var(--ok-bg); }
.filled-warn input, .filled-warn select { border-color: #e0a800; background: var(--warn-bg); }
label .badge { position: absolute; top: 0; inset-inline-end: 0; }
.badge { font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 99px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.legend { font-size: .85rem; color: var(--muted); margin: -6px 0 12px; }
.alert { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: .9rem; }
.invalid { border-color: var(--err) !important; }

/* الكاميرا */
dialog#camera { padding: 0; border: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none; background: #000; }
.cam { position: relative; width: 100%; height: 100%; }
.cam video { width: 100%; height: 100%; object-fit: cover; }
.frame { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.cardbox { width: min(88vw, 74dvh * 1.585); aspect-ratio: 85.6/54; border: 3px solid #fff; border-radius: 14px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.5); }
@media (orientation: portrait) { .cardbox { width: 88vw; } }
.hint { position: absolute; top: max(16px, env(safe-area-inset-top)); inset-inline: 0; text-align: center; color: #fff; font-weight: 700; text-shadow: 0 1px 4px #000; margin: 0; padding: 0 16px; }
.cam-actions { position: absolute; bottom: max(24px, env(safe-area-inset-bottom)); inset-inline: 0; display: flex; justify-content: space-around; align-items: center; }
.shutter { width: 72px; height: 72px; border-radius: 50%; border: 5px solid #fff; background: rgba(255,255,255,.3); cursor: pointer; }
.ghost { color: #fff; background: rgba(0,0,0,.4); border: 0; padding: 10px 14px; border-radius: 10px; font: inherit; cursor: pointer; min-width: 84px; text-align: center; }

dialog#result { border: 0; border-radius: var(--radius); width: min(92vw, 560px); }
dialog#result pre { background: var(--bg); padding: 12px; border-radius: 10px; max-height: 50vh; overflow: auto; font-size: .8rem; }

@media (max-width: 520px) {
  .grid { grid-template-columns: 1fr; }
  .card { padding: 16px; }
}
