/* DC Web — واجهة جديدة. الألوان رموز (tokens) في مكان واحد، الفاتح والداكن كلٌّ مُختار
 * ومُدقَّق (palette.md: الفئات 1–5 + سلّم العمر الترتيبي). لا لون hex خارج هذا القسم. */

:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 8px 28px rgba(11, 11, 11, 0.05);
  --glow-1: rgba(42, 120, 214, 0.11);
  --glow-2: rgba(27, 175, 122, 0.08);

  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: rgba(42, 120, 214, 0.10);
  --accent-strong: #1c5cab;

  /* فئات (slots 1..5): اللون يتبع المجموعة لا ترتيبها */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --c-review: #2a78d6;
  --deemph: #c3c2b7;

  /* سلّم العمر (ordinal): أفتح = أحدث */
  --age-0: #86b6ef;
  --age-1: #5598e7;
  --age-2: #2a78d6;
  --age-3: #1c5cab;
  --age-4: #104281;

  /* حالة (status): دائماً مع أيقونة + نص */
  --st-late: #b86e00;
  --st-late-bg: rgba(250, 178, 25, 0.16);
  --st-crit: #d03b3b;
  --st-crit-bg: rgba(208, 59, 59, 0.12);
  --st-good: #0ca30c;

  --radius: 16px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
    --glow-1: rgba(57, 135, 229, 0.16);
    --glow-2: rgba(25, 158, 112, 0.10);
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --accent-strong: #6da7ec;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --c-review: #3987e5;
    --deemph: #4a4a46;
    --age-0: #184f95;
    --age-1: #256abf;
    --age-2: #3987e5;
    --age-3: #6da7ec;
    --age-4: #9ec5f4;
    --st-late: #fab219;
    --st-late-bg: rgba(250, 178, 25, 0.14);
    --st-crit: #ee6a6a;
    --st-crit-bg: rgba(238, 106, 106, 0.14);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  --glow-1: rgba(57, 135, 229, 0.16);
  --glow-2: rgba(25, 158, 112, 0.10);
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.16);
  --accent-strong: #6da7ec;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --c-review: #3987e5;
  --deemph: #4a4a46;
  --age-0: #184f95;
  --age-1: #256abf;
  --age-2: #3987e5;
  --age-3: #6da7ec;
  --age-4: #9ec5f4;
  --st-late: #fab219;
  --st-late-bg: rgba(250, 178, 25, 0.14);
  --st-crit: #ee6a6a;
  --st-crit-bg: rgba(238, 106, 106, 0.14);
}

/* ───────── أساسيات ───────── */
* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 14.5px/1.55 var(--font);
  color: var(--ink);
  background: var(--bg);
}
body::before { /* توهّج خلفي هادئ يعطي عمقاً دون ازدحام */
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 420px at 88% -8%, var(--glow-1), transparent 62%),
    radial-gradient(760px 380px at 4% -4%, var(--glow-2), transparent 58%);
}

h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 15px; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--st-crit); margin-top: 8px; }
.empty { color: var(--muted); padding: 22px 8px; text-align: center; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ───────── أزرار وحقول ───────── */
.icon-btn, .ghost, .select-btn, select, input[type="search"], input[type="text"], input[type="password"] {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 0 12px;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.icon-btn { display: inline-grid; place-items: center; width: 36px; padding: 0; color: var(--ink-2); }
.icon-btn.text { width: auto; padding: 0 12px; font-size: 13px; font-weight: 600; }
.icon-btn:hover, .ghost:hover, .select-btn:hover, select:hover { background: var(--surface-2); }
.ghost { color: var(--ink-2); font-weight: 550; }
.ghost:disabled { opacity: .45; cursor: default; }
input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button.primary {
  height: 42px; border: 0; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-ink); font-weight: 650; padding: 0 20px;
  box-shadow: 0 6px 18px -6px var(--accent);
}
button.primary:hover { background: var(--accent-strong); }
button.primary.wide { width: 100%; margin-top: 18px; }
button.link { border: 0; background: none; color: var(--accent-strong); padding: 0; margin-top: 16px; font-weight: 550; }

.field-v { display: block; margin-top: 14px; font-size: 13px; color: var(--muted); }
.field-v input { display: block; width: 100%; height: 42px; margin-top: 5px; color: var(--ink); }

/* ───────── صفحات الدخول والدور ───────── */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: min(400px, 100%); padding: 32px; animation: rise .45s ease both; }
.auth.wide { width: min(640px, 100%); }
.auth h1 { margin-bottom: 6px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand.big { margin-bottom: 18px; }
.brand.big .brand-name { font-size: 22px; }
.logo {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  color: #fff; font-weight: 800; font-size: 13px; letter-spacing: .02em; direction: ltr;
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }

.roles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-top: 20px; }
.role {
  text-align: start; direction: ltr; padding: 16px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 650; display: grid; gap: 4px;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.role small { color: var(--muted); font-weight: 450; }
.role:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow); }
.role.selected { border-color: var(--accent); background: var(--accent-soft); }

