/* THE CLEARANCE STATEMENT — security-document brutalism, Arabic-first.
   A radical break from the dark-devtool cliché: a LIGHT bone-paper official certificate,
   girih (Islamic 8-fold) seal as security engraving, a violent ink CLEARANCE stamp slammed
   across it. Monochrome paper + ink, exactly one warning red and one official green (NOT
   neon mint). Brutalist: 0px corners, heavy ink rules, huge type, visible structure.
   The memorable moat = the stamped, unmistakably-Saudi clearance certificate (share artifact). */

:root {
  --paper: #f2ece0;        /* warm bone paper */
  --paper-2: #e9e1d1;      /* inset panel */
  --paper-edge: #ddd3bf;
  --ink: #14110c;          /* near-black ink (AA on paper) */
  --ink-dim: #4f4838;      /* secondary */
  --ink-faint: #837a64;    /* tertiary / fine print */
  --reject: #b00d28;       /* official customs red — fear */
  --cleared: #0a5c33;      /* deep official green — relief (NOT mint) */
  --rule: #1c1812;         /* heavy ink rule */
  --hair: #cabfa7;

  --f-disp: "Archivo Black", "Arial Black", system-ui, sans-serif; /* brutalist Latin */
  --f-body: "Archivo", system-ui, -apple-system, sans-serif;
  --f-ar: "Reem Kufi", "Noto Kufi Arabic", sans-serif;            /* geometric Kufi ~ girih */
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --maxw: 940px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  /* real paper scan + faint girih security tile layered on top */
  background-color: var(--paper);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%2314110c' stroke-width='0.6' opacity='0.05'%3E%3Cpolygon points='32,4 60,32 32,60 4,32'/%3E%3Cpolygon points='50,14 50,50 14,50 14,14'/%3E%3C/g%3E%3C/svg%3E"),
    url("assets/paper.png");
  background-size: 64px 64px, cover;
  background-position: 0 0, center;
  background-blend-mode: multiply, normal;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 26px 20px 60px; }
.mono { font-family: var(--f-mono); font-feature-settings: "tnum" 1; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); }
[dir="rtl"] { font-family: var(--f-ar); }
[dir="rtl"] .mono { font-family: var(--f-mono); } /* keep XML/rule_ids LTR mono */

/* ===== Masthead: an authority-style document header ===== */
.masthead {
  display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 18px;
  border-bottom: 3px solid var(--rule); padding-bottom: 16px;
}
.seal { width: 64px; height: 64px; color: var(--ink); }
.seal svg, .seal img { width: 100%; height: 100%; display: block; object-fit: contain; }
.seal img { mix-blend-mode: multiply; filter: contrast(1.12); }
.masthead .title { line-height: 1.12; }
.masthead .title .ar { font-family: var(--f-ar); font-weight: 700; font-size: 1.5rem; letter-spacing: .01em; }
.masthead .title .en { font-family: var(--f-mono); font-size: .72rem; letter-spacing: .34em; text-transform: uppercase; color: var(--ink-dim); margin-top: 3px; }
.lang-toggle { display: flex; }
.lang-toggle button { font-family: var(--f-mono); font-size: .8rem; padding: 8px 12px; background: var(--paper); color: var(--ink); border: 2px solid var(--rule); cursor: pointer; margin-inline-start: -2px; }
.lang-toggle button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* ===== Hero ===== */
.hero { padding: 40px 0 22px; border-bottom: 1px solid var(--hair); }
.refline { display: flex; justify-content: space-between; font-family: var(--f-mono); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 22px; }
.hero h1 {
  font-family: var(--f-disp); font-weight: 900;
  font-size: clamp(2.5rem, 8vw, 5.2rem); line-height: 0.92; letter-spacing: -0.02em;
  text-transform: uppercase; margin: 0 0 16px;
}
[dir="rtl"] .hero h1 { font-family: var(--f-ar); text-transform: none; line-height: 1.05; }
.hero h1 .fear { color: var(--reject); -webkit-text-stroke: 0; }
.hero p.lede { font-size: 1.08rem; max-width: 56ch; color: var(--ink-dim); margin: 0; }
[dir="rtl"] .hero p.lede { margin-inline-start: auto; }

