:root {
  --bg: #f3f1f9; --surface: #ffffff; --line: #e3e0f0; --ink: #1d1a3b; --muted: #5d5a7e;
  --accent: #4338ca; --accent-2: #6d4be0; --accent-ink: #ffffff; --accent-soft: #ece9fd;
  --hero-a: #2b1a63; --hero-b: #4a2fa8;
  --good: #1a7f46; --warn: #a15c07; --bad: #c0302b; --info: #2457d6;
  --shadow: 0 1px 2px rgba(43,26,99,.06), 0 8px 24px rgba(43,26,99,.07);
  --radius: 18px;
}
:root[data-theme="dark"] {
  --bg: #120f26; --surface: #1c1836; --line: #322c57; --ink: #f1effc; --muted: #aaa6cc;
  --accent: #8b7cf6; --accent-2: #a594ff; --accent-ink: #14102b; --accent-soft: #2a2455;
  --hero-a: #1a1040; --hero-b: #33207a;
  --good: #4cc27f; --warn: #e0a64a; --bad: #ff7a74; --info: #7aa2ff;
  --shadow: 0 8px 24px rgba(0,0,0,.35); color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 "Segoe UI", Tahoma, system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 17px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.num { direction: ltr; unicode-bidi: plaintext; font-variant-numeric: tabular-nums; }

/* layout */
.shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-inline-end: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 8px; padding: 4px 8px 14px; white-space: nowrap; }
.brand > div { min-width: 0; }
.brand img, .login img { border-radius: 10px; flex: none; }
.wm { font-weight: 900; letter-spacing: 5px; line-height: 1.05; font-size: 20px; direction: ltr; unicode-bidi: isolate; white-space: nowrap; }
.wm span { color: #F7A014; }
.wm small { font-size: 12px; letter-spacing: 0; font-weight: 600; color: var(--muted); direction: rtl; }
.brand .tg { white-space: nowrap; font-size: 9px; letter-spacing: 1.6px; font-weight: 700; color: var(--muted); direction: ltr; margin-top: 2px; }
.nav a { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 600; }
.nav a:hover { background: var(--bg); color: var(--ink); }
.nav a.on { background: var(--ink); color: var(--bg); }
.side .me { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); }
.userbtn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink); cursor: pointer; font: inherit; text-align: start; min-height: 44px; }
.userbtn:hover { border-color: var(--ink); }
.userbtn .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--ink); color: var(--bg); display: grid; place-items: center; font-weight: 800; flex: none; }
.userbtn .who { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; align-items: flex-start; }
.userbtn .who b { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.govgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(170px, 100%), 1fr)); gap: 8px; }
.govcell { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
.govcell input { width: 76px; min-height: 34px; }
.kvs { display: grid; gap: 2px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.kv .num { overflow-wrap: anywhere; text-align: end; }
.main { padding: 22px 26px 60px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top .grow { flex: 1; }

/* components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 800; margin: 2px 0; }
.stat .sub { color: var(--muted); font-size: 13px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 600; min-height: 38px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.danger { color: var(--bad); }
.btn.sm { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 10px; min-height: 38px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 140px; margin-bottom: 0; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 160px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--bg); }
.scroll { overflow-x: auto; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--line); display: block; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.pill.s0, .pill.s1 { color: var(--warn); } .pill.s2, .pill.s3 { color: var(--info); } .pill.s4 { color: var(--good); } .pill.s9 { color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

/* charts */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 150px; padding-top: 8px; }
.bar { flex: 1; height: 100%; display: flex; align-items: flex-end; min-width: 3px; }
.bar i { display: block; width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; }
.bars.alt .bar i { background: var(--info); }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 4px; direction: ltr; }
.hbar { height: 8px; border-radius: 99px; background: var(--bg); overflow: hidden; min-width: 80px; }
.hbar i { display: block; height: 100%; background: var(--accent); }

/* modal / toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-start; justify-content: center; padding: 20px 12px; overflow-y: auto; overscroll-behavior: contain; z-index: 50; }
.sheet { background: var(--surface); border-radius: 16px; padding: 20px; width: 100%; max-width: 560px; border: 1px solid var(--line); max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet.wide { max-width: 860px; }
.sheet .head { position: sticky; top: -20px; z-index: 2; background: var(--surface); padding: 20px 0 10px; margin: -20px 0 4px; display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sheet .head h2 { margin: 0; flex: 1; }
.toast { position: fixed; bottom: 22px; inset-inline-start: 22px; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 100; font-weight: 600; }
.toast.bad { background: var(--bad); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; display: grid; gap: 12px; }
.err { color: var(--bad); font-size: 14px; }

/* product form */
.imgs { display: flex; gap: 10px; flex-wrap: wrap; }
.imgbox { position: relative; width: 92px; }
.imgbox img { width: 92px; height: 92px; object-fit: cover; border-radius: 10px; display: block; background: var(--line); }
.imgbox .x, .imgbox .first { position: absolute; top: 4px; inset-inline-start: 4px; }
.imgbox .first { top: auto; bottom: 4px; }
.vrow { display: grid; grid-template-columns: 1.2fr 1.2fr .8fr auto; gap: 8px; margin-bottom: 8px; }
.tag { font-size: 11px; background: var(--ink); color: var(--bg); border-radius: 6px; padding: 1px 6px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px; }
  .brand { padding: 4px 8px; } .side .me { margin: 0; border: 0; padding: 0 8px; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; width: 100%; order: 3; }
  .nav a { padding: 8px 10px; }
  .main { padding: 16px 12px 60px; }
  .vrow { grid-template-columns: 1fr 1fr; }
}