/* ───────── الإطار ───────── */
.shell { max-width: 1280px; margin: 0 auto; padding: 0 20px 48px; }

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 0; margin-bottom: 4px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
}

.tabs {
  display: inline-flex; gap: 4px; padding: 4px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.tabs button {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 16px;
  border: 0; border-radius: 9px; background: transparent; color: var(--ink-2); font-weight: 600;
  transition: background .18s, color .18s, box-shadow .18s;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

.top-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.live { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; margin-inline-end: 6px; }
.live b { color: var(--ink); font-weight: 650; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--st-good); box-shadow: 0 0 0 0 var(--st-good); animation: pulse 2.4s infinite; }
.live.stale .dot { background: var(--muted); animation: none; }

.menu-wrap { position: relative; }
.user-btn {
  display: inline-flex; align-items: center; gap: 10px; height: 40px; padding: 0 12px 0 6px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
}
.user-btn:hover { background: var(--surface-2); }
.avatar {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong); font-weight: 700; font-size: 12px;
}
.user-meta { display: grid; line-height: 1.15; text-align: start; }
.user-meta b { font-size: 13px; }
.user-meta small { color: var(--muted); font-size: 11.5px; direction: ltr; text-align: start; }

.menu {
  position: absolute; inset-inline-end: 0; top: calc(100% + 8px); z-index: 40; min-width: 200px;
  padding: 6px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .18); animation: pop .14s ease both;
}
.menu.pad { inset-inline-start: 0; inset-inline-end: auto; min-width: 260px; max-height: 340px; overflow: auto; padding: 8px; }
.menu > button, .menu label {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; text-align: start; font-weight: 500;
}
.menu > button:hover, .menu label:hover { background: var(--surface-2); }
.menu input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.menu .n { margin-inline-start: auto; color: var(--muted); font-size: 12.5px; direction: ltr; }

/* ───────── شريط الفلاتر (صف واحد فوق كل ما يؤثر عليه) ───────── */
.filterbar { display: grid; gap: 12px; padding: 4px 0 18px; }
.frow { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.field select, .select-btn { min-width: 150px; color: var(--ink); font-size: 13.5px; text-align: start; }
.select-btn { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; }
.select-btn::after { content: ""; width: 7px; height: 7px; border-inline-end: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted); transform: rotate(45deg) translateY(-2px); }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 560; font-size: 13.5px; direction: ltr;
  transition: background .15s, border-color .15s, color .15s, transform .12s;
}
.pill:hover { border-color: var(--accent); transform: translateY(-1px); }
.pill .n { color: var(--muted); font-weight: 500; font-size: 12.5px; }
.pill.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pill.active .n { color: rgba(255, 255, 255, .8); }
.chips:empty { display: none; }
.chip-x {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 6px 0 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-strong); border: 0; font-size: 12.5px; font-weight: 600; direction: ltr;
}
.chip-x i { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; font-style: normal; background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* ───────── نظرة عامة ───────── */
.hello { padding: 6px 0 18px; }
.hello p { margin-top: 2px; }
.hint { margin-top: 8px; display: inline-block; padding: 4px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 12.5px; font-weight: 550; }

.hero-row { display: grid; grid-template-columns: minmax(300px, 0.9fr) 2fr; gap: 16px; margin-bottom: 16px; }

.hero {
  position: relative; overflow: hidden; display: grid; gap: 6px; align-content: start; text-align: start; padding: 24px;
  background:
    radial-gradient(320px 200px at 100% 0%, var(--accent-soft), transparent 70%),
    var(--surface);
  transition: transform .18s, box-shadow .18s, border-color .18s;
}
.hero:hover { transform: translateY(-2px); border-color: var(--accent); }
.hero.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow); }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 650; }
.hero-number { font-size: 68px; line-height: 1; font-weight: 760; letter-spacing: -0.03em; margin-top: 4px; }
.hero-sub { color: var(--ink-2); font-size: 13.5px; margin-top: 2px; }
.meter { display: block; height: 8px; border-radius: 999px; background: var(--accent-soft); margin-top: 14px; overflow: hidden; direction: ltr; }
.meter-fill { display: block; height: 100%; border-radius: 999px; background: var(--accent); width: 0; transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.hero-split { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 12.5px; color: var(--ink-2); }
.hero-split span { display: inline-flex; align-items: center; gap: 6px; }
.hero-split b { font-weight: 650; color: var(--ink); }
.rule { display: block; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--grid); font-size: 11.5px; line-height: 1.55; color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.kpi {
  position: relative; padding: 16px 18px; display: grid; gap: 2px; align-content: start; min-height: 108px;
  transition: transform .18s, box-shadow .18s, border-color .18s;
}
button.kpi { text-align: start; }
button.kpi:hover { transform: translateY(-2px); border-color: var(--accent); }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 32px; line-height: 1.1; font-weight: 720; letter-spacing: -0.02em; }
.kpi-value small { font-size: 14px; font-weight: 550; color: var(--muted); margin-inline-start: 4px; }
.kpi-sub { font-size: 12.5px; color: var(--ink-2); }
.kpi .spark-slot { position: absolute; inset-inline-end: 14px; top: 14px; }
.spark { direction: ltr; }
.flag {
  display: inline-flex; align-items: center; gap: 6px; width: fit-content; margin-top: 4px; padding: 2px 10px 2px 8px;
  border-radius: 999px; font-size: 12px; font-weight: 650; direction: ltr;
}
.flag.late { background: var(--st-late-bg); color: var(--st-late); }
.flag.crit { background: var(--st-crit-bg); color: var(--st-crit); }
.flag.good { background: color-mix(in srgb, var(--st-good) 14%, transparent); color: var(--st-good); }

