/* ================================================================
   نظام الإدارة المدرسية — الأنماط العامة (عربي / RTL)
   ثلاثة ثيمات: green (أخضر وذهبي) | navy (كحلي وفضي) | maroon (عنابي وذهبي)
   ================================================================ */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --r: 10px;
  --r-lg: 14px;
  --shadow: 0 2px 10px rgba(18, 28, 45, .06);
  --shadow-lg: 0 18px 46px rgba(18, 28, 45, .18);
  --font: "Segoe UI", "Tahoma", "Arial", "Traditional Arabic", sans-serif;
  --sidebar: 232px;
}

/* ------------------------------- الثيمات ------------------------------- */
body[data-theme="green"] {
  --side: #0d4636; --side-2: #0a3a2d; --side-tx: #eaf3ef;
  --side-line: rgba(255,255,255,.15); --side-on: rgba(255,255,255,.13);
  --gold: #c9a227; --gold-soft: #f6eccd; --gold-ink: #7a6210;
  --bg: #f4f7f5; --card: #ffffff; --panel-h: #f0f5f2;
  --line: #dbe5e0; --track: #e7eeea;
  --ink: #12251e; --muted: #5d7269; --muted-2: #9aa9a2;
  --accent: #0d4636; --accent-2: #14664e; --accent-soft: #e0ece7;
  --ok: #1c6b4a; --ok-bg: #dcefe6;
}
body[data-theme="navy"] {
  --side: #152a4a; --side-2: #0f2039; --side-tx: #e8edf5;
  --side-line: rgba(255,255,255,.15); --side-on: rgba(255,255,255,.13);
  --gold: #7f96b8; --gold-soft: #e6ecf4; --gold-ink: #3b5478;
  --bg: #f4f6fa; --card: #ffffff; --panel-h: #f1f4f9;
  --line: #dde3ec; --track: #e8edf4;
  --ink: #13203a; --muted: #5f6d85; --muted-2: #9aa5b8;
  --accent: #1d3f70; --accent-2: #2a5490; --accent-soft: #e4eaf4;
  --ok: #1b5e8a; --ok-bg: #dceaf3;
}
body[data-theme="maroon"] {
  --side: #4a1230; --side-2: #3b0e26; --side-tx: #f6eaf0;
  --side-line: rgba(255,255,255,.15); --side-on: rgba(255,255,255,.13);
  --gold: #c8a04a; --gold-soft: #f7edd8; --gold-ink: #7d5f14;
  --bg: #faf6f8; --card: #ffffff; --panel-h: #f7f0f4;
  --line: #e9dde3; --track: #f0e6eb;
  --ink: #2b0f1e; --muted: #7a6070; --muted-2: #b09aa5;
  --accent: #6d1c46; --accent-2: #8a2557; --accent-soft: #f3e4ec;
  --ok: #2f6b52; --ok-bg: #e0efe8;
}
:root { --danger: #a32626; --danger-bg: #f8e3e3; --warn: #9a6a10; --warn-bg: #fbeecd; }

/* ------------------------------- أساسيات ------------------------------- */
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 14.5px; line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1,h2,h3,h4 { margin: 0 0 .4em; font-weight: 700; letter-spacing: -.2px; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }

/* ------------------------------- التخطيط ------------------------------- */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.sidebar {
  background: linear-gradient(180deg, var(--side), var(--side-2));
  color: var(--side-tx); padding: 16px 12px; display: flex; flex-direction: column;
  gap: 3px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 2px 6px 14px;
  margin-bottom: 10px; border-bottom: 1px solid var(--side-line);
}
.sidebar .brand .logo {
  width: 44px; height: 44px; border-radius: 11px; flex: none; overflow: hidden;
  background: var(--gold); color: var(--side); display: grid; place-items: center;
  font-weight: 800; font-size: 13px; border: 1px solid rgba(255,255,255,.25);
}
.sidebar .brand .logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.sidebar .brand b { display: block; font-size: 14px; line-height: 1.25; }
.sidebar .brand span { font-size: 11px; opacity: .72; display: block; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar a.nav {
  display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 8px;
  color: var(--side-tx); opacity: .82; font-size: 13.5px; transition: .15s;
}
.sidebar a.nav:hover { background: rgba(255,255,255,.08); opacity: 1; }
.sidebar a.nav.on {
  background: var(--side-on); opacity: 1; font-weight: 700;
  box-shadow: inset 3px 0 0 var(--gold);
}
.sidebar a.nav svg { width: 17px; height: 17px; flex: none; opacity: .9; }
.sidebar .sec { font-size: 10.5px; opacity: .5; padding: 12px 11px 4px; letter-spacing: .5px; }
.sidebar button.sec { width: 100%; text-align: right; background: transparent; color: var(--side-tx); border: 0; cursor: pointer; display:flex; justify-content:space-between; }
.theme-switcher { display:flex; gap:10px; margin-bottom:10px; }
.theme-switcher button.theme-dot {
  width:20px; height:20px; padding:0; flex:0 0 20px;
  border-radius:50%; cursor:pointer; border:2px solid;
}
.theme-switcher button.theme-dot:hover { transform:scale(1.12); }
.theme-switcher button.theme-dot.green { background-color:#0f4922; border-color:#ffd966; }
.theme-switcher button.theme-dot.navy { background-color:#1d3259; border-color:#9dc3e6; }
.theme-switcher button.theme-dot.maroon { background-color:#660033; border-color:#ffd966; }
.sidebar .foot { margin-top: auto; font-size: 10.5px; opacity: .55; padding: 12px 8px 0;
                 border-top: 1px solid var(--side-line); }

.content { display: flex; flex-direction: column; min-width: 0; }
.mobile-menu-toggle, .mobile-menu-close, .mobile-menu-backdrop { display: none; }
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 12px 22px; display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar .crumb { font-size: 11.5px; color: var(--muted); }
.topbar .spacer { margin-inline-start: auto; }
.topbar .term { display: flex; gap: 6px; align-items: center; margin-inline-start: 18px; }
@media (max-width: 980px) { .topbar .term { display: none; } }
.topbar .who { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12.5px; }
.topbar .av {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); display: grid; place-items: center; font-weight: 800; font-size: 13px;
}
.page { padding: 20px 22px 60px; }

/* ------------------------------- بطاقات ------------------------------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow); overflow: hidden; margin-bottom: 16px;
}
.card > .head {
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel-h);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.card > .head h3 { margin: 0; font-size: 14.5px; }
.card > .head .sub { font-size: 11.5px; color: var(--muted); }
.card > .body { padding: 16px; }
.card > .body.tight { padding: 0; }

.grid { display: grid; gap: 14px; }
.dashboard-single { grid-template-columns: minmax(0, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 780px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

/* ------------------------------- مؤشرات ------------------------------- */
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px 16px; border-top: 3px solid var(--accent); box-shadow: var(--shadow);
}
.kpi.gold { border-top-color: var(--gold); }
.kpi.red { border-top-color: var(--danger); }
.kpi.ok { border-top-color: var(--ok); }
.kpi .n { font-size: 28px; font-weight: 800; line-height: 1.1; }
.kpi .l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .s { font-size: 11px; color: var(--muted-2); margin-top: 4px; }
.kpi.clickable { cursor:pointer; transition:transform .15s,box-shadow .15s; }
.kpi.clickable:hover { transform:translateY(-2px); box-shadow:var(--shadow-lg); }

/* ------------------------------- نماذج ------------------------------- */
.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field > label .req { color: var(--danger); }
input[type=text], input[type=password], input[type=date], input[type=time],
input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); outline: none; transition: .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input:disabled, select:disabled { background: var(--panel-h); color: var(--muted); }
textarea { min-height: 74px; resize: vertical; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 180px; min-width: 0; }
.row.tight { gap: 8px; }
.inline { display: flex; align-items: center; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.check input { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  background: var(--accent); color: #fff; font-weight: 700; cursor: pointer;
  transition: .15s; white-space: nowrap;
}
.btn:hover { background: var(--accent-2); }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); font-weight: 600; }
.btn.ghost:hover { background: var(--panel-h); }
.btn.gold { background: var(--gold); color: #26200a; }
.btn.gold:hover { filter: brightness(.95); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }
.btn.xs { padding: 3px 9px; font-size: 11.5px; border-radius: 6px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------- جداول ------------------------------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th {
  background: var(--panel-h); color: var(--muted); font-weight: 700; text-align: right;
  padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
  position: sticky; top: 0; z-index: 2;
}
table.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tbody tr:hover { background: var(--panel-h); }
table.tbl td.actions { white-space: nowrap; }
table.tbl .empty { text-align: center; color: var(--muted-2); padding: 34px 12px; }
table.tbl input, table.tbl select { padding: 5px 8px; font-size: 13px; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.no { background: var(--danger-bg); color: var(--danger); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.gold { background: var(--gold-soft); color: var(--gold-ink); }
.pill.muted { background: var(--track); color: var(--muted); }

/* ------------------------------- تنبيهات ------------------------------- */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 12px;
         border: 1px solid transparent; }
.alert.error { background: var(--danger-bg); color: var(--danger); border-color: #eec7c7; }
.alert.ok { background: var(--ok-bg); color: var(--ok); border-color: #c9e3d6; }
.alert.info { background: var(--accent-soft); color: var(--accent); }
.alert.warn { background: var(--warn-bg); color: var(--warn); border-color: #ecd9a5; }

#toast {
  position: fixed; bottom: 22px; left: 22px; z-index: 999; display: flex;
  flex-direction: column; gap: 8px;
}
#toast .t {
  background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 9px;
  box-shadow: var(--shadow-lg); font-size: 13.5px; animation: up .25s ease;
  max-width: 380px;
}
#toast .t.ok { background: var(--ok); }
#toast .t.err { background: var(--danger); }
@keyframes up { from { opacity: 0; transform: translateY(10px); } }

/* ------------------------------- نوافذ ------------------------------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15, 22, 33, .55); z-index: 100;
  display: none; align-items: flex-start; justify-content: center; padding: 40px 16px;
  overflow-y: auto; backdrop-filter: blur(2px);
}
.modal-bg.on { display: flex; }
.modal {
  background: var(--card); border-radius: var(--r-lg); width: 100%; max-width: 620px;
  box-shadow: var(--shadow-lg); animation: up .2s ease; overflow: hidden;
}
.modal.wide { max-width: 900px; }
.modal .head { padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--panel-h);
               display: flex; align-items: center; }
.modal .head h3 { margin: 0; font-size: 15px; }
.modal .head .x { margin-inline-start: auto; cursor: pointer; color: var(--muted); font-size: 20px;
                  line-height: 1; background: none; border: 0; }
.modal .body { padding: 18px; max-height: 68vh; overflow-y: auto; }
.modal .foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex;
               gap: 8px; justify-content: flex-start; background: var(--panel-h); }

/* ------------------------------- اختيار طالبة ------------------------------- */
.picker-wrap { position: relative; }
.picker {
  position: absolute; top: 100%; inset-inline-start: 0; inset-inline-end: 0; z-index: 40;
  background: #fff; border: 1px solid var(--line); border-radius: 9px; margin-top: 4px;
  box-shadow: var(--shadow-lg); max-height: 250px; overflow-y: auto; display: none;
}
.picker .opt { padding: 8px 12px; cursor: pointer; display: flex; align-items: center; gap: 8px;
               border-bottom: 1px solid var(--line); font-size: 13.5px; }
.picker .opt:last-child { border-bottom: 0; }
.picker .opt:hover { background: var(--accent-soft); }
.picker .opt span { margin-inline-start: auto; font-size: 11.5px; color: var(--muted); }

/* ------------------------------- رسوم بيانية ------------------------------- */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; font-size: 12.5px; }
.bar-row .lbl { width: 92px; flex: none; color: var(--ink); }
.bar-row .track { flex: 1; display: block; background: var(--track); border-radius: 5px;
                  height: 12px; overflow: hidden; }
.bar-row .fill { display: block; height: 12px; background: var(--accent); border-radius: 5px;
                 transition: width .4s; }
.bar-row .fill.g { background: var(--gold); }
.bar-row .val { width: 34px; text-align: left; color: var(--muted); font-weight: 700; }
.chart { width: 100%; height: 190px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-inline-end: 5px; }

/* ------------------------------- تسجيل الدخول ------------------------------- */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(180deg, var(--side), var(--side-2)); position: relative; overflow: hidden;
}
.login-page::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(110% 80% at 20% 0%, rgba(255,255,255,.14), transparent 60%);
}
.login-card {
  position: relative; background: var(--card); border-radius: 18px; padding: 30px 28px;
  width: 100%; max-width: 372px; text-align: center; box-shadow: var(--shadow-lg);
}
.login-card .logo {
  width: 74px; height: 74px; margin: 0 auto 14px; border-radius: 18px; overflow: hidden;
  background: var(--gold); color: var(--side); display: grid; place-items: center;
  font-weight: 800; font-size: 15px;
}
.login-card .logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.login-card h2 { font-size: 18px; margin-bottom: 2px; }
.login-card .sub { font-size: 12.5px; color: var(--muted); margin-bottom: 20px; }
.login-card .field { text-align: right; }
.login-card .btn { width: 100%; margin-top: 6px; padding: 11px; }
.login-card .hint { margin-top: 14px; font-size: 11px; color: var(--muted-2); }

/* ------------------------------- متفرقات ------------------------------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.nowrap { white-space: nowrap; }
.sep { height: 1px; background: var(--line); margin: 16px 0; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  background: var(--accent-soft); color: var(--accent); padding: 3px 10px;
  border-radius: 20px; font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px;
}
.tag button { background: none; border: 0; color: inherit; cursor: pointer; opacity: .6; font-size: 14px; line-height: 1; }
.tag button:hover { opacity: 1; }
.spinner {
  width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { text-align: center; padding: 30px; color: var(--muted); }

/* اختيار الثيم في الإعدادات */
.theme-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 700px) { .theme-picker { grid-template-columns: 1fr; } }
.theme-opt {
  border: 2px solid var(--line); border-radius: var(--r); padding: 12px; cursor: pointer;
  background: #fff; transition: .15s; text-align: center;
}
.theme-opt:hover { border-color: var(--muted-2); }
.theme-opt.sel { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.theme-opt .prev { height: 62px; border-radius: 8px; overflow: hidden; display: flex; margin-bottom: 9px; }
.theme-opt .prev .a { width: 34%; }
.theme-opt .prev .b { flex: 1; position: relative; background: #f4f6f8; }
.theme-opt .prev .b::after {
  content: ""; position: absolute; inset: 12px 10px auto 10px; height: 8px;
  border-radius: 3px; background: rgba(0,0,0,.12);
}
.theme-opt .prev .c { position: absolute; bottom: 10px; inset-inline-start: 10px;
                      width: 42%; height: 8px; border-radius: 3px; }
.theme-opt b { font-size: 13px; }
.theme-opt span { display: block; font-size: 11.5px; color: var(--muted); }

/* الطباعة */
@media print {
  .sidebar, .topbar, .no-print, #toast { display: none !important; }
  .layout { display: block; }
  body { background: #fff; font-size: 12px; }
  .page { padding: 0; }
  .card { box-shadow: none; border: 0; }
  table.tbl th { background: #eee !important; -webkit-print-color-adjust: exact; }
}
.print-head { display: none; }
@media print { .print-head { display: block; } }

/* ------------------------------- الجوال ------------------------------- */
@media (max-width: 760px) {
  html, body { min-width: 320px; overflow-x: hidden; }
  body.menu-open { overflow: hidden; }
  .layout { display: block; min-height: 100dvh; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 80; width: min(84vw, 300px);
    height: 100dvh; transform: translateX(-105%); transition: transform .22s ease;
    box-shadow: 8px 0 30px rgba(0,0,0,.18);
  }
  html[dir="rtl"] .sidebar { inset: 0 0 0 auto; transform: translateX(105%); }
  .sidebar.mobile-open, html[dir="rtl"] .sidebar.mobile-open { transform: translateX(0); }
  .mobile-menu-close {
    display: block; align-self: flex-start; width: 38px; height: 38px; margin: -4px 0 2px;
    border: 0; border-radius: 9px; background: rgba(255,255,255,.1); color: var(--side-tx);
    font-size: 25px; line-height: 1; cursor: pointer;
  }
  .mobile-menu-backdrop {
    position: fixed; inset: 0; z-index: 70; border: 0; background: rgba(15,22,33,.48);
  }
  body.menu-open .mobile-menu-backdrop { display: block; }
  .topbar {
    min-height: 62px; padding: 9px 12px; gap: 9px; align-items: center;
  }
  .mobile-menu-toggle {
    display: inline-grid; place-items: center; flex: 0 0 40px; width: 40px; height: 40px;
    border: 1px solid var(--line); border-radius: 9px; background: var(--panel-h);
    color: var(--accent); font-size: 21px; line-height: 1; cursor: pointer;
  }
  .heading-group { min-width: 0; }
  .topbar h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .crumb { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .who { margin-inline-start: auto; gap: 6px; }
  .topbar .who > span:first-child { display: none; }
  .topbar .who .btn { padding-inline: 8px; }
  .topbar .spacer { display: none; }
  .page { padding: 13px 12px 38px; }
  .card { margin-bottom: 12px; border-radius: 11px; }
  .card > .head { padding: 11px 12px; }
  .card > .body { padding: 12px; }
  .btn-row { width: 100%; }
  .btn-row .btn { flex: 1 1 135px; }
  .row { gap: 8px; }
  .row > * { flex-basis: 100%; }
  .table-wrap { margin-inline: -12px; padding-inline: 12px; }
  table.tbl { min-width: 620px; font-size: 13px; }
  table.tbl th, table.tbl td { padding: 8px 10px; }
  .modal-bg { padding: 12px; align-items: flex-end; }
  .modal { max-height: calc(100dvh - 24px); border-radius: 14px 14px 0 0; }
  .modal .body { max-height: 60dvh; padding: 14px; }
  .modal .foot { padding: 10px 14px; }
  .modal .foot .btn { flex: 1; }
  .bar-row .lbl { width: 72px; }
  #toast { right: 12px; left: 12px; bottom: 12px; }
  #toast .t { max-width: none; }
}
