/* Theotokos Institute — student portal
   Brand: deep blue #1a3a5c, gold #8b6914, cream #faf7f0 / #e0d5c0.
   Standalone chrome (like the admin panel) — the marketing nav is not used here.
   RTL is driven by [dir="rtl"] on <html>; logical properties do most of the work. */

:root {
  --blue:        #1a3a5c;
  --blue-dark:   #12293f;
  --blue-light:  #2b5580;
  --gold:        #8b6914;
  --gold-light:  #b08a2e;
  --cream:       #faf7f0;
  --border:      #e0d5c0;
  --text:        #24303c;
  --text-muted:  #6b7785;
  --white:       #ffffff;
  --green:       #1e7a4c;
  --green-bg:    #e7f4ed;
  --red:         #b3261e;
  --red-bg:      #fdecea;
  --amber:       #92610a;
  --amber-bg:    #fdf3e0;
  --radius:      10px;
  --shadow:      0 2px 12px rgba(26, 58, 92, 0.08);
  --shadow-lg:   0 8px 32px rgba(26, 58, 92, 0.16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--cream);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[dir="rtl"] body {
  font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
}

a { color: var(--blue); }

/* ── Auth pages (login / register / setup) ─────────────────────────────────── */
body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 32px 16px;
  background: linear-gradient(160deg, var(--blue) 0%, var(--blue-dark) 100%);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--white);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  text-align: center;
}

.auth-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  margin-bottom: 16px;
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 6px;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.auth-form { text-align: start; }

.field { margin-bottom: 18px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 11px 13px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--blue-light);
  box-shadow: 0 0 0 3px rgba(43, 85, 128, .12);
}

.field textarea { resize: vertical; min-height: 84px; }

.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
}

/* ── Programs picker ─────────────────────────────────────────────────────── */
.program-picker {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
}

.program-picker-loading {
  font-size: 13px;
  color: var(--text-muted);
  padding: 10px 8px;
}

.program-group + .program-group { margin-top: 6px; }

.program-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  padding: 8px 8px 4px;
}

/* Scoped under .program-picker so these beat the `.field label` rule, which is
   more specific than a bare `.program-option` and would otherwise force the
   label back to display:block (killing the flex gap and vertical centering). */
.program-picker .program-option {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 10px 10px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background-color .12s;
}

.program-picker .program-option:hover { background: var(--cream); }

/* Override the full-width .field input rule for the checkboxes. */
.program-picker .program-option input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
  accent-color: var(--blue);
  cursor: pointer;
}

.program-picker .program-option span {
  flex: 1;
  line-height: 1.3;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s, opacity .15s;
}

.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }

.btn-gold { background: var(--gold); color: var(--white); }
.btn-gold:hover:not(:disabled) { background: var(--gold-light); }

.btn-ghost {
  background: transparent;
  color: var(--blue);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--cream); }

