/* ================= تخطيط لوحة الأدمن ================= */
body.admin { background: var(--page); }
.app { display: grid; grid-template-columns: 268px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
  background: var(--pattern), var(--hero); color: #fff; padding: 20px 14px;
}
.side-brand { display: flex; flex-direction: column; gap: 12px; padding: 0 4px 18px; border-bottom: 1px solid rgba(255,255,255,.12); }
.side-brand .logo { justify-content: center; padding: 10px 14px; }
.side-brand .logo img { height: auto; width: 100%; max-width: 200px; }
.side-brand > div { padding: 0 6px; }
.side-brand b { font-size: 16px; }
.side-brand .brand-org { font-size: 12px; opacity: .78; line-height: 1.4; }
.nav { display: flex; flex-direction: column; gap: 3px; margin-top: 14px; }
.nav-h { font-size: 11.5px; font-weight: 600; letter-spacing: .3px; opacity: .55; padding: 14px 12px 6px; }
.nav .tab {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; border: 0; border-radius: 12px;
  background: transparent; color: rgba(255,255,255,.82); font-weight: 500; font-size: 14.5px; cursor: pointer; text-align: start;
  transition: background .15s, color .15s;
}
.nav .tab .ic { width: 19px; height: 19px; opacity: .9; }
.nav .tab:hover { background: rgba(255,255,255,.09); color: #fff; }
.nav .tab.active { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: 0 8px 20px -10px rgba(0,0,0,.45); }
.nav .tab.active .ic { color: var(--brand); opacity: 1; }
.side-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid rgba(255,255,255,.12); display: grid; gap: 8px; }
.side-foot .pill { justify-self: start; background: rgba(255,255,255,.14); color: #fff; border-color: transparent; }
.side-foot .pill.ok { background: rgba(95,227,161,.18); color: #b9f5d6; }
.side-foot .pill.bad { background: rgba(255,138,128,.2); color: #ffd1cc; }
.side-foot .small { opacity: .75; line-height: 1.5; }

.main { min-width: 0; display: flex; flex-direction: column; }
.appbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 28px; background: color-mix(in srgb, var(--page) 86%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.appbar h1 { margin: 0; font-size: 21px; font-weight: 700; }
.appbar .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.content { padding: 24px 28px 60px; max-width: 1400px; width: 100%; }
.tabpane > .card + .card, .tabpane > .grid + .card, .tabpane > .card + .grid, .tabpane > .grid + .grid { margin-top: 18px; }

/* شاشة الدخول */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--pattern), var(--hero); position: relative; }
.auth-tools { position: absolute; top: 16px; inset-inline-end: 16px; display: flex; gap: 8px; }
.auth-card { width: 100%; max-width: 430px; padding: 30px; box-shadow: var(--shadow-lg); border: 0; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.auth-brand .logo img { height: 48px; }
.auth-brand b { display: block; color: var(--ink); font-size: 16px; }
.auth-brand .brand-org { color: var(--muted); }
.auth h2 { margin: 0 0 4px; font-size: 22px; }

/* ================= عناصر التحليلات ================= */
.hbars { display: flex; flex-direction: column; gap: 9px; }
.hb { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.hb-l { flex: 0 0 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.hbars.wrap .hb-l { white-space: normal; line-height: 1.4; font-size: 12.5px; }
.hb-t { flex: 1; height: 12px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.hb-t i { display: block; height: 100%; border-radius: 99px; }
.hb-v { flex: 0 0 auto; min-width: 46px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hb-v small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; line-height: 1.2; }
.report .hb-l { color: #374641; }
.report .hb-t { background: #eef3f1; }

.gbars { position: relative; display: flex; align-items: flex-end; gap: 18px; padding: 0 30px 34px 0; margin-top: 10px; }
.gb-grid { position: absolute; right: 30px; left: 0; border-top: 1px solid var(--line); height: 0; }
.gb-grid span { position: absolute; right: -24px; top: -9px; font-size: 11px; color: var(--muted); }
.gb-g { flex: 1; height: 100%; display: flex; flex-direction: column; position: relative; z-index: 1; }
.gb-bars { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.gb-b { flex: 0 1 34px; border-radius: 5px 5px 0 0; position: relative; min-height: 0; transition: opacity .15s; }
.gb-b:hover { opacity: .8; }
.gb-x { position: absolute; bottom: -28px; left: 0; right: 0; text-align: center; font-size: 12.5px; color: var(--ink-2); font-weight: 600; }

.dist { display: flex; height: 24px; border-radius: 8px; overflow: hidden; gap: 2px; background: var(--surface-3); }
.dist i { display: block; height: 100%; }

.gauge { display: block; width: 100%; max-width: 230px; margin: 4px auto 0; }
.gauge-wrap { text-align: center; }
.gauge-wrap .v { font-size: 34px; font-weight: 700; margin-top: -54px; letter-spacing: -.5px; }
.gauge-wrap .band-tag { justify-content: center; margin-top: 2px; }

.heat td.h { text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 54px; }
.heat th.v { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; height: 170px; vertical-align: bottom; font-size: 12px; }

.band-tag { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.clickable { cursor: pointer; }
.clickable:hover td { background: var(--brand-soft) !important; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.kv > * { min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.seg label { padding: 9px 16px; cursor: pointer; font-weight: 600; font-size: 14px; border-inline-end: 1px solid var(--line-2); }
.seg label:last-child { border-inline-end: 0; }
.seg input { display: none; }
.seg input:checked + span { color: var(--brand); }
.seg label:has(input:checked) { background: var(--brand-soft); }
.sec-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.sec-title h3 { margin: 0; }
.cmt { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); margin-bottom: 8px; font-size: 13.5px; }
.report .cmt { background: #f8faf9; border-color: #e2e8e5; }
.quick { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
/* إجراءات الحذف */
.card-ic.bad { background: var(--danger-soft); color: var(--danger); }
.btn.danger.solid { background: #c2413b; border-color: #c2413b; color: #fff; }
.btn.danger.solid:hover { background: #a93530; border-color: #a93530; color: #fff; }
.lim-grid { display: grid; grid-template-columns: minmax(110px, 1fr) 110px 110px; gap: 10px 12px; align-items: center; }
.lim-grid .input { text-align: center; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; white-space: nowrap; }

/* ================= مخطط علاقات المقيّم ================= */
.map { display: flex; flex-direction: column; align-items: center; }
.mlink { width: 2px; height: 22px; background: var(--line-2); }
.mlegend { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.mgroup { width: 100%; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-2); padding: 14px 16px; }
.mgroup.top { max-width: 420px; }
.mhead { display: flex; align-items: center; gap: 8px; font-size: 14.5px; }
.mhead .count { margin-inline-start: auto; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-3); padding: 2px 9px; border-radius: 99px; font-variant-numeric: tabular-nums; }
.mhint { font-size: 12.5px; color: var(--muted); margin: 2px 0 10px; min-height: 4px; }
.mnodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 8px; }
.mgroup.top .mnodes { grid-template-columns: 1fr; }
.mnone { font-size: 13px; color: var(--muted); }
.mnode { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); min-width: 0; }
.mnode .mav { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; background: var(--surface-3); color: var(--muted); }
.mnode .mav .ic { width: 16px; height: 16px; }
.mnode .mtx { min-width: 0; line-height: 1.35; }
.mnode b { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mnode small { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mnode.done { background: var(--ok-soft); border-color: transparent; }
.mnode.done .mav { background: var(--ok); color: #fff; }
.mmid { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) 250px minmax(0, 1fr); gap: 16px; align-items: center; }
.mgroup.side .mnodes { grid-template-columns: 1fr; }
.mmid.solo { grid-template-columns: 250px; justify-content: center; }
.mcenter { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 18px 14px; border-radius: 18px; border: 2px solid var(--brand); background: var(--brand-soft); }
.mcenter b { font-size: 15.5px; }
.mcenter small { color: var(--ink-2); font-size: 12.5px; }
.mcenter .pill { margin-top: 4px; }
@media (max-width: 760px) {
  .mmid { grid-template-columns: 1fr; }
  .mmid .mcenter { order: -1; }
  .mlegend { display: none; }
}

/* ================= شاشات صغيرة ================= */
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 30; height: auto; flex-direction: row; align-items: center; gap: 10px; padding: 10px 12px; overflow-x: auto; }
  .side-brand { border: 0; padding: 0; }
  .side-brand > div, .nav-h, .side-foot { display: none; }
  .side-brand .logo { padding: 4px; border-radius: 10px; }
  .side-brand .logo img { width: auto; height: 32px; }
  .side-brand .logo-full { display: none; }
  .side-brand .logo-mark { display: block; }
  .nav { flex-direction: row; margin: 0; gap: 4px; }
  .nav .tab { width: auto; white-space: nowrap; padding: 9px 12px; }
  .appbar { position: static; padding: 14px 16px; }
  .content { padding: 18px 16px 48px; }
}
@media (max-width: 640px) {
  .hb-l { flex-basis: 120px !important; }
  .kv { grid-template-columns: 1fr; }
  .nav .tab span { display: none; }
  .appbar .actions .btn { padding: 8px 12px; }
}

/* ================= الطباعة: يُعرض التقرير المطلوب وحده ================= */
#printRoot { display: none; }
@media print {
  @page { size: A4; margin: 10mm; }
  body.printing { background: #fff; }
  body.printing > *:not(#printRoot) { display: none !important; }
  body.printing #printRoot { display: block; }
  #printRoot .report { padding: 0; }
  #printRoot .pb { break-before: page; page-break-before: always; }
  #printRoot .avoid, #printRoot tr { break-inside: avoid; page-break-inside: avoid; }
  #printRoot * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
