:root {
  --primary: #0B4EA2;
  --primary-dark: #083C7E;
  --accent: #F15A3B;
  --tile: #E4ECF7;
  --bg: #F7F9FC;
  --surface: #FFFFFF;
  --text: #1A1A1A;
  --muted: #8A8F98;
  --border: #E3E7EE;
  --success: #1E9E5A;
  --warning: #E09B00;
  --danger: #D93025;
  --radius: 18px;
  --shadow: 0 2px 10px rgba(11, 78, 162, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.boot { padding: 60px; text-align: center; color: var(--muted); }

/* ---------- Layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 22px 18px 16px; text-align: center; border-bottom: 1px solid rgba(255,255,255,.12); }
.sidebar .brand img { max-width: 150px; max-height: 70px; background: #fff; border-radius: 14px; padding: 6px 10px; }
.sidebar .brand .brand-name { margin-top: 8px; font-weight: 700; font-size: 14px; opacity: .95; }
.sidebar nav { flex: 1; padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  color: #fff; opacity: .85; padding: 11px 16px; border-radius: 14px;
  display: flex; align-items: center; gap: 10px; font-weight: 600;
}
.sidebar nav a:hover { background: rgba(255,255,255,.1); opacity: 1; text-decoration: none; }
.sidebar nav a.active { background: #fff; color: var(--primary); opacity: 1; }
.sidebar nav a .ico { width: 22px; text-align: center; }
.sidebar .user { padding: 16px 18px; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar .user .name { font-weight: 700; }
.sidebar .user .role { font-size: 13px; opacity: .8; margin-bottom: 10px; }
.main { flex: 1; min-width: 0; padding: 26px 30px 50px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.back { font-size: 14px; display: inline-block; margin-bottom: 6px; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 18px 14px 40px; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px;
}
.card h2 { font-size: 17px; margin-bottom: 14px; color: var(--primary-dark); }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 18px 20px 0; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.two { grid-template-columns: 1fr; } }
.grid > .card { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.stack > .card { margin-bottom: 0; }

/* ---------- Stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.tile {
  background: var(--tile); border-radius: var(--radius); padding: 16px 18px; color: var(--primary-dark);
  display: block; border: 1px solid transparent;
}
.tile .num { font-size: 30px; font-weight: 800; line-height: 1.1; }
.tile .lbl { font-size: 14px; font-weight: 600; opacity: .85; }
a.tile:hover { text-decoration: none; border-color: var(--primary); }
.tile.hero { background: var(--accent); color: #fff; grid-column: span 2; }
.tile.hero .num { font-size: 42px; }
.tile.hero .go { font-size: 13px; opacity: .95; margin-top: 4px; }
.tile.white { background: var(--surface); border-color: var(--border); }
.section-title { font-size: 16px; font-weight: 700; color: var(--muted); margin: 6px 0 10px; }

/* ---------- Buttons ---------- */
.btn {
  border: none; border-radius: 999px; padding: 9px 20px; font: inherit; font-weight: 700;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  background: var(--accent); color: #fff; transition: filter .15s, opacity .15s; white-space: nowrap;
}
.btn:hover { filter: brightness(.94); text-decoration: none; }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn.blue { background: var(--primary); }
.btn.green { background: var(--success); }
.btn.red { background: var(--danger); }
.btn.ghost { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn.ghost.light { color: #fff; border-color: rgba(255,255,255,.6); }
.btn.sm { padding: 5px 14px; font-size: 13px; }
.btn.lg { padding: 12px 28px; font-size: 16px; }
.btn.block { width: 100%; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 3px; }
.field .err { color: var(--danger); font-size: 13px; margin-top: 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 12px;
  background: #fff; color: var(--text); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); }
textarea { min-height: 90px; resize: vertical; }
input.ltr { direction: ltr; text-align: right; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
/* One line per cell; .table-wrap scrolls sideways on narrow screens. */
th, td { padding: 12px 16px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
th { font-size: 13px; color: var(--muted); font-weight: 700; background: #FAFBFD; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #F3F7FD; }
td.num, .mono { font-family: Consolas, "Courier New", monospace; direction: ltr; unicode-bidi: embed; }
td .muted, .muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 3px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 700;
  background: var(--tile); color: var(--primary-dark); white-space: nowrap;
}
.badge.success { background: #E3F5EB; color: var(--success); }
.badge.warning { background: #FDF3DC; color: #A87400; }
.badge.danger { background: #FCE6E4; color: var(--danger); }
.badge.muted { background: #EEF0F3; color: #5F656E; }
.badge.orange { background: #FDE7E1; color: var(--accent); }
.badge.blue { background: var(--tile); color: var(--primary); }

/* ---------- Tabs / toolbar ---------- */
.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 16px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; background: var(--surface); padding: 5px; border-radius: 999px; border: 1px solid var(--border); }
.tabs button {
  border: none; background: transparent; font: inherit; font-weight: 600; font-size: 14px;
  padding: 7px 16px; border-radius: 999px; cursor: pointer; color: var(--muted);
}
.tabs button.active { background: var(--primary); color: #fff; }
.search { max-width: 320px; }

/* ---------- Misc states ---------- */
.empty, .loading { padding: 40px 20px; text-align: center; color: var(--muted); }
.loading::before {
  content: ""; display: block; width: 28px; height: 28px; margin: 0 auto 10px;
  border: 3px solid var(--tile); border-top-color: var(--primary); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.alert { border-radius: 14px; padding: 12px 16px; margin-bottom: 16px; font-weight: 600; }
.alert.danger { background: #FCE6E4; color: var(--danger); border: 1px solid #F5C2BD; }
.alert.warning { background: #FDF3DC; color: #8A5F00; border: 1px solid #F3DDA4; }
.alert.info { background: var(--tile); color: var(--primary-dark); }
.alert.success { background: #E3F5EB; color: var(--success); }

/* ---------- Key/value ---------- */
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 14px; }
dl.kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.nid {
  font-family: Consolas, "Courier New", monospace; direction: ltr; unicode-bidi: embed; display: inline-block;
  font-size: 26px; letter-spacing: 3px; font-weight: 700; color: var(--primary-dark);
  background: var(--tile); padding: 6px 14px; border-radius: 12px;
}

/* ---------- Documents ---------- */
.docs { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.doc { text-align: center; }
.doc .lbl { font-weight: 700; margin-bottom: 6px; }
.doc .frame {
  background: #F0F3F8; border: 1px solid var(--border); border-radius: 14px; height: 220px;
  display: flex; align-items: center; justify-content: center; overflow: hidden; cursor: zoom-in;
}
.doc .frame img { max-width: 100%; max-height: 100%; object-fit: contain; }
.doc .missing { color: var(--muted); font-size: 14px; }

/* ---------- Overlay / modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(10, 20, 40, .55); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 20px; padding: 24px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal h3 { font-size: 19px; margin-bottom: 12px; color: var(--primary-dark); }
.modal .body { margin-bottom: 18px; }
.modal .body p { margin: 0 0 10px; }
.modal .foot { display: flex; gap: 10px; justify-content: flex-start; }
.viewer { flex-direction: column; background: rgba(5, 10, 20, .88); }
.viewer .stage { flex: 1; width: 100%; overflow: auto; display: flex; align-items: center; justify-content: center; }
.viewer .stage img { transition: transform .2s; max-width: 90vw; max-height: 80vh; }
.viewer .controls { display: flex; gap: 8px; padding: 12px; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 22px; left: 22px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: #fff; padding: 12px 20px; border-radius: 14px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 380px; animation: pop .2s ease-out;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(160deg, var(--primary) 0%, var(--primary-dark) 100%);
}
.login-card { background: #fff; border-radius: 22px; padding: 34px 30px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-card .logo { text-align: center; margin-bottom: 14px; }
.login-card .logo img { max-width: 190px; max-height: 90px; }
.login-card h1 { text-align: center; font-size: 20px; color: var(--primary-dark); margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 22px; }

/* ---------- Stepper ---------- */
.stepper { display: flex; align-items: flex-start; gap: 0; margin: 4px 0 6px; overflow: hidden; }
.step { flex: 1; text-align: center; position: relative; }
.step .dot {
  width: 34px; height: 34px; border-radius: 50%; margin: 0 auto 6px; display: flex; align-items: center; justify-content: center;
  background: var(--border); color: var(--muted); font-weight: 800; position: relative; z-index: 1;
}
/* Connector to the previous step. In RTL the previous step is on the right. */
.step::before {
  content: ""; position: absolute; top: 16px; left: 50%; width: 100%; height: 3px; background: var(--border);
}
.step:first-child::before { display: none; }
.step.done .dot { background: var(--success); color: #fff; }
.step.done::before, .step.current::before { background: var(--success); }
.step.current .dot { background: var(--accent); color: #fff; box-shadow: 0 0 0 5px #FDE7E1; }
.step .lbl { font-size: 13.5px; font-weight: 700; }
.step .when { font-size: 12px; color: var(--muted); }
.step.pending .lbl { color: var(--muted); }

.explain { background: var(--tile); border-radius: 16px; padding: 16px 18px; color: var(--primary-dark); font-size: 14px; }
.explain p { margin: 0 0 8px; }
.explain p:last-child { margin: 0; }
.counts { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.counts .c { background: #FAFBFD; border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; }
.counts .c .n { font-size: 22px; font-weight: 800; }
.counts .c .l { font-size: 13px; color: var(--muted); }
.counts .c.warn { background: #FCE6E4; border-color: #F5C2BD; color: var(--danger); }
.points-edit { display: flex; gap: 6px; align-items: center; }
.points-edit input { width: 90px; padding: 5px 10px; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.history li:last-child { border-bottom: none; }

/* Users & access */
.access-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.access-matrix table { width: 100%; }
.access-matrix th, .access-matrix td { padding: 6px 8px; text-align: center; }
.access-matrix th:first-child, .access-matrix td:first-child { text-align: start; }
.access-matrix input[type=radio] { width: 18px; height: 18px; accent-color: var(--primary); }
.temp-pass { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px;
  background: var(--tile); border-radius: 10px; font-family: ui-monospace, Consolas, monospace; font-size: 16px; }
