/* يجب أن تسبق أي قاعدة display صريحة على العناصر نفسها (login-wrap/app-shell/modal-wrap)
   وإلا تكسر خاصية hidden لتعادل الخصوصية مع القاعدة الافتراضية للمتصفح. */
[hidden] { display: none !important; }

:root {
  --brand: #0f766e;
  --brand-dark: #0c5c56;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --line: #e2e8f0;
  --bg: #f8fafc;
  --card: #ffffff;
  --good: #15803d; --good-soft: #dcfce7;
  --warn: #b45309; --warn-soft: #fef3c7;
  --bad: #b91c1c;  --bad-soft: #fee2e2;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif; font-size: 14px; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

.muted { color: var(--ink-2); }
.error { color: var(--bad); font-weight: 600; }

/* ═══ تسجيل الدخول ═══ */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; width: 100%; max-width: 380px; box-shadow: 0 10px 30px rgba(15,23,42,.06); }
.login-card h1 { font-size: 19px; margin: 0 0 4px; }
.login-card .muted { font-size: 12.5px; margin: 0 0 18px; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 5px; font-weight: 600; }
.field input, .field select { width: 100%; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 9px; background: #fff; color: var(--ink); }
.field input:focus, .field select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

.btn { background: var(--brand); color: #fff; border: none; border-radius: 9px; padding: 10px 16px;
  font-weight: 700; width: 100%; }
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.sm { width: auto; padding: 6px 12px; font-size: 12.5px; }
.btn.inline { width: auto; }

/* ═══ الهيكل ═══ */
#app-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
#sidebar { background: var(--brand-dark); color: #eafffb; display: flex; flex-direction: column;
  padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 800; font-size: 14.5px; line-height: 1.5; margin-bottom: 22px; }
.brand span { display: block; font-weight: 500; font-size: 11.5px; opacity: .75; }
#nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
#nav button { text-align: right; background: transparent; border: none; color: #d7fbf4;
  padding: 10px 12px; border-radius: 9px; font-size: 13.5px; font-weight: 600; }
#nav button:hover { background: rgba(255,255,255,.08); }
#nav button.active { background: #fff; color: var(--brand-dark); }
.side-foot { border-top: 1px solid rgba(255,255,255,.15); padding-top: 12px; }
#who { font-size: 12px; margin-bottom: 8px; opacity: .9; line-height: 1.6; }
#main { padding: 26px 30px; min-width: 0; }

/* ═══ عناصر عامة ═══ */
h1.page-title { font-size: 19px; margin: 0 0 4px; }
p.page-sub { color: var(--ink-2); margin: 0 0 20px; font-size: 13px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 12px; margin-bottom: 24px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi b { display: block; font-size: 24px; font-weight: 800; }
.kpi span { font-size: 12px; color: var(--ink-2); }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 180px; padding: 8px 12px; border: 1px solid var(--line);
  border-radius: 9px; background: #fff; }
.spacer { flex: 1; }

table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
th { background: #f1f5f9; font-weight: 700; color: var(--ink-2); font-size: 12px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad  { background: var(--bad-soft);  color: var(--bad); }
.badge.grey { background: #e2e8f0; color: var(--ink-2); }
.pill-row { display: flex; gap: 4px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.hint { color: var(--ink-3); font-size: 12px; }
.loading { padding: 40px; text-align: center; color: var(--ink-3); }

/* ═══ نافذة منبثقة ═══ */
.modal-wrap { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.45); }
.modal-card { position: relative; background: #fff; border-radius: var(--radius); padding: 22px;
  width: 100%; max-width: 440px; max-height: 88vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { font-size: 16px; margin: 0; }
.icon-x { background: none; border: none; font-size: 16px; color: var(--ink-2); }
.checks { display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow: auto;
  border: 1px solid var(--line); border-radius: 9px; padding: 10px; }
.checks label { display: flex; align-items: center; gap: 8px; font-size: 13px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100; }
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  #app-shell { grid-template-columns: 1fr; }
  #sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 14px; }
  #nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { border-top: none; padding-top: 0; }
  #main { padding: 18px; }
}
