:root {
  --background: #f4f7f6;
  --surface: #ffffff;
  --foreground: #1a231d;
  --muted: #667066;
  --border: #e2e6e1;
  --brand: #009e8f;
  --brand-hover: #007e72;
  --brand-soft: #e7f3f1;
  --accent: #62c3b6;
  --accent-soft: #e2f1ef;
  --gold: #b8912f;
  --gold-soft: #f6efdc;
  --danger: #b3432f;
  --danger-soft: #fbe9e5;
  --shadow-sm: 0 1px 2px rgba(16, 40, 34, 0.05), 0 1px 3px rgba(16, 40, 34, 0.06);
  --shadow-md: 0 4px 10px rgba(16, 40, 34, 0.06), 0 2px 4px rgba(16, 40, 34, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 400px at 100% -10%, rgba(0,158,143,0.06), transparent),
    var(--background);
  color: var(--foreground);
  font-family: 'Cairo', Arial, Helvetica, sans-serif;
}

/* المتصفحات لا تُورّث خط الصفحة تلقائياً لعناصر النماذج (زر/إدخال/قائمة) — بدونها
   تظهر بخط النظام الافتراضي بدل Cairo، وهو ما كان يسبب اختلاف الخط في بعض الصفحات */
button, input, select, textarea { font-family: inherit; }

a { color: inherit; text-decoration: none; }

.important-links-btn {
  position: fixed; top: 20px; left: 20px; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 16px; font-size: 13px; font-weight: 700; color: var(--brand);
  cursor: pointer; box-shadow: var(--shadow-sm); font-family: inherit;
}
.important-links-btn:hover { border-color: var(--brand); }
.important-links-box {
  position: fixed; top: 66px; left: 20px; z-index: 100;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  width: 320px; max-width: calc(100vw - 40px); padding: 16px; box-shadow: var(--shadow-md);
}
@media (max-width: 500px) { .important-links-box { left: 12px; right: 12px; width: auto; } }
.important-links-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.important-links-header h3 { margin: 0; font-size: 16px; }
.important-links-header button { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--muted); font-family: inherit; }
.important-links-list { display: flex; flex-direction: column; gap: 8px; }
.important-links-list a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); }
.important-links-list a:hover { border-color: var(--brand); background: var(--brand-soft); }
.important-links-list a span { font-size: 20px; }
.important-links-list a strong { display: block; font-size: 13px; }
.important-links-list a small { display: block; font-size: 11px; color: var(--muted); }

.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  position: relative;
}
.app-sidebar::before {
  content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 4px;
  background: linear-gradient(180deg, var(--brand), var(--accent));
}

.app-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
.app-brand-icon {
  width: 52px; height: 40px; border-radius: 8px; background: #fff; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; padding: 4px; flex-shrink: 0;
}
.app-brand-icon img { max-width: 100%; max-height: 100%; object-fit: contain; }
.app-brand-title { font-size: 14px; font-weight: 700; }
.app-brand-sub { font-size: 12px; color: var(--muted); }

.app-nav { display: flex; flex-direction: column; gap: 4px; }
.app-nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; font-size: 14px; font-weight: 500;
  color: var(--muted); border-inline-end: 3px solid transparent; transition: background .15s, color .15s;
}
.app-nav-link:hover { background: rgba(0,158,143,0.08); color: var(--foreground); }
.app-nav-link.active { background: var(--brand-soft); color: var(--brand); border-inline-end-color: var(--brand); font-weight: 700; }

.app-sidebar-footer { margin-top: auto; padding-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.app-user-card { background: var(--brand-soft); border-radius: 12px; padding: 10px 12px; border-inline-start: 3px solid var(--brand); }
.app-user-name { font-size: 14px; font-weight: 700; color: var(--foreground); }
.app-user-role { font-size: 12px; color: var(--brand); font-weight: 600; }

.app-main { flex: 1; width: 100%; min-width: 0; padding: 24px 20px; overflow-x: hidden; }

.app-topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.app-topbar-search { flex: 1; min-width: 220px; max-width: 420px; position: relative; }
.app-topbar-search input {
  width: 100%; padding: 9px 14px 9px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); font-size: 13px;
}
.app-topbar-clock {
  font-size: 13px; color: var(--muted); font-weight: 600; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; white-space: nowrap;
}
.app-topbar-clock strong { color: var(--brand); font-weight: 700; }
@media (max-width: 700px) { .app-topbar { flex-direction: column; align-items: stretch; } .app-topbar-search { max-width: none; } }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-header h1 {
  font-size: 20px; font-weight: 800; margin: 0; padding-inline-start: 12px;
  border-inline-start: 4px solid var(--brand); line-height: 1.3;
}
.page-header p { margin: 4px 0 0 16px; font-size: 13px; color: var(--muted); }
.back-link { font-size: 13px; color: var(--muted); }
.back-link:hover { color: var(--brand); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px;
  box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.card::before {
  content: ""; position: absolute; inset-inline: 0; top: 0; height: 3px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; } }

