/* منصاتي | Mansati — نظام التصميم (RTL أولًا، فاتح/داكن، متجاوب) */
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 400; font-display: swap; src: url(../fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 500; font-display: swap; src: url(../fonts/ibm-plex-sans-arabic-arabic-500-normal.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 600; font-display: swap; src: url(../fonts/ibm-plex-sans-arabic-arabic-600-normal.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 700; font-display: swap; src: url(../fonts/ibm-plex-sans-arabic-arabic-700-normal.woff2) format("woff2"); }

:root {
  --primary: #4338CA;
  --accent: #0D9488;
  --on-primary: #fff;

  --bg: #F5F6FB;
  --surface: #FFFFFF;
  --surface-2: #F0F2F9;
  --text: #0F172A;
  --muted: #536078;
  --border: #E1E6F0;
  --border-strong: #C9D1E2;
  --ring: color-mix(in srgb, var(--primary) 45%, transparent);

  --ok: #15803D; --ok-bg: #E7F6EC;
  --warn: #A16207; --warn-bg: #FEF3C7;
  --danger: #B91C1C; --danger-bg: #FDE8E8;
  --info: var(--primary); --info-bg: color-mix(in srgb, var(--primary) 12%, transparent);

  --shadow-sm: 0 1px 2px rgb(15 23 42 / .06);
  --shadow: 0 6px 24px rgb(15 23 42 / .08);
  --shadow-lg: 0 20px 60px rgb(15 23 42 / .22);

  --r-sm: 8px; --r: 12px; --r-lg: 18px;
  --sidebar: 264px;
  --font: "IBM Plex Sans Arabic", "Geeza Pro", "Segoe UI", Tahoma, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --primary-shade: color-mix(in srgb, var(--primary) 62%, white);
  --bg: #0A0F1E;
  --surface: #121A2E;
  --surface-2: #19223B;
  --text: #E8ECF8;
  --muted: #A3AFC9;
  --border: #25314F;
  --border-strong: #34436A;
  --ok: #4ADE80; --ok-bg: #12301F;
  --warn: #FBBF24; --warn-bg: #33270B;
  --danger: #F87171; --danger-bg: #3A1618;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
  --shadow: 0 6px 24px rgb(0 0 0 / .4);
  --shadow-lg: 0 20px 60px rgb(0 0 0 / .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 400 16px/1.65 var(--font); -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.35; font-weight: 600; }
p { margin: 0; }
a { color: var(--link, var(--primary)); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:root[data-theme="dark"] { --link: var(--primary-shade); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: isolate; text-align: start; }
.mono { font-family: var(--mono); font-size: .88em; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 6px; }

svg.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 16px; height: 16px; }
svg.i.lg { width: 26px; height: 26px; }

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: var(--r); border: 1px solid transparent;
  background: var(--primary); color: var(--on-primary); font-weight: 600; text-decoration: none;
  transition: background-color .18s, border-color .18s, transform .12s, box-shadow .18s;
}
:root[data-theme="dark"] .btn:not(.ghost):not(.danger):not(.soft) { background: var(--primary-shade); color: #0A0F1E; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn.ghost:hover { background: var(--surface-2); filter: none; }
.btn.soft { background: var(--info-bg); color: var(--link, var(--primary)); }
.btn.danger { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .btn.danger { background: #DC2626; color: #fff; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn.icon { width: 44px; padding: 0; }
.btn.icon.sm { width: 36px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ---------- النماذج ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > label, .field > .lbl { font-weight: 500; font-size: .93rem; }
.hint { font-size: .85rem; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 9px 14px; border-radius: var(--r);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { min-height: 88px; resize: vertical; }
.input:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border-strong)); }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.field-err { color: var(--danger); font-size: .85rem; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1 1 200px; }
input[type="color"].input { padding: 4px; height: 44px; cursor: pointer; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

/* ---------- البطاقات والشارات ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.card.pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2, .card-head h3 { font-size: 1.05rem; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: .8rem; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; line-height: 1.7;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: var(--info-bg); color: var(--link, var(--primary)); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- الهيكل ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 20px 14px;
  background: var(--surface); border-inline-end: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 18px; text-decoration: none; color: var(--text); }
.brand .logo { width: 42px; height: 42px; border-radius: 12px; flex: none; display: grid; place-items: center; overflow: hidden; }
.brand img.logo { object-fit: contain; background: var(--surface-2); }
.brand .name { font-weight: 700; font-size: 1.2rem; line-height: 1.2; }
.brand .sub { font-size: .75rem; color: var(--muted); font-weight: 400; }
.nav-label { font-size: .75rem; color: var(--muted); padding: 14px 12px 4px; font-weight: 600; letter-spacing: .02em; }
.nav a {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: var(--r);
  color: var(--muted); text-decoration: none; font-weight: 500; transition: background-color .15s, color .15s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--info-bg); color: var(--link, var(--primary)); font-weight: 600; }
.nav .count { margin-inline-start: auto; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 12px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
}
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 24px; max-width: 1280px; width: 100%; margin-inline: auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.6rem; }
.page-head p { color: var(--muted); margin-top: 4px; }
.page-head .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.scrim { position: fixed; inset: 0; background: rgb(8 12 24 / .5); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .2s; }
.user-menu { position: relative; }
.pop {
  position: absolute; inset-inline-end: 0; top: calc(100% + 8px); min-width: 230px; z-index: 50; padding: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow);
}
.pop .who { padding: 8px 12px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.pop button.item { width: 100%; display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 12px; border: 0; background: none; border-radius: 8px; text-align: start; }
.pop button.item:hover { background: var(--surface-2); }
.notif-list { width: min(360px, 88vw); max-height: 60vh; overflow-y: auto; }
.notif-item { padding: 10px 12px; border-radius: 8px; font-size: .9rem; }
.notif-item + .notif-item { border-top: 1px solid var(--border); }
.notif-item.unread { background: var(--info-bg); }
.dot-badge { position: absolute; top: 4px; inset-inline-end: 4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: .7rem; line-height: 18px; text-align: center; }
.btn.icon { position: relative; }

/* ---------- بطاقات المنصات ---------- */
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.search { position: relative; flex: 1 1 260px; max-width: 460px; }
.search .input { padding-inline-start: 42px; }
.search svg { position: absolute; inset-inline-start: 13px; top: 12px; color: var(--muted); pointer-events: none; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); font-weight: 500; font-size: .92rem; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
:root[data-theme="dark"] .chip[aria-pressed="true"] { background: var(--primary-shade); color: #0A0F1E; border-color: transparent; }
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.pcard {
  --c: var(--primary); position: relative; display: flex; flex-direction: column; gap: 14px; padding: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  transition: transform .18s, box-shadow .18s, border-color .18s;
}
.pcard:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--c) 45%, var(--border)); }
.pcard .top { display: flex; align-items: flex-start; gap: 14px; }
.pcard .tile { width: 52px; height: 52px; border-radius: 15px; display: grid; place-items: center; flex: none; background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); }
:root[data-theme="dark"] .pcard .tile { color: color-mix(in srgb, var(--c) 55%, white); }
.pcard h3 { font-size: 1.08rem; }
.pcard .desc { color: var(--muted); font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 3.1em; }
.pcard .meta { display: flex; gap: 6px; flex-wrap: wrap; }
.pcard .foot { display: flex; gap: 8px; align-items: center; margin-top: auto; }
.pcard .foot .btn.open { flex: 1; }
.pcard.is-off .tile { filter: grayscale(.7); }
.pcard .fav { position: absolute; top: 14px; inset-inline-end: 14px; }
.fav[aria-pressed="true"] { color: #D97706; }
.pcard .top > div { padding-inline-end: 34px; min-width: 0; }

/* ---------- الإحصائيات ---------- */
.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 20px; }
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; }
.stat .k { color: var(--muted); font-size: .88rem; display: flex; align-items: center; gap: 8px; }
.stat .v { font-size: 1.9rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat.warn .v { color: var(--warn); } .stat.danger .v { color: var(--danger); }
.cols { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding: 8px 4px 0; }
.bars .bar { flex: 1; min-width: 6px; background: color-mix(in srgb, var(--primary) 70%, transparent); border-radius: 6px 6px 2px 2px; position: relative; min-height: 3px; transition: background-color .15s; }
.bars .bar:hover { background: var(--primary); }
.bars-axis { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); padding: 6px 4px 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 20px; }
.list li + li { border-top: 1px solid var(--border); }
.list .grow { flex: 1; min-width: 0; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: start; font-weight: 600; font-size: .83rem; color: var(--muted); padding: 11px 16px; background: var(--surface-2); white-space: nowrap; }
.t td { padding: 13px 16px; border-top: 1px solid var(--border); vertical-align: middle; }
.t tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.t .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.t td.clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 20px; scrollbar-width: none; }
.tabs button { min-height: 46px; padding: 0 16px; border: 0; background: none; color: var(--muted); font-weight: 500; border-bottom: 3px solid transparent; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--link, var(--primary)); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------- النوافذ والتنبيهات ---------- */
.modal-root { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgb(8 12 24 / .55); animation: fade .16s ease-out; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); animation: rise .2s ease-out; }
.modal.wide { width: min(760px, 100%); }
.modal header { position: sticky; top: 0; z-index: 1; background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0; display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal header h2 { font-size: 1.1rem; }
.modal .body { padding: 22px; }
.modal footer { position: sticky; bottom: 0; display: flex; gap: 10px; justify-content: flex-start; padding: 16px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.toasts { position: fixed; inset-block-end: 20px; inset-inline-start: 20px; z-index: 200; display: grid; gap: 10px; max-width: min(420px, calc(100vw - 40px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); animation: rise .2s ease-out; }
.toast.ok { border-inline-start: 4px solid var(--ok); } .toast.err { border-inline-start: 4px solid var(--danger); }
.alert { display: flex; gap: 10px; padding: 12px 16px; border-radius: var(--r); background: var(--warn-bg); color: var(--warn); margin-bottom: 16px; }
.alert.danger { background: var(--danger-bg); color: var(--danger); }
.alert.info { background: var(--info-bg); color: var(--link, var(--primary)); }

.empty { text-align: center; padding: 56px 20px; display: grid; justify-items: center; gap: 12px; }
.empty .art { width: 84px; height: 84px; border-radius: 26px; display: grid; place-items: center; background: var(--info-bg); color: var(--link, var(--primary)); }
.empty h3 { font-size: 1.15rem; } .empty p { color: var(--muted); max-width: 420px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), color-mix(in srgb, var(--surface-2) 60%, var(--surface)), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--r); }
.copy { display: flex; gap: 8px; align-items: center; }
.copy .input { font-family: var(--mono); font-size: .88rem; direction: ltr; text-align: start; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 16px; }
.perm-tags { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- الدخول ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-art {
  position: relative; overflow: hidden; color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(1200px 600px at 100% 0%, color-mix(in srgb, var(--accent) 70%, transparent), transparent 60%),
              linear-gradient(160deg, color-mix(in srgb, var(--primary) 92%, black), color-mix(in srgb, var(--primary) 60%, black));
}
.auth-art h1 { font-size: clamp(2rem, 4vw, 3rem); line-height: 1.25; max-width: 14ch; }
.auth-art p { opacity: .88; max-width: 38ch; margin-top: 14px; font-size: 1.05rem; }
.auth-art .tiles { position: absolute; inset-inline-end: -40px; bottom: -40px; display: grid; grid-template-columns: repeat(3, 84px); gap: 14px; opacity: .22; transform: rotate(-8deg); }
.auth-art .tiles span { height: 84px; border-radius: 22px; background: #fff; }
.auth-art .tiles span:nth-child(3n+2) { opacity: .55; } .auth-art .tiles span:nth-child(4) { background: var(--accent); }
.auth-art .brand { color: #fff; padding: 0; }
.auth-art .brand .sub { color: rgb(255 255 255 / .75); }
.auth-form { display: grid; place-items: center; padding: 32px 24px; }
.auth-box { width: min(420px, 100%); }
.auth-box h2 { font-size: 1.6rem; margin-bottom: 6px; }
.auth-box .lead { color: var(--muted); margin-bottom: 26px; }
.code-input { font-size: 1.8rem; letter-spacing: .5em; text-align: center; direction: ltr; font-family: var(--mono); min-height: 56px; }
.auth-foot { margin-top: 22px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- التجاوب ---------- */
@media (max-width: 960px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; top: 0; bottom: 0; inset-inline-start: 0; width: min(300px, 86vw); height: 100%; z-index: 50; transform: translateX(100%); transition: transform .24s ease; box-shadow: var(--shadow-lg); }
  html[dir="rtl"] .sidebar { transform: translateX(100%); }
  html[dir="ltr"] .sidebar { transform: translateX(-100%); }
  .app.nav-open .sidebar { transform: none !important; }
  .app.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 18px 16px 40px; }
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-art { display: none; }
}
@media (max-width: 640px) {
  .page-head h1 { font-size: 1.3rem; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: 1fr; gap: 2px 0; } .kv dt { margin-top: 10px; }
  .modal-root { align-items: end; padding: 0; }
  .modal { width: 100%; border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92vh; }
  .modal footer { flex-wrap: wrap; } .modal footer .btn { flex: 1; }
  .toasts { inset-inline: 12px; inset-block-end: 12px; }
  /* الجداول تتحول إلى بطاقات */
  table.t.stack thead { display: none; }
  table.t.stack, table.t.stack tbody, table.t.stack tr, table.t.stack td { display: block; width: 100%; }
  table.t.stack tr { padding: 12px 14px; border-top: 1px solid var(--border); }
  table.t.stack td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
  table.t.stack td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; flex: none; }
  table.t.stack td.clip { max-width: none; white-space: normal; }
  table.t.stack td[data-label=""]::before, table.t.stack td:not([data-label])::before { content: none; }
  table.t.stack .actions { justify-content: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .pcard:hover { transform: none; }
}
@media print { .sidebar, .topbar { display: none; } }
