/* تصميم لوحة الإدارة: شريط جانبي، بطاقات مؤشرات، جداول، ألوان بنفسجية-زرقاء. يتحمّل فوق app.css */
:root {
  --bg: #060916;
  --side: #0A0F20;
  --surface: rgba(15, 21, 40, .78);
  --surface-2: #131A31;
  --surface-3: #0D1328;
  --line: #1C2442;
  --line-2: #2A3558;
  --text: #F3F5FB;
  --text-2: #C9D0E3;
  --muted: #95A0BB;
  --faint: #7480A0;
  --accent: #7C5CFF;
  --accent-2: #3B82F6;
  --accent-soft: rgba(124, 92, 255, .16);
  --accent-line: #4A3AA0;
  --lav: #B9A8FF;
  --lav-2: #D9D0FF;
  --green: #34D399;
  --amber: #F5B76B;
  --danger: #FB7185;
  --grad: linear-gradient(135deg, #7C5CFF 0%, #3B82F6 100%);
  --font: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --display: 'Readex Pro', 'IBM Plex Sans Arabic', sans-serif;
}

html, body { background: var(--bg); }
[hidden] { display: none !important; }
body {
  margin: 0; min-height: 100vh; color: var(--text); font-family: var(--font); overflow-y: auto;
  background:
    radial-gradient(900px 480px at 88% -12%, rgba(124, 92, 255, .20), transparent 62%),
    radial-gradient(760px 440px at -6% 112%, rgba(59, 130, 246, .14), transparent 62%),
    var(--bg);
}

/* ---- الهيكل ---- */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side {
  background: linear-gradient(180deg, rgba(17, 23, 48, .92), rgba(8, 11, 24, .96));
  border-inline-end: 1px solid var(--line); padding: 22px 16px; display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 600; font-size: 17px; padding: 0 6px; }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; background: var(--grad); display: grid; place-items: center; box-shadow: 0 8px 22px rgba(124, 92, 255, .35); flex: none; }
.brand-mark svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; stroke-linejoin: round; }
.brand-logo { width: 38px; height: 38px; border-radius: 12px; flex: none; box-shadow: 0 8px 22px rgba(124, 92, 255, .35); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
  color: var(--text-2); text-decoration: none; font-size: 14px; transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255, 255, 255, .04); color: var(--text); }
.nav a[aria-current="page"] {
  background: linear-gradient(90deg, rgba(124, 92, 255, .30), rgba(59, 130, 246, .10));
  color: var(--text); box-shadow: inset 0 0 0 1px rgba(124, 92, 255, .38);
}
.nav svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.side-foot { margin-top: auto; }
.status-card { padding: 14px; border-radius: 16px; background: var(--surface-3); border: 1px solid var(--line-2); font-size: 13px; color: var(--muted); line-height: 1.7; }
.status-card b { display: block; color: var(--text); font-family: var(--display); font-weight: 600; margin-bottom: 4px; }
.status-card a { color: var(--lav); text-decoration: none; }

