/* Training Course Management System — stylesheet
   Right-to-left layout, one font family (Noto Kufi Arabic, bundled locally). */

@font-face { font-family: "Noto Kufi Arabic"; src: url("../fonts/noto-kufi-arabic-regular.woff") format("woff"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Noto Kufi Arabic"; src: url("../fonts/noto-kufi-arabic-bold.woff") format("woff"); font-weight: 700; font-display: swap; }

:root {
  --navy: #1b365d;
  --navy-dark: #12263f;
  --navy-soft: #e8eef6;
  --gold: #b8892f;
  --gold-soft: #f6eedc;
  --ink: #1f2937;
  --muted: #667085;
  --line: #dfe4ec;
  --bg: #f4f6f9;
  --card: #ffffff;
  --ok: #1e7b45;
  --ok-soft: #e4f4ea;
  --no: #b42318;
  --no-soft: #fdecea;
  --warn: #9a6400;
  --warn-soft: #fff4dc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Noto Kufi Arabic", Tahoma, sans-serif; line-height: 1.7;
}
a { color: var(--navy); }
h1, h2, h3 { line-height: 1.4; margin: 0 0 .6rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .7rem; }
small { font-size: .82rem; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.hint { display: block; color: var(--muted); font-size: .82rem; margin-top: .3rem; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.lead { font-size: 1.02rem; color: #344054; }
.empty { color: var(--muted); padding: 1rem 0; margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem 1rem; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-size: .92rem; font-weight: 700; text-decoration: none; cursor: pointer;
  background: var(--card); color: var(--navy); transition: background .15s, border-color .15s;
}
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgba(27, 54, 93, .35); outline-offset: 2px;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-dark); }
.btn-ghost { border-color: var(--line); }
.btn-ghost:hover { background: var(--navy-soft); }
.btn-light { background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(255, 255, 255, .35); }
.btn-light:hover { background: rgba(255, 255, 255, .22); }
.btn-gold { background: var(--gold); color: #fff; }
.btn-gold:hover { background: #9c7326; }
.btn-danger-ghost { border-color: #f1c4bf; color: var(--no); }
.btn-danger-ghost:hover { background: var(--no-soft); }
.btn-sm { padding: .3rem .7rem; font-size: .82rem; }
.btn-lg { padding: .75rem 2rem; font-size: 1.05rem; }
.btn-block { display: flex; width: 100%; }
.inline-form { display: inline; margin: 0; }
.btn-block + .btn-block, .inline-form + .btn-block, .btn-block + .inline-form { margin-top: .5rem; }
.tools .inline-form { display: block; }

/* ----------------------------------------------------------------- badges */
.badge {
  display: inline-block; padding: .05rem .6rem; border-radius: 999px;
  font-size: .78rem; font-weight: 700; background: var(--navy-soft); color: var(--navy);
}
.badge-ok, .badge-running { background: var(--ok-soft); color: var(--ok); }
.badge-no { background: var(--no-soft); color: var(--no); }
.badge-upcoming { background: var(--warn-soft); color: var(--warn); }
.badge-finished, .badge-muted { background: #eef0f3; color: var(--muted); }

/* ----------------------------------------------------------------- alerts */
.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.alert-success { background: var(--ok-soft); border-color: #b7e0c5; color: #145a32; }
.alert-error { background: var(--no-soft); border-color: #f1c4bf; color: #8a1c12; }
.alert-info { background: var(--navy-soft); border-color: #c9d6e8; color: var(--navy); }
.secret-box .secret { font-size: 1.5rem; font-weight: 700; letter-spacing: .08em; margin: .3rem 0; }

/* ----------------------------------------------------------------- layout */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--navy); color: #fff; padding: .6rem 1.4rem; border-bottom: 3px solid var(--gold);
}
.brand { display: flex; align-items: center; gap: .75rem; color: #fff; text-decoration: none; }
.brand-logo { width: 46px; height: 46px; border-radius: 50%; background: #fff; }
.brand-text { display: flex; flex-direction: column; line-height: 1.35; }
.brand-text small { color: #c8d3e3; }
.topbar-user { display: flex; align-items: center; gap: .9rem; }
.user-name small { color: #c8d3e3; margin-inline-start: .3rem; }

.shell { display: grid; grid-template-columns: 230px 1fr; min-height: calc(100vh - 66px); }
.sidebar { background: var(--card); border-inline-end: 1px solid var(--line); padding: 1rem .7rem; }
.sidebar a {
  display: block; padding: .55rem .9rem; border-radius: 8px; color: #344054;
  text-decoration: none; font-weight: 700; margin-bottom: .2rem;
}
.sidebar a:hover { background: var(--bg); }
.sidebar a.active { background: var(--navy-soft); color: var(--navy); box-shadow: inset -3px 0 0 var(--navy); }
.content { padding: 1.4rem 1.8rem 3rem; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.page-head p { margin: 0; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.2rem 1.3rem; margin-bottom: 1.2rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; }
.card-head h2 { margin: 0; }
.card-form { max-width: 720px; }
.card-narrow { max-width: 520px; margin: 0 auto 1.2rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.2rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.2rem; margin-bottom: 1.2rem; }
.grid-3 > .card, .grid-3 > .qr-card { margin-bottom: 0; }

/* ------------------------------------------------------------------ stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .9rem 1.1rem; text-decoration: none; color: var(--ink); border-top: 3px solid var(--navy);
}
.stat b { display: block; font-size: 1.7rem; color: var(--navy); line-height: 1.3; }
.stat span { color: var(--muted); font-size: .88rem; }
.stats-small .stat { box-shadow: none; padding: .6rem .9rem; }
.stats-small .stat b { font-size: 1.3rem; }

/* ----------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: start; color: var(--muted); font-size: .82rem; font-weight: 700; padding: .55rem .6rem; border-bottom: 2px solid var(--line); white-space: nowrap; }
.table td { padding: .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:hover td { background: #fafbfc; }
.table .actions { text-align: end; white-space: nowrap; }
.table .actions > * + * { margin-inline-start: .3rem; }
.table-compact td { padding: .4rem .6rem; font-size: .86rem; }
.row-muted td { color: var(--muted); }
.row-warn td { background: #fffaf0; }
.code-cell { font-weight: 700; letter-spacing: .1em; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: .8rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }

/* ------------------------------------------------------------------ forms */
.form .field, .field { margin-bottom: 1rem; border: 0; padding: 0; }
label, legend { display: block; font-weight: 700; font-size: .9rem; margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel],
input:not([type]), select, textarea {
  width: 100%; padding: .55rem .75rem; border: 1px solid #cdd5df; border-radius: 8px;
  font: inherit; font-size: .95rem; background: #fff; color: var(--ink);
}
textarea { resize: vertical; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--no); background: #fffafa; }
.has-error label { color: var(--no); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 1rem; align-items: end; }
.field-button { display: flex; align-items: flex-end; }
.form-buttons { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }
.form-inline { display: flex; align-items: flex-end; gap: .7rem; }
.form-inline .field { flex: 1; margin-bottom: 0; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; margin-bottom: .5rem; cursor: pointer; }
.check input { width: 1.1rem; height: 1.1rem; }
.pin-input { font-size: 1.4rem; letter-spacing: .4em; text-align: center; font-weight: 700; }
.option-row { display: flex; align-items: center; gap: .6rem; margin-bottom: .5rem; }
.option-row input[type=radio] { width: 1.2rem; height: 1.2rem; flex: none; }

/* ------------------------------------------------------------------- QR */
.qr-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; text-align: center; }
.qr { width: 170px; height: 170px; margin: .4rem auto .5rem; background: #fff; }
.qr svg { width: 100%; height: 100%; display: block; }
.qr-large { width: 260px; height: 260px; }
.qr-link { font-size: .78rem; color: var(--muted); word-break: break-all; margin-bottom: .5rem; }
.qr-actions { display: flex; justify-content: center; gap: .4rem; }
.code-card { text-align: center; }
.access-code { font-size: 2.4rem; font-weight: 700; letter-spacing: .25em; color: var(--navy); margin: .6rem 0 .2rem; }

/* -------------------------------------------------------------- questions */
.question-list { padding-inline-start: 1.3rem; margin: 0; }
.question-list > li { padding: .7rem 0; border-bottom: 1px solid var(--line); }
.question-list > li:last-child { border-bottom: 0; }
.q-text { font-weight: 700; }
.q-options { list-style: none; padding: 0; margin: .4rem 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.q-options li { padding: .15rem .7rem; border-radius: 6px; background: var(--bg); font-size: .88rem; }
.q-options li.correct { background: var(--ok-soft); color: var(--ok); font-weight: 700; }
.question-list .actions { display: flex; gap: .4rem; }

/* ---------------------------------------------------------- attendance */
.attendance-grid .day { text-align: center; white-space: nowrap; }
.attendance-grid th.day small { display: block; font-weight: 400; }
.attendance-grid .today { background: var(--gold-soft); }
.attendance-grid input[type=checkbox] { width: 1.2rem; height: 1.2rem; cursor: pointer; }
.attendance-grid .total { font-weight: 700; text-align: center; }
.attendance-grid tr.saving td { opacity: .6; }

/* ------------------------------------------------------- public pages */
.public { background: var(--bg) linear-gradient(180deg, var(--navy) 0, var(--navy) 210px, var(--bg) 210px) no-repeat; min-height: 100vh; }
.public-head { display: flex; align-items: center; justify-content: center; gap: .8rem; color: #fff; padding: 1.4rem 1rem 1.2rem; text-align: start; }
.public-head div { display: flex; flex-direction: column; line-height: 1.4; }
.public-head small { color: #c8d3e3; }
.public-logo { width: 54px; height: 54px; border-radius: 50%; background: #fff; }
.public-main { padding: 0 1rem 2rem; }
.public-foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 1rem 1.5rem; }
.eyebrow { color: var(--gold); font-weight: 700; font-size: .85rem; margin-bottom: .2rem; }
.facts { list-style: none; padding: 0; margin: 1rem 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.facts li { background: var(--bg); border-radius: 8px; padding: .5rem; text-align: center; }
.facts b { display: block; font-size: 1.3rem; color: var(--navy); }
.facts span { font-size: .8rem; color: var(--muted); }
.notes { padding-inline-start: 1.1rem; color: var(--muted); font-size: .85rem; margin: 1rem 0 0; }
.big-icon { width: 64px; height: 64px; border-radius: 50%; margin: 0 auto .8rem; display: grid; place-items: center; font-size: 2rem; font-weight: 700; }
.big-icon-ok { background: var(--ok-soft); color: var(--ok); }
.big-icon-no { background: var(--no-soft); color: var(--no); }
.score { font-size: 3rem; font-weight: 700; color: var(--navy); margin: .2rem 0; line-height: 1.2; }
.result-line { font-weight: 700; }
.result-line.ok { color: var(--ok); }
.result-line.no { color: var(--no); }
.verify-result { margin-top: 1.2rem; padding-top: 1.2rem; border-top: 1px solid var(--line); text-align: center; }
.verify-result dl { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; text-align: start; margin: 1rem 0 0; }
.verify-result dt { color: var(--muted); }
.verify-result dd { margin: 0; font-weight: 700; }

/* ---------------------------------------------------------------- exam */
.exam-main { max-width: 760px; margin: 0 auto; }
.exam-bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .6rem 1rem; margin-bottom: 1rem;
}
.exam-bar div { display: flex; flex-direction: column; line-height: 1.4; }
.exam-bar small { color: var(--muted); }
.exam-timer { font-size: 1.5rem; font-weight: 700; color: var(--navy); }
.exam-timer.warning { color: var(--no); }
.exam-status { color: var(--muted); min-width: 6rem; text-align: end; }
.question { margin-bottom: 1rem; }
/* float keeps the legend inside the card instead of on its border */
.question legend { float: right; width: 100%; display: flex; gap: .6rem; font-size: 1rem; margin-bottom: .7rem; padding: 0; }
.question legend + * { clear: both; }
.q-number { flex: none; width: 1.8rem; height: 1.8rem; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-size: .85rem; }
.options { display: grid; gap: .5rem; }
.option { display: flex; align-items: center; gap: .7rem; padding: .65rem .8rem; border: 1px solid var(--line); border-radius: 8px; font-weight: 400; cursor: pointer; margin: 0; }
.option:hover { background: var(--bg); }
.option input { width: 1.2rem; height: 1.2rem; flex: none; }
.option:has(input:checked) { border-color: var(--navy); background: var(--navy-soft); }
.exam-submit { text-align: center; padding: 1rem 0 2rem; }

/* ---------------------------------------------------------- PIN screen */
.pin-screen { background: var(--navy-dark); color: #fff; }
.pin-layout { min-height: 100vh; display: flex; flex-direction: column; padding: 2rem 3rem; }
.pin-head { display: flex; align-items: center; gap: 1.2rem; border-bottom: 2px solid var(--gold); padding-bottom: 1rem; }
.pin-head img { width: 72px; height: 72px; border-radius: 50%; background: #fff; }
.pin-head h1 { font-size: 2rem; margin: 0; }
.pin-head p { margin: 0; color: #c8d3e3; }
.pin-body { flex: 1; display: grid; grid-template-columns: 1fr 1.3fr; gap: 3rem; align-items: center; }
.pin-steps { background: rgba(255, 255, 255, .06); border-radius: 16px; padding: 1.5rem; text-align: center; }
.pin-steps ol { text-align: start; font-size: 1.1rem; }
.pin-steps .qr { padding: 10px; border-radius: 8px; }
.pin-steps .qr-link { color: #c8d3e3; }
.pin-code-box { text-align: center; }
.pin-label { font-size: 1.5rem; color: #c8d3e3; margin: 0; }
.pin-code { font-size: 9rem; font-weight: 700; letter-spacing: .12em; line-height: 1.1; margin: .5rem 0 1rem; color: #fff; }
.pin-bar { height: 10px; background: rgba(255, 255, 255, .15); border-radius: 99px; overflow: hidden; max-width: 560px; margin: 0 auto 1rem; }
.pin-bar span { display: block; height: 100%; width: 100%; background: var(--gold); transition: width 1s linear; }
.pin-left, .pin-present { font-size: 1.3rem; color: #c8d3e3; margin: .2rem 0; }
.pin-left b, .pin-present b { color: #fff; }
.pin-inactive { font-size: 1.4rem; color: #ffd27a; }

/* --------------------------------------------------------- certificate */
.certificate-page { background: #e9ecf1; }
.print-toolbar { display: flex; justify-content: center; gap: .6rem; padding: 1rem; }
.certificate { width: 297mm; height: 210mm; margin: 0 auto 2rem; background: #fffdf7; padding: 10mm; box-shadow: 0 4px 20px rgba(0, 0, 0, .12); }
.cert-frame { height: 100%; border: 3px double var(--gold); outline: 1px solid var(--gold); outline-offset: -8px; padding: 10mm 16mm; display: flex; flex-direction: column; align-items: center; text-align: center; }
.cert-head { display: flex; align-items: center; gap: 1rem; align-self: stretch; justify-content: center; }
.cert-head img { width: 70px; height: 70px; }
.cert-head p { margin: 0; line-height: 1.5; }
.cert-body { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.cert-title { font-size: 2.8rem; color: var(--navy); margin: 0 0 .6rem; }
.cert-intro, .cert-text { font-size: 1.2rem; margin: .25rem 0; }
.cert-name { font-size: 2.4rem; font-weight: 700; color: var(--gold); margin: .3rem 0; border-bottom: 1px solid var(--gold-soft); padding: 0 2rem; }
.cert-course { font-size: 1.55rem; font-weight: 700; color: var(--navy); margin: .2rem 0; }
.cert-foot { align-self: stretch; display: flex; align-items: flex-end; justify-content: space-between; }
.cert-qr { text-align: center; }
.cert-qr .qr { width: 95px; height: 95px; margin: 0 auto .2rem; }
.cert-meta p { margin: 0; font-size: .9rem; }
.cert-sign { text-align: center; min-width: 180px; }
.sign-line { display: block; border-bottom: 1px solid var(--ink); height: 40px; margin-bottom: .3rem; }

@media print {
  @page { size: A4 landscape; margin: 0; }
  .print-toolbar { display: none; }
  .certificate-page { background: #fff; }
  .certificate { margin: 0; box-shadow: none; }
}

/* ---------------------------------------------------------- responsive */
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: flex; overflow-x: auto; gap: .3rem; border-inline-end: 0; border-bottom: 1px solid var(--line); padding: .5rem; }
  .sidebar a { white-space: nowrap; margin: 0; }
  .sidebar a.active { box-shadow: inset 0 -3px 0 var(--navy); }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 1rem; }
  .pin-body { grid-template-columns: 1fr; }
  .pin-code { font-size: 5rem; }
}
@media (max-width: 600px) {
  html { font-size: 14px; }
  .topbar { padding: .5rem .8rem; }
  .brand-text small, .user-name { display: none; }
  .card { padding: 1rem; }
  .form-inline { flex-direction: column; align-items: stretch; }
}
