/* CourseHome — بوابة المعاهد */
:root {
  --brand: #1f63f2;
  --brand-600: #1a54d1;
  --brand-50: #eef3ff;
  --navy: #0e1b3d;
  --navy-2: #16274f;
  --ink: #0e1b3d;
  --ink-2: #44506b;
  --muted: #6b7591;
  --line: #e3e8f2;
  --bg: #f4f6fb;
  --card: #fff;
  --green: #0f8a5f; --green-bg: #e6f6ef;
  --amber: #a86400; --amber-bg: #fff4e0;
  --red: #c4323a; --red-bg: #fdecee;
  --gray: #5b6478; --gray-bg: #eef0f5;
  --blue-bg: #e8efff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(14,27,61,.04), 0 4px 16px rgba(14,27,61,.05);
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.7; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.4; font-weight: 700; }
h2 { font-size: 1.35rem; } h3 { font-size: 1.05rem; } h4 { font-size: .95rem; margin-top: 1.2em; }
p { margin: 0 0 .8em; }
code { background: var(--gray-bg); padding: 1px 6px; border-radius: 6px; font-size: .9em; }
.ic { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
.nowrap { white-space: nowrap; }
.err { color: var(--red); }
.spacer { flex: 1; }

/* ===== الهيكل ===== */
.shell { display: flex; min-height: 100vh; background: linear-gradient(to left, var(--navy) 260px, transparent 260px); }
.side { width: 260px; flex: none; background: var(--navy); color: #c9d3ea; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 20px 14px; }
.side-head { padding: 4px 10px 18px; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 14px; }
.side-tag { display: block; font-size: .8rem; color: #8b9bc4; margin-top: 4px; }
.brand { display: inline-flex; align-items: center; gap: 8px; color: #fff; text-decoration: none !important; direction: ltr; }
.brand-logo { max-height: 34px; max-width: 180px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, var(--brand) 0 55%, #5b8cff 55% 100%); display: inline-block; }
.brand-word { font-weight: 700; font-size: 1.25rem; letter-spacing: -.01em; font-family: "Segoe UI", system-ui, sans-serif; }
.brand-word b { color: #7fa6ff; font-weight: 700; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a, .side-foot a, .side-foot .linklike { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: #c9d3ea; font-weight: 500; text-decoration: none; }
.nav a:hover, .side-foot a:hover, .side-foot .linklike:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.on { background: var(--brand); color: #fff; }
.nav a span { flex: 1; }
.badge { font-style: normal; background: #ff8a3d; color: #fff; font-size: .75rem; font-weight: 700; min-width: 22px; height: 22px; border-radius: 11px; display: inline-grid; place-items: center; padding: 0 6px; }
.nav a.on .badge { background: #fff; color: var(--brand); }
.side-foot { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; display: flex; flex-direction: column; gap: 2px; }
.side-foot form { margin: 0; }
.who { padding: 4px 12px 10px; display: flex; flex-direction: column; }
.who b { color: #fff; font-weight: 600; } .who span { font-size: .82rem; color: #8b9bc4; }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; width: 100%; text-align: start; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 20px 32px 4px; }
.topbar h1 { font-size: 1.5rem; margin: 0; }
.menu-btn { display: none; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; color: var(--ink); }
.content { padding: 16px 32px 48px; max-width: 1280px; width: 100%; }
.scrim { display: none; }

/* ===== البطاقات ===== */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card.narrow { max-width: 720px; }
.card-accent { border-color: #b9cdfb; box-shadow: 0 0 0 3px var(--brand-50), var(--shadow); }
.card-warn { border-color: #f3d29a; background: #fffcf5; }
.card-success { border-color: #a7dfc6; background: #f6fcf9; }
.row-between { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.grid-2.wide-first { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.grid-2 > .card, .grid-2 > div > .card:last-child { margin-bottom: 0; }
.grid-2 + .card, .grid-2 + .grid-2 { margin-top: 18px; }
.empty { text-align: center; padding: 36px 20px; }
.empty-inline { color: var(--muted); padding: 10px 0; margin: 0; }

/* ===== المؤشرات ===== */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; color: var(--ink); box-shadow: var(--shadow); text-decoration: none !important; transition: border-color .15s, transform .15s; }
a.kpi:hover { border-color: #b9cdfb; transform: translateY(-1px); }
.kpi span { color: var(--muted); font-size: .88rem; font-weight: 500; }
.kpi b { font-size: 2rem; line-height: 1.2; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi b.b-sm { font-size: 1.35rem; padding: 6px 0 4px; }
.kpi small { color: var(--muted); font-size: .8rem; }
.kpi-accent { background: var(--brand); border-color: var(--brand); color: #fff; }
.kpi-accent span, .kpi-accent small { color: #dbe6ff; }
.kpi-warn { border-color: #f3d29a; background: #fffbf2; }
.kpi-warn b { color: var(--amber); }

.hero-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.hero-title { font-size: 1.3rem; margin: 0; }

/* ===== الأزرار ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--brand); color: #fff; border: 1px solid var(--brand); border-radius: 10px; padding: 9px 18px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important; white-space: nowrap; transition: background .15s; }
.btn:hover { background: var(--brand-600); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 5px 12px; font-size: .88rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-ghost { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--red); border-color: var(--red); }
.btn-danger:hover { background: #a6272e; }
.btn-danger-ghost { background: var(--card); color: var(--red); border-color: #f1c4c8; }
.btn-danger-ghost:hover { background: var(--red-bg); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.actions form, form.inline { display: inline; margin: 0; }

/* ===== الحالات ===== */
.chip { display: inline-flex; align-items: center; font-size: .78rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; white-space: nowrap; line-height: 1.7; }
.chip-green { background: var(--green); color: #fff; } .chip-green.chip-soft { background: var(--green-bg); color: var(--green); }
.chip-amber { background: #e08a00; color: #fff; } .chip-amber.chip-soft { background: var(--amber-bg); color: var(--amber); }
.chip-red { background: var(--red); color: #fff; } .chip-red.chip-soft { background: var(--red-bg); color: var(--red); }
.chip-gray { background: var(--gray-bg); color: var(--gray); }
.chip-blue { background: var(--blue-bg); color: var(--brand); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }

/* ===== التنبيهات ===== */
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; border: 1px solid; font-size: .93rem; }
.alert-success { background: var(--green-bg); border-color: #a7dfc6; color: #0b5f42; }
.alert-error { background: var(--red-bg); border-color: #f1c4c8; color: #8f1f26; }
.alert-warn { background: var(--amber-bg); border-color: #f3d29a; color: #7a4800; }
.alert-info { background: var(--brand-50); border-color: #c8d8fc; color: #1a3f99; }
.alert-link { display: flex; align-items: center; gap: 8px; text-decoration: none !important; }
.alert-link:hover { filter: brightness(.98); }

/* ===== النماذج ===== */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .9rem; color: var(--ink-2); }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid #d3dae8; border-radius: 10px; padding: 9px 12px; width: 100%; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
textarea { resize: vertical; line-height: 1.7; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; flex: none; margin: 3px 0 0; accent-color: var(--brand); }
input[type=file] { padding: 7px; background: var(--bg); }
.has-err input, .has-err select, .has-err textarea { border-color: var(--red); }
small.err { font-weight: 500; }
.hint { color: var(--muted); font-weight: 400; }
.form label.check, label.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; color: var(--ink); cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.span2 { grid-column: span 2; }
.sep { font-weight: 700; font-size: .85rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
.input-group { display: flex; gap: 6px; }
.input-group input { flex: 1; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
legend { font-weight: 700; font-size: .9rem; padding: 0 6px; }
.course-form .card h3 { margin-bottom: 14px; }
.course-form .card { display: flex; flex-direction: column; gap: 14px; }
.course-form .card h3 { margin: 0; }
.submit-card { background: var(--bg); box-shadow: none; }
.upload { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.upload label { flex: 1; min-width: 240px; }
.thumb { max-width: 160px; max-height: 100px; border-radius: 8px; display: block; }
.thumb-lg { width: 180px; height: 110px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 16px; }
.filters input, .filters select { width: auto; min-width: 150px; padding: 7px 10px; }
.filters input[name=q] { flex: 1; min-width: 220px; }
.inline-label { display: inline-flex !important; flex-direction: row !important; align-items: center; gap: 6px; font-size: .88rem; color: var(--muted); }
.inline-form { flex-direction: row; gap: 8px; margin-top: 10px; }
.inline-form input { flex: 1; }
.danger-row { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.copy-src { font-size: .85rem; background: var(--bg); margin: 8px 0; }
.review-form { margin-top: 6px; }
.accept-box { background: var(--brand-50); border: 1px solid #c8d8fc; border-radius: 12px; padding: 16px; margin-top: 20px; }
.acks { background: var(--bg); }
.select-all { user-select: all; color: var(--ink); }
.danger-zone h2 { margin-bottom: 2px; }

/* ===== الجداول ===== */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: start; font-weight: 600; color: var(--muted); font-size: .82rem; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td:first-child b { white-space: nowrap; }
.table td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfe; }
.table a b { color: var(--ink); }
.table a:hover b { color: var(--brand); }
.diff th { color: var(--ink-2); font-size: .88rem; width: 140px; }
.diff .old { color: var(--muted); text-decoration: line-through; text-decoration-color: #d9a2a6; }
.diff .new { background: #f2fbf6; font-weight: 500; }
.bar-col { width: 22%; min-width: 80px; }
.hbar { display: block; height: 8px; border-radius: 4px; background: var(--brand); margin-top: 8px; min-width: 2px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 16px; }

/* ===== القوائم ===== */
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a { display: flex; flex-direction: column; padding: 10px 0; color: var(--ink); text-decoration: none; }
.list a:hover b { color: var(--brand); }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { position: relative; padding: 8px 18px 8px 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.feed li:last-child { border-bottom: 0; }
.feed .dot { position: absolute; right: 2px; top: 16px; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); }
.feed time { display: block; color: var(--muted); font-size: .8rem; }

/* ===== صفحة الدورة ===== */
.course-head { display: flex; gap: 20px; align-items: stretch; }
.course-head .cover { width: 220px; height: 150px; object-fit: cover; border-radius: 12px; flex: none; }
.course-head-body { flex: 1; min-width: 0; }
.course-head h2 { margin-bottom: 2px; }
.details { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin: 0; }
.details dt { color: var(--muted); font-size: .88rem; }
.details dd { margin: 0; font-weight: 500; }
.desc { white-space: normal; color: var(--ink-2); }
.terms-body { background: var(--bg); border-radius: 12px; padding: 20px 24px; margin-top: 14px; max-height: 60vh; overflow-y: auto; line-height: 2; }

/* ===== الرسم البياني ===== */
.legend { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-inline-start: 8px; }
.lg-approved, .vbar.approved { background: var(--brand); }
.lg-cancelled, .vbar.cancelled { background: #f0a04b; }
.vbars { display: flex; align-items: flex-end; gap: 6px; height: 220px; padding-top: 24px; overflow-x: auto; }
.vbar-group { flex: 1; min-width: 34px; height: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.vbar-pair { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; border-bottom: 1px solid var(--line); }
.vbar { width: 40%; max-width: 18px; border-radius: 4px 4px 0 0; position: relative; min-height: 0; }
.vbar em { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-style: normal; font-size: .72rem; color: var(--ink-2); font-weight: 600; }
.vbar-group small { color: var(--muted); font-size: .75rem; }

/* ===== التبويبات ===== */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 10px 16px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); }
details.add-user { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
details.add-user summary { cursor: pointer; font-weight: 600; color: var(--brand); margin-bottom: 12px; }
.radios .check span { line-height: 1.6; }

/* ===== صفحة الدخول ===== */
.bare { min-height: 100vh; display: flex; flex-direction: column; }
.bare > .alert { max-width: 960px; margin: 16px auto 0; width: calc(100% - 32px); }
.auth { flex: 1; display: flex; align-items: center; justify-content: center; padding: 32px 16px; gap: 0; }
.auth-side { width: 400px; align-self: stretch; max-height: 560px; background: var(--navy); color: #c9d3ea; border-radius: 20px 0 0 20px; padding: 40px 36px; display: flex; flex-direction: column; justify-content: space-between; background-image: radial-gradient(circle at 15% 110%, rgba(31,99,242,.55), transparent 55%); }
.auth-side h2 { color: #fff; font-size: 1.6rem; margin-top: 28px; }
.auth-points { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.auth-points li::before { content: "✓"; color: #7fa6ff; font-weight: 700; margin-inline-end: 8px; }
.auth-card { width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 40px 36px; box-shadow: 0 10px 40px rgba(14,27,61,.08); }
.auth-side + .auth-card { border-radius: 0 20px 20px 0; border-inline-start: 0; display: flex; flex-direction: column; justify-content: center; max-height: 560px; align-self: stretch; }
.auth-brand { display: flex; align-items: center; gap: 8px; direction: ltr; justify-content: flex-end; margin-bottom: 22px; }
.auth-brand.light { justify-content: flex-start; color: #fff; }
.auth-card .auth-brand .brand-word { color: var(--navy); }
.auth-card .auth-brand .brand-word b { color: var(--brand); }
.auth-card .form { margin: 18px 0; }

/* ===== الجوال ===== */
@media (max-width: 980px) {
  .grid-2, .grid-2.wide-first { grid-template-columns: 1fr; }
  .grid-2 > .card { margin-bottom: 0; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .auth-side { display: none; }
  .auth-side + .auth-card { border-radius: 20px; border-inline-start: 1px solid var(--line); }
}
@media (max-width: 820px) {
  .side { position: fixed; inset: 0 0 0 auto; z-index: 50; transform: translateX(100%); transition: transform .2s; visibility: hidden; }
  body.side-open .side { transform: none; visibility: visible; box-shadow: -8px 0 30px rgba(0,0,0,.2); }
  .shell { background: none; }
  body.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(14,27,61,.4); z-index: 40; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 14px 16px 0; }
  .topbar h1 { font-size: 1.2rem; }
  .content { padding: 12px 16px 40px; }
  .card { padding: 16px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .course-head { flex-direction: column; }
  .course-head .cover { width: 100%; height: 180px; }
  .details { grid-template-columns: 110px 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi b { font-size: 1.6rem; }
  .filters input, .filters select { min-width: 0; flex: 1 1 140px; }
  .auth-card { padding: 28px 22px; }
}
@media print {
  .side, .topbar .menu-btn, .filters, .actions, .scrim { display: none !important; }
  .content { padding: 0; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
}