/* ===== Console / intake ===== */
.console { margin-top: 26px; border: 3px solid var(--rule); background: var(--paper); }
.console-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 2px solid var(--rule); font-family: var(--f-mono); font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-dim); }
.console-head .led { width: 9px; height: 9px; background: var(--ink-faint); }
.console-head .led.live { background: var(--cleared); }
textarea#xml { width: 100%; min-height: 170px; resize: vertical; border: 0; outline: 0; background: repeating-linear-gradient(var(--paper), var(--paper) 27px, var(--paper-edge) 27px, var(--paper-edge) 28px); color: var(--ink); padding: 14px; font-family: var(--f-mono); font-size: 13px; line-height: 28px; }
textarea#xml::placeholder { color: var(--ink-faint); }
.console-foot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 14px; border-top: 2px solid var(--rule); }
.samples { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { font-family: var(--f-mono); font-size: .78rem; padding: 9px 13px; background: var(--paper); color: var(--ink); border: 2px solid var(--rule); cursor: pointer; text-transform: uppercase; letter-spacing: .06em; transition: background .12s, color .12s; }
.btn:hover { background: var(--ink); color: var(--paper); }
.spacer { flex: 1 1 auto; }
/* the single decisive action */
.cta { font-family: var(--f-disp); font-weight: 900; font-size: 1rem; text-transform: uppercase; letter-spacing: .02em; padding: 13px 26px; background: var(--ink); color: var(--paper); border: 3px solid var(--ink); cursor: pointer; }
.cta:hover { background: var(--reject); border-color: var(--reject); }
.cta[disabled] { opacity: .45; cursor: progress; }
[dir="rtl"] .cta, [dir="rtl"] .btn { font-family: var(--f-ar); }

/* ===== Skeleton ===== */
.skeleton { margin-top: 24px; border: 3px solid var(--rule); padding: 24px; }
.skeleton .bar { height: 16px; background: var(--paper-2); margin: 12px 0; }
.skeleton .bar.big { height: 64px; width: 55%; }
.progress-copy { font-family: var(--f-mono); font-size: .8rem; color: var(--ink-faint); margin-top: 14px; }

/* ===== The certificate (result) ===== */
.result { margin-top: 24px; }
.cert { position: relative; border: 3px solid var(--rule); background: var(--paper); padding: 30px 26px 26px; overflow: hidden; }
.cert::before { /* inner engraving frame */ content: ""; position: absolute; inset: 9px; border: 1px solid var(--hair); pointer-events: none; }
.cert-masthead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--hair); padding-bottom: 10px; margin-bottom: 18px; position: relative; z-index: 1; }
.cert-masthead .doc { font-family: var(--f-mono); font-size: .72rem; letter-spacing: .2em; text-transform: uppercase; color: var(--ink-dim); }
.cert-body { position: relative; z-index: 1; min-height: 220px; }

/* guilloche security watermark behind the certificate */
.cert .watermark { position: absolute; inset: 0; display: grid; place-items: center; z-index: 0; pointer-events: none; }
.cert .watermark img { width: min(74%, 520px); mix-blend-mode: multiply; opacity: .07; }

/* microprint security strip + serial + faux barcode */
.microprint { position: relative; z-index: 1; font-family: var(--f-mono); font-size: 6.5px; line-height: 1; letter-spacing: .26em; text-transform: uppercase; color: var(--ink-faint); white-space: nowrap; overflow: hidden; padding: 5px 0; border-top: 1px solid var(--hair); border-bottom: 1px solid var(--hair); margin-bottom: 16px; }
.cert-foot { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 22px; padding-top: 12px; border-top: 1px solid var(--hair); }
.cert-foot .serial { font-family: var(--f-mono); font-size: .68rem; letter-spacing: .12em; color: var(--ink-faint); }
.barcode { height: 26px; width: 132px; background: repeating-linear-gradient(90deg, var(--ink) 0 1px, transparent 1px 3px, var(--ink) 3px 4px, transparent 4px 7px, var(--ink) 7px 9px, transparent 9px 12px, var(--ink) 12px 13px, transparent 13px 16px); opacity: .85; }