/* ───────── البطاقات والشبكة ───────── */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.c4 { grid-column: span 4; } .c5 { grid-column: span 5; } .c6 { grid-column: span 6; }
.c7 { grid-column: span 7; } .c8 { grid-column: span 8; } .c12 { grid-column: span 12; }

.panel { padding: 18px 20px 14px; display: flex; flex-direction: column; animation: rise .5s ease both; }
.panel-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.panel-head .titles { flex: 1; min-width: 0; }
.panel-head .hint-line { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.view-toggle { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); }
.view-toggle button { height: 26px; padding: 0 10px; border: 0; border-radius: 7px; background: transparent; font-size: 12px; font-weight: 600; color: var(--muted); }
.view-toggle button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.panel-body { flex: 1; min-height: 120px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i, .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.note { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.loading #grid, .loading .hero-row { opacity: .6; transition: opacity .2s; }

/* ألوان العلامات: فئة CSS لكل علامة */
.c-review { --mark: var(--c-review); }
.c-done { --mark: var(--deemph); }
.c-age0 { --mark: var(--age-0); } .c-age1 { --mark: var(--age-1); } .c-age2 { --mark: var(--age-2); }
.c-age3 { --mark: var(--age-3); } .c-age4 { --mark: var(--age-4); }
.g-open { --mark: var(--series-1); } .g-pending { --mark: var(--series-2); } .g-inprocess { --mark: var(--series-3); }
.g-closed { --mark: var(--series-4); } .g-coded { --mark: var(--series-5); }
.legend i, .swatch, .tip-key, .seg:not(svg *), .sseg { background: var(--mark); }
svg .seg { fill: var(--mark); }

/* أعمدة أفقية */
.hrow {
  display: grid; grid-template-columns: minmax(80px, 150px) 1fr auto; align-items: center; gap: 12px; width: 100%;
  padding: 6px 8px; border: 1px solid transparent; border-radius: 10px; background: transparent; text-align: start; direction: ltr;
  transition: background .15s, border-color .15s;
}
.hrow:hover { background: var(--surface-2); }
.hrow.sel { background: var(--accent-soft); border-color: var(--accent); }
.hlabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.htrack { display: flex; gap: 2px; height: 12px; min-width: 0; }
.htrack .seg { display: block; height: 100%; transform-origin: left; animation: growx .45s cubic-bezier(.2, .8, .2, 1) both; }
.htrack .seg.last { border-radius: 0 4px 4px 0; }
.hval { font-size: 13px; white-space: nowrap; min-width: 64px; text-align: end; }
.hval .of { color: var(--muted); }

/* أعمدة رأسية (SVG) */
.chart { display: block; overflow: visible; direction: ltr; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .val { fill: var(--ink-2); font-size: 11px; font-weight: 650; font-family: var(--font); }
.chart .hit { fill: transparent; transition: fill .12s; }
.chart .bar { cursor: pointer; outline: none; }
.chart .bar:hover .hit, .chart .bar:focus-visible .hit { fill: var(--accent-soft); }
.chart .bar:focus-visible .hit { stroke: var(--accent); stroke-width: 1.5; }
.chart .bar .seg { transform-box: fill-box; transform-origin: 50% 100%; animation: growy .5s cubic-bezier(.2, .8, .2, 1) both; transition: opacity .15s, filter .15s; }
.chart .bar:hover .seg { filter: brightness(1.08); }
.chart.has-sel .bar:not(.sel) .seg { opacity: .35; }

/* شريط النسب */
.sbar { display: flex; gap: 2px; height: 16px; direction: ltr; }
.sseg { flex-basis: 0; min-width: 4px; height: 100%; border: 0; padding: 0; transition: filter .15s, opacity .15s, transform .15s; animation: growx .5s cubic-bezier(.2, .8, .2, 1) both; transform-origin: left; }
.sseg.first { border-radius: 4px 0 0 4px; } .sseg.last { border-radius: 0 4px 4px 0; } .sseg.first.last { border-radius: 4px; }
.sseg:hover { filter: brightness(1.1); transform: scaleY(1.25); }
.sbar:has(.sel) .sseg:not(.sel) { opacity: .35; }
.slegend { display: grid; gap: 2px; margin-top: 14px; }
.srow { display: grid; grid-template-columns: 12px 1fr auto 44px; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border: 1px solid transparent; border-radius: 10px; background: transparent; text-align: start; }
.srow:hover { background: var(--surface-2); }
.srow.sel { background: var(--accent-soft); border-color: var(--accent); }
.srow.zero { opacity: .5; }
.scount { direction: ltr; } .spct { color: var(--muted); font-size: 12.5px; text-align: end; direction: ltr; }

/* خط صغير */
.spark { display: block; overflow: visible; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.spark-area { fill: var(--accent); opacity: .10; }
.spark-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }

/* قائمة «تحتاج انتباهك» */
.att { display: grid; gap: 2px; }
.att-row {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; width: 100%; padding: 9px 10px;
  border: 1px solid transparent; border-radius: 12px; background: transparent; text-align: start;
  transition: background .15s, transform .15s;
}
.att-row:hover { background: var(--surface-2); }
.att-main { min-width: 0; display: grid; direction: ltr; text-align: start; }
.att-main b { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-main span { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-go { color: var(--muted); }
.age-chip {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-width: 62px; height: 26px; padding: 0 10px;
  border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--ink-2); direction: ltr;
}
.age-chip.late { background: var(--st-late-bg); color: var(--st-late); }
.age-chip.crit { background: var(--st-crit-bg); color: var(--st-crit); }

/* جدول بديل (twin) */
table.twin { width: 100%; border-collapse: collapse; font-size: 13px; direction: ltr; }
table.twin th, table.twin td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: start; }
table.twin thead th { color: var(--muted); font-weight: 600; }
table.twin tbody th { font-weight: 550; }
table.twin td { font-variant-numeric: tabular-nums; }

/* ───────── التفاصيل ───────── */
.details { padding: 16px 18px; animation: rise .4s ease both; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1 1 260px; min-width: 200px; max-width: 420px; }
.spacer { flex: 1; }
.count { font-size: 13.5px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; color: var(--ink-2); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { position: relative; width: 38px; height: 22px; border-radius: 999px; background: var(--axis); transition: background .18s; }
.switch-track::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: inset-inline-start .18s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { inset-inline-start: 19px; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); }
#docs { width: 100%; border-collapse: collapse; font-size: 13.5px; direction: ltr; }
#docs th, #docs td { padding: 10px 14px; text-align: start; white-space: nowrap; border-bottom: 1px solid var(--grid); max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
#docs thead th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 650; font-size: 12px; letter-spacing: .02em; user-select: none; }
#docs thead th[data-sort] { cursor: pointer; }
#docs thead th[data-sort]:hover { color: var(--ink); }
#docs th[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; color: var(--accent); }
#docs th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; color: var(--accent); }
#docs tbody tr { cursor: pointer; transition: background .12s; }
#docs tbody tr:hover, #docs tbody tr:focus-visible { background: var(--accent-soft); outline: none; }
#docs tbody tr:last-child td { border-bottom: 0; }
.mono { font-variant-numeric: tabular-nums; font-weight: 600; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; font-weight: 550; }
.status-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--mark, var(--muted)); }
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 14px; }

