/*
 * Learn certificates. One signature: the guilloche border of the certificate,
 * the security pattern of banknotes and official papers, because the whole point
 * of this certificate is that it can be checked. Everything else stays quiet.
 *
 * Ink navy for text, teal (the series' health colour) for actions, muted gold only
 * on the certificate's seal and rules.
 */
:root {
  --ink: #14213d;
  --ink-soft: #4a5568;
  --paper: #f6f7f9;
  --sheet: #fdfdfb;
  --teal: #0e7a6d;
  --teal-dark: #0a5c52;
  --gold: #b08d3c;
  --line: #d9dde4;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --ok-bg: #e6f4f1;

  --ar: "Noto Kufi Arabic", "Segoe UI", Tahoma, sans-serif;
  --ar-display: "Amiri", "Noto Naskh Arabic", serif;
  --en: "Inter", "Segoe UI", Arial, sans-serif;
  --en-display: "Cormorant Garamond", Georgia, serif;
  --mono: "JetBrains Mono", Consolas, monospace;

  --r: 10px;
  --gutter: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--en);
  line-height: 1.6;
}
html[lang="ar"] body { font-family: var(--ar); line-height: 1.85; }
[lang="ar"] { font-family: var(--ar); }
[lang="en"] { font-family: var(--en); }

a { color: var(--teal-dark); }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px var(--gutter) 48px; }
.narrow { max-width: 760px; }
h1 { font-size: clamp(1.5rem, 4vw, 2rem); line-height: 1.35; margin: 0 0 12px; }
.lead-text { color: var(--ink-soft); font-size: 1.05rem; }

/* ---------------------------------------------------------------- chrome */
.site-head, .site-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  max-width: 1180px; margin: 0 auto; padding: 14px var(--gutter);
}
.site-head { border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; }
.site-nav { display: flex; gap: 16px; align-items: center; font-size: 0.95rem; }
.site-foot { color: var(--ink-soft); font-size: 0.875rem; border-top: 1px solid var(--line); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 18px; border-radius: var(--r);
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--teal); }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.alert { background: var(--danger-bg); color: var(--danger); padding: 12px 16px; border-radius: var(--r); }
.note-ok { background: var(--ok-bg); color: var(--teal-dark); padding: 12px 16px; border-radius: var(--r); }

/* ---------------------------------------------------------------- home & verify */
.track-list { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 10px; }
.track-list li { display: flex; align-items: center; gap: 14px; background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.track-list li div { flex: 1; display: flex; flex-direction: column; }
.track-list li span { color: var(--ink-soft); font-size: 0.9rem; }
.verify-form label { display: block; font-weight: 600; margin: 20px 0 6px; }
.verify-form .row { display: flex; gap: 8px; flex-wrap: wrap; }
.verify-form input { flex: 1; min-width: 220px; }

input, select, textarea {
  min-height: 44px; padding: 8px 12px; font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r); background: #fff;
}
input[dir="ltr"] { font-family: var(--mono); letter-spacing: 0.04em; }

