/* ============== نظام التصميم المشترك (فاتح / داكن) ============== */
:root {
  color-scheme: light;
  --bg: #f6f7fb; --bg-2: #eef0f7; --surface: #ffffff; --surface-2: #f8f9fc; --elev: #ffffff;
  --line: #e4e7ef; --line-2: #d5d9e4;
  --text: #0f1222; --text-2: #4a4f66; --muted: #7c8199;
  --brand: #5b4bff; --brand-2: #00b4d8; --brand-ink: #ffffff;
  --grad: linear-gradient(135deg, #5b4bff 0%, #8b5cf6 45%, #00b4d8 100%);
  --good: #0f9d6b; --good-bg: #e6f7ef; --warn: #b26a00; --warn-bg: #fff4e0; --bad: #d63a3a; --bad-bg: #fdecec;
  --flash: #ff5a1f; --flash-2: #ff2e7e; --flash-bg: #fff1ea;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow: 0 8px 30px rgba(16, 24, 40, .08);
  --shadow-lg: 0 24px 60px rgba(16, 24, 40, .16);
  --radius: 16px; --radius-sm: 10px;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #07091a; --bg-2: #0c0f24; --surface: #10132b; --surface-2: #151935; --elev: #191d3d;
    --line: #232848; --line-2: #2e3459;
    --text: #eef0ff; --text-2: #b7bcda; --muted: #8288ab;
    --brand: #7c6cff; --brand-2: #22d3ee;
    --good: #34d399; --good-bg: rgba(52, 211, 153, .12); --warn: #fbbf24; --warn-bg: rgba(251, 191, 36, .12); --bad: #f87171; --bad-bg: rgba(248, 113, 113, .12);
    --flash-bg: rgba(255, 90, 31, .12);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 10px 30px rgba(0, 0, 0, .35); --shadow-lg: 0 30px 80px rgba(0, 0, 0, .55);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #07091a; --bg-2: #0c0f24; --surface: #10132b; --surface-2: #151935; --elev: #191d3d;
  --line: #232848; --line-2: #2e3459;
  --text: #eef0ff; --text-2: #b7bcda; --muted: #8288ab;
  --brand: #7c6cff; --brand-2: #22d3ee;
  --good: #34d399; --good-bg: rgba(52, 211, 153, .12); --warn: #fbbf24; --warn-bg: rgba(251, 191, 36, .12); --bad: #f87171; --bad-bg: rgba(248, 113, 113, .12);
  --flash-bg: rgba(255, 90, 31, .12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 10px 30px rgba(0, 0, 0, .35); --shadow-lg: 0 30px 80px rgba(0, 0, 0, .55);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'IBM Plex Sans Arabic', 'Cairo', system-ui, 'Segoe UI', Tahoma, sans-serif;
  font-size: 15px; line-height: 1.6; -webkit-font-smoothing: antialiased;
  transition: background .3s, color .3s;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { line-height: 1.3; margin: 0; }
.num, .money { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* أزرار */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
  padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--text); transition: transform .15s, box-shadow .2s, background .2s, border-color .2s, opacity .2s;
}
.btn:hover { border-color: var(--brand); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 8px 20px rgba(91, 75, 255, .3); }
.btn.primary:hover { box-shadow: 0 10px 28px rgba(91, 75, 255, .45); }
.btn.flash { background: linear-gradient(135deg, var(--flash), var(--flash-2)); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.icon { padding: 9px; width: 40px; height: 40px; }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; flex: none; }

/* حقول */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.input, select.input, textarea.input {
  font: inherit; width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--text); outline: none; transition: border-color .2s, box-shadow .2s;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(91, 75, 255, .15); }
textarea.input { min-height: 90px; resize: vertical; }

/* شارات */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.flash { background: linear-gradient(135deg, var(--flash), var(--flash-2)); color: #fff; border-color: transparent; }
.badge.brand { background: rgba(91, 75, 255, .12); color: var(--brand); border-color: transparent; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }

/* نافذة منبثقة */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(5, 8, 20, .55); backdrop-filter: blur(6px); opacity: 0; pointer-events: none; transition: opacity .25s; }
.modal.open { opacity: 1; pointer-events: auto; }
.modal-box { width: min(640px, 100%); max-height: 92vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-lg); transform: translateY(20px) scale(.98); transition: transform .3s cubic-bezier(.2, .8, .2, 1); }
.modal.open .modal-box { transform: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h3 { font-size: 18px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-start; padding: 16px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* إشعارات */
.toasts { position: fixed; z-index: 200; top: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 14px; background: var(--elev); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow-lg); font-weight: 600; font-size: 14px; animation: toastIn .4s cubic-bezier(.2, .8, .2, 1); pointer-events: auto; }
.toast.good { border-color: var(--good); }
.toast.bad { border-color: var(--bad); }
.toast.flash { border-color: var(--flash); }
.toast.out { animation: toastOut .3s forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-16px) scale(.96); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-12px); } }

/* جداول */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 12px 14px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { font-size: 12px; font-weight: 700; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
.table tr:hover td { background: var(--surface-2); }

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 12px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-top-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

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