/* ==========================================================================
   Rawan Saleh A. Alghamdi — KYC form
   Layout is written with CSS logical properties throughout, so the Arabic
   (RTL) and English (LTR) directions share one stylesheet.
   ========================================================================== */

@import url('../fonts/fonts.css?v=1');
@import url('./tokens.css?v=1');

/* --- Reset ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

body {
  min-height: 100vh;
  font-family: var(--font-ar);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
html[lang="en"] body { font-family: var(--font-latin); }

img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Visible focus everywhere, never removed. */
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- Page ground ---------------------------------------------------------
   Off-white gradient carrying an oversized, very faint fragment of the house
   calligraphy — the treatment used on the printed brochure covers.          */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(180deg, #FFFFFF 0%, var(--bg) 46%, #EFEFF2 100%),
    url('../assets/brand/watermark.png') no-repeat;
  background-size: cover, 150% auto;
  background-position: center, center 22%;
  opacity: 1;
}
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: url('../assets/brand/watermark.png') no-repeat center 20%;
  background-size: 165% auto;
  opacity: .035;
  pointer-events: none;
}

.page {
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--sp-5);
}

/* --- Header --------------------------------------------------------------- */
.site-header {
  padding-block: var(--sp-6) var(--sp-5);
  text-align: center;
  position: relative;
}

.lang-switch {
  position: absolute;
  inset-block-start: var(--sp-5);
  inset-inline-end: var(--sp-5);
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, .8);
  backdrop-filter: blur(6px);
  overflow: hidden;
}
.lang-switch button {
  border: 0;
  background: transparent;
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.lang-switch button:hover { color: var(--ink); }
.lang-switch button[aria-pressed="true"] { background: var(--navy); color: var(--ink-invert); }

/* On narrow screens the absolute toggle would sit on top of the wordmark,
   so it returns to the normal flow above it. */
@media (max-width: 34rem) {
  .site-header { padding-block-start: var(--sp-4); }
  .lang-switch {
    position: static;
    margin-block-end: var(--sp-4);
  }
}

.site-header .logo {
  width: min(420px, 78%);
  margin-inline: auto;
  height: auto;
}

.tagline {
  margin-block-start: var(--sp-4);
  font-size: var(--fs-sm);
  letter-spacing: .06em;
  color: var(--ink-muted);
}
.tagline .sep { color: var(--gold); margin-inline: .5em; }

.rule-gold {
  width: 120px;
  height: 2px;
  margin: var(--sp-5) auto 0;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  border: 0;
}

/* --- Form title ----------------------------------------------------------- */
.form-intro { text-align: center; margin-block: var(--sp-6) var(--sp-5); }
.form-intro h1 {
  font-size: clamp(1.6rem, 1.1rem + 2vw, var(--fs-3xl));
  font-weight: 700;
  line-height: var(--lh-tight);
  color: var(--navy);
}
html[lang="en"] .form-intro h1 {
  font-family: var(--font-display);
  font-variant: small-caps;
  letter-spacing: .02em;
}
.form-intro p {
  margin-block-start: var(--sp-3);
  color: var(--ink-muted);
  font-size: var(--fs-md);
  max-width: 46rem;
  margin-inline: auto;
}

/* --- Card ----------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  padding: clamp(var(--sp-5), 3vw, var(--sp-7));
  margin-block-end: var(--sp-6);
}

/* --- Sections ------------------------------------------------------------- */
.section { border: 0; padding: 0; margin: 0; }
.section + .section {
  margin-block-start: var(--sp-7);
  padding-block-start: var(--sp-6);
  border-block-start: 1px solid var(--border-soft);
}

.section > legend {
  padding: 0;
  margin-block-end: var(--sp-5);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--navy);
  width: 100%;
}
.section > legend .num {
  flex: none;
  display: grid;
  place-items: center;
  inline-size: 1.85rem;
  block-size: 1.85rem;
  border-radius: 50%;
  background: var(--navy);
  color: var(--gold-light);
  font-size: var(--fs-sm);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.section > legend::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--gold), transparent);
}
html[dir="rtl"] .section > legend::after {
  background: linear-gradient(270deg, var(--gold), transparent);
}

/* --- Field grid ----------------------------------------------------------- */
.grid {
  display: grid;
  gap: var(--sp-5) var(--sp-5);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid > .full { grid-column: 1 / -1; }
@media (max-width: 46rem) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}

.field { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }

.field > label,
.q-legend {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink);
}
.req { color: var(--error); margin-inline-start: .15em; }
.optional { color: var(--ink-faint); font-weight: 400; }

.hint { font-size: var(--fs-xs); color: var(--ink-faint); }

