/* ===== التصميم الموحد لجميع الأنظمة ===== */
:root {
    --bg: #f2f4fa;
    --card: #ffffff;
    --text: #253050;
    --muted: #8a91a8;
    --line: #e7eaf3;
    --blue: #2d8cf0;
    --orange: #ff9a1f;
    --green: #1bb98c;
    --purple: #a855f7;
    --red: #ff6b4a;
    --pink: #ec4899;
    --sb: 236px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: 'Cairo', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.6;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; }
p { margin: 0; }
code { background: #eef1fa; padding: 2px 6px; border-radius: 6px; font-size: 13px; direction: ltr; }

/* ===== الهيكل ===== */
.app-shell { display: flex; flex-direction: row; min-height: 100vh; }
.sidebar {
    width: var(--sb); flex-shrink: 0; background: #fff;
    border-left: 1px solid var(--line); padding: 20px 14px;
    display: flex; flex-direction: column; gap: 4px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.main { flex: 1; min-width: 0; padding: 16px 26px 36px; }

/* ===== الشريط الجانبي ===== */
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 800; font-size: 17px; color: var(--text); }
.bi {
    width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
    background: linear-gradient(135deg, #2d8cf0, #7b5cff); color: #fff;
    display: flex; align-items: center; justify-content: center;
}
.sb-search { position: relative; margin: 0 0 14px; }
.sb-search input {
    width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 10px;
    padding: 0 36px 0 12px; font: inherit; background: #fafbff; outline: none; color: var(--text);
}
.sb-search svg { position: absolute; right: 11px; top: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-link {
    display: flex; align-items: center; gap: 12px; padding: 9px 10px;
    border-radius: 10px; color: #3a4160; font-weight: 600; font-size: 14px; transition: .15s;
}
.nav-link:hover { background: #f5f7fd; }
.nav-link.active { background: #eaf3ff; color: #1f6fd1; }
.sb-ic {
    width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0; color: #fff;
    display: flex; align-items: center; justify-content: center;
}
.c1 { background: #2d8cf0; } .c2 { background: #ff9a1f; } .c3 { background: #1bb98c; }
.c4 { background: #a855f7; } .c5 { background: #ff6b4a; } .c6 { background: #ec4899; }
.sb-ic.c1 { background: #2d8cf0; } .sb-ic.c2 { background: #ff9a1f; } .sb-ic.c3 { background: #1bb98c; }
.sb-ic.c4 { background: #a855f7; } .sb-ic.c5 { background: #ff6b4a; } .sb-ic.c6 { background: #ec4899; }

/* ===== الشريط العلوي ===== */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.menu-toggle {
    width: 40px; height: 40px; border: 0; border-radius: 10px; background: var(--blue); color: #fff;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.tb-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pill {
    display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line);
    border-radius: 10px; padding: 8px 14px; font-weight: 700; color: #1f6fd1; font-size: 13.5px;
}
.school-select {
    height: 40px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
    padding: 0 12px; font: inherit; color: #1f6fd1; font-weight: 700; min-width: 200px;
}
.user-pill { position: relative; }
.user-pill summary {
    list-style: none; display: flex; align-items: center; gap: 10px; cursor: pointer;
    padding: 5px 14px 5px 6px; border-radius: 12px; color: #fff;
    background: linear-gradient(135deg, #f25fb6, #8e44ef);
}
.user-pill summary::-webkit-details-marker { display: none; }
.u-av {
    width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,.25);
    display: flex; align-items: center; justify-content: center; font-weight: 800;
    position: relative; overflow: hidden; flex: none;
}
.u-av .u-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.u-text { display: flex; flex-direction: column; line-height: 1.2; font-size: 11.5px; }
.u-text b { font-size: 13px; }
.user-menu-body {
    position: absolute; inset-inline-end: 0; top: calc(100% + 8px); width: 240px; z-index: 30;
    background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px;
    box-shadow: 0 16px 36px rgba(30, 40, 90, .16);
}
.um-name { font-weight: 700; }
.um-role { color: var(--muted); font-size: 12.5px; margin-bottom: 10px; }
.tb-btn {
    width: 40px; height: 40px; border: 0; border-radius: 10px; color: #fff; position: relative;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    background: linear-gradient(135deg, #ffb037, #ff8a1f);
    box-shadow: 0 6px 14px rgba(255, 138, 31, .28);
}
.tb-btn .dot {
    position: absolute; top: 8px; right: 9px; width: 8px; height: 8px; border-radius: 50%;
    background: #ff3b5c; border: 2px solid #ff9a1f;
}
.crumbs-row { display: flex; align-items: center; justify-content: flex-start; margin: 2px 2px 16px; }
.crumbs { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.crumbs b { color: var(--text); font-size: 14px; }

/* ===== البطاقات ===== */
.card {
    background: var(--card); border: 1px solid var(--line); border-radius: 14px;
    padding: 20px; box-shadow: 0 1px 3px rgba(20, 30, 70, .04); margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { font-size: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h2 { font-size: 20px; }
.page-head p { color: var(--muted); font-size: 13px; margin-top: 2px; }
.muted { color: var(--muted); font-size: 13px; }

/* بطاقات الإحصاءات الملونة */
.tile-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 18px; }
.tile { border-radius: 14px; color: #fff; padding: 20px 14px; text-align: center; box-shadow: 0 8px 20px rgba(30, 40, 90, .12); }
.tile .ti {
    width: 52px; height: 52px; margin: 0 auto 10px; border-radius: 12px; background: rgba(255,255,255,.22);
    display: flex; align-items: center; justify-content: center;
}
.tile .tl { font-size: 13px; opacity: .95; }
.tile .tv { font-size: 24px; font-weight: 800; margin-top: 4px; direction: ltr; }
.g1 { background: linear-gradient(135deg, #55c8fb, #2b8ff0); }
.g2 { background: linear-gradient(135deg, #ffb84a, #ff8a1f); }
.g3 { background: linear-gradient(135deg, #3fd7a1, #14a883); }
.g4 { background: linear-gradient(135deg, #c17cff, #9336ee); }
.g5 { background: linear-gradient(135deg, #ffa488, #ff6b4a); }

/* صناديق الملخص بالإطار الملون */
.mini-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.mini { border: 1.5px solid; border-radius: 12px; padding: 14px; text-align: center; background: #fff; }
.mini .mv { font-size: 22px; font-weight: 800; direction: ltr; }
.mini .ml { font-size: 13px; color: var(--muted); }
.m1 { border-color: #2d8cf0; color: #2d8cf0; }
.m2 { border-color: #ff9a1f; color: #ff9a1f; }
.m3 { border-color: #1bb98c; color: #1bb98c; }
.m4 { border-color: #a855f7; color: #a855f7; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }

/* ===== الجداول ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
    background: #eaf4fd; color: #2b3a5c; font-weight: 700; font-size: 13px;
    text-align: right; padding: 11px 12px; white-space: nowrap;
}
td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #fbfcff; }
.user-cell { display: flex; align-items: center; gap: 12px; }
.mini-avatar {
    width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0; color: #fff;
    background: linear-gradient(135deg, #55c8fb, #2b8ff0);
    display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.actions { display: flex; gap: 8px; }
.actions form { margin: 0; }
.act {
    width: 34px; height: 34px; border: 0; border-radius: 9px; background: #eef3fc; color: #3a4a70;
    display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.act.danger { background: #fff0ec; color: #e5402a; }
.btn-login {
    display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 8px;
    padding: 7px 14px; font: inherit; font-weight: 700; font-size: 13px; color: #fff; cursor: pointer;
    background: linear-gradient(135deg, #ffb037, #ff8a1f); box-shadow: 0 4px 10px rgba(255,138,31,.3);
}

/* الشارات */
.badge { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge-ok { background: #e3f8f1; color: #14976f; }
.badge-off { background: #ffeee9; color: #e5402a; }
.badge-muted { background: #f0f2f8; color: #7a8198; }
.badge-primary { background: #eaf3ff; color: #1f6fd1; }

/* ===== الأزرار والنماذج ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 42px; padding: 0 18px; border: 0; border-radius: 10px;
    font: inherit; font-weight: 700; cursor: pointer; transition: .15s;
}
.btn:hover { filter: brightness(1.04); }
.btn-primary { background: linear-gradient(135deg, #2d8cf0, #2370d8); color: #fff; box-shadow: 0 6px 14px rgba(45,140,240,.28); }
.btn-ghost { background: #fff; color: var(--text); border: 1px solid var(--line); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: 13.5px; }
.field input, .field select {
    height: 42px; border: 1px solid var(--line); background: #fafbff; border-radius: 10px;
    padding: 0 12px; font: inherit; color: var(--text); outline: none;
}
.field input:focus, .field select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(45,140,240,.14); }
.field input:disabled { color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }
.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 600; }
.check input { width: 18px; height: 18px; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input, .filters select {
    height: 40px; min-width: 220px; border: 1px solid var(--line); background: #fafbff;
    border-radius: 10px; padding: 0 12px; font: inherit; outline: none;
}
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.pager a {
    min-width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line); background: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.pager a.current { background: var(--blue); color: #fff; border-color: var(--blue); }

/* رسائل التنبيه */
.flashes { margin-bottom: 14px; }
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 10px; font-weight: 600; font-size: 14px; }
.flash-success { background: #e3f8f1; color: #14976f; }
.flash-error { background: #ffeee9; color: #c2301c; }
.errs { margin: 0; padding-inline-start: 20px; }

/* ===== حالة فارغة ===== */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 40px 20px; color: var(--muted); gap: 6px; }
.empty .ic {
    width: 66px; height: 66px; border-radius: 18px; background: #eaf3ff; color: #2d8cf0;
    display: flex; align-items: center; justify-content: center; margin-bottom: 8px;
}
.empty h2 { color: var(--text); font-size: 18px; }
.empty.big { padding: 60px 20px; }

/* أشرطة التوزيع */
.bar-row { margin-bottom: 14px; }
.bar-head { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 5px; }
.bar { height: 8px; background: #f0f2f8; border-radius: 10px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 10px; background: linear-gradient(90deg, #55c8fb, #2b8ff0); }

/* الأنظمة */
.sys-row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.sys-row:last-child { border-bottom: 0; }
.sys-row:hover { color: #1f6fd1; }
.sys-name { flex: 1; font-weight: 600; }

/* ===== الدخول وصفحات الأخطاء ===== */
body.guest { min-height: 100vh; background: linear-gradient(160deg, #eaf3ff, #f2f4fa); }
.guest-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; }
.guest-wrap .flashes { width: 100%; max-width: 400px; }
.guest-wrap .card.empty { max-width: 460px; width: 100%; }
.auth-wrap { width: 100%; display: flex; justify-content: center; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; overflow: hidden; box-shadow: 0 24px 60px rgba(30, 40, 90, .14); }
.auth-hero { background: linear-gradient(135deg, #55c8fb, #2b8ff0); color: #fff; padding: 30px 24px; text-align: center; }
.auth-hero .logo { width: 58px; height: 58px; border-radius: 16px; background: rgba(255,255,255,.22); display: inline-flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.auth-hero h2 { font-size: 22px; }
.auth-hero p { opacity: .92; font-size: 13.5px; }
.auth-body { padding: 24px; display: block; }
.auth-body .field input { width: 100%; }

/* ===== التجاوب ===== */
@media (max-width: 1200px) {
    .tile-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 1000px) {
    .grid-2, .mini-row { grid-template-columns: 1fr; }
    .tile-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; border-left: 0; border-bottom: 1px solid var(--line); }
    body.sb-collapsed .sidebar { display: none; }
    .main { padding: 14px; }
    .form-grid { grid-template-columns: 1fr; }
    .tile-row { grid-template-columns: 1fr; }
}

/* ===== مبدّل اللغة ===== */
.lang-switch { display: flex; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; height: 40px; }
.lang-switch a { display: flex; align-items: center; padding: 0 11px; font-size: 12.5px; font-weight: 700; color: #3a4160; white-space: nowrap; }
.lang-switch a + a { border-inline-start: 1px solid var(--line); }
.lang-switch a:hover { background: #f5f7fd; }
.lang-switch a.active { background: var(--blue); color: #fff; }
.guest-lang { position: fixed; top: 16px; inset-inline-end: 16px; z-index: 40; }

/* ===== English: عكس الاتجاه ===== */
html[dir="ltr"] .sidebar { border-left: 0; border-right: 1px solid var(--line); }
html[dir="ltr"] .sb-search input { padding: 0 12px 0 36px; }
html[dir="ltr"] .sb-search svg { right: auto; left: 11px; }
html[dir="ltr"] th { text-align: left; }
html[dir="ltr"] .user-pill summary { padding: 5px 6px 5px 14px; }
@media (max-width: 760px) {
    html[dir="ltr"] .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
}

/* ===== شعار المدرسة وأقسامها ===== */
.school-logo { width: 40px; height: 40px; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); background: #fff; display: block; }
.pill-logo { width: 22px; height: 22px; object-fit: contain; border-radius: 5px; }
.logo-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.logo-preview { width: 84px; height: 84px; object-fit: contain; border-radius: 12px; border: 1px solid var(--line); background: #fff; }
.logo-preview[hidden] { display: none; }
.logo-controls { display: flex; flex-direction: column; gap: 6px; min-width: 240px; }
.dept-list { display: flex; flex-direction: column; gap: 8px; }
.dept-row { display: flex; align-items: center; gap: 8px; }
.dept-row input { flex: 1; }

/* ===== الأعوام الدراسية ===== */
.ay-rule { margin-bottom: 12px; }
.ay-year { margin-bottom: 16px; }
.ay-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ay-fields { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; flex: 1; min-width: 260px; }
.ay-fields > input { flex: 1; min-width: 160px; }
.ay-date { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.ay-fields input { height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: #fff; }
.ay-radio { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13px; white-space: nowrap; cursor: pointer; }
.ay-radio input { width: 18px; height: 18px; }
.ay-children { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; padding-inline-start: 22px; border-inline-start: 3px solid var(--line); }
.ay-term { background: #f7f9fe; border-radius: 12px; padding: 12px; }
.ay-period { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.ay-actions { justify-content: space-between; margin-bottom: 24px; }
#ay-empty[hidden] { display: none; }

/* ===== شعار أعلى القائمة الجانبية ===== */
.sb-logo { display: flex; align-items: center; justify-content: center; padding: 4px 4px 10px; }
.sb-logo img { width: 100%; max-width: 190px; max-height: 130px; object-fit: contain; display: block; }
.brand-school { justify-content: center; text-align: center; padding: 0 8px 16px; font-size: 16px; line-height: 1.5; }

/* ===== قائمة الأنظمة في الهيدر ===== */
.apps-menu { position: relative; }
.apps-menu summary { list-style: none; }
.apps-menu summary::-webkit-details-marker { display: none; }
.apps-panel {
    position: absolute; inset-inline-end: 0; top: calc(100% + 8px); width: 300px; max-height: 70vh; overflow: auto; z-index: 30;
    background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 8px;
    box-shadow: 0 16px 36px rgba(30, 40, 90, .16);
}
.apps-title { padding: 6px 10px 8px; font-weight: 800; font-size: 13px; color: var(--muted); }
.apps-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--text); font-weight: 600; font-size: 13.5px; }
.apps-item:hover { background: #f1f5ff; }

/* ===== تصميم التقارير والطباعة ===== */
.field textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
    font: inherit; background: #fff; color: var(--text); resize: vertical;
}
.field textarea:focus { outline: 0; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(45,140,240,.14); }
.field input[type="color"] { padding: 3px; height: 42px; width: 90px; cursor: pointer; }

/* ===== عرض الإعلانات في لوحة التحكم ===== */
.an-list { display: flex; flex-direction: column; gap: 14px; }
.an-item { background: #f8faff; border: 1px solid var(--line); border-inline-start: 4px solid var(--blue); border-radius: 12px; padding: 14px 18px; }
.an-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.an-title { font-size: 16px; font-weight: 700; flex: 1; min-width: 200px; line-height: 1.5; }
.an-date { color: var(--muted); font-size: 12.5px; }
.an-body { color: var(--text); line-height: 1.9; max-width: 80ch; }
.an-body p { margin: 0 0 .7em; }
.an-body p:last-child { margin-bottom: 0; }
.an-media { display: block; max-width: min(100%, 520px); max-height: 360px; margin-top: 12px; border-radius: 10px; background: #000; }
.an-modal { position: fixed; inset: 0; background: rgba(20, 30, 70, .55); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.an-modal[hidden] { display: none; }
.an-dialog { background: #fff; border-radius: 16px; padding: 22px 24px; max-width: 580px; width: 100%; max-height: 88vh; overflow: auto; box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.an-dialog .an-title { font-size: 18px; margin-bottom: 12px; }
.an-actions { margin-top: 18px; display: flex; justify-content: flex-end; }