.stat-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 7px 8px;
  box-shadow: var(--shadow-sm); border-inline-end: 3px solid var(--brand); text-align: center;
}
.stat-tile:nth-of-type(4n+2) { border-inline-end-color: var(--accent); }
.stat-tile:nth-of-type(4n+3) { border-inline-end-color: var(--gold); }
.stat-tile:nth-of-type(4n+4) { border-inline-end-color: #6b8fce; }
.stat-tile .label { font-size: 10px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.stat-tile .value { font-size: 15px; font-weight: 800; margin-top: 1px; color: var(--foreground); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-sm); }
th { text-align: right; padding: 9px 14px; color: var(--brand); font-weight: 700; font-size: 12px; background: var(--brand-soft); border-bottom: 1px solid var(--border); }
td { padding: 8px 14px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(0,158,143,0.04); }

.cell-truncate { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* شارة داخل خلية مقصوصة: القصّ يجب أن يظهر كنقاط "..." داخل الشارة نفسها فتبقى محتفظة
   بشكلها البيضاوي الكامل، بدل أن يقصّها overflow:hidden الخاص بالخلية بشكل خشن من المنتصف */
.cell-truncate .badge { max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.badge-group { display: inline-flex; gap: 4px; white-space: nowrap; max-width: 100%; }
.badge-group .badge { min-width: 0; }

.tab-bar { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
.tab-bar .tab-btn { white-space: nowrap; flex-shrink: 0; }
.tab-bar::-webkit-scrollbar { height: 5px; }
.tab-bar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge-muted { background: var(--background); color: var(--muted); border: 1px solid var(--border); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-gold { background: var(--gold-soft); color: var(--gold); }

.link-tile {
  display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  text-decoration: none; color: inherit; transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.link-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--brand); }
.link-tile-icon {
  width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 22px; background: var(--brand-soft); flex-shrink: 0;
}
.link-tile strong { display: block; font-size: 14px; margin-bottom: 2px; color: var(--foreground); }
.link-tile small { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.link-category-title { display: flex; align-items: center; gap: 8px; font-size: 15px; margin: 28px 0 12px; }
.link-category-title:first-of-type { margin-top: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 9px 18px; border-radius: 10px; font-size: 14px; font-weight: 700;
  border: 1px solid transparent; cursor: pointer; background: var(--brand); color: #fff;
  box-shadow: 0 2px 6px rgba(0,158,143,0.25); transition: background .15s, box-shadow .15s, transform .1s;
}
.btn:hover { background: var(--brand-hover); box-shadow: 0 4px 10px rgba(0,158,143,0.3); transform: translateY(-1px); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--foreground); box-shadow: var(--shadow-sm); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand); transform: translateY(-1px); }
.btn-link { background: none; border: none; color: var(--brand); font-weight: 700; padding: 0; font-size: 14px; }
.btn-link:hover { text-decoration: underline; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 13px; box-shadow: none; }

form.form-card { max-width: 100%; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 900px) { .field-row-3 { grid-template-columns: 1fr; } }
.field-row-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 900px) { .field-row-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .field-row-4 { grid-template-columns: 1fr; } }
.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--background); font-family: inherit; font-size: 14px; color: var(--foreground);
}
.field input[type="date"] { direction: ltr; text-align: right; }

