:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #16202e;
  --muted: #6b7a90;
  --line: #e2e8f0;
  --brand: #16557a;
  --brand-soft: #e8f1f7;
  --present: #159b63;
  --absent: #d94848;
  --excused: #d9881f;
  --late: #7a5bd1;
  --shadow: 0 1px 3px rgba(16,32,52,.08), 0 6px 18px rgba(16,32,52,.06);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Arial", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- الهيكل ---------- */

header.top {
  background: var(--brand);
  color: #fff;
  padding: 14px 18px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 10px rgba(16,32,52,.18);
}
header.top h1 { margin: 0; font-size: 18px; font-weight: 700; }
header.top .sub { font-size: 12.5px; opacity: .82; margin-top: 2px; }

nav.tabs {
  display: flex;
  gap: 4px;
  background: var(--card);
  padding: 6px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 60px;
  z-index: 19;
  overflow-x: auto;
}
nav.tabs button {
  flex: 1 0 auto;
  border: 0;
  background: transparent;
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
nav.tabs button.on { background: var(--brand-soft); color: var(--brand); }

main { padding: 16px; max-width: 1100px; margin: 0 auto 70px; }
.view { display: none; }
.view.on { display: block; }

/* ---------- عناصر عامة ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }

h2.title { margin: 0 0 12px; font-size: 17px; }
h3 { margin: 0 0 8px; font-size: 15px; }

input[type=text], input[type=date], input[type=password], select, textarea {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand-soft);
  border-color: var(--brand);
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  padding: 9px 15px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { background: #f7f9fc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--absent); border-color: #f2c9c9; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--brand-soft);
  color: var(--brand);
}

/* ---------- بطاقات الشعب ---------- */

.sections { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); }
.sec-card { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.sec-card:hover { transform: translateY(-2px); box-shadow: 0 6px 22px rgba(16,32,52,.12); }
.sec-card .name { font-weight: 700; font-size: 16px; margin-bottom: 4px; }
.sec-card .meta { font-size: 13px; color: var(--muted); }
.sec-card .nums { margin-top: 10px; display: flex; gap: 8px; }

/* ---------- قائمة الحضور ---------- */

.stu-list { display: flex; flex-direction: column; gap: 7px; }

.stu {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
}
.stu.has-present { border-right: 4px solid var(--present); }
.stu.has-absent  { border-right: 4px solid var(--absent); }
.stu.has-excused { border-right: 4px solid var(--excused); }
.stu.has-late    { border-right: 4px solid var(--late); }

.stu .idx { width: 26px; color: var(--muted); font-size: 12.5px; text-align: center; flex: none; }
.stu .who { flex: 1; min-width: 0; }
.stu .who b { font-weight: 600; display: block; }
.stu .who small { color: var(--muted); }

.marks { display: flex; gap: 5px; flex: none; }
.marks button {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  font-weight: 800;
  font-size: 15px;
  color: var(--muted);
}
.marks button[data-s=present].on { background: var(--present); border-color: var(--present); color: #fff; }
.marks button[data-s=absent].on  { background: var(--absent);  border-color: var(--absent);  color: #fff; }
.marks button[data-s=excused].on { background: var(--excused); border-color: var(--excused); color: #fff; }
.marks button[data-s=late].on    { background: var(--late);    border-color: var(--late);    color: #fff; }

.clip {
  flex: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  width: 38px; height: 38px;
  cursor: pointer;
  font-size: 15px;
}
.clip.has { background: var(--excused); border-color: var(--excused); color: #fff; }
.clip:disabled { opacity: .35; cursor: default; }

/* ---------- الجداول ---------- */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; }
th { background: #f7f9fc; font-size: 13px; color: var(--muted); position: sticky; top: 0; }
tbody tr:hover { background: #fafbfd; }
td.num, th.num { text-align: center; }
.scroll { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 12px; background: #fff; }

.warn { color: var(--absent); font-weight: 700; }

/* ---------- نافذة ---------- */

.modal-bg {
  position: fixed; inset: 0;
  background: rgba(16,32,52,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 50;
}
.modal {
  background: #fff; border-radius: 16px; padding: 18px;
  width: min(520px, 100%); max-height: 88vh; overflow: auto;
  box-shadow: 0 20px 60px rgba(16,32,52,.3);
}
.modal h3 { margin-top: 0; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; }

.file-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border: 1px solid var(--line);
  border-radius: 10px; margin-bottom: 6px; background: #fafbfd;
}
.file-row a { color: var(--brand); text-decoration: none; font-weight: 600; flex: 1; word-break: break-all; }

/* ---------- تنبيه ---------- */

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

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend span b { display: inline-block; width: 20px; height: 20px; line-height: 20px;
  text-align: center; border-radius: 6px; color: #fff; margin-left: 5px; font-size: 12px; }

.empty { padding: 36px 12px; text-align: center; color: var(--muted); }

@media (max-width: 560px) {
  main { padding: 10px; }
  .marks button, .clip { width: 34px; height: 34px; font-size: 14px; }
  .stu { padding: 8px; gap: 6px; }
  .stu .idx { display: none; }

  /* على الجوال تُضغط بطاقة الخيارات كي تبدأ قائمة الطلاب فوق الطيّة */
  header.top { padding: 9px 14px; }
  header.top h1 { font-size: 16px; }
  header.top .sub { font-size: 11px; }
  nav.tabs { top: 52px; padding: 4px; }
  nav.tabs button { padding: 7px 10px; font-size: 14px; }

  .card { padding: 10px; margin-bottom: 10px; }
  .row { gap: 7px; }
  .row + .row { margin-top: 7px !important; }
  input[type=text], input[type=date], select { padding: 7px 9px; font-size: 14px; }
  .btn { padding: 7px 11px; font-size: 14px; }

  /* الرموز سطر واحد صغير — شرحها موجود على الأزرار نفسها */
  .legend { gap: 9px; font-size: 11px; margin-top: 7px !important; }
  .legend span b { width: 17px; height: 17px; line-height: 17px; font-size: 11px; margin-left: 3px; }
}