/* The big STAMP */
.stamp-wrap { display: flex; justify-content: center; padding: 14px 0 4px; }
.stamp {
  display: inline-block; padding: 14px 30px; border: 5px solid currentColor; border-radius: 8px;
  font-family: var(--f-disp); font-weight: 900; text-transform: uppercase; letter-spacing: .06em;
  font-size: clamp(2rem, 8vw, 4.2rem); line-height: 1; transform: rotate(-6deg);
  position: relative; filter: url(#inkbleed); opacity: .94; isolation: isolate;
}
/* real rubber-stamp ink grit overlaid + tinted to the verdict colour */
.stamp::before {
  content: ""; position: absolute; inset: -10px; z-index: 2; pointer-events: none;
  background: url("assets/stampink.png") center/115% no-repeat;
  mix-blend-mode: multiply; opacity: .5;
}
.cert.cleared .stamp::before { filter: hue-rotate(108deg) saturate(.65) brightness(.85); }
.stamp .ar { display: block; font-family: var(--f-ar); font-size: .42em; letter-spacing: 0; margin-bottom: 4px; text-transform: none; }
.cert.cleared .stamp { color: var(--cleared); }
.cert.failed .stamp  { color: var(--reject); }
.cert.failed::after { /* fear wash on the document */ content: ""; position: absolute; inset: 0; background: radial-gradient(80% 60% at 50% 40%, rgba(176,13,40,.07), transparent 70%); pointer-events: none; }
.cert.cleared.animate .stamp, .cert.failed.animate .stamp { animation: slam .42s cubic-bezier(.2,1.4,.3,1) 1; }

.cert h2 { font-family: var(--f-disp); font-weight: 900; text-transform: uppercase; font-size: clamp(1.2rem, 3.6vw, 1.9rem); text-align: center; margin: 20px 0 8px; letter-spacing: -.01em; }
[dir="rtl"] .cert h2 { font-family: var(--f-ar); text-transform: none; }
.cert .sub { text-align: center; color: var(--ink-dim); max-width: 52ch; margin: 0 auto; }

/* official tally instead of a thin gauge */
.tally { display: flex; align-items: baseline; justify-content: center; gap: 12px; margin: 22px 0 4px; font-family: var(--f-mono); }
.tally .big { font-family: var(--f-disp); font-weight: 900; font-size: 2.4rem; line-height: 1; }
.tally.cleared .big { color: var(--cleared); }
.tally.failed .big { color: var(--reject); }
.tally .unit { font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); }

/* ===== Findings: grouped by severity ===== */
.findings { margin-top: 22px; display: grid; gap: 0; border-top: 2px solid var(--rule); }

/* Section group headers (FATAL / WARNING) */
.findings-group-hdr {
  font-family: var(--f-mono); font-size: .7rem; letter-spacing: .2em; text-transform: uppercase;
  padding: 7px 10px; border-bottom: 1px solid var(--hair);
  display: flex; align-items: center; gap: 8px;
}
.findings-group-hdr::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 0;
}
.findings-group-hdr.fatal { color: var(--reject); background: rgba(176,13,40,.04); }
.findings-group-hdr.fatal::before { background: var(--reject); }
.findings-group-hdr.warning { color: var(--ink-dim); background: var(--paper-2); }
.findings-group-hdr.warning::before { background: var(--ink-dim); }

/* Individual finding rows */
.finding {
  display: grid; grid-template-columns: 44px 1fr; border-bottom: 1px solid var(--hair); padding: 14px 8px;
}
.finding .no { font-family: var(--f-disp); font-weight: 900; font-size: 1.1rem; color: var(--ink-faint); padding-top: 2px; }
.finding.fatal .no { color: var(--reject); }
.finding.warning .no { color: var(--ink-dim); }

.finding-body { min-width: 0; }
.finding-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
.finding .rid { font-family: var(--f-mono); font-weight: 600; font-size: .8rem; color: var(--ink); }
.finding .tag {
  font-family: var(--f-mono); font-size: .62rem; letter-spacing: .12em; text-transform: uppercase;
  padding: 2px 7px; border: 1px solid currentColor; line-height: 1.4;
}
.finding.fatal .tag { color: var(--reject); }
.finding.warning .tag { color: var(--ink-dim); }
.finding .path { font-family: var(--f-mono); font-size: .7rem; color: var(--ink-faint); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 38ch; }

/* Both EN + AR messages shown, stacked */
.finding .msg { font-size: .93rem; margin: 3px 0 0; line-height: 1.45; }
.finding .msg-en { color: var(--ink-dim); }
.finding .msg-ar { font-family: var(--f-ar); direction: rtl; color: var(--ink-dim); font-size: .95rem; }

