/* نظام التصميم — مطابق للهوية البصرية المعتمدة:
   خط Readex Pro، أزرق #163AAC، حواف 3px، خطوط فاصلة رفيعة، تخطيط مسطّح بلا ظلال. */

:root {
  --brand: #163AAC; --brand-deep: #0F2C87; --brand-wash: #EBEFFA;
  --ink: #161C26; --ink-2: #4A515C; --ink-3: #767C87; --ink-4: #9AA1AA;
  --paper: #FFFFFF; --mist: #F3F5F8; --mist-2: #E9ECF1;
  --rule: #DEE2E9; --rule-soft: #EDEFF4;
  --amber: #8F6310; --amber-wash: #FAF1DE;
  --red: #A6332A; --red-wash: #FAEBE9;
  --green: #146B4C; --green-wash: #E6F2EC;
  --scrim: rgba(12,16,24,.38);
  --toast-bg: #161C26; --toast-ink: #FFFFFF;
  --r: 3px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #7E9EEE; --brand-deep: #9AB4F3; --brand-wash: #17224A;
    --ink: #E9ECF1; --ink-2: #A9B0BC; --ink-3: #808894; --ink-4: #6B727D;
    --paper: #141A22; --mist: #0E1218; --mist-2: #1B2029;
    --rule: #262D38; --rule-soft: #1F252F;
    --amber: #D6A44E; --amber-wash: #2E2412;
    --red: #E0776B; --red-wash: #331916;
    --green: #4CB68C; --green-wash: #0F2A20;
    --scrim: rgba(0,0,0,.55);
    --toast-bg: #E9ECF1; --toast-ink: #141A22;
  }
}

