:root {
  --bg: #f0f1f7;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #8a93a6;
  --line: #e7e9f0;
  --head: #4b5675;
  --gold: #b89d5b;
  --gold-dark: #9c834a;
  --ok: #16a34a;
  --ok-bg: #e8f7ee;
  --bad: #dc2626;
  --bad-bg: #fdecec;
  --check: #3e4a6b;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Cairo', system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }
button, input, select { font: inherit; }
.center { min-height: 60vh; display: grid; place-items: center; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ── شاشة الدخول ── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 16px; box-shadow: 0 10px 30px rgba(40, 50, 80, .08); padding: 32px 28px; }
.login-card .logo { width: 56px; height: 56px; margin: 0 auto 12px; display: block; }
.login-card h1 { margin: 0 0 4px; text-align: center; font-size: 20px; }
.login-card p.sub { margin: 0 0 22px; text-align: center; color: var(--muted); font-size: 13px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input, .field select { width: 100%; height: 42px; border: 1.5px solid var(--line); border-radius: 10px; padding: 0 12px; background: #fafbfd; }
.field input:focus, .field select:focus { outline: none; border-color: var(--head); background: #fff; }
.btn { height: 40px; padding: 0 16px; border-radius: 10px; border: 0; cursor: pointer; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn-primary { background: var(--gold); color: #fff; }
.btn-primary:hover { background: var(--gold-dark); }
.btn-dark { background: var(--head); color: #fff; }
.btn-light { background: #eef0f6; color: var(--ink); }
.btn-danger { background: var(--bad-bg); color: var(--bad); }
.btn-block { width: 100%; height: 44px; }
.btn:disabled { opacity: .6; cursor: default; }
.error { background: var(--bad-bg); color: var(--bad); padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 14px; }

/* ── الإطار العام ── */
.topbar { background: #fff; border-bottom: 1px solid var(--line); }
.topbar .in { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; }
.brand img { width: 30px; height: 30px; }
.spacer { flex: 1; }
.who { text-align: left; line-height: 1.3; }
.who b { display: block; font-size: 13px; }
.who small { color: var(--muted); }
.nav { background: var(--head); }
.nav .in { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; gap: 2px; overflow-x: auto; }
.nav a { color: #dfe3ee; text-decoration: none; padding: 11px 14px; font-weight: 600; white-space: nowrap; border-bottom: 3px solid transparent; }
.nav a.active, .nav a:hover { color: #fff; border-bottom-color: var(--gold); }
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 3px rgba(40, 50, 80, .06); }
.card-pad { padding: 18px; }
h2.title { font-size: 18px; margin: 0 0 4px; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }

/* ── بطاقات البرامج ── */
.apps-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.app-tile { display: flex; flex-direction: column; gap: 8px; padding: 20px 18px; text-decoration: none; color: inherit; border: 1.5px solid transparent; transition: .15s; }
.app-tile:hover { border-color: var(--gold); transform: translateY(-2px); }
.app-tile .ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; background: #f3efe5; }
.app-tile b { font-size: 16px; }
.app-tile small { color: var(--muted); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ── جدول الصلاحيات ── */
.search { height: 38px; border: 1.5px solid var(--line); border-radius: 10px; padding: 0 12px; min-width: 220px; background: #fff; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.matrix { width: 100%; border-collapse: collapse; min-width: 760px; }
.matrix thead th { background: var(--head); color: #fff; font-weight: 700; padding: 13px 10px; text-align: center; white-space: nowrap; }
.matrix thead th:first-child { text-align: right; padding-right: 18px; }
.matrix td { border-bottom: 1px solid var(--line); padding: 12px 10px; text-align: center; vertical-align: middle; }
.matrix tr:last-child td { border-bottom: 0; }
.matrix td.user { text-align: right; padding-right: 18px; min-width: 170px; }
.matrix td.user b { display: block; font-size: 14px; }
.matrix td.user small { color: var(--muted); font-size: 11.5px; }
.matrix tr.inactive td.user b { color: var(--muted); text-decoration: line-through; }
.cell { display: inline-flex; flex-direction: column; align-items: center; gap: 6px; }
.cbx { width: 20px; height: 20px; accent-color: var(--check); cursor: pointer; }
.cbx:disabled { cursor: default; opacity: .45; }
.role-select { height: 28px; font-size: 11.5px; border: 1px solid var(--line); border-radius: 7px; background: #f8f9fc; max-width: 130px; padding: 0 4px; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 6px; font-size: 11.5px; font-weight: 700; cursor: pointer; border: 0; margin: 0 2px; }
.chip-ok { background: var(--ok-bg); color: var(--ok); }
.chip-bad { background: var(--bad-bg); color: var(--bad); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; background: #eef0f6; color: #4b5675; }
.badge-warn { background: #fff4e0; color: #b26a00; }
.badge-off { background: var(--bad-bg); color: var(--bad); }
.lock { font-size: 12px; opacity: .6; }

/* ── جدول عادي ── */
table.list { width: 100%; border-collapse: collapse; }
.list th { text-align: right; font-size: 12.5px; color: var(--muted); font-weight: 700; padding: 10px; border-bottom: 1px solid var(--line); }
.list td { padding: 10px; border-bottom: 1px solid var(--line); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions .btn { height: 32px; font-size: 12.5px; padding: 0 10px; }

/* ── نافذة منبثقة ── */
.modal-bg { position: fixed; inset: 0; background: rgba(20, 25, 40, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 460px; max-height: 90vh; overflow: auto; padding: 22px; }
.modal h3 { margin: 0 0 14px; }
.modal .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-start; margin-top: 8px; }
.check-line { display: flex; align-items: center; gap: 8px; margin: 6px 0 14px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 60; font-weight: 600; max-width: calc(100% - 32px); }
.toast.bad { background: var(--bad); }
textarea { width: 100%; min-height: 140px; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px; font-family: monospace; direction: ltr; }
code.key { display: block; direction: ltr; background: #f3f4f8; padding: 10px; border-radius: 8px; word-break: break-all; font-size: 13px; }
@media (max-width: 640px) {
  .modal .row2 { grid-template-columns: 1fr; }
  .who { display: none; }
  .search { min-width: 0; width: 100%; }
}
@media print {
  .topbar, .nav, .no-print { display: none !important; }
  body { background: #fff; }
}