/* أدوات اللغة والثيم + فلتر القسم */
.tools { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.login .tools { margin: 0; }
select.sec { width: auto; min-width: 150px; font-weight: 700; }

/* بحث عام + شارة الطلبات الجديدة */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.topbar .gsearch { flex: 1 1 260px; margin-bottom: 0; }
.side > .userbtn { margin: 4px 0 10px; }
.gsearch { position: relative; margin-bottom: 16px; max-width: 560px; }
.gsr { position: absolute; inset-inline: 0; top: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; z-index: 40; max-height: 60vh; overflow: auto; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.gsr:empty { display: none; }
.gsr .gh { padding: 6px 12px; font-size: 12px; color: var(--muted); background: var(--bg); }
.gsr a { display: block; padding: 8px 12px; cursor: pointer; text-decoration: none; }
.gsr a:hover { background: var(--bg); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 12px; text-align: center; margin-inline-start: 6px; }
.nav { overflow-y: auto; }

.pwwrap { position: relative; }
.pwwrap input { padding-inline-end: 42px; }
.pwwrap .eye { position: absolute; inset-block: 0; inset-inline-end: 4px; border: 0; background: none; cursor: pointer; font-size: 18px; padding: 0 8px; }

/* ترتيب وبحث الجداول (tables.js) */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable::after { content: ' ⇅'; opacity: .35; font-size: 11px; }
th.sortable[aria-sort=ascending]::after { content: ' ▲'; opacity: 1; }
th.sortable[aria-sort=descending]::after { content: ' ▼'; opacity: 1; }
tr.tfilter th { padding: 2px 4px; background: transparent; }
tr.tfilter input.tf { min-height: 28px; padding: 2px 6px; font-size: 12px; min-width: 70px; font-weight: normal; }
tr[hidden] { display: none; }


/* ===== تصميم v2: بنفسجي/نيلي هادي، بطاقات ناعمة، هيرو متدرّج ===== */
[hidden] { display: none !important; }
body { background: var(--bg); }
.top { background: radial-gradient(700px 220px at 90% -50%, rgba(167,139,250,.5), transparent 70%), linear-gradient(135deg, var(--hero-a), var(--hero-b));
  color: #fff; border-radius: var(--radius); padding: 18px 22px; box-shadow: var(--shadow); }
.top h1 { color: #fff; font-size: 26px; letter-spacing: .2px; }
.top .muted, .top label { color: rgba(255,255,255,.85); }
.top .btn, .top select, .top input { background: rgba(255,255,255,.96); color: #1d1a3b; border-color: transparent; }
.top .btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.topbar .gsearch input { border-radius: 99px; padding-inline: 16px; box-shadow: var(--shadow); border-color: transparent; }

.side { background: linear-gradient(180deg, var(--surface), var(--surface)); box-shadow: var(--shadow); border-inline-end: 0; }
.nav a { border-radius: 12px; transition: background .15s, color .15s; }
.nav a:hover { background: var(--accent-soft); color: var(--accent); }
.nav a.on { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 6px 16px rgba(67,56,202,.28); }
.nav a:focus-visible, th.sortable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.userbtn { background: var(--accent-soft); border-color: transparent; }
.userbtn .avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }

.card { border-radius: var(--radius); border-color: transparent; box-shadow: var(--shadow); }
.main > .grid > .card.stat:first-child, .cols-4 > .card.stat:first-child { background: linear-gradient(135deg, #3a2fd0, #5b3fe0); color: #fff; }
.cols-4 > .card.stat:first-child .label, .cols-4 > .card.stat:first-child .sub { color: rgba(255,255,255,.85); }
.stat .value { font-size: 28px; letter-spacing: -.3px; }

.btn { border-radius: 12px; border-color: var(--line); transition: transform .1s, box-shadow .15s, border-color .15s; }
.btn:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(67,56,202,.15); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }
.btn.sm { min-height: 32px; }
input, select, textarea { border-radius: 12px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
select.sec { border-radius: 99px; font-weight: 700; padding-inline: 16px; }

th { background: var(--accent-soft); color: var(--muted); }
th:first-child { border-start-start-radius: 10px; } th:last-child { border-start-end-radius: 10px; }
tr.click:hover td, tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.pill { background: var(--accent-soft); border-color: transparent; }
.tag { background: var(--accent); color: var(--accent-ink); }
.badge { background: var(--bad); color: #fff; }
.bar i, .hbar i { background: linear-gradient(180deg, var(--accent-2), var(--accent)); }
.hbar { background: var(--accent-soft); }
.sheet { border-radius: 20px; border-color: transparent; box-shadow: 0 24px 60px rgba(20,10,60,.35); }
.modal { background: rgba(20,12,50,.55); backdrop-filter: blur(3px); }
.toast { background: var(--hero-a); color: #fff; box-shadow: 0 8px 24px rgba(20,10,60,.35); }

.login { background: linear-gradient(135deg, var(--hero-a), var(--hero-b)); }
.login .card { border-radius: 22px; box-shadow: 0 24px 60px rgba(10,5,40,.4); }
.login .wm { color: var(--ink); }

@media (max-width: 860px) {
  .top { padding: 14px 16px; }
  .side { box-shadow: 0 2px 12px rgba(43,26,99,.08); }
  /* القائمة بتتحرك أفقيًا بدل ما تتلف على أسطر كتير */
  .nav { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; padding-bottom: 4px; scrollbar-width: thin; }
  .nav a { white-space: nowrap; flex: none; }
  .top h1 { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .side, .topbar { display: none !important; } .top { background: none; color: #000; box-shadow: none; } .top h1 { color: #000; } }

.thumb.ph { display: grid; place-items: center; font-size: 20px; opacity: .55; background: var(--accent-soft); }

/* شعار DJED: الكلمة بلون النص، والرمز ذهبي */
.wmsvg { height: 18px; width: auto; display: block; color: var(--ink); }
.login .wmsvg { height: 22px; display: inline-block; vertical-align: middle; }
.wm { letter-spacing: 0; display: block; }
.brand .tg { font-size: 9px; letter-spacing: 2px; margin-top: 5px; }

/* DJED في نص الشعار الفرعي */
.brand > div { text-align: center; }
.brand .wmsvg { margin-inline: auto; }
.brand .tg { text-align: center; }

/* فلتر الداشبورد: من / إلى / القسم / تحديث في صف واحد */
.dfilters { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.dfilters input[type=date] { width: auto; min-width: 140px; }
.dfilters select.sec { min-width: 130px; }
.dfilters label { margin: 0; white-space: nowrap; }
@media (max-width: 1100px) { .dfilters { flex-wrap: wrap; } }
