/* ============================================================
   نظام التصميم - إدارة بيانات الطلاب
   فكرة التصميم: "سجل الحضور الورقي" - ورق دافئ، حبر أخضر داكن
   لتمييز الأقسام، مع لون العلامات الأخضر/الأحمر المستخدم أصلاً
   في تسجيل الحضور والغياب.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@600;700;800&family=Almarai:wght@400;700;800&display=swap');

:root{
  /* ألوان */
  --paper: #FBF8F2;
  --surface: #FFFFFF;
  --surface-2: #F3EFE4;
  --ink: #20302B;
  --ink-soft: #5C6B63;
  --border: #E5DECB;

  --brand: #2F6F5E;
  --brand-dark: #21503F;
  --brand-tint: #E7F0EC;

  --present: #3F8F5F;
  --present-tint: #E7F5EB;
  --absent: #B54A3A;
  --absent-tint: #FBEAE7;

  --warn: #B98900;
  --warn-tint: #FBF3DA;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(32,48,43,.06), 0 6px 20px -8px rgba(32,48,43,.18);
  --shadow-sm: 0 1px 2px rgba(32,48,43,.08);

  --font-display: 'Cairo', 'Tahoma', sans-serif;
  --font-body: 'Almarai', 'Tahoma', sans-serif;
}

*{ box-sizing: border-box; }

html, body{
  direction: rtl;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

h1,h2,h3,h4, .brand-font{
  font-family: var(--font-display);
}

a{ color: var(--brand-dark); }

::selection{ background: var(--brand-tint); }

:focus-visible{
  outline: 3px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- شريط علوي ---------- */
.app-bar{
  position: fixed;
  inset-inline: 0;
  top: 0;
  z-index: 40;
  height: 60px;
  background: var(--brand-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  box-shadow: var(--shadow);
}
.bar-start{
  display: flex;
  align-items: center;
  gap: 10px;
}
.bar-end{
  display: flex;
  align-items: center;
  gap: 6px;
}
.menu-wrap{ position: relative; }
.menu-btn{
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,.14);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}
.menu-btn:hover{ background: rgba(255,255,255,.26); }

/* ---------- القائمة الجانبية المنزلقة (Drawer) ---------- */
.drawer-overlay{
  position: fixed;
  inset: 0;
  background: rgba(20,26,23,.45);
  z-index: 70;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}
.drawer-overlay.open{
  opacity: 1;
  pointer-events: auto;
}
.drawer{
  position: fixed;
  top: 0;
  bottom: 0;
  inset-inline-start: 0;
  width: 85vw;
  max-width: 360px;
  background: var(--surface);
  z-index: 80;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 24px rgba(0,0,0,.18);
  transform: translateX(-100%);
  transition: transform .26s ease;
}
[dir="rtl"] .drawer{ transform: translateX(100%); }
.drawer.open{ transform: translateX(0); }

@media (min-width: 720px){
  .drawer{ width: 380px; max-width: 380px; }
}

.drawer-head{
  background: var(--brand-dark);
  color: #fff;
  padding: 24px 20px 20px;
  flex: 0 0 auto;
  position: relative;
}
.drawer-head .drawer-close{
  position: absolute;
  top: 16px;
  inset-inline-end: 16px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.14);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.drawer-head .drawer-close:hover{ background: rgba(255,255,255,.26); }
.drawer-head .avatar{
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--present);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: 12px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25);
}
.drawer-head .school-name{
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 17px;
  margin: 0 0 3px;
}
.drawer-head .user-name{
  font-size: 13px;
  opacity: .8;
  margin: 0;
}

.drawer-body{
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.drawer-body a{
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 14px;
  border-radius: 12px;
  color: var(--ink);
  text-decoration: none;
  font-size: 16px;
  font-weight: 700;
  transition: background .15s ease;
}
.drawer-body a .icon{ font-size: 20px; width: 26px; text-align: center; }
.drawer-body a:hover{ background: var(--surface-2); }
.drawer-body a.active{ background: var(--brand-tint); color: var(--brand-dark); }

.drawer-foot{
  flex: 0 0 auto;
  padding: 14px;
  border-top: 1px solid var(--border);
}
.drawer-foot a{
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px;
  border-radius: 12px;
  background: var(--absent-tint);
  color: var(--absent);
  text-decoration: none;
  font-weight: 800;
  font-size: 15px;
}
.drawer-foot a:hover{ background: var(--absent); color: #fff; }


.app-bar .brand{
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  text-decoration: none;
}
.app-bar .brand .mark{
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--present);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25);
}
.app-bar nav{
  display: flex;
  align-items: center;
  gap: 6px;
}
.app-bar .who{
  font-size: 13px;
  opacity: .85;
  padding-inline-start: 10px;
  margin-inline-start: 4px;
  border-inline-start: 1px solid rgba(255,255,255,.25);
  white-space: nowrap;
}
.app-bar a.nav-link{
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 999px;
  transition: background .15s ease;
  white-space: nowrap;
}
.app-bar a.nav-link:hover{ background: rgba(255,255,255,.14); }
.app-bar a.nav-link.exit{ background: rgba(181,74,58,.85); }
.app-bar a.nav-link.exit:hover{ background: var(--absent); }