/* ───────── لوحة التفاصيل الجانبية ───────── */
dialog#drawer {
  position: fixed; inset-block: 0; inset-inline: auto 0; margin: 0; padding: 0; width: min(540px, 100vw); height: 100dvh; max-height: 100dvh;
  border: 0; border-inline-start: 1px solid var(--border); background: var(--surface); color: var(--ink);
  box-shadow: -20px 0 60px rgba(0, 0, 0, .22); overflow: auto;
}
dialog#drawer[open] { animation: slide .26s cubic-bezier(.2, .8, .2, 1) both; }
dialog#drawer::backdrop { background: rgba(10, 10, 10, .42); backdrop-filter: blur(2px); animation: fade .2s both; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 14px; position: sticky; top: 0; background: var(--surface); z-index: 1; border-bottom: 1px solid var(--grid); }
.drawer-titles h2 { font-size: 18px; direction: ltr; text-align: start; overflow-wrap: anywhere; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.badge { display: inline-flex; align-items: center; gap: 7px; height: 26px; padding: 0 12px; border-radius: 999px; background: var(--surface-2); font-size: 12.5px; font-weight: 600; direction: ltr; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--mark, var(--muted)); }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; padding: 16px 22px 4px; }
.fact { padding: 12px; border-radius: 12px; background: var(--surface-2); }
.fact small { display: block; color: var(--muted); font-size: 11.5px; font-weight: 600; }
.fact b { font-size: 17px; display: block; }
#drawer-body { margin: 0; padding: 8px 22px 28px; display: grid; grid-template-columns: minmax(110px, 190px) 1fr; gap: 0 16px; direction: ltr; }
#drawer-body dt { color: var(--muted); font-size: 12.5px; padding: 9px 0; border-bottom: 1px solid var(--grid); }
#drawer-body dd { margin: 0; padding: 9px 0; border-bottom: 1px solid var(--grid); overflow-wrap: anywhere; white-space: pre-wrap; }