/* --- Controls ------------------------------------------------------------- */
.input, .select, .textarea {
  inline-size: 100%;
  padding: .7rem .9rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--ink);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input::placeholder, .textarea::placeholder { color: #A9A7BC; }

.input:hover, .select:hover, .textarea:hover { border-color: #C6C5D2; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: var(--ring);
}

.textarea { resize: vertical; min-block-size: 5.5rem; line-height: 1.55; }

/* Native arrow removed so the caret can follow the writing direction. */
.select {
  appearance: none;
  padding-inline-end: 2.4rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23292759' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 12px;
  background-position: right .9rem center;
  cursor: pointer;
}
html[dir="rtl"] .select { background-position: left .9rem center; padding-inline-end: 2.4rem; }
.select option[disabled] { color: var(--ink-faint); }

/* Numeric fields stay LTR even in Arabic — IDs, IBANs and phone numbers are
   read left-to-right regardless of the surrounding script. */
.input--ltr {
  direction: ltr;
  text-align: start;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
html[dir="rtl"] .input--ltr { text-align: right; }

/* Phone / currency affix */
.affix {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-alt);
  overflow: hidden;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.affix:hover { border-color: #C6C5D2; }
.affix:focus-within { border-color: var(--gold); box-shadow: var(--ring); }
.affix > .input, .affix > .input:focus {
  border: 0; box-shadow: none; background: transparent; flex: 1; min-width: 0;
}
.affix > .tag {
  display: grid;
  place-items: center;
  padding-inline: .85rem;
  background: var(--navy-tint);
  color: var(--ink-muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  border-inline-end: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}
.affix > .tag--end { border-inline-end: 0; border-inline-start: 1px solid var(--border); }

/* The dialling-code tag is a real <select>. It keeps the flat tag look while
   staying operable: the closed control is narrow enough to show the flag and
   the code and then clip, so a long country name can never push the number
   field out of the row, and the clip lands in open space rather than halfway
   through a word. The open list is sized by the browser and still shows every
   label in full, which is what makes the list scannable.

   The closed control shows a short "flag +code" label that app.js swaps in,
   so this width only has to fit the longest dialling code (+998) and the
   ellipsis below is a safety net rather than the normal case. */
.affix > .tag--select {
  appearance: none;
  -webkit-appearance: none;
  direction: ltr;
  inline-size: 5.9rem;
  flex: none;
  padding-inline: .7rem 1.5rem;
  border-radius: 0;
  text-overflow: ellipsis;
  cursor: pointer;
  /* Chevron, drawn inline so no network request is involved. */
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B6A7B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .5rem center;
  background-size: .85rem;
}
.affix > .tag--select:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.affix > .tag--select option { direction: ltr; text-align: left; }

/* --- Choice controls ------------------------------------------------------ */
.choices { display: flex; flex-direction: column; gap: var(--sp-3); margin-block-start: var(--sp-1); }
.q-block { border: 0; padding: 0; margin: 0; }
.q-legend { margin-block-end: var(--sp-2); }

.choice {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: .7rem .9rem;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-alt);
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.choice:hover { border-color: var(--gold); background: var(--gold-tint); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }

.choice .box {
  flex: none;
  inline-size: 1.15rem;
  block-size: 1.15rem;
  margin-block-start: .18rem;
  border: 1.5px solid #B6B4C6;
  background: var(--bg-alt);
  display: grid;
  place-items: center;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.choice .box { border-radius: var(--r-sm); }
.choice--radio .box { border-radius: 50%; }

.choice .box::after {
  content: '';
  opacity: 0;
  transition: opacity var(--t-fast);
}
.choice--check .box::after {
  inline-size: .34rem; block-size: .62rem;
  border: solid #fff; border-width: 0 2px 2px 0;
  transform: translateY(-1px) rotate(45deg);
}
.choice--radio .box::after {
  inline-size: .5rem; block-size: .5rem; border-radius: 50%; background: #fff;
}
.choice input:checked + .box { background: var(--navy); border-color: var(--navy); }
.choice input:checked + .box::after { opacity: 1; }
.choice input:focus-visible + .box { outline: 2px solid var(--gold); outline-offset: 2px; }
.choice:has(input:checked) { border-color: var(--navy); background: var(--navy-tint); }

.choice .txt { font-size: var(--fs-sm); }

/* Conditional "Other" input */
.reveal {
  margin-block-start: var(--sp-3);
  margin-inline-start: 2.05rem;
  display: none;
}
.reveal.is-open { display: block; }
html[dir="rtl"] .reveal { margin-inline-start: 2.05rem; }

/* --- Acknowledgement ------------------------------------------------------ */
.ack-panel {
  background: var(--navy-tint);
  border-radius: var(--r-md);
  border-inline-start: 3px solid var(--gold);
  padding: var(--sp-5);
  margin-block-end: var(--sp-4);
}
.ack-text {
  font-size: var(--fs-md);
  line-height: 1.9;
  color: var(--ink);
}
/* The Arabic wording is the operative text; in English mode the translation
   sits above it and the original is retained beneath. */
.ack-original {
  margin-block-start: var(--sp-4);
  padding-block-start: var(--sp-4);
  border-block-start: 1px dashed #C9C7DA;
  font-family: var(--font-ar);
  direction: rtl;
  text-align: right;
  font-size: var(--fs-base);
  line-height: 1.9;
  color: var(--ink-muted);
}
/* Caption reads in the page direction, not the quoted text's direction. */
.ack-original-label {
  display: block;
  direction: ltr;
  text-align: left;
  font-family: var(--font-latin);
  font-size: var(--fs-xs);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-block-end: var(--sp-2);
}
html[lang="ar"] .ack-original { display: none; }

.ack-confirm { border-color: var(--gold); }

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: .85rem 2rem;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-base), color var(--t-base),
              border-color var(--t-base), box-shadow var(--t-base), transform var(--t-fast);
}
.btn:active { transform: translateY(1px); }

.btn--primary { background: var(--navy); color: var(--gold-light); }
.btn--primary:hover:not(:disabled) { background: var(--navy-soft); box-shadow: var(--shadow-lift); }
.btn--primary:disabled { background: #B9B8C8; color: #EFEFF3; cursor: not-allowed; }

.btn--ghost { background: transparent; border-color: var(--navy); color: var(--navy); }
.btn--ghost:hover { background: var(--navy); color: var(--ink-invert); }

.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  margin-block-start: var(--sp-6);
}
.actions .btn { min-inline-size: 16rem; }

/* Spinner shown while the submission is in flight */
.spinner {
  inline-size: 1rem; block-size: 1rem;
  border: 2px solid currentColor;
  border-block-start-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: none;
}
.is-sending .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Validation ----------------------------------------------------------- */
/* Shown whenever it carries text, rather than keying off an ancestor class —
   that keeps a group-level error from revealing empty siblings inside it. */
.error-msg {
  display: none;
  font-size: var(--fs-xs);
  color: var(--error);
}
.error-msg:not(:empty) { display: block; }

.field.is-invalid .input,
.field.is-invalid .select,
.field.is-invalid .textarea,
.field.is-invalid .affix { border-color: var(--error); }
.field.is-invalid .input:focus,
.field.is-invalid .select:focus,
.field.is-invalid .textarea:focus,
.field.is-invalid .affix:focus-within { box-shadow: var(--ring-error); }

.form-error {
  display: none;
  margin-block-start: var(--sp-4);
  padding: var(--sp-4);
  border: 1px solid #E8C2C8;
  border-radius: var(--r-md);
  background: var(--error-bg);
  color: var(--error);
  font-size: var(--fs-sm);
  text-align: center;
}
.form-error.is-open { display: block; }
.form-error a { color: inherit; font-weight: 500; }

/* --- Confirmation --------------------------------------------------------- */
.confirm { display: none; text-align: center; padding-block: var(--sp-7); }
.confirm.is-open { display: block; }

.confirm .tick {
  inline-size: 4.5rem; block-size: 4.5rem;
  margin-inline: auto;
  border-radius: 50%;
  background: var(--navy);
  display: grid; place-items: center;
  margin-block-end: var(--sp-5);
}
.confirm .tick svg { inline-size: 2rem; block-size: 2rem; stroke: var(--gold-light); }

.confirm h2 { font-size: var(--fs-xl); color: var(--navy); margin-block-end: var(--sp-3); }
.confirm p { color: var(--ink-muted); max-width: 34rem; margin-inline: auto; }

.ref-box {
  display: inline-flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-block: var(--sp-5);
  padding: var(--sp-4) var(--sp-6);
  border: 1px dashed var(--gold);
  border-radius: var(--r-md);
  background: var(--gold-tint);
}
.ref-box .lbl { font-size: var(--fs-xs); color: var(--ink-muted); letter-spacing: .08em; }
.ref-box .val {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--navy);
  direction: ltr;
  font-variant-numeric: tabular-nums;
  letter-spacing: .06em;
}

/* --- Footer --------------------------------------------------------------- */
.site-footer {
  background: var(--navy);
  color: rgba(255, 255, 255, .82);
  padding-block: var(--sp-6);
  margin-block-start: var(--sp-7);
  font-size: var(--fs-sm);
}
/* Full lockup, sized close to the header mark. min() keeps it from running
   edge to edge on a phone. */
.site-footer .logo-light {
  width: min(400px, 78%);
  height: auto;
  margin-inline: auto;
  margin-block-end: var(--sp-6);
}
.footer-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-3) var(--sp-6);
  text-align: center;
}
.footer-grid span { display: inline-flex; align-items: center; gap: var(--sp-2); }
.footer-grid svg { inline-size: 1rem; block-size: 1rem; stroke: var(--gold-light); flex: none; }
.footer-grid a { color: inherit; text-decoration: none; }
.footer-grid a:hover { color: #fff; text-decoration: underline; }
.footer-legal {
  margin-block-start: var(--sp-5);
  padding-block-start: var(--sp-4);
  border-block-start: 1px solid rgba(255, 255, 255, .14);
  text-align: center;
  font-size: var(--fs-xs);
  color: rgba(255, 255, 255, .6);
}
.footer-legal .ltr { direction: ltr; unicode-bidi: isolate; }

/* Honeypot — off-screen, never shown to a human. */
.hp { position: absolute; inset-inline-start: -9999px; opacity: 0; pointer-events: none; }

/* Print-only nodes stay hidden on screen. */
.print-only { display: none; }