.btn-block { width: 100%; }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.auth-footer {
  margin-top: 22px;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-footer a { font-weight: 600; text-decoration: none; }
.auth-footer a:hover { text-decoration: underline; }

/* Messages */
.msg {
  margin-top: 16px;
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  text-align: start;
}
.msg:empty { display: none; }
.msg-error   { background: var(--red-bg);   color: var(--red);   border: 1px solid #f3c9c5; }
.msg-success { background: var(--green-bg); color: var(--green); border: 1px solid #c3e4d2; }
.msg-info    { background: var(--amber-bg); color: var(--amber); border: 1px solid #f0dcb4; }

/* ── Dashboard shell ───────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  height: 64px;
  background: var(--blue);
  color: var(--white);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-logo { width: 38px; height: 38px; object-fit: contain; }

.topbar-brand {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .2px;
}

.topbar-spacer { flex: 1; }

.topbar-user {
  font-size: 14px;
  opacity: .9;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-btn {
  background: rgba(255, 255, 255, .12);
  color: var(--white);
  border: none;
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.topbar-btn:hover { background: rgba(255, 255, 255, .22); }

.layout {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  max-width: 1140px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 88px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.nav-item i { width: 18px; text-align: center; color: var(--text-muted); }
.nav-item:hover { background: var(--cream); }
.nav-item.active { background: var(--blue); color: var(--white); }
.nav-item.active i { color: var(--white); }

.content { flex: 1; min-width: 0; }

.panel { display: none; }
.panel.active { display: block; }

.panel-loading {
  padding: 48px;
  text-align: center;
  color: var(--text-muted);
}

.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.card-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--blue);
  margin: 0 0 4px;
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 18px;
}

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

/* ── Tables ────────────────────────────────────────────────────────────────── */
.data-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-grid th {
  text-align: start;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-grid td {
  padding: 13px 12px;
  border-bottom: 1px solid #eef2f5;
  vertical-align: middle;
}

.data-grid tr:last-child td { border-bottom: none; }

.table-wrap { overflow-x: auto; }

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red   { background: var(--red-bg);   color: var(--red); }
.badge-grey  { background: #eef2f5;         color: var(--text-muted); }

/* ── Grade breakdown (expandable course → quizzes + exam) ───────────────────── */
.grade-row--expandable { cursor: pointer; }
.grade-row--expandable:hover { background: #faf7f0; }
.grade-caret {
  display: inline-block;
  color: var(--gold);
  font-size: 11px;
  transition: transform .15s ease;
}
.grade-row--open .grade-caret { transform: rotate(90deg); }

.grade-detail-row > td {
  background: #faf7f0;
  padding: 6px 12px 14px;
}

.grade-breakdown {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--white, #fff);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.grade-breakdown th {
  text-align: start;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.grade-breakdown td {
  padding: 9px 12px;
  border-bottom: 1px solid #eef2f5;
}
.grade-breakdown tr:last-child td { border-bottom: none; }

.item-tag {
  display: inline-block;
  margin-inline-start: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
  background: #eef2f5;
  color: var(--blue);
  vertical-align: middle;
}
.grade-breakdown .muted { color: var(--text-muted); font-style: italic; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  inset-inline-end: 24px;
  padding: 12px 18px;
  border-radius: var(--radius);
  color: var(--white);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--green); }
.toast-error   { background: var(--red); }

.hidden { display: none !important; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  .layout { flex-direction: column; gap: 16px; padding: 16px; }
  .sidebar {
    width: 100%;
    position: static;
    display: flex;
    gap: 4px;
    overflow-x: auto;
  }
  .nav-item { white-space: nowrap; }
  .topbar { padding: 0 16px; }
  .topbar-brand { font-size: 14px; }
  .auth-card { padding: 32px 24px; }
}

/* ── Program grouping ───────────────────────────────────────────────────────── */
/* A student may study more than one diploma at once, so courses and grades are
   always shown under the program they belong to — never as one flat list. */
.program-group + .program-group { margin-top: 26px; }

.program-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 2px solid var(--gold);
}

.program-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--blue);
}

.program-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.program-chip {
  display: inline-block;
  padding: 3px 11px;
  margin: 2px 0;
  border-radius: 999px;
  background: var(--cream);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
}
.program-chip + .program-chip { margin-inline-start: 6px; }

.pass-mark-note { margin-top: 16px; }

/* ── Enroll in another program ─────────────────────────────────────────────── */
/* The request form sits under any pending requests, so give it air when it
   follows one — otherwise the form reads as part of the table above it. */
.program-group + .enroll-form { margin-top: 26px; }
.enroll-form + .program-group { margin-top: 26px; }

.enroll-form { max-width: 520px; }
.enroll-form .field-hint { margin-top: 10px; }

/* Logical, not left/right: the portal flips to RTL for Arabic. */
.cell-right { text-align: end; white-space: nowrap; }

.data-grid .muted { color: var(--text-muted); font-style: italic; }

/* ── Transcript downloads ───────────────────────────────────────────────────── */
.transcript-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0 16px;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.transcript-divider::before,
.transcript-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.transcript-programs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.transcript-program-btn {
  justify-content: flex-start;
  text-align: start;
  text-decoration: none;
  max-width: 100%;
}

/* ── Exam list cards ────────────────────────────────────────────────────────── */
.exam-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid #eef2f5;
}
.exam-card:last-child { border-bottom: none; }
.exam-card-main { flex: 1; min-width: 0; }

.exam-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 3px;
}

.exam-card-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.exam-card-score {
  margin-top: 6px;
  font-size: 13px;
  color: var(--green);
}

.exam-blocked {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}

/* An exam already running — its clock does not care whether the tab is open */
.exam-card-live {
  background: #fff8e8;
  border-inline-start: 3px solid var(--gold);
  padding-inline-start: 14px;
  border-radius: 8px;
}

/* ── Exam runner ────────────────────────────────────────────────────────────── */
body.exam-page { background: var(--cream); }

.exam-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.exam-clock {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.exam-clock.clock-warning { background: #b8860b; }
.exam-clock.clock-danger {
  background: #c0392b;
  animation: clock-pulse 1s ease-in-out infinite;
}
@keyframes clock-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .65; }
}

.exam-progress { margin-bottom: 20px; }
.exam-progress-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.exam-progress-bar span {
  display: block;
  height: 100%;
  background: var(--gold);
  transition: width .25s ease;
}
.exam-progress-text {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: end;
}

.question {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 26px;
  margin-bottom: 16px;
}

.question-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.question-number { font-weight: 700; color: var(--blue); }
.question-worth {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--cream);
  border: 1px solid var(--border);
}
.save-state { margin-inline-start: auto; font-size: 11px; }
.save-state.saved  { color: var(--green); }
.save-state.saving { color: var(--text-muted); }
.save-state.failed { color: var(--red); font-weight: 600; }

.question-text {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.45;
  margin: 0 0 18px;
}

.choices-hint {
  font-size: 13px;
  font-weight: 600;
  color: var(--gold);
  margin: -6px 0 12px;
}

.choices { display: flex; flex-direction: column; gap: 9px; }

.choice {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 15px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 15px;
  transition: border-color .12s, background .12s;
}
.choice:hover { border-color: var(--blue-light); background: #fafbfc; }
.choice input { accent-color: var(--blue); }
.choice-selected {
  border-color: var(--blue);
  background: #eef3f8;
  font-weight: 600;
}

.exam-nav {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 20px;
}
.exam-nav .btn:only-child { margin-inline-start: auto; }

.question-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 26px;
}
.dot {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.dot:hover { border-color: var(--blue-light); }
.dot-answered { background: #e7f4ed; border-color: #c3e4d2; color: var(--green); }
.dot-current {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
/* A flagged dot keeps its answered/current look and gets an amber corner marker. */
.dot-flagged { position: relative; }
.dot-flagged::after {
  content: '';
  position: absolute;
  top: -3px;
  inset-inline-end: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--amber);
  border: 1.5px solid var(--white);
}

/* ── Flag for review ────────────────────────────────────────────────────────── */
.flag-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .12s, border-color .12s, background-color .12s;
}
.flag-btn:hover { border-color: var(--amber); color: var(--amber); }
.flag-btn.flag-on {
  background: var(--amber-bg);
  border-color: var(--amber);
  color: var(--amber);
}

.question.is-flagged { border-inline-start: 3px solid var(--amber); }

.progress-flagged {
  margin-inline-start: 10px;
  color: var(--amber);
  font-weight: 600;
}

.flag-jump {
  display: flex;
  justify-content: center;
  margin-top: 14px;
}

/* ── Result ─────────────────────────────────────────────────────────────────── */
.result-card { text-align: center; padding: 40px 32px; }

.result-icon { font-size: 46px; margin-bottom: 14px; }
.result-icon-done { color: var(--green); }
.result-icon-time { color: var(--amber); }

.result-score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: 24px auto;
  padding: 22px 28px;
  border-radius: 14px;
  max-width: 360px;
}
.result-pass { background: var(--green-bg); border: 1px solid #c3e4d2; }
.result-fail { background: var(--red-bg);   border: 1px solid #f3c9c5; }

.result-number { font-size: 40px; font-weight: 800; line-height: 1; }
.result-pass .result-number { color: var(--green); }
.result-fail .result-number { color: var(--red); }

.result-verdict { text-align: start; font-weight: 700; }
.result-verdict small {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}
