/* =====================================================================
   هوية الحرمين — نظام التصميم
   ===================================================================== */
@font-face { font-family: 'Haramain Arabic'; src: url('/assets/arabic-regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Haramain Arabic'; src: url('/assets/arabic-medium.ttf') format('truetype'); font-weight: 500 600; font-display: swap; }
@font-face { font-family: 'Haramain Arabic'; src: url('/assets/arabic-bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }

:root {
  /* هوية النسخة الأولى: الداكن هو الأصل، والفاتح اختياري */
  --gold: #bc9661;
  --gold-2: #b29c65;
  --ink: #1a232d;
  --panel: #1f2a37;
  --bg: #1a232d;
  --surface: #222e3b;
  --soft: #2c3846;
  --text: #ffffff;
  --muted: #c0c7ce;
  --border: #44505c;
  --field: #1a232d;
  --accent-text: #d5bd87;
  --ok: #7fc79a; --ok-bg: #1f3a2b;
  --warn: #f0c27a; --warn-bg: #3d2f18;
  --bad: #ff9a94; --bad-bg: #43201f;
  --info-bg: #2c3846;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow: none;
  --font: 'Haramain Arabic', 'IBM Plex Sans Arabic', -apple-system, 'Segoe UI', Tahoma, sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #ffffff; --surface: #ffffff; --soft: #f5f4f1; --text: #1f2a37; --muted: #62686f;
  --border: #d8dadd; --field: #ffffff; --accent-text: #7b5d31;
  --ok: #2d6846; --ok-bg: #e4efe7; --warn: #9a5b12; --warn-bg: #f8ecd9; --bad: #a3322b; --bad-bg: #f7e1df; --info-bg: #eef0f3;
  --shadow: 0 1px 2px rgb(16 21 27 / 6%), 0 4px 16px rgb(16 21 27 / 5%);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.8 var(--font); }
img { max-width: 100%; }
a { color: var(--accent-text); }
h1, h2, h3, h4 { line-height: 1.35; margin: 0 0 .4em; font-weight: 700; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.1rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.skip { position: absolute; inset-inline-start: -999px; top: 8px; background: var(--gold); color: #fff; padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip:focus { inset-inline-start: 8px; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.boot { min-height: 100vh; display: grid; place-items: center; background: var(--ink); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- الترويسة (شعار الهيئة | شعار الرئاسة، ثم اسم المنصة) ---------- */
.topbar { background: var(--ink) url('/assets/pattern.png') center; color: #fff; border-bottom: 1px solid #b29c6566; }
.topbar .inner { max-width: 1440px; margin: 0 auto; min-height: 74px; padding: 10px 24px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 22px; color: #fff; text-decoration: none; }
.identity-logos { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.identity-logos img { object-fit: contain; filter: brightness(0) invert(1); }
.identity-logos .authority { width: 94px; height: 50px; }
.identity-logos .presidency { width: 75px; height: 50px; }
.identity-logos .sep { display: block; width: 1px; height: 42px; background: #b5b6b2; }
.brand-copy { border-inline-start: 1px solid #b29c6570; padding-inline-start: 22px; }
.brand-copy b { display: block; font-size: 1.15rem; color: #fff; line-height: 1.5; }
.brand-copy span { display: block; font-size: .875rem; color: #d5bd87; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .9rem; text-align: end; }
.topbar .who small { display: block; color: #d1c8b5; }
.topbar .btn { border-color: #b29c6566; color: #fff; background: #ffffff0c; border-radius: 99px; }
.topbar .btn:hover { background: rgb(255 255 255 / 10%); }
@media (max-width: 800px) {
  .topbar .inner { padding: 12px 18px; gap: 12px; }
  .brand { gap: 12px; }
  .brand-copy { border: 0; padding: 0; }
  .brand-copy b { font-size: 1rem; }
  .identity-logos .authority { width: 83px; height: 45px; }
  .identity-logos .presidency { width: 67px; height: 45px; }
  .topbar .who { display: none; }
}
@media (max-width: 520px) { .brand-copy span { display: none; } }

/* ---------- التذييل ---------- */
footer.site { background: var(--ink) url('/assets/pattern.png') center; color: #c9c5ba; border-top: 1px solid #b29c654d; font-size: .875rem; }
footer.site .inner { max-width: 1440px; margin: 0 auto; padding: 20px 24px; display: flex; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; }

.env-flag { background: var(--warn-bg); color: var(--warn); text-align: center; font-size: .8rem; padding: 4px 12px; }

/* ---------- التخطيط: قائمة جانبية بعرض 225 ---------- */
.layout { max-width: 1488px; margin: 0 auto; display: grid; grid-template-columns: 225px minmax(0, 1fr); align-items: stretch; min-height: calc(100vh - 150px); }
.sidenav { background: var(--bg); border-inline-end: 1px solid var(--border); padding: 22px 12px; display: flex; flex-direction: column; gap: 4px; }
.sidenav a { display: block; padding: 10px 14px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: .9375rem; border-inline-start: 3px solid transparent; }
.sidenav a:hover { background: var(--soft); }
.sidenav a[aria-current="page"] { background: #bc966126; color: var(--accent-text); border-inline-start-color: var(--gold); font-weight: 600; }
.layout > main { padding: 28px; }
main { min-width: 0; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .grow { flex: 1; min-width: 220px; }
.eyebrow { color: var(--accent-text); font-size: .85rem; font-weight: 600; margin-bottom: 2px; }
@media (max-width: 650px) {
  .layout { grid-template-columns: 1fr; }
  .sidenav { flex-direction: row; flex-wrap: wrap; gap: 5px; padding: 12px; border-inline-end: 0; border-bottom: 1px solid var(--border); }
  .sidenav a { flex: 1 1 130px; font-size: .875rem; text-align: center; }
  .layout > main { padding: 18px 14px; }
}

/* ---------- البطاقات ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
:is(.grid, .grid-2, .kpis, .portal-grid) > .card { margin-top: 0; }
.card h3 { margin-bottom: 10px; }
.stack { display: grid; gap: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--gold); border-radius: var(--radius); padding: 14px 16px; }
.kpi b { display: block; font-size: 1.8rem; line-height: 1.2; color: var(--accent-text); }
.kpi span { font-weight: 600; }
.kpi small { display: block; color: var(--muted); font-size: .8rem; }
.kpi.bad { border-top-color: var(--bad); } .kpi.bad b { color: var(--bad); }
.kpi.warn { border-top-color: var(--warn); }
.kpi.ok { border-top-color: var(--ok); }

/* ---------- الأزرار والحقول ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 9px 18px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--soft); border-color: var(--gold); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #1a232d; }
.btn.primary:hover { background: #cfad7d; }
.btn.pill { border-radius: 99px; }
.btn.danger { color: var(--bad); border-color: currentColor; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 36px; padding: 4px 14px; font-size: .875rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
label.field { display: grid; gap: 6px; font-weight: 600; font-size: .92rem; }
label.field > small { font-weight: 400; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--field); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 12px; min-height: 46px; width: 100%; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); outline: 2px solid color-mix(in srgb, var(--gold) 35%, transparent); }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--gold); }
.check { display: inline-flex; gap: 8px; align-items: center; font-weight: 500; cursor: pointer; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 0; }
legend { font-weight: 700; padding: 0 6px; }
.err { color: var(--bad); font-size: .88rem; }
.form-errors { background: var(--bad-bg); color: var(--bad); border-radius: var(--radius-sm); padding: 10px 14px; }
.form-errors ul { margin: 0; padding-inline-start: 18px; }

/* ---------- الشارات والجداول ---------- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 6px; font-size: .8rem; font-weight: 600; background: var(--info-bg); color: var(--text); white-space: nowrap; }
.badge.gold { background: #bc96612b; color: var(--accent-text); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .82rem; color: var(--muted); font-weight: 600; background: var(--soft); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td .sub { display: block; color: var(--muted); font-size: .82rem; }
/* الجداول على الشاشات الضيقة: كل صف بطاقة، وكل خلية معنونة */
@media (max-width: 720px) {
  table.responsive thead { display: none; }
  table.responsive tr { display: block; border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.responsive td { display: grid; grid-template-columns: 110px 1fr; gap: 8px; border: 0; padding: 4px 12px; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; }
}
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: 4px; }

/* ---------- شريط المراحل ---------- */
.stages { display: flex; gap: 6px; flex-wrap: wrap; }
.stage { flex: 1 1 120px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; background: var(--soft); font-size: .85rem; min-width: 110px; }
.stage b { display: block; }
.stage .who { color: var(--muted); }
.stage.done { background: var(--ok-bg); border-color: transparent; }
.stage.active { background: var(--surface); border: 2px solid var(--gold); }
.stage.late .when { color: var(--bad); font-weight: 600; }
.progress { height: 8px; border-radius: 999px; background: var(--soft); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--gold); }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; }
.timer.late { color: var(--bad); }
.timer.soon { color: var(--warn); }

/* ---------- المحرر ---------- */
.editor { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--field); }
.editor .tools { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; border-bottom: 1px solid var(--border); background: var(--soft); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.editor .tools button, .editor .tools select { min-height: 32px; padding: 2px 8px; font-size: .85rem; width: auto; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-family: inherit; }
.editor .area { min-height: 260px; padding: 14px; outline: none; line-height: 1.9; font-size: 1.02rem; }
.editor .area:empty::before { content: attr(data-placeholder); color: var(--muted); }
.editor.readonly .area { background: var(--soft); }
.source-text { background: var(--soft); border-radius: var(--radius-sm); padding: 14px; line-height: 2; max-height: 70vh; overflow: auto; }
.workspace { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 980px) { .workspace { grid-template-columns: 1fr; } }

/* ---------- النوافذ والتنبيهات ---------- */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / 35%); }
dialog::backdrop { background: rgb(16 21 27 / 55%); }
dialog .dlg-body { padding: 20px; max-height: 75vh; overflow: auto; }
dialog .dlg-foot { display: flex; gap: 8px; justify-content: flex-start; padding: 12px 20px; border-top: 1px solid var(--border); background: var(--soft); }
#toasts { position: fixed; inset-inline-start: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow); border-inline-start: 4px solid var(--gold); animation: pop .2s ease-out; }
.toast.bad { border-inline-start-color: #ff6b61; }
.toast.ok { border-inline-start-color: #5fbf85; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- الموقع العام (تصميم النسخة الأولى) ---------- */
.wrap { max-width: 1280px; margin: 0 auto; padding-inline: 28px; }
.hero { padding: 28px 0 8px; }
.hero .eyebrow { color: var(--accent-text); font-weight: 700; font-size: 1rem; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: .3rem 0; }
.hero p { color: var(--muted); max-width: 720px; margin: 0; }
.tabs { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0 28px; }
.tabs button { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 9px; padding: 11px 18px; font: inherit; cursor: pointer; min-height: 44px; }
.tabs button[aria-selected="true"] { background: var(--gold); border-color: var(--gold); color: var(--ink); font-weight: 700; }
.public { padding-bottom: 56px; }
.public .section-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.public .section-head h2 { font-size: 1.75rem; margin: 0; }
.public .section-head p { margin: 0; color: var(--muted); }
.public .card { background: linear-gradient(145deg, var(--surface), var(--panel)); border-top: 3px solid var(--gold); border-radius: 14px; padding: 22px; }
:root[data-theme="light"] .public .card { background: var(--surface); }
.public .card h3 { font-size: 1.35rem; margin: 4px 0; }
.live-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #e65353; margin-inline-end: 7px; box-shadow: 0 0 0 5px #e6535322; }
.video { position: relative; aspect-ratio: 16 / 9; background: #0d141c; border-radius: 10px; overflow: hidden; margin-top: 16px; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.lang-pills { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.lang-pills button { border: 1px solid var(--border); background: var(--soft); color: var(--text); border-radius: 999px; padding: 7px 13px; font: inherit; font-size: .9rem; cursor: pointer; }
.lang-pills button:hover { border-color: var(--gold); color: var(--accent-text); }
.lang-pills button[aria-pressed="true"] { background: var(--gold); border-color: var(--gold); color: var(--ink); font-weight: 700; }
.translation-text { background: #fff; color: #222b37; border-radius: var(--radius-sm); padding: 16px; line-height: 1.9; }
@media (max-width: 760px) {
  .wrap { padding-inline: 16px; }
  .tabs { display: grid; grid-template-columns: repeat(2, 1fr); }
  .public .section-head { display: block; }
  .public .card { padding: 17px; }
}

/* ---------- صفحة الوجهات «اختر وجهتك» ---------- */
.portals { max-width: 1280px; margin: 0 auto; padding: 40px 28px 70px; }
.portal-title { text-align: center; margin-bottom: 30px; }
.portal-title h1 { font-size: 1.8rem; margin: 6px 0; }
.portal-title p { color: var(--muted); }
.portal-grid { display: grid; gap: 20px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.portal-card { display: flex; flex-direction: column; gap: 14px; padding: 26px; border: 1px solid var(--border); border-top: 1px solid #b29c65; border-radius: 10px;
  background: linear-gradient(155deg, #ffffff08, transparent), var(--surface); }
.portal-card > .num { color: var(--accent-text); font-size: 1.4rem; line-height: 1.2; font-weight: 700; }
.portal-card h2 { font-size: 1.4rem; margin: 0; }
.portal-card .for { color: var(--muted); font-size: .875rem; }
.portal-card p { flex: 1; margin: 0; }
.portal-card .btn { border-radius: 99px; width: 100%; }
.portals .fine { text-align: center; color: var(--muted); font-size: .875rem; margin-top: 24px; }
@media (max-width: 900px) { .portal-grid { grid-template-columns: 1fr; } .portals { padding: 28px 16px; } }

/* ---------- شريط مساحة العمل ---------- */
.workspace-banner { background: var(--panel) url('/assets/pattern.png') center; border: 1px solid #b29c6550; color: #fff; border-radius: 10px; padding: 18px 22px; margin-bottom: 18px; }
.workspace-banner :is(h1, h2) { color: #fff; margin: 0; }
.workspace-banner .eyebrow { color: #d5bd87; }
.workspace-banner .btn { color: #fff; border-color: #b29c6566; background: #ffffff0c; }
.workspace-banner .sub, .workspace-banner .muted { color: #d1c8b5; }

/* ---------- المصادقة ---------- */
.auth-wrap { min-height: calc(100vh - 80px); display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(540px, 100%); border-top: 3px solid var(--gold-2); padding: 28px; }
.auth-card.wide { width: min(720px, 100%); }

/* ---------- الطباعة (حفظ PDF) ---------- */
@media print {
  .topbar, .sidenav, footer.site, .no-print, #toasts, .env-flag { display: none !important; }
  body { background: #fff; color: #000; }
  .layout { display: block; padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .print-doc { font-size: 13pt; line-height: 1.9; }
}