/* محدد وسوم متعدد (Tag select) */
.tagselect { position: relative; }
.tagselect-control {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 42px;
  padding: 6px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--background); cursor: text;
}
.tagselect-control:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(0,158,143,0.15); }
.tagselect-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-pill {
  display: inline-flex; align-items: center; gap: 5px; background: var(--brand-soft); color: var(--brand);
  font-size: 12.5px; font-weight: 700; padding: 4px 8px; border-radius: 999px; white-space: nowrap;
}
.tag-pill button {
  border: none; background: none; color: var(--brand); cursor: pointer; font-size: 14px; line-height: 1;
  padding: 0; display: flex; align-items: center;
}
.tagselect-search {
  flex: 1; min-width: 90px; border: none; background: transparent; font-size: 13px; padding: 4px 2px;
  font-family: inherit; color: var(--foreground); outline: none;
}
.tagselect-panel {
  position: absolute; inset-inline: 0; top: calc(100% + 6px); z-index: 20; max-height: 240px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-md); padding: 6px;
}
.tagselect-option {
  display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 400; padding: 7px 8px;
  border-radius: 8px; cursor: pointer;
}
.tagselect-option:hover { background: var(--brand-soft); }
.tagselect-option.is-hidden { display: none; }
.tagselect-empty { padding: 10px; text-align: center; font-size: 12.5px; color: var(--muted); }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,124,120,0.15);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }

.alert { padding: 12px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 16px; border-inline-start: 3px solid; font-weight: 600; }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-inline-start-color: var(--danger); }
.alert-info { background: var(--brand-soft); color: var(--brand); border-inline-start-color: var(--brand); }

.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); font-size: 14px; }

/* شاشة الدخول */
.login-shell { display: flex; min-height: 100vh; flex-wrap: wrap; }
.login-panel { flex: 1; min-width: 320px; display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.login-panel form { width: 100%; max-width: 360px; }
.login-brand-panel {
  flex: 1; min-width: 320px; position: relative; color: #fff; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 32px; background: linear-gradient(135deg, var(--brand), var(--brand), var(--accent));
}
.login-brand-icon {
  width: 160px; height: 80px; border-radius: 16px; background: #fff;
  display: flex; align-items: center; justify-content: center; padding: 10px; margin-bottom: 18px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
.login-brand-icon img { max-width: 100%; max-height: 100%; object-fit: contain; }
.login-badge { background: rgba(255,255,255,0.15); border-radius: 999px; padding: 4px 14px; font-size: 12px; margin-bottom: 8px; }
.login-brand-panel h2 { font-size: 24px; font-weight: 800; margin: 0; }
.login-brand-panel .en { font-size: 13px; opacity: 0.85; margin: 2px 0 0; }
.login-brand-panel .desc { max-width: 320px; margin: 16px auto 0; font-size: 14px; line-height: 1.7; opacity: 0.85; }
.login-features { margin-top: 28px; width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 10px; }
.login-feature { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.1); border-radius: 12px; padding: 10px 14px; text-align: right; backdrop-filter: blur(4px); }
.login-feature .icon { font-size: 18px; }
.login-feature .title { font-size: 13px; font-weight: 700; }
.login-feature .desc { font-size: 11px; opacity: 0.75; }
.login-credit { position: absolute; bottom: 16px; font-size: 16px; font-weight: 700; opacity: 1; letter-spacing: 0.3px; }

.print-only { display: none; }
@media print {
  .app-sidebar, .app-topbar, .no-print { display: none !important; }
  .print-only { display: table-cell; }
  .app-main { padding: 0; }
  .app-shell { display: block; }
  .report-page-break { break-before: page; page-break-before: always; }
}

/* ترويسة رسمية للتقارير القابلة للطباعة: الشعار يساراً، بيانات الجهة يميناً، والعنوان بالمنتصف */
.report-letterhead {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border-bottom: 3px solid var(--brand); padding-bottom: 14px; margin-bottom: 20px;
}
.report-letterhead-text { font-size: 13px; line-height: 1.9; color: var(--foreground); white-space: nowrap; }
.report-letterhead-text .line-1 { font-weight: 700; }
.report-letterhead-text .school-line { font-weight: 700; color: var(--brand); margin-top: 2px; }
.report-letterhead-title { flex: 1; text-align: center; padding: 0 12px; }
.report-letterhead-title h2 { margin: 0; font-size: 18px; color: var(--brand); }
.report-letterhead-title p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.report-letterhead-logo img { height: 58px; }
@media (max-width: 700px) {
  .report-letterhead { flex-wrap: wrap; }
  .report-letterhead-text { white-space: normal; }
}