.main { padding: 26px 30px 60px; display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.top { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.top .titles { flex: 1; min-width: 0; }
.top h1 { margin: 0; font-family: var(--display); font-size: 26px; font-weight: 600; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* ---- أزرار ---- */
.btn-ghost {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line-2); color: var(--text-2); text-decoration: none; font-size: 14px; background: transparent; cursor: pointer;
}
.btn-ghost:hover { border-color: var(--accent-line); color: var(--text); }
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 18px;
  border: 0; border-radius: 12px; background: var(--grad); color: #fff; font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; box-shadow: 0 8px 24px rgba(124, 92, 255, .28);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-primary.sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; box-shadow: none; }
.btn-primary.ghost { background: transparent; border: 1px solid var(--line-2); color: var(--text-2); box-shadow: none; }

/* ---- بطاقات المؤشرات ---- */
.kpis, .stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat {
  position: relative; padding: 18px 18px 16px; border-radius: 18px; background: var(--surface);
  border: 1px solid var(--line); overflow: hidden;
}
.stat::before { content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 3px; background: var(--grad); }
.stat b { display: block; margin-top: 6px; font-family: var(--display); font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }

.stat-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ico { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 12px; background: var(--accent-soft); color: var(--lav-2); flex: none; }
.ico svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- الألواح والجداول ---- */
.panel { border-radius: 18px; background: var(--surface); border: 1px solid var(--line); padding: 18px; }
.panel h2 { margin: 0 0 14px; font-family: var(--display); font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.count { font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--lav-2); font-family: var(--font); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-wide { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .grid2, .grid-wide { grid-template-columns: 1fr; } }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: start; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 10px; border-bottom: 1px solid rgba(28, 36, 66, .7); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.muted { color: var(--muted); font-size: 12px; }
.note { color: var(--muted); font-size: 12px; margin: 12px 0 0; line-height: 1.8; }
.note a { color: var(--lav); }
.empty { color: var(--faint); padding: 8px 2px; }
td.ok { color: var(--green); font-weight: 600; }
td.bad { color: var(--danger); font-weight: 600; }

/* شرائط النسبة (حصة الأداة من الطلبات) */
.bar { height: 6px; min-width: 110px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 999px; background: var(--grad); }

/* ---- الوسوم والشرائح ---- */
.tag { display: inline-block; font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line-2); color: var(--text-2); white-space: nowrap; }
.tag.ok, .tag.on { background: rgba(52, 211, 153, .12); border-color: rgba(52, 211, 153, .35); color: var(--green); }
.tag.error, .tag.off, .tag.bad { background: rgba(251, 113, 133, .12); border-color: rgba(251, 113, 133, .35); color: var(--danger); }
.tag.fallback, .tag.paid { background: rgba(245, 183, 107, .12); border-color: rgba(245, 183, 107, .35); color: var(--amber); }
.tag.stopped, .tag.idle { color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { min-height: 36px; padding: 0 13px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line-2); color: var(--text-2); font: inherit; font-size: 13px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent-soft); color: var(--lav-2); border-color: var(--accent); }
.chip.save { background: var(--accent-soft); color: var(--lav-2); border-color: var(--accent); }
.sel, .days, select { min-height: 36px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--line-2); color: var(--text); padding: 0 10px; font: inherit; }
.days { width: 72px; }
.pin { width: 104px; min-height: 36px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--line-2); color: var(--text); padding: 0 10px; font-variant-numeric: tabular-nums; font: inherit; }
.pin.cur { width: 70px; }
.search { min-height: 42px; width: 100%; max-width: 380px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--line-2); color: var(--text); padding: 0 12px; margin-bottom: 12px; font: inherit; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ---- بطاقات معلومات ---- */
.card-body { display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.kv { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.kv > span:first-child { color: var(--muted); }
.ltr { direction: ltr; unicode-bidi: isolate; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- شاشة الدخول ---- */
.deny { max-width: 420px; margin: 12vh auto; padding: 28px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); text-align: center; color: var(--muted); }
.deny h1 { font-family: var(--display); font-size: 24px; margin: 0 0 6px; color: var(--text); }
#login { display: flex; flex-direction: column; gap: 4px; }
#login .search { max-width: none; margin: 6px 0; }
#login .btn-primary { margin-top: 8px; width: 100%; }

/* ---- الجوال: الشريط الجانبي يصير شريط أفقي ---- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 14px 14px 10px; gap: 12px; border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .side-foot { display: none; }
  .nav { flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 2px; }
  .nav a { white-space: nowrap; padding: 8px 12px; }
  .main { padding: 18px 16px 48px; }
  .top h1 { font-size: 22px; }
  .stat b { font-size: 26px; }
  .deny { margin: 8vh auto; }
}

/* ---- الرئيسية: مخطط الاستدعاءات، القوائم، الأدوات ---- */
.chart { height: 236px; display: flex; gap: 10px; align-items: stretch; padding-top: 4px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.chart-stack { height: 180px; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.chart-bar {
  width: 56%; max-width: 46px; min-height: 3px; border-radius: 10px 10px 4px 4px; overflow: hidden;
  display: flex; flex-direction: column; background: var(--surface-2);
}
.chart-bar i { display: block; width: 100%; }
.chart-bar i.bad { background: var(--danger); }
.chart-bar i.ok { background: var(--grad); }
.chart-label { color: var(--muted); font-size: 12px; }
.chart-val { color: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 0; border-bottom: 1px solid rgba(28, 36, 66, .7); font-size: 14px; flex-wrap: wrap; }
.list-row:last-child { border-bottom: 0; }
.list-main { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.alert-row .muted { font-size: 12px; }
.tool-row { flex-direction: column; align-items: stretch; }
.tool-top { display: flex; justify-content: space-between; gap: 10px; }
.tool-row .bar { min-width: 0; }
.status-card span { display: block; color: var(--text-2); }
@media (max-width: 860px) { .chart { height: 200px; } .chart-stack { height: 140px; } }
/* صفحة السجل: الأقسام تحت بعض عشان الجداول ما تنقصش */
.stack { display: flex; flex-direction: column; gap: 16px; }