:root[data-theme="dark"] {
  --brand: #7E9EEE; --brand-deep: #9AB4F3; --brand-wash: #17224A;
  --ink: #E9ECF1; --ink-2: #A9B0BC; --ink-3: #808894; --ink-4: #6B727D;
  --paper: #141A22; --mist: #0E1218; --mist-2: #1B2029;
  --rule: #262D38; --rule-soft: #1F252F;
  --amber: #D6A44E; --amber-wash: #2E2412;
  --red: #E0776B; --red-wash: #331916;
  --green: #4CB68C; --green-wash: #0F2A20;
  --scrim: rgba(0,0,0,.55);
  --toast-bg: #E9ECF1; --toast-ink: #141A22;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { direction: rtl; }
body {
  margin: 0; background: var(--mist); color: var(--ink);
  font-family: "Readex Pro", "Segoe UI", Tahoma, sans-serif;
  font-size: 14.5px; font-weight: 300; line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 500; line-height: 1.35; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; }
.n, .num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- الشريط العلوي ---------- */
.top { background: var(--paper); border-bottom: 1px solid var(--rule); }
.top .in { max-width: 1240px; margin: 0 auto; padding: 12px 22px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sep { width: 1px; height: 26px; background: var(--rule); }
.mark { height: 30px; width: auto; display: block; flex: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .mark { filter: brightness(2.1) saturate(.95); } }
:root[data-theme="dark"] .mark { filter: brightness(2.1) saturate(.95); }
.mark-wrap { display: flex; align-items: center; gap: 9px; flex: none; }
.mark-wrap small { font-size: 11.5px; font-weight: 300; color: var(--ink-3); line-height: 1.3; }

.nav { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.nav a {
  font-size: 13.5px; font-weight: 400; color: var(--ink-2);
  padding: 6px 11px; border-radius: var(--r); border: 1px solid transparent;
  display: inline-flex; align-items: center; gap: 6px;
}
.nav a:hover { color: var(--brand); background: var(--brand-wash); text-decoration: none; }
.nav a.active { color: #fff; background: var(--brand); border-color: var(--brand); font-weight: 400; }
.nav a.active .pill { background: rgba(255,255,255,.22); color: #fff; }

.top .right { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.icon-btn {
  position: relative; border: 1px solid var(--rule); background: var(--paper);
  color: var(--ink-2); border-radius: var(--r); padding: 6px 11px; font-size: 13.5px;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.icon-btn.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.icon-btn .badge {
  position: absolute; top: -6px; inset-inline-start: -6px; background: var(--red); color: #fff;
  border-radius: 999px; font-size: 10px; min-width: 17px; height: 17px; padding: 0 4px;
  display: grid; place-items: center; line-height: 1;
}
.as { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-3); }
.sel {
  font-size: 13.5px; font-weight: 400; color: var(--ink);
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r); padding: 6px 10px;
}

/* ---------- شريط الملخص ---------- */
.summary { background: var(--paper); border-bottom: 1px solid var(--rule); }
.summary .in {
  max-width: 1240px; margin: 0 auto; padding: 0 22px 11px;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--ink-3);
}
.summary .pt { display: inline-flex; align-items: center; gap: 7px; }
.summary .pt::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-4); }
.summary .pt.b::before { background: var(--brand); }
.summary .pt.a::before { background: var(--amber); }
.summary .pt.r::before { background: var(--red); }
.summary .pt.g::before { background: var(--green); }
.summary .pt b { font-weight: 500; color: var(--ink); }
.summary .pt a { color: inherit; }
.summary .pt a:hover b { color: var(--brand); }
.summary .date { margin-inline-start: auto; }

/* ---------- الشبكة والبطاقات ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 18px 22px 60px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .grid.c4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 900px) { .grid, .grid.c3, .grid.c4 { grid-template-columns: 1fr; } }
.w { grid-column: span 1; }
.w.full { grid-column: 1 / -1; }
@media (max-width: 900px) { .w, .w.full { grid-column: 1 / -1; } }

.card { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r); overflow: hidden; }
.card > header { display: flex; align-items: center; gap: 9px; padding: 13px 17px; border-bottom: 1px solid var(--rule-soft); flex-wrap: wrap; }
.card > header h2 { font-size: 14.5px; font-weight: 500; }
.card > header .cnt { font-size: 11.5px; font-weight: 500; padding: 1px 8px; border-radius: 999px; background: var(--brand-wash); color: var(--brand); }
.card > header .hint { margin-inline-start: auto; font-size: 12px; color: var(--ink-3); }
.card > header .acts { margin-inline-start: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.card > header .acts + .hint { margin-inline-start: 0; }
.card .body { padding: 6px 17px 15px; }
.card .body.flush { padding: 0; }
.card .body.pad { padding: 15px 17px; }
.linkbtn { border: none; background: none; color: var(--brand); font-size: 12.5px; padding: 0; }
.linkbtn:hover { text-decoration: underline; }

/* ---------- الأزرار والشارات ---------- */
.btn { border: 1px solid var(--brand); background: var(--brand); color: #fff; font-weight: 400; font-size: 13.5px; padding: 7px 16px; border-radius: var(--r); display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.btn:hover { background: var(--brand-deep); border-color: var(--brand-deep); color: #fff; text-decoration: none; }
.btn.line { background: none; color: var(--brand); }
.btn.line:hover { background: var(--brand-wash); color: var(--brand); }
.btn.grey { background: none; border-color: var(--rule); color: var(--ink-2); }
.btn.grey:hover { border-color: var(--ink-3); color: var(--ink); background: none; }
.btn.danger { background: none; border-color: var(--rule); color: var(--red); }
.btn.danger:hover { border-color: var(--red); background: var(--red-wash); color: var(--red); }
.btn.danger.solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn.sm { padding: 4px 12px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.pill { font-size: 11.5px; font-weight: 400; padding: 1px 9px; border-radius: 999px; background: var(--brand-wash); color: var(--brand); white-space: nowrap; display: inline-block; }
.pill.amber { background: var(--amber-wash); color: var(--amber); }
.pill.red { background: var(--red-wash); color: var(--red); }
.pill.green { background: var(--green-wash); color: var(--green); }
.pill.grey { background: var(--mist-2); color: var(--ink-3); }
.pill.line { background: none; border: 1px solid var(--rule); color: var(--ink-3); }
.pills { display: flex; gap: 5px; flex-wrap: wrap; }

/* ---------- القوائم ---------- */
.lst .it { display: flex; align-items: baseline; gap: 11px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--rule-soft); }
.lst .it:last-child { border-bottom: none; }
.lst .it .nm { flex: 1 1 190px; font-size: 13.5px; font-weight: 400; min-width: 0; }
.lst .it .nm small { display: block; font-size: 12px; color: var(--ink-3); font-weight: 300; }
.lst .it .rt { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; }
.lst .it .rt.red { color: var(--red); }
.lst .it .rt.amber { color: var(--amber); }
.lst .it .rt.green { color: var(--green); }
.lst .it .rt.blue { color: var(--brand); }

/* ---------- الجداول ---------- */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: start; font-weight: 500; font-size: 12px; color: var(--ink-3);
  padding: 9px 17px; border-bottom: 1px solid var(--rule); background: var(--paper);
  white-space: nowrap;
}
tbody td { padding: 10px 17px; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--mist); }
td small, th small { display: block; font-size: 11.5px; color: var(--ink-3); font-weight: 300; }
td.end, th.end { text-align: end; }
.nowrap { white-space: nowrap; }

/* ---------- الحقول ---------- */
label { display: block; font-size: 12px; color: var(--ink-3); margin-bottom: 4px; }
.field, input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="datetime-local"], input[type="number"], input[type="search"], select, textarea {
  width: 100%; font-size: 13.5px; border: 1px solid var(--rule); border-radius: var(--r);
  padding: 8px 12px; background: var(--paper); color: var(--ink);
}
textarea { min-height: 84px; resize: vertical; line-height: 1.75; }
input::placeholder, textarea::placeholder { color: var(--ink-4); }
input[type="checkbox"], input[type="radio"] { width: auto; }
.fgrid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px 14px; }
.fgrid.c3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.fgrid .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .fgrid, .fgrid.c3 { grid-template-columns: 1fr; } }
.qrow { display: flex; gap: 7px; flex-wrap: wrap; align-items: flex-end; }
.qrow > * { flex: 1; min-width: 140px; }
.qrow > .none { flex: 0 0 auto; min-width: 0; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--ink-2); margin: 0; }