/* Fix hint */
.finding .fix { margin: 6px 0 0; font-size: .84rem; color: var(--cleared); font-weight: 600; display: flex; gap: 6px; flex-wrap: wrap; }
.finding .fix .fix-label { font-family: var(--f-mono); font-size: .72rem; color: var(--ink-faint); font-weight: 400; letter-spacing: .06em; text-transform: uppercase; flex-shrink: 0; }
.finding .fix .ar { font-family: var(--f-ar); }

/* ===== QR TLV panel ===== */
.qr-panel {
  position: relative; z-index: 1;
  margin-top: 28px; border: 1px solid var(--hair); background: var(--paper-2);
}
.qr-panel-hdr {
  font-family: var(--f-mono); font-size: .7rem; letter-spacing: .22em; text-transform: uppercase;
  color: var(--ink-dim); padding: 8px 14px; border-bottom: 1px solid var(--hair);
  background: var(--paper);
}
.qr-section { padding: 12px 14px 6px; min-height: 44px; }
.qr-none { font-family: var(--f-mono); font-size: .8rem; color: var(--ink-faint); margin: 0; padding: 4px 0; }
.qr-none.qr-error { color: var(--reject); }

/* QR TLV decoded table */
.qr-table {
  width: 100%; border-collapse: collapse; font-size: .82rem;
}
.qr-table td {
  padding: 6px 10px 6px 0; vertical-align: top; border-bottom: 1px solid var(--hair);
}
.qr-table tr:last-child td { border-bottom: 0; }
.qr-tag-no {
  font-family: var(--f-mono); font-weight: 600; font-size: .76rem; color: var(--ink-faint);
  width: 28px; white-space: nowrap; padding-inline-end: 14px;
}
.qr-label { width: 38%; padding-inline-end: 14px; }
.qr-label-ar { font-family: var(--f-ar); display: block; font-size: .9rem; color: var(--ink); line-height: 1.3; }
.qr-label-en { display: block; font-family: var(--f-mono); font-size: .68rem; color: var(--ink-faint); letter-spacing: .06em; margin-top: 2px; }
.qr-val { word-break: break-all; }
.qr-text { color: var(--ink); font-weight: 600; }
.qr-hex { font-family: var(--f-mono); font-size: .72rem; color: var(--ink-dim); word-break: break-all; }
[dir="rtl"] .qr-table td { padding: 6px 0 6px 10px; }
[dir="rtl"] .qr-tag-no { padding-inline-end: 0; padding-inline-start: 14px; }
[dir="rtl"] .qr-label { padding-inline-end: 0; padding-inline-start: 14px; }

/* QR manual decode row */
.qr-manual-row {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px 12px;
  border-top: 1px solid var(--hair);
}
.qr-manual-input {
  flex: 1 1 0; min-width: 0; border: 2px solid var(--paper-edge); background: var(--paper);
  color: var(--ink); padding: 8px 10px; font-family: var(--f-mono); font-size: 11px;
  line-height: 1.5; resize: none; outline: 0;
}
.qr-manual-input::placeholder { color: var(--ink-faint); font-size: .78rem; }
.qr-manual-input:focus { border-color: var(--ink-dim); }

.actions { margin-top: 24px; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; position: relative; z-index: 1; }
.actions .cta.alt { background: var(--paper); color: var(--ink); }
.actions .cta.alt:hover { background: var(--ink); color: var(--paper); }

.errbox { margin-top: 24px; border: 3px solid var(--reject); padding: 18px; color: var(--ink-dim); }
.errbox b { color: var(--reject); font-family: var(--f-disp); text-transform: uppercase; }

.share { margin-top: 22px; text-align: center; }
.share canvas { max-width: 100%; height: auto; border: 3px solid var(--rule); }

.disclaimer { margin-top: 38px; padding-top: 16px; border-top: 1px solid var(--hair); color: var(--ink-faint); font-size: .8rem; line-height: 1.6; }
.disclaimer .mono { color: var(--ink-dim); font-weight: 600; }
footer { margin-top: 18px; color: var(--ink-faint); font-size: .8rem; }
footer a { color: var(--ink-dim); }

.hidden { display: none !important; }

@keyframes slam { 0% { transform: rotate(-6deg) scale(2.4); opacity: 0; } 60% { opacity: .92; } 100% { transform: rotate(-6deg) scale(1); opacity: .92; } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .masthead { grid-template-columns: 48px 1fr auto; gap: 12px; }
  .seal { width: 48px; height: 48px; }
  .hero { padding: 28px 0 18px; }
  .qr-manual-row { flex-direction: column; }
  .finding .path { max-width: 22ch; }
}