/* ───────── تلميح ───────── */
#tip {
  position: fixed; z-index: 100; pointer-events: none; max-width: 280px; padding: 9px 12px; border-radius: 10px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .22); font-size: 12.5px; direction: ltr; text-align: start;
}
.tip-title { font-weight: 650; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; line-height: 1.7; }
.tip-key { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.tip-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.tip-label { color: var(--ink-2); }

/* ───────── حركة ───────── */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide { from { transform: translateX(32px); opacity: 0; } to { transform: none; opacity: 1; } }
:root[dir="rtl"] dialog#drawer[open] { animation-name: slide-rtl; }
@keyframes slide-rtl { from { transform: translateX(-32px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes growx { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes growy { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--st-good) 55%, transparent); } 70%, 100% { box-shadow: 0 0 0 8px transparent; } }
.panel:nth-child(2) { animation-delay: .04s; } .panel:nth-child(3) { animation-delay: .08s; }
.panel:nth-child(4) { animation-delay: .12s; } .panel:nth-child(5) { animation-delay: .16s; } .panel:nth-child(6) { animation-delay: .2s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ───────── متجاوب ───────── */
@media (max-width: 1000px) {
  .hero-row { grid-template-columns: 1fr; }
  .c4, .c5, .c6, .c7, .c8 { grid-column: span 12; }
}
@media (max-width: 640px) {
  .shell { padding: 0 12px 40px; }
  .top { gap: 10px; }
  .tabs { order: 3; width: 100%; } .tabs button { flex: 1; justify-content: center; }
  .user-meta { display: none; } .user-btn { padding: 0 6px; }
  .live-text, #live-text { display: none; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 26px; } .hero-number { font-size: 54px; }
  .kpi .spark-slot { position: static; margin-top: 6px; }
  .facts { grid-template-columns: 1fr 1fr; }
  #drawer-body { grid-template-columns: 1fr; } #drawer-body dt { border-bottom: 0; padding-bottom: 0; }
  .hrow { grid-template-columns: minmax(70px, 110px) 1fr auto; }
}
