:root {
  --red: #C62828;
  --red-dark: #9F1D1D;
  --red-soft: #FDECEC;
  --ink: #1F2933;
  --muted: #6B7785;
  --line: #E4E7EB;
  --bg: #F5F6F8;
  --card: #FFFFFF;
  --green: #2E7D32;
  --green-soft: #E8F5E9;
  --amber: #B26A00;
  --amber-soft: #FFF4E0;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Cairo', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
button, input, select, textarea { font-family: inherit; font-size: 15px; }

.loading { padding: 80px 20px; text-align: center; color: var(--muted); }

/* ---------- صفحات الدخول ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #1F2933 0%, #2D3A46 55%, var(--red-dark) 140%);
}
.auth-card {
  background: var(--card);
  width: 100%; max-width: 420px;
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--red); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px;
}
.brand-name { font-weight: 800; font-size: 22px; }
.auth-sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }

.tabs { display: flex; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px;
  cursor: pointer; color: var(--muted); font-weight: 600;
}
.tabs button.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- نماذج ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  outline: none; transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--red); }
.field textarea { min-height: 70px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

.btn {
  border: 0; border-radius: 8px; padding: 10px 18px; cursor: pointer;
  font-weight: 700; display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--red-dark); }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid #F3C4C4; }
.btn-danger:hover { background: var(--red-soft); }
.btn-block { width: 100%; justify-content: center; padding: 12px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.msg { padding: 10px 12px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; }
.msg.error { background: var(--red-soft); color: var(--red-dark); }
.msg.ok { background: var(--green-soft); color: var(--green); }
.msg.warn { background: var(--amber-soft); color: var(--amber); }

/* ---------- هيكل التطبيق ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: #1F2933; color: #CBD2D9;
  padding: 20px 14px; flex-shrink: 0;
  display: flex; flex-direction: column;
}
.sidebar .brand-name { color: #fff; font-size: 19px; }
.sidebar .company { font-size: 13px; color: #9AA5B1; margin: 4px 0 24px; padding-right: 50px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; color: #CBD2D9; text-decoration: none;
  margin-bottom: 4px; font-weight: 600;
}
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active { background: var(--red); color: #fff; }
.nav a.soon { opacity: .45; pointer-events: none; }
.nav .soon-tag { font-size: 11px; margin-right: auto; background: rgba(255,255,255,.12); padding: 0 8px; border-radius: 10px; }
.sidebar-foot { margin-top: auto; font-size: 13px; border-top: 1px solid rgba(255,255,255,.1); padding-top: 14px; }
.sidebar-foot .who { color: #fff; font-weight: 600; }
.sidebar-foot button { margin-top: 8px; background: transparent; border: 1px solid rgba(255,255,255,.2); color: #CBD2D9; border-radius: 8px; padding: 6px 12px; cursor: pointer; }

.main { flex: 1; padding: 28px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; }
.page-head .sub { color: var(--muted); font-size: 14px; }

/* موبايل */
.topbar { display: none; }
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { display: none; }
  .sidebar.open { display: flex; position: fixed; inset: 0 0 0 auto; z-index: 50; width: 260px; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: #1F2933; color: #fff; padding: 12px 16px;
  }
  .topbar button { background: transparent; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .main { padding: 18px 14px; }
  .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
}

/* ---------- بطاقات وإحصائيات ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.card h2 { margin: 0 0 14px; font-size: 17px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .num { font-size: 30px; font-weight: 800; line-height: 1.2; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.alert { border-color: #F3C4C4; background: var(--red-soft); }
.stat.alert .num { color: var(--red); }

/* ---------- جداول ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 11px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 13px; color: var(--muted); font-weight: 600; background: #FAFBFC; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #FAFBFC; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.badge { display: inline-block; padding: 1px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.gray { background: var(--bg); color: var(--muted); }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 200px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }

.back { color: var(--muted); text-decoration: none; font-size: 14px; display: inline-block; margin-bottom: 8px; }
.back:hover { color: var(--red); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 20px; }
.kv div span { display: block; color: var(--muted); font-size: 12px; }
.kv div b { font-weight: 600; }

/* ---------- نافذة منبثقة ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,32,.5); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; padding: 24px; }
.modal h3 { margin: 0 0 18px; font-size: 19px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 8px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120px);
  background: var(--ink); color: #fff; padding: 10px 20px; border-radius: 10px;
  transition: transform .25s; z-index: 200; font-weight: 600;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red); }