/* ---------------------------------------------------------------- certificate page */
.page-certificate { background: linear-gradient(180deg, #eef1f6 0, var(--paper) 420px); }
.cert-layout {
  display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 28px; align-items: start;
}

/* Side panel: verdict, recorded facts, all actions together. */
.panel-verify {
  position: sticky; top: 20px;
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 6px 24px rgba(20, 33, 61, 0.06);
  overflow: hidden;
}
.verdict { display: flex; gap: 12px; align-items: flex-start; padding: 18px 18px 16px; }
.verdict.is-valid { background: var(--ok-bg); color: var(--teal-dark); }
.verdict.is-revoked { background: var(--danger-bg); color: var(--danger); }
.verdict div { display: flex; flex-direction: column; gap: 2px; }
.verdict strong { font-size: 1.05rem; }
.verdict span { font-size: 0.86rem; line-height: 1.6; }
.verdict-icon {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; color: #fff; background: currentColor;
}
.verdict.is-valid .verdict-icon { background: var(--teal); }
.verdict.is-revoked .verdict-icon { background: var(--danger); }

.panel-facts { margin: 0; padding: 6px 18px; }
.panel-facts div { padding: 10px 0; border-bottom: 1px solid var(--line); }
.panel-facts div:last-child { border-bottom: 0; }
.panel-facts dt { font-size: 0.78rem; color: var(--ink-soft); }
.panel-facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.panel-facts .mono { font-size: 0.86rem; }

.panel-actions { display: flex; flex-direction: column; gap: 10px; padding: 16px 18px 18px; border-top: 1px solid var(--line); background: #fafbfc; }
.panel-label { margin: 0; font-size: 0.78rem; color: var(--ink-soft); font-weight: 600; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; gap: 4px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 6px; }
.segmented a {
  display: grid; place-items: center; min-height: 38px; border-radius: 7px;
  color: var(--ink-soft); font-weight: 600; text-decoration: none;
}
.segmented a[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(20, 33, 61, 0.15); }
.segmented a[lang="en"] { font-family: var(--en); }
.segmented a[lang="ar"] { font-family: var(--ar); }
.btn-block { width: 100%; }
.panel-hint { margin: 0; font-size: 0.78rem; color: var(--ink-soft); }

/* Stage: the A4 sheet scaled to the column (certificate.js sets --scale). */
.sheet-stage { min-width: 0; }
.sheet-fit { --scale: 1; width: calc(1123px * var(--scale)); height: calc(794px * var(--scale)); margin-inline: auto; }
.sheet-fit .sheet { transform: scale(var(--scale)); transform-origin: top left; }
[dir="rtl"] .sheet-fit .sheet { transform-origin: top right; }

/* ---------------------------------------------------------------- the sheet (A4 landscape, 1123 × 794 at 96dpi) */
.sheet {
  width: 1123px; height: 794px; padding: 20px; position: relative;
  background: var(--sheet) url("guilloche.svg") repeat; background-size: 48px 24px;
  color: var(--ink); box-shadow: 0 24px 60px rgba(20, 33, 61, 0.16);
}
.sheet[hidden] { display: none; }
.sheet-frame {
  position: relative; height: 100%;
  background: var(--sheet);
  border: 2px solid var(--gold); outline: 1px solid var(--gold); outline-offset: -8px;
  padding: 36px 64px 22px; display: flex; flex-direction: column;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 1.6rem; }
.sheet-en .sheet-brand { font-family: var(--en-display); letter-spacing: 0.03em; }
.sheet-ar .sheet-brand { font-family: var(--ar); color: var(--teal-dark); font-size: 1.45rem; }

.sheet-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.sheet-body p { margin: 0; }
.sheet-title { margin: 0; line-height: 1.2; color: var(--ink); }
.sheet-en .sheet-title { font-family: var(--en-display); font-weight: 600; font-size: 3.1rem; letter-spacing: 0.16em; text-transform: uppercase; }
.sheet-ar .sheet-title { font-family: var(--ar-display); font-weight: 700; font-size: 3.6rem; line-height: 1.45; }
.sheet-ornament {
  display: block; width: 180px; height: 12px; margin: 10px 0 22px;
  background:
    radial-gradient(circle, var(--gold) 0 3.5px, transparent 4px) center / 12px 12px no-repeat,
    linear-gradient(var(--gold), var(--gold)) left center / 76px 1px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right center / 76px 1px no-repeat;
}
.sheet-lead { font-size: 1.1rem; color: var(--ink-soft); letter-spacing: 0.03em; }
.sheet-name { color: var(--ink); margin: 10px 0 16px !important; text-wrap: balance; max-width: 860px; }
.sheet-en .sheet-name { font-family: var(--en-display); font-weight: 700; font-size: 3.4rem; line-height: 1.15; }
.sheet-ar .sheet-name { font-family: var(--ar-display); font-weight: 700; font-size: 3.3rem; line-height: 1.5; }
.sheet-name.is-long { font-size: 2.6rem !important; }
.sheet-line { font-size: 1.1rem; color: var(--ink-soft); }
.sheet-track { margin: 4px 0 2px !important; font-size: 1.6rem; font-weight: 700; color: var(--teal-dark); }
.sheet-en .sheet-track { font-family: var(--en); }
.sheet-scope { font-size: 1rem; color: var(--ink-soft); margin-bottom: 10px !important; }

.sheet-foot { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; align-items: end; }
.facts { margin: 0; display: grid; gap: 10px; }
.facts dt { font-size: 0.78rem; color: var(--ink-soft); }
.sheet-en .facts dt { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.7rem; }
.facts dd { margin: 0; font-weight: 600; font-size: 1rem; }
.mono { font-family: var(--mono); letter-spacing: 0.05em; }
.signature { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.sig-name { font-size: 1.7rem; font-weight: 600; }
.sheet-en .sig-name { font-family: var(--en-display); font-style: italic; }
.sheet-ar .sig-name { font-family: var(--ar-display); font-weight: 700; }
.sig-line { width: 220px; height: 1px; background: var(--ink); opacity: 0.45; }
.sig-role { font-size: 0.85rem; color: var(--ink-soft); }
.qr { justify-self: end; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 0.8rem; color: var(--ink-soft); }
.qr svg { width: 108px; height: 108px; }
.qr-url { font-family: var(--mono); font-size: 0.62rem; }
.sheet-note { margin: 14px 0 0; text-align: center; font-size: 0.72rem; color: var(--ink-soft); }

.is-revoked .sheet-frame { filter: grayscale(1); }
.void-stamp {
  position: absolute; inset: 0; display: grid; place-items: center;
  font: 700 7rem/1 var(--en); color: rgba(180, 35, 24, 0.3); transform: rotate(-16deg); pointer-events: none;
}

@media (max-width: 900px) {
  .cert-layout { grid-template-columns: 1fr; }
  .panel-verify { position: static; display: flex; flex-direction: column; }
  .panel-actions { order: 1; border-top: 0; border-bottom: 1px solid var(--line); }
  .panel-facts { order: 2; }
  .sheet-stage { order: -1; }
}

@page { size: A4 landscape; margin: 0; }
@media print {
  html, body { background: #fff !important; }
  .site-head, .site-foot, .no-print { display: none !important; }
  .wrap, .cert-layout { display: block; padding: 0; margin: 0; max-width: none; }
  .sheet-fit { width: auto; height: auto; }
  .sheet-fit .sheet { transform: none; }
  .sheet { width: 297mm; height: 210mm; box-shadow: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------------------------------------------------------------- exam flow */
.track-head { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.track-head h1 { margin: 0; }
.kicker { margin: 0; color: var(--teal-dark); font-weight: 600; font-size: 0.9rem; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 22px; margin-bottom: 16px; }
.panel h2 { margin: 0 0 10px; font-size: 1.2rem; }
.steps { padding-inline-start: 20px; margin: 10px 0 18px; }
.steps li { margin-bottom: 6px; }

.exam-bar {
  position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--r); margin-bottom: 14px; font-weight: 600;
}
.exam-bar .time.is-low { color: #ffd27a; }
.question { border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 18px; margin: 0 0 12px; }
.question legend { font-weight: 600; padding: 0; margin-bottom: 10px; float: inline-start; width: 100%; }
.question legend .num { color: var(--teal-dark); margin-inline-end: 6px; }
.option { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); margin-top: 8px; cursor: pointer; clear: both; }
.option:hover { border-color: var(--teal); }
.option input { min-height: auto; margin-top: 6px; accent-color: var(--teal); }
.option:has(input:checked) { border-color: var(--teal); background: var(--ok-bg); }

.result-score { font-size: 3rem; font-weight: 700; line-height: 1.1; margin: 6px 0; }
.result-pass { color: var(--teal-dark); }
.result-fail { color: var(--danger); }

.form-grid { display: grid; gap: 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.form-grid small { font-weight: 400; color: var(--ink-soft); }
.field-error { color: var(--danger); font-weight: 400; font-size: 0.9rem; }

.pay-code { font-family: var(--mono); font-size: 1.6rem; font-weight: 700; letter-spacing: 0.08em; background: var(--paper); border: 1px dashed var(--teal); border-radius: var(--r); padding: 8px 14px; display: inline-block; }
.waiting { display: flex; align-items: center; gap: 10px; color: var(--ink-soft); }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--teal); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* ---------------------------------------------------------------- admin */
.page-admin table { width: 100%; border-collapse: collapse; background: #fff; font-size: 0.88rem; margin-bottom: 24px; }
.page-admin th, .page-admin td { border-bottom: 1px solid var(--line); padding: 8px; text-align: start; vertical-align: top; }
.page-admin h2 { margin-top: 28px; }
