:root {
  --bg: #FAF8F4;
  --card: #FFFFFF;
  --text: #2A2118;
  --muted: #6E6E6E;
  --line: #E4DDD0;
  --brand: #4A3721;
  --gold: #C89A3C;
  --btn-bg: #4A3721;
  --btn-fg: #FFFFFF;
  --ok: #1E7A46;
  --ok-bg: #E6F4EC;
  --err: #B3261E;
  --err-bg: #FDECEA;
  --focus: #1B5FAA;
  --input-bg: #FFFFFF;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130E;
    --card: #221C14;
    --text: #F2EBDD;
    --muted: #B8AE9C;
    --line: #3A3226;
    --brand: #D9AE55;
    --gold: #D9AE55;
    --btn-bg: #D9AE55;
    --btn-fg: #1B140A;
    --ok: #6FD39A;
    --ok-bg: #16301F;
    --err: #FF9C93;
    --err-bg: #3A1B18;
    --focus: #8AB8F0;
    --input-bg: #17130E;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Naskh Arabic", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  background: var(--card);
  border-bottom: 3px solid var(--gold);
}
.brand { font-weight: 700; color: var(--brand); font-size: 1.05rem; }
.langs { display: flex; gap: 6px; }
.langs button {
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: .95rem;
  cursor: pointer;
}
.langs button[aria-pressed="true"] { background: var(--btn-bg); color: var(--btn-fg); border-color: var(--btn-bg); font-weight: 700; }

main {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
h1 { font-size: 1.35rem; margin: 8px 0; }
h2 { font-size: 1.1rem; margin: 0 0 12px; color: var(--brand); }

.trip { margin: 0; display: grid; grid-template-columns: 1fr; gap: 0; }
.trip .row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.trip .row:last-child { border-bottom: 0; }
.trip dt { color: var(--muted); font-size: .92rem; flex: 0 0 auto; }
.trip dd { margin: 0; font-weight: 700; text-align: end; overflow-wrap: anywhere; }
.trip dd.num { direction: ltr; unicode-bidi: isolate; }
.trip .price dd { color: var(--brand); font-size: 1.15rem; }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
label { display: block; font-weight: 700; margin-bottom: 6px; }
input[type="text"], input[type="tel"] {
  width: 100%;
  min-height: 50px;
  padding: 10px 12px;
  font: inherit;
  font-size: 18px; /* يمنع تكبير iOS التلقائي */
  color: var(--text);
  background: var(--input-bg);
  border: 1.5px solid var(--line);
  border-radius: 10px;
}
input[type="tel"] { text-align: start; }
input:focus-visible, button:focus-visible, .pick:focus-within, .check input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.field.invalid input { border-color: var(--err); }
.hint { display: block; color: var(--muted); font-size: .9rem; margin-top: 4px; }
p.hint { margin: 0 0 12px; }
.err { display: block; color: var(--err); font-weight: 600; font-size: .95rem; margin-top: 4px; min-height: 0; }
.err:empty { display: none; }

/* خانات المستندات */
.doc {
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  align-items: center;
}
.doc:last-child { margin-bottom: 0; }
.doc.invalid { border-color: var(--err); background: var(--err-bg); }
.doc.done, .doc.reused { border-color: var(--ok); background: var(--ok-bg); }
.thumb {
  width: 64px; height: 64px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  overflow: hidden;
  font-size: 1.6rem;
  color: var(--muted);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.doc-title { font-weight: 700; display: block; margin: 0; }
.doc-hint { color: var(--muted); font-size: .88rem; display: block; }
.doc-status { font-size: .95rem; margin: 2px 0 6px; display: block; }
.doc.done .doc-status, .doc.reused .doc-status { color: var(--ok); font-weight: 700; }
.doc.error .doc-status, .doc.invalid .doc-status { color: var(--err); font-weight: 700; }
.doc-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
.pick, .linkbtn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px; padding: 0 16px;
  border-radius: 10px;
  font: inherit; font-weight: 700; font-size: .98rem;
  border: 1.5px solid var(--btn-bg);
  background: transparent; color: var(--brand);
  cursor: pointer;
}
.pick.solid { background: var(--btn-bg); color: var(--btn-fg); }
.doc.busy .pick { opacity: .5; pointer-events: none; }

.check { display: flex; gap: 12px; align-items: flex-start; font-weight: 600; margin: 0; cursor: pointer; }
.check input { width: 26px; height: 26px; margin: 2px 0 0; flex: 0 0 auto; accent-color: var(--btn-bg); }

.primary {
  width: 100%;
  min-height: 56px;
  border: 0; border-radius: 12px;
  background: var(--btn-bg); color: var(--btn-fg);
  font: inherit; font-size: 1.15rem; font-weight: 800;
  cursor: pointer;
}
.primary[disabled] { opacity: .6; cursor: progress; }
.form-error { color: var(--err); font-weight: 700; margin: 0 0 10px; }
.form-error:empty { display: none; }

.state { text-align: center; padding: 40px 8px; }
.state .icon { font-size: 2.6rem; line-height: 1; margin-bottom: 8px; }
.state .icon.ok { color: var(--ok); }
.state .icon.warn { color: var(--err); }
.state p { color: var(--text); margin: 6px 0; }
.contact { margin-top: 16px; }
.contact a { color: var(--brand); font-weight: 700; direction: ltr; unicode-bidi: isolate; }
.spinner { width: 34px; height: 34px; margin: 0 auto 12px; border: 4px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 0 16px 20px; }
code { background: var(--card); padding: 2px 6px; border-radius: 6px; }

@media (min-width: 640px) {
  body { font-size: 18px; }
  main { padding-top: 28px; }
}
