/* =====================================================================
   تمكين — نظام التصميم الأساسي (مشترك بين الواجهة العامة ولوحة التحكم)
   الألوان مستخرجة من الشعارات: نيلي (#2B3689) وبنفسجي (#A22680)
   ===================================================================== */

/* خط Tajawal مستضاف محلياً (رخصة OFL — assets/fonts/OFL.txt) */
@font-face { font-family: "Tajawal"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/Tajawal-Regular.woff") format("woff"); }
@font-face { font-family: "Tajawal"; font-weight: 500; font-style: normal; font-display: swap; src: url("../fonts/Tajawal-Medium.woff") format("woff"); }
@font-face { font-family: "Tajawal"; font-weight: 700; font-style: normal; font-display: swap; src: url("../fonts/Tajawal-Bold.woff") format("woff"); }
@font-face { font-family: "Tajawal"; font-weight: 800; font-style: normal; font-display: swap; src: url("../fonts/Tajawal-ExtraBold.woff") format("woff"); }

:root {
  /* الموقع نهاري دائماً، حتى لو كان المتصفح أو النظام في الوضع الليلي */
  color-scheme: light only;
  --indigo: #2b3689;
  --indigo-600: #333fa0;
  --indigo-800: #1f276a;
  --indigo-50: #eef0fa;
  --indigo-100: #dfe3f5;
  --plum: #a22680;
  --plum-50: #f8ecf4;

  --ink: #1a1f36;
  --ink-2: #3b4160;
  --muted: #666c85;
  --faint: #9398ad;
  --line: #e3e6ef;
  --line-2: #eef0f5;
  --paper: #f5f6fa;
  --surface: #ffffff;

  --ok: #1f6f4e;     --ok-bg: #eaf5ef;
  --warn: #946007;   --warn-bg: #fbf3e2;
  --bad: #a83232;    --bad-bg: #fbeeee;
  --info: #2b3689;   --info-bg: #eef0fa;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --shadow-1: 0 1px 2px rgba(26, 31, 54, .04), 0 1px 1px rgba(26, 31, 54, .03);
  --shadow-2: 0 10px 30px -12px rgba(26, 31, 54, .12), 0 2px 6px rgba(26, 31, 54, .04);
  --ring: 0 0 0 4px rgba(43, 54, 137, .14);

  --font: "Tajawal", "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img { max-width: 100%; display: block; }
a { color: var(--indigo); text-decoration: none; }
a:hover { color: var(--indigo-800); }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; color: var(--ink); }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--indigo); outline-offset: 2px; }