.app-shell{
  max-width: 1180px;
  margin: 0 auto;
  padding: 84px 20px 40px;
}

/* ---------- بطاقات ---------- */
.card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card-title{
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 15px;
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}

/* ---------- شريط التحكم (اختيار الصف/الشعبة/الإجراء) ---------- */
.control-bar{
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}
.control-bar .field{
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
  flex: 1 1 220px;
}
.control-bar label{
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 700;
}

/* ---------- عناصر النموذج ---------- */
select, input[type=text], input[type=date], input[type=month],
input[type=number], input[type=password]{
  width: 100%;
  height: 42px;
  padding: 0 12px;
  font-size: 15px;
  font-family: var(--font-body);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
select:focus, input:focus{
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
  outline: none;
}
select{ cursor: pointer; }

/* ---------- أزرار ---------- */
.btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 42px;
  padding: 0 20px;
  border-radius: 999px;
  border: none;
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 14.5px;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
  text-decoration: none;
}
.btn:active{ transform: scale(.97); }
.btn-primary{ background: var(--brand); color: #fff; }
.btn-primary:hover{ background: var(--brand-dark); }
.btn-danger{ background: var(--absent); color: #fff; }
.btn-danger:hover{ background: #953b2e; }
.btn-ghost{ background: var(--surface-2); color: var(--ink); }
.btn-ghost:hover{ background: var(--border); }
.btn-sm{ height: 34px; padding: 0 14px; font-size: 13px; }
.btn[disabled]{ opacity: .55; cursor: not-allowed; }

/* ---------- جداول البيانات ---------- */
.table-wrap{
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
table.data{
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
  background: var(--surface);
  font-size: 14.5px;
}
table.data thead th, table.data thead td{
  position: sticky;
  top: 0;
  background: var(--brand-dark);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13.5px;
  padding: 12px 10px;
  text-align: center;
  white-space: nowrap;
  z-index: 2;
}
table.data tbody td{
  padding: 10px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data tbody tr:nth-child(even){ background: #FAF7EF; }
table.data tbody tr:hover{ background: var(--brand-tint); }
table.data td.section-title{
  background: var(--surface-2);
  color: var(--brand-dark);
  font-family: var(--font-display);
  font-weight: 800;
  text-align: start;
  padding-inline-start: 14px;
}

/* عمود اسم الطالب ثابت عند التمرير الأفقي */
table.data .sticky-col{
  position: sticky;
  inset-inline-end: 0;
  background: inherit;
}

/* ---------- شارة الحضور/الغياب (العنصر المميز) ---------- */
.stamp-toggle{
  --size: 42px;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  border: 2.5px solid var(--border);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  font-weight: 800;
  color: transparent;
  user-select: none;
  transition: transform .12s ease, border-color .15s ease, background .15s ease, color .15s ease;
}
.stamp-toggle:hover{ border-color: var(--brand); }
.stamp-toggle.is-present{
  background: var(--present-tint);
  border-color: var(--present);
  color: var(--present);
}
.stamp-toggle.is-absent{
  background: var(--absent-tint);
  border-color: var(--absent);
  color: var(--absent);
}
.stamp-toggle.stamped{
  animation: stamp-in .18s ease;
}
@keyframes stamp-in{
  0%{ transform: scale(1.35); }
  100%{ transform: scale(1); }
}
tr.row-present{ background: var(--present-tint) !important; }
tr.row-absent{ background: var(--absent-tint) !important; }

/* ---------- تنبيهات / رسائل ---------- */
.error, .alert{
  background: var(--absent-tint);
  color: #7C2E21;
  border: 1px solid var(--absent);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 14px;
}
.alert.success{
  background: var(--present-tint);
  color: #1F5B39;
  border-color: var(--present);
}
.alert.notice{
  background: var(--warn-tint);
  color: #6B5100;
  border-color: var(--warn);
}

/* ---------- صندوق تأكيد مخصّص (بديل عن confirm() الافتراضي) ---------- */
.confirm-overlay{
  position: fixed;
  inset: 0;
  background: rgba(20,26,23,.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}
.confirm-overlay.open{
  opacity: 1;
  pointer-events: auto;
}
.confirm-box{
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 380px;
  width: 100%;
  padding: 22px 22px 18px;
  text-align: center;
  transform: translateY(10px);
  transition: transform .18s ease;
}
.confirm-overlay.open .confirm-box{ transform: translateY(0); }
.confirm-box .confirm-icon{
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--absent-tint);
  color: var(--absent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin: 0 auto 14px;
}
.confirm-box .confirm-message{
  font-size: 15px;
  color: var(--ink);
  line-height: 1.7;
  margin-bottom: 20px;
}
.confirm-box .confirm-actions{
  display: flex;
  gap: 10px;
}
.confirm-box .confirm-actions .btn{ flex: 1; }

/* ---------- تنبيهات عائمة (Toast) ---------- */
#toast-stack{
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 380px);
  align-items: stretch;
}
@media (max-width: 640px){
  #toast-stack{ top: 64px; }
}
.toast{
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 14px;
  text-align: center;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show{ opacity: 1; transform: translateY(0); }
.toast.toast-success{ background: var(--present); }
.toast.toast-error{ background: var(--absent); }
.toast.toast-notice{ background: #6B5100; }

/* ---------- شبكة صفحة الدخول ---------- */
.auth-shell{
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle at 20% 15%, var(--brand-tint), transparent 55%),
    var(--paper);
}
.auth-card{
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.auth-head{
  background: var(--brand-dark);
  color: #fff;
  padding: 26px 24px 22px;
  text-align: center;
}
.auth-head .mark{
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--present);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin-bottom: 10px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25);
}
.auth-head h1{
  font-size: 19px;
  margin: 0 0 4px;
}
.auth-head p{
  margin: 0;
  font-size: 13px;
  opacity: .8;
}
.auth-body{ padding: 22px 24px 26px; }
.input-group{ margin-bottom: 14px; }
.input-group label{
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

/* ---------- تذييل مساعد ---------- */
.hint{ font-size: 12.5px; color: var(--ink-soft); }
.badge{
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--ink-soft);
}

/* ---------- استجابة الجوال ---------- */
@media (max-width: 640px){
  .app-shell{ padding: 78px 12px 30px; }
  .app-bar{ padding: 0 10px; height: 54px; }
  .app-bar .brand{ font-size: 15px; }
  .app-bar .who{ display: none; }
  .app-bar a.nav-link{ padding: 7px 10px; font-size: 13px; }
  .control-bar .field{ min-width: 100%; }
  .card{ padding: 14px; }
}

/* ---------- بطاقات إحصائية (صفحة الرئيسية) ---------- */
.stats-grid{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  text-align: center;
}
.stat-card .stat-num{
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 30px;
  color: var(--brand-dark);
  line-height: 1.1;
}
.stat-card .stat-label{
  font-size: 13.5px;
  color: var(--ink-soft);
  margin-top: 6px;
  font-weight: 700;
}
.stat-card.accent-present .stat-num{ color: var(--present); }
.stat-card.accent-absent .stat-num{ color: var(--absent); }

/* رسم بياني بسيط بالأعمدة */
.bar-chart{
  display: flex;
  align-items: flex-end;
  gap: 14px;
  height: 220px;
  padding: 10px 6px 0;
  overflow-x: auto;
}
.bar-chart .bar-col{
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-width: 54px;
  height: 100%;
  flex: 1 1 0;
}
.bar-chart .bar-count{
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 13px;
  color: var(--brand-dark);
  margin-bottom: 6px;
}
.bar-chart .bar{
  width: 100%;
  max-width: 46px;
  background: linear-gradient(180deg, var(--brand), var(--brand-dark));
  border-radius: 8px 8px 3px 3px;
  min-height: 4px;
  transition: height .4s ease;
}
.bar-chart .bar-label{
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 8px;
  text-align: center;
  font-weight: 700;
}

/* ---------- قائمة عمودية أنيقة (صفحة بيانات الطالب) ---------- */
.info-list{
  display: flex;
  flex-direction: column;
}
.info-row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--border);
}
.info-row:last-child{ border-bottom: none; }
.info-row .info-main{ display: flex; flex-direction: column; gap: 4px; }
.info-row .info-label{
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 700;
}
.info-row .info-value{
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}
.info-row .info-actions{ display: flex; align-items: center; gap: 8px; }

/* باج حالة (أونروا/إعاقة) */
.pill{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
}
.pill-yes{ background: var(--absent-tint); color: var(--absent); }
.pill-no{ background: var(--present-tint); color: var(--present); }

/* ---------- بطاقات روابط (صفحة التقارير) ---------- */
.link-cards{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.link-card{
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  text-decoration: none;
  color: var(--ink);
  transition: transform .1s ease, box-shadow .15s ease, border-color .15s ease;
}
.link-card:hover{
  border-color: var(--brand);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.link-card .link-icon{
  width: 46px; height: 46px;
  border-radius: 12px;
  background: var(--brand-tint);
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex: 0 0 auto;
}
.link-card .link-text{ display: flex; flex-direction: column; gap: 3px; }
.link-card .link-title{ font-weight: 800; font-size: 15px; }
.link-card .link-desc{ font-size: 12.5px; color: var(--ink-soft); }

/* إخفاء عناصر w3.css القديمة إن بقيت مرجعية في صفحات لم تُحدَّث بعد */
.w3-table{ width: 100%; border-collapse: collapse; }

/* حقل البحث مع زر مسح داخلي */
.search-field{ position: relative; }
.search-field input{ padding-inline-end: 40px; }
.search-field .clear-btn{
  position: absolute;
  inset-inline-end: 6px;
  top: 50%;
  transform: translateY(-50%);
}