/* ---------- تفاصيل ---------- */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 2px 18px; }
.facts.top-rule { padding-top: 11px; border-top: 1px solid var(--rule-soft); }
.facts div { min-width: 0; padding-bottom: 7px; }
.facts dt { font-size: 11.5px; color: var(--ink-3); line-height: 1.5; }
.facts dd { margin: 1px 0 0; font-size: 13.5px; font-weight: 400; line-height: 1.45; }
.facts dd small { display: block; font-weight: 300; color: var(--ink-3); font-size: 11.5px; }

.scope { margin-top: 12px; padding: 10px 13px; border-radius: var(--r); background: var(--mist); font-size: 12.5px; color: var(--ink-2); }
.scope b { font-weight: 500; color: var(--ink); }
.note { font-size: 12.5px; color: var(--ink-2); background: var(--mist); padding: 9px 12px; border-radius: var(--r); }
.note.amber { color: var(--amber); background: var(--amber-wash); }
.note.red { color: var(--red); background: var(--red-wash); }
.note.green { color: var(--green); background: var(--green-wash); }
.note.brand { color: var(--ink); background: var(--brand-wash); }
.note + .note { margin-top: 8px; }

.big { font-size: 24px; font-weight: 500; letter-spacing: -.01em; line-height: 1.25; }
.big.red { color: var(--red); }
.big.amber { color: var(--amber); }
.big.green { color: var(--green); }
.sub { font-size: 12px; color: var(--ink-3); }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }

.empty { padding: 22px 14px; text-align: center; color: var(--ink-3); font-size: 13.5px; }
.empty b { display: block; color: var(--ink); font-weight: 500; font-size: 14.5px; margin-bottom: 3px; }

/* ---------- التبويبات ---------- */
.tabs { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--rule); margin-bottom: 14px; }
.tabs a {
  font-size: 13.5px; color: var(--ink-3); padding: 8px 13px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--brand); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 400; }
.tabs a .pill { margin-inline-start: 4px; }

/* ---------- الخط الزمني ---------- */
ol.plan, ul.tl { list-style: none; margin: 0; padding: 0; }
ul.tl li { position: relative; padding: 0 20px 14px 0; border-inline-start: none; }
ul.tl li::before {
  content: ""; position: absolute; inset-inline-start: 4px; top: 7px;
  width: 7px; height: 7px; border-radius: 50%; background: var(--brand-wash);
  border: 1.5px solid var(--brand);
}
ul.tl li::after {
  content: ""; position: absolute; inset-inline-start: 7.2px; top: 17px; bottom: 0;
  width: 1px; background: var(--rule);
}
ul.tl li:last-child::after { display: none; }
ul.tl li .when { font-size: 11.5px; color: var(--ink-3); }
ul.tl li .tx { font-size: 13.5px; }
ul.tl li .tx small { display: block; color: var(--ink-3); font-size: 12px; }

/* ---------- سلسلة المراحل ---------- */
.chain {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 8px 10px; background: var(--mist); border-radius: var(--r); font-size: 12.5px;
}
.chain .ch-h { color: var(--ink-2); margin-inline-end: 4px; }
.ap { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 999px; border: 1px solid var(--rule); background: var(--paper); color: var(--ink-3); }
.ap small { font-size: 11px; opacity: .85; }
.ap.ok { border-color: transparent; background: var(--green-wash); color: var(--green); }
.ap.now { border-color: var(--brand); color: var(--brand); background: var(--brand-wash); }