.ltr { direction: ltr; unicode-bidi: isolate; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.icon { width: 1.15em; height: 1.15em; flex: none; }

/* ─────────────── الأزرار ─────────────── */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink);
  --btn-bd: var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: .55rem 1.1rem;
  border: 1px solid var(--btn-bd); border-radius: var(--r);
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 700; font-size: .95rem; line-height: 1.2;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color .18s var(--ease), border-color .18s var(--ease), box-shadow .18s var(--ease), transform .12s var(--ease), color .18s;
}
.btn:hover { --btn-bd: #cfd3e2; color: var(--btn-fg); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn[disabled], .btn.is-loading { cursor: not-allowed; opacity: .75; }

.btn-primary { --btn-bg: var(--indigo); --btn-fg: #fff; --btn-bd: var(--indigo); }
.btn-primary:hover { --btn-bg: var(--indigo-800); --btn-bd: var(--indigo-800); }
.btn-soft { --btn-bg: var(--indigo-50); --btn-fg: var(--indigo); --btn-bd: transparent; }
.btn-soft:hover { --btn-bg: var(--indigo-100); --btn-bd: transparent; }
.btn-danger { --btn-bg: var(--bad); --btn-fg: #fff; --btn-bd: var(--bad); }
.btn-danger:hover { --btn-bg: #8e2828; --btn-bd: #8e2828; }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--ink-2); }
.btn-ghost:hover { --btn-bg: var(--line-2); --btn-bd: transparent; }
.btn-sm { min-height: 36px; padding: .35rem .8rem; font-size: .88rem; border-radius: var(--r-sm); }
.btn-lg { min-height: 54px; padding: .8rem 1.6rem; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn-icon { width: 36px; min-height: 36px; padding: 0; border-radius: var(--r-sm); }

.spinner {
  width: 1.1em; height: 1.1em; border-radius: 50%;
  border: 2px solid currentColor; border-inline-end-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─────────────── الحقول ─────────────── */
.field { display: flex; flex-direction: column; gap: .4rem; min-width: 0; }
.field-label { font-weight: 700; font-size: .93rem; color: var(--ink-2); }
.field-label .req { color: var(--plum); margin-inline-start: .15rem; }
.field-label .opt { color: var(--faint); font-weight: 500; font-size: .82rem; margin-inline-start: .3rem; }
.field-hint { font-size: .82rem; color: var(--muted); }
.field-error { font-size: .84rem; color: var(--bad); display: flex; gap: .35rem; align-items: flex-start; }
.field-error:empty { display: none; }

.control { position: relative; }
.control > .icon {
  position: absolute; inset-inline-start: .9rem; top: 50%; transform: translateY(-50%);
  color: var(--faint); pointer-events: none; transition: color .18s;
}
.control.is-textarea > .icon { top: 1.05rem; transform: none; }

.input, .select, .textarea {
  width: 100%; min-height: 48px;
  padding: .6rem .95rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r);
  font-size: 1rem; line-height: 1.5;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease), background-color .18s;
  appearance: none; -webkit-appearance: none;
}
.control > .icon ~ .input,
.control > .icon ~ .textarea { padding-inline-start: 2.75rem; }
.textarea { min-height: 84px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: #a5a9bb; }
.input:hover, .select:hover, .textarea:hover { border-color: #cdd1df; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--indigo); box-shadow: var(--ring); }
.control:focus-within > .icon { color: var(--indigo); }
.select {
  padding-inline-end: 2.4rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666c85' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-size: 16px; background-position: left .85rem center;
}
input[type="date"].input, input[type="time"].input { direction: rtl; text-align: right; }
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .55; }

.field.has-error .input, .field.has-error .textarea, .field.has-error .select { border-color: #d9a3a3; background: #fffafa; }
.field.has-error .control > .icon { color: var(--bad); }
.field.is-valid .input { border-color: #b9d8c8; }

/* ─────────────── المفتاح Toggle ─────────────── */
.switch { position: relative; display: inline-flex; align-items: center; gap: .75rem; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative; width: 46px; height: 26px; flex: none;
  background: #cfd3e0; border-radius: 99px; transition: background-color .2s var(--ease);
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18); transition: transform .22s var(--ease);
}
.switch input:checked + .switch-track { background: var(--indigo); }
.switch input:checked + .switch-track::after { transform: translateX(-20px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring); }
.switch-text { font-weight: 700; }

/* ─────────────── التنبيهات ─────────────── */
.alert {
  display: flex; gap: .7rem; align-items: flex-start;
  padding: .85rem 1rem; border-radius: var(--r);
  border: 1px solid transparent; font-size: .95rem; line-height: 1.6;
}
.alert .icon { margin-top: .2rem; }
.alert-success { background: var(--ok-bg); color: var(--ok); border-color: #cfe7da; }
.alert-warning { background: var(--warn-bg); color: var(--warn); border-color: #f0dfb9; }
.alert-error   { background: var(--bad-bg); color: var(--bad); border-color: #f0d2d2; }
.alert-info    { background: var(--info-bg); color: var(--info); border-color: var(--indigo-100); }

/* ─────────────── الشارات ─────────────── */
.badge {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .18rem .6rem; border-radius: 99px;
  font-size: .8rem; font-weight: 700; line-height: 1.5; white-space: nowrap;
  background: var(--line-2); color: var(--ink-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-new      { background: var(--indigo-50); color: var(--indigo); }
.badge-reviewed { background: var(--warn-bg); color: var(--warn); }
.badge-accepted { background: var(--ok-bg); color: var(--ok); }
.badge-rejected { background: var(--bad-bg); color: var(--bad); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.dot-live { box-shadow: 0 0 0 0 currentColor; animation: pulse 2.4s var(--ease) infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(31, 111, 78, .35); }
  70% { box-shadow: 0 0 0 7px rgba(31, 111, 78, 0); }
  100% { box-shadow: 0 0 0 0 rgba(31, 111, 78, 0); }
}

/* ─────────────── النافذة المنبثقة ─────────────── */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 1rem;
  background: rgba(20, 24, 44, .42);
  opacity: 0; visibility: hidden; transition: opacity .2s var(--ease), visibility .2s;
}
.modal.is-open { opacity: 1; visibility: visible; }
.modal-dialog {
  width: min(440px, 100%);
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: 0 30px 60px -20px rgba(20, 24, 44, .35);
  padding: 1.6rem; transform: translateY(8px) scale(.98); transition: transform .22s var(--ease);
}
.modal.is-open .modal-dialog { transform: none; }
.modal-icon {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  background: var(--bad-bg); color: var(--bad); margin-bottom: 1rem;
}
.modal-icon.warn { background: var(--warn-bg); color: var(--warn); }
.modal-icon .icon { width: 22px; height: 22px; }
.modal-title { font-size: 1.15rem; font-weight: 800; margin-bottom: .4rem; }
.modal-text { color: var(--muted); font-size: .95rem; }
.modal-actions { display: flex; gap: .6rem; margin-top: 1.4rem; justify-content: flex-start; flex-wrap: wrap; }

/* ─────────────── حالات فارغة ─────────────── */
.empty {
  text-align: center; padding: 3rem 1.5rem; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: .6rem;
}
.empty-icon {
  width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  background: var(--line-2); color: var(--faint); margin-bottom: .4rem;
}
.empty-icon .icon { width: 26px; height: 26px; }
.empty h3 { font-size: 1.05rem; color: var(--ink-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

.modal-icon .ic-warn { display: none; }
.modal-icon.warn .ic-danger { display: none; }
.modal-icon.warn .ic-warn { display: block; }

/* ─────────────── حقل ببادئة ثابتة (المحافظة) ─────────────── */
.control.has-prefix {
  display: flex; align-items: stretch;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  overflow: hidden;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.control.has-prefix:hover { border-color: #cdd1df; }
.control.has-prefix:focus-within { border-color: var(--indigo); box-shadow: var(--ring); }
.input-prefix {
  display: flex; align-items: center; gap: .4rem; flex: none;
  padding-inline: .9rem .8rem;
  background: var(--paper); border-inline-end: 1px solid var(--line);
  color: var(--ink-2); font-weight: 700; font-size: .95rem; white-space: nowrap;
  cursor: default; user-select: none;
}
.input-prefix .icon { color: var(--indigo); }
.control.has-prefix .input { flex: 1; min-width: 0; border: 0; border-radius: 0; box-shadow: none; background: transparent; }
.control.has-prefix .input:focus { box-shadow: none; }
.field.has-error .control.has-prefix { border-color: #d9a3a3; background: #fffafa; }
.field.has-error .control.has-prefix .input { background: transparent; }
