:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #16202e;
  --muted: #5d6878;
  --line: #e2e6ec;
  --brand: #12355b;
  --brand-2: #1d4f86;
  --gold: #b8892b;
  --ok: #1f7a4d;
  --ok-bg: #e6f4ec;
  --warn: #9a6400;
  --warn-bg: #fff4dc;
  --bad: #b3261e;
  --bad-bg: #fdecea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Cairo', system-ui, sans-serif; background: var(--bg); color: var(--ink); direction: rtl; font-size: 15px; line-height: 1.7; }
a { color: var(--brand-2); text-decoration: none; }
button, input, select, textarea { font: inherit; }
h1, h2, h3 { line-height: 1.35; }

/* شريط علوي */
.topbar { background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar .in { max-width: 1120px; margin: auto; display: flex; align-items: center; gap: 16px; padding: 10px 16px; }
.logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 800; font-size: 20px; }
.logo .mark { width: 36px; height: 36px; flex: none; }
.logo .word { font-family: 'Cairo', sans-serif; font-weight: 800; font-size: 22px; line-height: 1.3; }
.logo .sub { font-size: 14px; font-weight: 600; opacity: .85; border-right: 1px solid rgba(255,255,255,.35); padding-right: 10px; }
.topbar nav { margin-inline-start: auto; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.topbar nav a, .topbar nav button { color: #dfe7f2; background: none; border: 0; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.topbar nav a:hover, .topbar nav button:hover, .topbar nav a.on { background: rgba(255, 255, 255, .12); color: #fff; }

.wrap { max-width: 1120px; margin: auto; padding: 20px 16px 60px; }

/* أزرار وحقول */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; background: var(--brand); color: #fff; padding: 9px 18px; border-radius: 10px; cursor: pointer; font-weight: 700; transition: background .15s; }
.btn:hover { background: var(--brand-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: #eef1f5; }
.btn.gold { background: var(--gold); color: #fff; }
.btn.ok { background: var(--ok); }
.btn.bad { background: var(--bad); }
.btn.sm { padding: 5px 12px; font-size: 13px; border-radius: 8px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 700; margin-bottom: 4px; font-size: 14px; }
.field .hint { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.field .err { color: var(--bad); font-size: 13px; margin-top: 3px; }
.input, select.input, textarea.input { width: 100%; border: 1px solid #cfd6df; background: #fff; border-radius: 10px; padding: 9px 12px; color: var(--ink); }
.input:focus { outline: 2px solid #a9c4e6; border-color: var(--brand-2); }
textarea.input { min-height: 96px; resize: vertical; }
.input.bad { border-color: var(--bad); }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice { border: 1px solid #cfd6df; background: #fff; padding: 7px 14px; border-radius: 999px; cursor: pointer; font-size: 14px; }
.choice.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 20px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; background: #eef1f5; color: var(--muted); }
.badge.free { background: var(--ok-bg); color: var(--ok); }
.badge.price { background: #fdf3df; color: #8a6312; }
.badge.paid { background: var(--ok-bg); color: var(--ok); }
.badge.pending_review { background: var(--warn-bg); color: var(--warn); }
.badge.awaiting_payment { background: #e8eef7; color: var(--brand-2); }
.badge.rejected { background: var(--bad-bg); color: var(--bad); }
.badge.cancelled { background: #eee; color: #777; }
.notice { padding: 12px 16px; border-radius: 10px; font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: #6b4700; }
.notice.ok { background: var(--ok-bg); color: #145235; }
.notice.bad { background: var(--bad-bg); color: #7d1b15; }
.notice.info { background: #e8eef7; color: #163b66; }

/* الرئيسية */
.hero { background: linear-gradient(135deg, var(--brand) 0%, #1b4a7c 100%); color: #fff; border-radius: 16px; padding: 34px 28px; margin-bottom: 22px; position: relative; overflow: hidden; }
.hero h1 { margin: 0 0 8px; font-size: 28px; }
.hero p { margin: 0 0 18px; color: #d6e1ee; max-width: 640px; }
.hero .search { display: flex; gap: 8px; max-width: 560px; }
.hero .search input { flex: 1; border: 0; border-radius: 10px; padding: 12px 14px; font-size: 16px; }
.hero .stats { display: flex; gap: 22px; margin-top: 18px; font-size: 13px; color: #c5d3e4; flex-wrap: wrap; }
.hero .stats b { color: #fff; font-size: 18px; display: block; }
.cats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.cats button { border: 1px solid var(--line); background: var(--surface); padding: 7px 14px; border-radius: 999px; cursor: pointer; font-size: 14px; }
.cats button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.tcard { padding: 16px; display: flex; flex-direction: column; gap: 6px; cursor: pointer; transition: transform .12s, box-shadow .12s; }
.tcard:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(16, 24, 40, .1); }
.tcard h3 { margin: 0; font-size: 16px; }
.tcard p { margin: 0; color: var(--muted); font-size: 13.5px; flex: 1; }
.tcard .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.section-title { display: flex; align-items: center; gap: 8px; margin: 26px 0 12px; font-size: 18px; }

/* المعالج */
.wizard { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 20px; align-items: start; }
.steps { display: flex; gap: 6px; margin: 4px 0 16px; flex-wrap: wrap; }
.steps span { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: #eef1f5; color: var(--muted); }
.steps span.on { background: var(--brand); color: #fff; }
.steps span.done { background: var(--ok-bg); color: var(--ok); }
.progress { height: 6px; background: #e6eaf0; border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.progress div { height: 100%; background: var(--gold); transition: width .2s; }
.mode-switch { display: flex; background: #eef1f5; border-radius: 10px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.mode-switch button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 700; color: var(--muted); }
.mode-switch button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.preview-box { position: sticky; top: 76px; }
.preview-box .paper-wrap { max-height: calc(100vh - 170px); overflow: auto; border-radius: 10px; border: 1px solid var(--line); background: #e9ecf1; padding: 14px; }
.paper.sheet { padding: 34px 38px; box-shadow: 0 2px 10px rgba(0, 0, 0, .08); min-height: 500px; font-size: 13.5px; }

/* التحرير المباشر على الوثيقة */
.wizard.inline { grid-template-columns: minmax(0, .62fr) minmax(0, 1.38fr); }
.wizard.inline .paper-wrap { max-height: none; overflow: visible; }
.wizard.inline .preview-box { position: static; }
.wizard.inline .paper.sheet { font-size: 15px; padding: 44px 48px; user-select: none; }
.ed-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; font-size: 13px; position: sticky; top: 66px; z-index: 4; }
.ed-bar .meter { flex: 1; min-width: 120px; height: 6px; background: #e6eaf0; border-radius: 99px; overflow: hidden; }
.ed-bar .meter div { height: 100%; background: var(--ok); transition: width .2s; }
.paper .slot { user-select: text; display: inline; min-width: 4em; padding: 1px 6px; margin: 0 1px; border-radius: 5px; background: #eef4fb; border-bottom: 1.5px solid #7ea6d6; outline: none; cursor: text; transition: background .15s, box-shadow .15s; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.paper .slot:hover { background: #e3edf9; }
.paper .slot:focus { background: #fff8e6; border-bottom-color: var(--gold); box-shadow: 0 0 0 2px #f1dfb4; }
.paper .slot:empty::before { content: attr(data-ph); color: #8a97a8; font-weight: 400; pointer-events: none; }
.paper .slot.multi { display: inline-block; min-width: 60%; white-space: pre-wrap; vertical-align: top; }
.paper li > .slot.multi:only-child { display: block; min-height: 3.6em; }
.paper .slot.filled { background: transparent; border-bottom-color: #c9d6e6; }
.paper .slot.filled:hover { background: #f3f7fc; }
.paper .slot.bad { background: #fdecea; border-bottom-color: var(--danger, #c0392b); }
.paper .slot-date { font: inherit; border: 0; border-bottom: 1.5px solid #7ea6d6; background: #eef4fb; border-radius: 5px; padding: 0 6px; color: inherit; }
.paper .slot-date.bad { background: #fdecea; }
.paper .auto { color: #2c5d3b; background: #edf7f0; border-radius: 4px; padding: 0 4px; }
.paper .pick { background: #fff3d6; color: #8a5a00; border: 1px dashed #d9a63c; border-radius: 5px; padding: 0 6px; cursor: pointer; font-size: .92em; }

/* نموذج توضيحي بعلامة مائية */
.paper.sample { position: relative; overflow: hidden; user-select: none; }
.paper.sample::after { content: attr(data-wm); position: absolute; inset: 0; display: grid; place-items: center; font-size: 64px; font-weight: 800; color: rgba(18, 53, 91, .07); transform: rotate(-30deg); pointer-events: none; white-space: nowrap; }
.linkish { background: none; border: 0; padding: 0; color: var(--brand-2); cursor: pointer; font: inherit; font-size: 13.5px; font-weight: 600; }
.linkish:hover { text-decoration: underline; }
.foot-links { margin-top: 8px; }
.foot-links a { color: var(--muted); text-decoration: underline; }

/* الأدوات */
.tools { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 16px; align-items: start; }
.tools h3 { margin: 0 0 12px; font-size: 17px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 12px; }

/* قائمة اختيار قابلة للبحث */
.combo { position: relative; }
.combo .combo-btn { display: flex; align-items: center; gap: 8px; width: 100%; text-align: right; cursor: pointer; font: inherit; }
.combo .combo-btn .val { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo .combo-btn .val.ph { color: #8a97a8; }
.combo .combo-btn .chev { transition: transform .15s; color: var(--muted); font-size: 12px; }
.combo.open .combo-btn { border-color: var(--brand-2); outline: 2px solid #a9c4e6; }
.combo.open .combo-btn .chev { transform: rotate(180deg); }
.combo .pop { position: absolute; inset-inline: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(16, 32, 56, .16); z-index: 30; overflow: hidden; }
.combo .pop .search { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.combo .pop .search input { flex: 1; border: 0; outline: none; font: inherit; background: none; }
.combo .pop ul { list-style: none; margin: 0; padding: 6px; max-height: 260px; overflow: auto; }
.combo .pop li { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.combo .pop li .ic { width: 28px; height: 28px; border-radius: 8px; background: #eef1f5; display: grid; place-items: center; font-size: 13px; flex: none; color: var(--brand); }
.combo .pop li.act { background: #eef4fb; }
.combo .pop li.sel { font-weight: 700; color: var(--brand); }
.combo .pop li.sel::after { content: '✓'; margin-inline-start: auto; color: var(--ok); }
.combo .pop li mark { background: #fff1c9; color: inherit; border-radius: 3px; }
.combo .pop li.custom { border-top: 1px dashed var(--line); margin-top: 4px; color: var(--brand-2); }
.combo .pop li.custom .ic { background: #fff3d6; color: #8a5a00; }
.combo .pop .none { padding: 14px; text-align: center; color: var(--muted); font-size: 13px; }
.combo .pop .foot { padding: 7px 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11.5px; background: #fafbfc; }

/* الدفع */
.cliq { display: grid; gap: 12px; }
.cliq .alias { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #0f2c4c; color: #fff; padding: 14px 16px; border-radius: 12px; }
.cliq .alias b { font-size: 22px; letter-spacing: 1px; font-family: monospace; direction: ltr; }
.cliq .kv { display: grid; grid-template-columns: auto 1fr auto; gap: 6px 14px; align-items: center; }
.cliq .kv span:nth-child(3n+1) { color: var(--muted); }
.ref-code { font-family: monospace; font-size: 20px; font-weight: 800; color: var(--gold); direction: ltr; }
.steps-list { margin: 0; padding-right: 20px; }
.steps-list li { margin: 4px 0; }
.timeline { display: flex; gap: 0; margin: 10px 0 18px; }
.timeline div { flex: 1; text-align: center; font-size: 12.5px; color: var(--muted); position: relative; padding-top: 22px; }
.timeline div::before { content: ''; position: absolute; top: 6px; right: 50%; transform: translateX(50%); width: 12px; height: 12px; border-radius: 50%; background: #cfd6df; }
.timeline div::after { content: ''; position: absolute; top: 11px; right: 50%; width: 100%; height: 2px; background: #cfd6df; z-index: -1; }
.timeline div:last-child::after { display: none; }
.timeline div.done { color: var(--ok); font-weight: 700; }
.timeline div.done::before { background: var(--ok); }
.timeline div.cur { color: var(--brand); font-weight: 700; }
.timeline div.cur::before { background: var(--gold); box-shadow: 0 0 0 4px #f4e6c7; }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: right; color: var(--muted); font-weight: 700; font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:hover td { background: #fafbfc; }

.modal-bg { position: fixed; inset: 0; background: rgba(10, 20, 35, .5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: min(440px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.modal.wide { width: min(1000px, 100%); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; font-size: 17px; }
.modal .body { padding: 18px; }
.x { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #16202e; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 60; font-size: 14px; }
.empty { text-align: center; padding: 50px 16px; color: var(--muted); }
.footer { text-align: center; color: var(--muted); font-size: 12.5px; padding: 24px 16px; border-top: 1px solid var(--line); margin-top: 40px; }

@media (max-width: 860px) {
  .wizard, .wizard.inline { grid-template-columns: 1fr; }
  .wizard.inline .paper.sheet { padding: 22px 18px; }
  .preview-box { position: static; }
  .hero h1 { font-size: 22px; }
  .hero { padding: 24px 18px; }
  .paper.sheet { padding: 18px; }
}
