/* نظام إدارة جداول التدريب — تنسيق RTL عربي */
/* خط Cairo مضمّن محلياً (لا يحتاج إنترنت) — وضوح أعلى للعربية */
@import url('fonts/cairo.css');
:root {
  --bg: #f2f5f9;
  --sidebar: #14243a;
  --sidebar-hi: #1f4e79;
  --card: #ffffff;
  --text: #1c2733;
  --muted: #68788c;
  --primary: #1f4e79;
  --primary-hi: #2a669b;
  --danger: #a02c2c;
  --ok: #1e6b45;
  --warn: #b45f0f;
  --line: #dde5ee;
  --radius: 12px;
}
* { box-sizing: border-box; }
html { direction: rtl; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Cairo", "Segoe UI", Tahoma, "Noto Naskh Arabic", "Noto Sans Arabic", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { font-family: "Cairo", "Segoe UI", Tahoma, sans-serif; letter-spacing: 0; }
select, input, button, textarea { font-family: inherit; }
.layout { display: flex; min-height: 100vh; }

/* ---------- الشريط الجانبي ---------- */
.sidebar {
  width: 240px; background: var(--sidebar); color: #dfe8f2;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px 18px 14px; border-bottom: 1px solid #ffffff14; }
.brand-title { font-weight: 700; font-size: 16.5px; color: #fff; }
.brand-sub { font-size: 12.5px; color: #9fb4cc; margin-top: 4px; }
.sidebar nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.navlink {
  display: flex; align-items: center; gap: 10px; color: #c9d7e6; text-decoration: none;
  padding: 9px 12px; border-radius: 9px; margin-bottom: 2px; font-size: 14.5px;
}
.navlink:hover { background: #ffffff10; color: #fff; }
.navlink.on { background: var(--sidebar-hi); color: #fff; font-weight: 600; }
.navlink .ic { width: 20px; text-align: center; }
.sidebar-foot { padding: 12px 16px; font-size: 11.5px; color: #8ba1bb; border-top: 1px solid #ffffff14; }

/* ---------- المحتوى ---------- */
.main { flex: 1; padding: 22px 26px 40px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.topbar h1 { font-size: 22px; margin: 0; color: var(--primary); }
.term-chip { background: #e7eef7; color: var(--primary); border-radius: 999px; padding: 7px 16px; font-size: 12.5px; }
.content { display: flex; flex-direction: column; gap: 16px; }
.pagefoot { margin-top: 26px; color: var(--muted); font-size: 12px; text-align: center; }

/* ---------- بطاقات ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: 0 1px 2px #0b1c2c0a;
}
.card-title { margin: 0 0 12px; font-size: 16.5px; color: var(--primary); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head .card-title { margin: 0; }
.cards-row { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.span-2 { grid-column: span 1; }
@media (max-width: 1000px) { .cards-row { grid-template-columns: 1fr; } }

/* ---------- بطاقات الإحصاء ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat-card { border-radius: var(--radius); padding: 16px; text-decoration: none; color: #fff; display: block; }
.stat-num { font-size: 30px; font-weight: 800; line-height: 1.1; }
.stat-label { font-size: 13px; opacity: .92; margin-top: 4px; }
.c-blue { background: #1f4e79; } .c-teal { background: #16707e; } .c-purple { background: #5b4b8a; }
.c-orange { background: #b45f0f; } .c-gray { background: #5a6b7d; }
.c-red { background: var(--danger); } .c-green { background: var(--ok); }

/* ---------- تنبيهات ---------- */
.alert { border-radius: 10px; padding: 12px 16px; font-size: 14px; border: 1px solid transparent; }
.alert a { color: inherit; font-weight: 700; }
.alert-warn { background: #fdf4e7; border-color: #f0d4ab; color: #8a4d0b; }
.alert-ok { background: #ecf7f0; border-color: #bfe0cb; color: #14582f; }
.alert-info { background: #eaf2fb; border-color: #c2d8ef; color: #1f4e79; }
.alert-err { background: #fdecec; border-color: #f2c1c1; color: #8f2222; }
.flash { border-radius: 10px; padding: 11px 15px; margin-bottom: 12px; font-size: 14px; }
.flash-ok { background: #ecf7f0; color: #14582f; border: 1px solid #bfe0cb; }
.flash-err { background: #fdecec; color: #8f2222; border: 1px solid #f2c1c1; }
.flash-warn { background: #fdf4e7; color: #8a4d0b; border: 1px solid #f0d4ab; }

/* ---------- جداول ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { border-bottom: 1px solid var(--line); padding: 9px 10px; text-align: right; vertical-align: top; }
.tbl thead th { background: #f4f7fb; color: var(--primary); font-size: 13px; }
.tbl tbody tr:hover { background: #f8fafc; }
.tbl-mini { font-size: 13px; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; vertical-align: middle; margin-inline-end: 6px; }
.bad-num { color: var(--danger); font-weight: 800; }
.ok-line { color: var(--ok); font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; }
.warn-cell { color: var(--warn); font-size: 12.5px; white-space: pre-line; }

/* ---------- شبكة الجدول ---------- */
.sched { width: 100%; border-collapse: separate; border-spacing: 6px; }
.sched thead th { background: var(--primary); color: #fff; border-radius: 9px; padding: 10px 6px; font-size: 14.5px; font-weight: 700; }
.sched thead th small { display: block; font-weight: 500; font-size: 11.5px; opacity: .9; margin-top: 3px; }
.sched .day-col { background: #eef2f7; color: var(--text); width: 86px; font-size: 14.5px; font-weight: 700; }
.cell { border-radius: 10px; min-height: 84px; padding: 9px 10px; vertical-align: top; width: 23%; }
.cell.filled { cursor: default; }
.cell.empty { background: #f4f7fa; border: 2px dashed #cdd9e5; text-align: center; cursor: pointer; }
.cell.empty:hover { background: #eaf1f8; }
.cell .plus { color: #9db1c5; font-size: 22px; line-height: 70px; }
.cell-subject { font-weight: 700; font-size: 14.5px; margin-bottom: 3px; line-height: 1.5; }
.cell-teacher, .cell-room { font-size: 12.5px; color: #3d4c5d; }
.cell-tools { margin-top: 7px; display: flex; gap: 6px; }

/* خلية بها تعارض (مدرب/قاعة محجوز في نفس الوقت بشعبة أخرى) */
.cell-conflict { box-shadow: inset 0 0 0 2.5px #e05050; }
.cell-conflict-badge {
  margin-top: 6px; display: inline-block; background: #fdecec; color: var(--danger);
  border: 1px solid #f2bcbc; border-radius: 999px; padding: 1px 9px;
  font-size: 11px; font-weight: 700;
}

/* ---------- أزرار ---------- */
.btn {
  display: inline-block; background: #e8eef5; color: var(--text); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 9px; font-size: 13.5px; cursor: pointer; text-decoration: none;
  font-family: inherit; line-height: 1.4;
}
.btn:hover { background: #dfe8f1; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hi); }
.btn-danger { background: #fbeaea; border-color: #eec3c3; color: var(--danger); }
.btn-danger:hover { background: #f6dcdc; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.mini { font-size: 11.5px; padding: 3px 9px; border-radius: 7px; border: 1px solid #ffffff70; background: #ffffff55; cursor: pointer; font-family: inherit; }
.mini:hover { background: #ffffff90; }
.mini-danger { border-color: #e9b9b9; background: #ffffff70; color: var(--danger); }
.actions { display: flex; gap: 6px; align-items: center; }

/* ---------- نماذج ---------- */
.filterbar { display: flex; gap: 14px; flex-wrap: wrap; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.filterbar label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
select, input[type="text"], input[type="number"], input[type="time"], input[type="color"], input[type="password"], input:not([type]) {
  font-family: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--text); min-width: 120px;
}
input[type="color"] { padding: 2px; min-width: 46px; height: 38px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.form-actions { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- نافذة منبثقة ---------- */
.modal-back { position: fixed; inset: 0; background: #0b1c2caa; display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 14px; padding: 22px 24px; width: min(460px, 92vw); box-shadow: 0 18px 60px #0006; }
.modal h3 { margin: 0 0 14px; color: var(--primary); }
.modal label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.modal select { width: 100%; }
.modal-errors { color: var(--danger); font-size: 13px; margin: 6px 0; }
.modal-errors div { margin-bottom: 4px; }

/* ---------- لوحة فحص التعارضات الفوري (نافذة الحصة) ---------- */
.conflict-panel {
  display: flex; flex-direction: column; gap: 5px;
  background: #f8fafc; border: 1px solid var(--line); border-inline-start: 4px solid var(--ok);
  border-radius: 10px; padding: 10px 12px; margin: 4px 0 10px;
  max-height: 150px; overflow: auto; font-size: 13px;
}
.conflict-panel:has(.conf-err) { border-inline-start-color: var(--danger); background: #fdf7f7; }
.conf-err { color: var(--danger); font-weight: 700; line-height: 1.7; }
.conf-warn { color: var(--warn); line-height: 1.7; }
.conf-ok { color: var(--ok); font-weight: 700; }
.free-row { margin-bottom: 9px; }
.free-title { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.chips-free { display: flex; flex-wrap: wrap; gap: 5px; max-height: 74px; overflow: auto; }
.chip-free {
  background: #f2f8f4; border: 1px solid #bfe0cb; color: #14582f;
  border-radius: 999px; padding: 3px 11px; font-size: 12px; cursor: pointer; font-family: inherit;
}
.chip-free:hover { background: #e2f1e7; }
.chip-free.chip-assigned { background: #e8f3fd; border-color: #b3d4f0; color: var(--primary); font-weight: 700; }
.chip-free.chip-assigned:hover { background: #d8eaf9; }

/* ---------- لوحة التعارضات ---------- */
.conf-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.conf-stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 18px; text-align: center; min-width: 110px; }
.conf-stat b { display: block; font-size: 26px; }
.conf-stat span { font-size: 12.5px; color: var(--muted); }
.conf-stat.bad b { color: var(--danger); }
.conf-stat.warn b { color: var(--warn); }
.conf-stat.good b { color: var(--ok); }
.conf-entry { padding: 3px 8px; margin: 3px 0; font-size: 13px; background: #f8fafc; border-radius: 6px; }

/* ---------- الإجراءات السريعة ---------- */
.quick-actions { display: flex; flex-direction: column; gap: 10px; }
.qa { display: flex; gap: 12px; align-items: center; background: #f7fafc; border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; text-decoration: none; color: var(--text); }
.qa:hover { background: #eef4fa; }
.qa-ic { font-size: 22px; }
.qa small { display: block; color: var(--muted); font-size: 12px; }

/* ---------- التغطية ---------- */
.cov-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.cov-dept { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.cov-dept-name { font-weight: 700; margin-bottom: 8px; color: var(--primary); font-size: 14px; }

/* ---------- الاستيراد ---------- */
.feature-list { line-height: 2; font-size: 14px; }
.import-form { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; max-width: 560px; }
.file-label, .radio-label { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.preview-summary { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.ps-item { background: #eef3f9; border-radius: 10px; padding: 10px 16px; text-align: center; }
.ps-item b { display: block; font-size: 22px; color: var(--primary); }
.ps-item span { font-size: 12px; color: var(--muted); }
.pv-table { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.pv-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.pv-title { font-weight: 700; color: var(--primary); }
.pv-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { background: #eef3f9; border-radius: 999px; font-size: 11.5px; padding: 3px 10px; color: #3d4c5d; }
.badge-blue { background: #dfe9f4; color: var(--primary); font-weight: 700; }
.pv-warn { background: #fdf4e7; color: #8a4d0b; border-radius: 8px; padding: 7px 10px; font-size: 12.5px; margin-bottom: 8px; }
.pv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 8px; }
.pv-cell { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; display: flex; flex-direction: column; }
.pv-slot { color: var(--muted); font-size: 11px; }
.newflag { color: var(--warn); font-style: normal; font-size: 10.5px; font-weight: 700; }
.slots-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .slots-wrap { grid-template-columns: 1fr; } }

/* ---------- الشعار والمستخدم ---------- */
.brand-logo {
  display: block; width: 160px; max-width: 100%; height: auto;
  background: #fff; border-radius: 10px; padding: 8px; margin-bottom: 10px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-chip {
  display: flex; align-items: center; gap: 8px; background: #fff;
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; font-size: 13px;
}
.user-chip .user-name small { color: var(--muted); font-size: 11px; }
.logo-preview { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; margin-bottom: 12px; }
.logo-preview img { max-width: 100%; max-height: 90px; }
.inline-form { display: inline; }

/* ---------- صفحة تسجيل الدخول ---------- */
.login-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #14243a 0%, #1f4e79 55%, #2a669b 100%); padding: 20px;
}
.login-card {
  background: #fff; border-radius: 18px; box-shadow: 0 24px 80px #00000059;
  padding: 32px 34px 24px; width: min(430px, 94vw); text-align: center;
}
.login-logo { max-width: 230px; max-height: 86px; margin: 0 auto 10px; display: block; }
.login-institute { font-size: 19px; font-weight: 800; color: var(--primary); }
.login-app { font-size: 13.5px; color: var(--muted); margin: 4px 0 18px; }
.login-form { display: flex; flex-direction: column; gap: 12px; text-align: right; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-btn { width: 100%; margin-top: 6px; }
.login-term { margin-top: 16px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- طباعة ---------- */
@media print {
  .sidebar, .topbar, .filterbar, .flash, .pagefoot, .cell-tools, .form-actions, .noprint { display: none !important; }
  .main { padding: 0; }
  .card { border: none; box-shadow: none; }
  .sched { border-spacing: 3px; }
  .sched thead th, .sched .day-col, .cell.filled {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .sched thead th { font-size: 13px; }
  .cell-subject { font-size: 13px; }
  .cell-teacher, .cell-room { font-size: 11.5px; }
  body { font-size: 13.5px; }
}

/* ---------- تسكين المدربين وأوقات الدوام ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.chip {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 16px; font-size: 12.5px; color: var(--muted); min-width: 110px;
}
.chip b { display: block; font-size: 16px; color: var(--text); margin-bottom: 2px; }
.chip-warn { border-color: #e2c48d; background: #fdf6ec; }
.chip-warn b { color: var(--warn); }
.dept-block { margin-bottom: 16px; }
.dept-block-title {
  font-weight: 700; font-size: 13.5px; color: var(--primary);
  display: flex; align-items: center; gap: 7px; margin: 10px 0 8px;
}
.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.subject-grid label {
  display: flex; align-items: center; gap: 8px; background: #fff;
  border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 11px;
  cursor: pointer; font-size: 13.5px; transition: border-color .15s, background .15s;
}
.subject-grid label:hover { border-color: #9fb8d4; }
.subject-grid label:has(input:checked) { border-color: var(--primary); background: #eef5fd; }
.subject-grid .cnt { color: var(--muted); font-size: 11px; margin-inline-start: auto; white-space: nowrap; }
.st-ok { color: var(--ok); font-weight: 700; }
.st-warn { color: var(--warn); font-weight: 700; }
.st-bad { color: var(--danger); font-weight: 700; }
.bar { height: 9px; background: #e5eaf1; border-radius: 6px; overflow: hidden; min-width: 90px; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 6px; }
.bar > i.hot { background: var(--danger); }
.bar > i.mid { background: var(--warn); }
.occ { text-align: center; font-weight: 600; }
.occ.mid { background: #eaf3ec; color: var(--ok); }
.occ.hot { background: #f8e7e3; color: var(--danger); }
.occ small { display: block; color: var(--muted); font-weight: 400; }
.alert-info { border-inline-start: 4px solid #2a669b; background: #eef5fd; }

/* رابط بوابة المتدربين في الشريط الجانبي (صفحة عامة منفصلة) */
.portal-link {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16);
  color: #fff; text-decoration: none; font-size: 13px; font-weight: 700;
  border-radius: 9px; padding: 9px 12px; margin-bottom: 8px;
  transition: background .15s;
}
.portal-link:hover { background: rgba(255,255,255,.16); }
.portal-link span { opacity: .8; }

/* ---------- خانة ختم المعهد ---------- */
.sched-foot { display: flex; justify-content: flex-start; margin-top: 12px; }
.stamp-box {
  width: 175px; background: #fff;
  border: 2px dashed #8fa9c4; border-radius: 12px;
  padding: 6px 8px 4px; text-align: center;
}
.stamp-area { height: 82px; display: flex; align-items: center; justify-content: center; }
.stamp-area img { max-width: 100%; max-height: 82px; object-fit: contain; }
.stamp-hint { color: #a8b8c9; font-size: 11.5px; }
.stamp-label {
  font-size: 11.5px; color: #68788c; font-weight: 600;
  border-top: 1px dashed #cdd9e5; margin-top: 4px; padding-top: 3px;
}
.stamp-admin-row { display: flex; gap: 26px; align-items: flex-start; flex-wrap: wrap; }
.stamp-preview-area { min-width: 200px; }
@media print {
  .stamp-box { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sched-foot { margin-top: 8px; }
}

/* ---------- صندوق رمز التحقق QR على الجداول المعروضة ---------- */
.verify-panel {
  display: flex; gap: 18px; align-items: center;
  margin-top: 14px; padding: 12px 14px;
  background: #f6f9fc; border: 1px solid #dde7f1; border-radius: 12px;
}
.verify-panel img {
  width: 96px; height: 96px; border: 6px solid #fff; border-radius: 8px;
  box-shadow: 0 1px 6px rgba(16, 51, 80, .18); flex: 0 0 auto; background: #fff;
}
.verify-panel-txt { display: flex; flex-direction: column; gap: 5px; }
.verify-panel-txt b { color: #1F4E79; font-size: 14.5px; }
.verify-panel-txt span { color: #5a6c80; font-size: 12.5px; line-height: 1.7; }
.verify-panel-txt .btn { align-self: flex-start; }
@media print {
  .verify-panel { -webkit-print-color-adjust: exact; print-color-adjust: exact; background: #fff; }
}

/* ---------- أدوات الجداول في الإدارة ---------- */
.tools-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.tools-row form { margin: 0; }
.btn-danger { background: #A02C2C; color: #fff; }
.btn-danger:hover { background: #8a2424; }