/* ---------- المساعد الذكي ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 58vh; overflow-y: auto; padding: 4px 2px; }
.msg { padding: 10px 13px; border-radius: var(--r); max-width: 88%; white-space: pre-wrap; font-size: 13.5px; line-height: 1.8; }
.msg.user { background: var(--brand); color: #fff; align-self: flex-start; }
.msg.bot { background: var(--mist); border: 1px solid var(--rule-soft); align-self: flex-end; }
.msg.bot blockquote, .msg.bot .dis { margin: 8px 0 0; padding-top: 7px; border-top: 1px solid var(--rule); font-size: 11.5px; color: var(--ink-3); }
.qgrid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 7px; }
@media (max-width: 560px) { .qgrid { grid-template-columns: 1fr; } }
.qbtn { border: 1px solid var(--rule); background: var(--paper); color: var(--ink); border-radius: var(--r); padding: 9px 12px; font-size: 13px; text-align: start; line-height: 1.45; }
.qbtn:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-wash); }
.qbtn small { display: block; font-size: 11.5px; color: var(--ink-3); }
.qbtn:hover small { color: var(--brand); }

.prose { white-space: pre-wrap; font-size: 13.5px; line-height: 1.9; color: var(--ink-2); }
.prose b, .prose strong { color: var(--ink); font-weight: 500; }

/* ---------- مراجعة الفروقات (ناجز) ---------- */
.diff { border: 1px solid var(--rule); border-radius: var(--r); overflow: hidden; }
.diff > .dh { padding: 9px 13px; background: var(--mist); border-bottom: 1px solid var(--rule); font-size: 12.5px; color: var(--ink-2); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.diff > .dh b { font-weight: 500; color: var(--ink); }
.drow { display: flex; gap: 10px; align-items: flex-start; padding: 9px 13px; border-bottom: 1px solid var(--rule-soft); font-size: 13px; }
.drow:last-child { border-bottom: none; }
.drow input { margin-top: 5px; flex: none; }
.drow .dl { flex: 1; min-width: 0; }
.drow .dl .k { font-size: 11.5px; color: var(--ink-3); }
.drow .old { color: var(--red); text-decoration: line-through; font-size: 12.5px; }
.drow .new { color: var(--green); }
.drow .arrow { color: var(--ink-4); }

/* ---------- الرسوم البسيطة ---------- */
.bar { display: flex; height: 9px; border-radius: 2px; overflow: hidden; margin: 12px 0 10px; background: var(--mist-2); }
.bar i { display: block; height: 100%; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.prog { display: inline-block; width: 46px; height: 5px; border-radius: 3px; background: var(--mist-2); overflow: hidden; vertical-align: middle; margin-inline-end: 6px; }
.prog i { display: block; height: 100%; background: var(--brand); }

/* ---------- التنبيهات العائمة ---------- */
.flash { max-width: 1240px; margin: 14px auto -4px; padding: 0 22px; }
.flash .msgbox { padding: 10px 14px; border-radius: var(--r); font-size: 13.5px; }
.flash .msgbox.ok { background: var(--green-wash); color: var(--green); }
.flash .msgbox.err { background: var(--red-wash); color: var(--red); }

footer.pg { max-width: 1240px; margin: 0 auto; padding: 0 22px 30px; font-size: 12px; color: var(--ink-4); display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
footer.pg .own { display: inline-flex; align-items: center; gap: 7px; margin-inline-start: auto; }
footer.pg .own img { height: 22px; width: auto; display: block; opacity: .85; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) footer.pg .own img { filter: brightness(1.7) saturate(1.05); } }
:root[data-theme="dark"] footer.pg .own img { filter: brightness(1.7) saturate(1.05); }

@media (max-width: 760px) {
  .top .in { padding: 10px 16px; }
  .summary .in { padding: 0 16px 10px; }
  main { padding: 14px 16px 50px; }
  .flash { padding: 0 16px; }
  .top .right { margin-inline-start: 0; width: 100%; }
  thead th, tbody td { padding: 9px 12px; }
}

/* ---- إضافات المرحلة ١ */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.narrow { width: min(420px, 100%); }
.center { display: flex; justify-content: center; margin-bottom: 20px; }
.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.btn.wide { width: 100%; justify-content: center; }
.btn.red { background: #b42318; border-color: #b42318; }
.inline { display: inline; }
.inline-row { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ltr { direction: ltr; unicode-bidi: isolate; text-align: start; font-family: Consolas, monospace; font-size: 12px; }
.token { direction: ltr; text-align: left; background: var(--brand-wash); padding: 10px; border-radius: var(--r); word-break: break-all; }
.narrow-card { max-width: 620px; }
.pad { padding: 14px; }
table.compact td, table.compact th { padding: 5px 8px; font-size: 12.5px; }
.msgbox { padding: 8px 12px; border-radius: var(--r); margin-bottom: 8px; }
.msgbox.ok { background: #e7f6ec; color: #1b5e20; }
.msgbox.err { background: #fdecea; color: #8a1c13; }
.note { padding: 8px 12px; border-radius: var(--r); margin-bottom: 12px; }
.note.red { background: #fdecea; color: #8a1c13; }
.note.amber { background: #fff4e0; color: #7a4b00; }
@media (max-width: 720px) { .grid, .grid2 { grid-template-columns: 1fr; } }

/* المرحلة ٦: نماذج مطوية ومؤشرات */
details > summary.btn { list-style: none; display: inline-block; cursor: pointer; }
details > summary.btn::-webkit-details-marker { display: none; }
details[open] > form { margin-top: 8px; min-width: 260px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r); padding: 10px 12px; }
.kpi b { display: block; font-size: 20px; }
.kpi span { font-size: 12px; color: var(--ink-2); }
