/*
 * ============================================================
 * Bootstrap 5 Compatibility Layer
 * ============================================================
 * Replaces Bootstrap CDN with ONLY the utility/component classes
 * actually used in this project's templates. Loads AFTER global.css.
 *
 * Once all templates are migrated to the Taibah design system,
 * this file will be removed (Phase 6 cleanup).
 * ============================================================
 */

/* ── DISPLAY ─────────────────────────────────────────────── */
.d-flex            { display: flex !important; }
.d-grid            { display: grid !important; }
.d-none            { display: none !important; }
.d-block           { display: block !important; }
.d-inline          { display: inline !important; }
.d-inline-block    { display: inline-block !important; }

/* ── FLEXBOX ─────────────────────────────────────────────── */
.flex-column        { flex-direction: column !important; }
.flex-wrap          { flex-wrap: wrap !important; }
.flex-grow-1        { flex-grow: 1 !important; }
.flex-fill          { flex: 1 1 auto !important; }
.align-items-center { align-items: center !important; }
.align-items-end    { align-items: flex-end !important; }
.align-items-start  { align-items: flex-start !important; }
.align-middle       { vertical-align: middle !important; }
.justify-content-between { justify-content: space-between !important; }
.justify-content-center  { justify-content: center !important; }
.ms-auto            { margin-inline-start: auto !important; }

/* ── GRID (Bootstrap row/col) ────────────────────────────── */
.container       { width: 100%; max-width: 1140px; margin-inline: auto; padding-inline: 0.75rem; }
.container-fluid { width: 100%; padding-inline: 0.75rem; }

.row {
  display: flex;
  flex-wrap: wrap;
  margin-inline: -0.375rem;
}
.row > * {
  flex-shrink: 0;
  width: 100%;
  padding-inline: 0.375rem;
  box-sizing: border-box;
}

/* col-md (≥768px) */
@media (min-width: 768px) {
  .col-md-1  { flex: 0 0 auto; width: 8.333333%; }
  .col-md-2  { flex: 0 0 auto; width: 16.666667%; }
  .col-md-3  { flex: 0 0 auto; width: 25%; }
  .col-md-4  { flex: 0 0 auto; width: 33.333333%; }
  .col-md-5  { flex: 0 0 auto; width: 41.666667%; }
  .col-md-6  { flex: 0 0 auto; width: 50%; }
  .col-md-7  { flex: 0 0 auto; width: 58.333333%; }
  .col-md-8  { flex: 0 0 auto; width: 66.666667%; }
  .col-md-9  { flex: 0 0 auto; width: 75%; }
  .col-md-10 { flex: 0 0 auto; width: 83.333333%; }
  .col-md-11 { flex: 0 0 auto; width: 91.666667%; }
  .col-md-12 { flex: 0 0 auto; width: 100%; }
}

/* col-lg (≥992px) */
@media (min-width: 992px) {
  .col-lg-4  { flex: 0 0 auto; width: 33.333333%; }
  .col-lg-5  { flex: 0 0 auto; width: 41.666667%; }
  .col-lg-7  { flex: 0 0 auto; width: 58.333333%; }
  .col-lg-8  { flex: 0 0 auto; width: 66.666667%; }
}

/* Grid gaps */
.g-2  { gap: 0.5rem !important; }
.g-3  { gap: 1rem !important; }

/* Bootstrap gutters do not consume extra horizontal width. A literal `gap`
   between two 50% columns makes the second column wrap, which left every
   student KPI row occupying only one side of the screen. Keep the vertical
   rhythm while the row's existing child padding supplies the horizontal
   gutter. */
.row.g-2 { column-gap: 0 !important; row-gap: 0.5rem !important; }
.row.g-3 { column-gap: 0 !important; row-gap: 1rem !important; }
.gap-1 { gap: 0.25rem !important; }
.gap-2 { gap: 0.5rem !important; }
.gap-3 { gap: 1rem !important; }

/* ── SPACING — Margin ────────────────────────────────────── */
.m-0  { margin: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.25rem !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.mt-1 { margin-top: 0.25rem !important; }
.mt-2 { margin-top: 0.5rem !important; }
.mt-3 { margin-top: 1rem !important; }
.mt-4 { margin-top: 1.5rem !important; }
.my-2 { margin-block: 0.5rem !important; }
.ms-2 { margin-inline-start: 0.5rem !important; }
.ms-3 { margin-inline-start: 1rem !important; }
.me-2 { margin-inline-end: 0.5rem !important; }

/* ── SPACING — Padding ───────────────────────────────────── */
.p-0  { padding: 0 !important; }
.p-2  { padding: 0.5rem !important; }
.p-3  { padding: 1rem !important; }
.p-4  { padding: 1.5rem !important; }
.pt-3 { padding-top: 1rem !important; }
.py-0 { padding-block: 0 !important; }
.py-2 { padding-block: 0.5rem !important; }

/* ── DIMENSIONS ──────────────────────────────────────────── */
.w-100 { width: 100% !important; }
.w-auto { width: auto !important; }
.h-100 { height: 100% !important; }

/* ── TYPOGRAPHY ──────────────────────────────────────────── */
.text-center          { text-align: center !important; }
.text-secondary       { color: var(--muted, #64748b) !important; }
.text-success         { color: var(--success, #12a259) !important; }
.text-danger          { color: var(--danger, #e03434) !important; }
.text-decoration-none { text-decoration: none !important; }
.fw-semibold          { font-weight: 600 !important; }
.fw-bold              { font-weight: 700 !important; }
.fs-6                 { font-size: 1rem !important; }
.small, small         { font-size: 0.875em; }

/* ── BACKGROUNDS ────────────────────────────────────────── */
.bg-light          { background-color: var(--glass-bg) !important; }

/* ── BORDERS ─────────────────────────────────────────────── */
.border            { border: 1px solid var(--line, #dde3ed) !important; }
.border-0          { border: 0 !important; }
.border-secondary  { border-color: var(--muted, #64748b) !important; }
.rounded           { border-radius: var(--radius-sm, 7px) !important; }

/* ── BADGES ──────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.25em 0.5em;
  font-size: 0.72em;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  vertical-align: baseline;
  border-radius: var(--radius-sm, 7px);
}
.text-bg-primary   { background-color: var(--brand, #0A8E6E) !important; color: #fff !important; }
.text-bg-secondary { background-color: var(--muted, #6c757d) !important; color: #fff !important; }
.text-bg-success   { background-color: var(--success, #12a259) !important; color: #fff !important; }
.text-bg-danger    { background-color: var(--danger, #e03434) !important; color: #fff !important; }
.text-bg-light     { background-color: var(--glass-bg, #f8f9fa) !important; color: var(--ink, #212529) !important; }

/* ── ALERTS ──────────────────────────────────────────────── */
.alert {
  position: relative;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm, 7px);
}
.alert-danger    { color: #842029; background-color: #f8d7da; border-color: #f5c2c7; }
.alert-info      { color: #055160; background-color: #cff4fc; border-color: #b6effb; }
.alert-warning   { color: #664d03; background-color: #fff3cd; border-color: #ffecb5; }
.alert-secondary { color: #41464b; background-color: #e2e3e5; border-color: #d3d6d8; }
.alert-light     { color: #636464; background-color: #fefefe; border-color: #fdfdfe; }

/* ── FORMS ───────────────────────────────────────────────── */
.form-label {
  display: inline-block;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink, #0d1526);
}

.form-control {
  display: block;
  width: 100%;
  padding: 0.55rem 1rem;
  font-size: 0.88rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--ink, #0d1526);
  background-color: var(--glass-bg-data);
  border: var(--border-mid);
  border-radius: 999px;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  appearance: none;
}
.form-control:focus {
  border-color: var(--brand, #0A8E6E);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(10,142,110,0.1);
  background-color: var(--glass-bg-header);
}
.form-control-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 999px;
}

.form-select {
  display: block;
  width: 100%;
  padding: 0.55rem 2.25rem 0.55rem 1rem;
  font-size: 0.88rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--ink, #0d1526);
  background-color: var(--glass-bg-data);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 14px 10px;
  border: var(--border-mid);
  border-radius: 999px;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  appearance: none;
}
html[dir="rtl"] .form-select {
  background-position: left 0.85rem center;
  padding-block: 0.55rem;
  padding-inline-start: 2.25rem;
  padding-inline-end: 1rem;
}
.form-select:focus {
  border-color: var(--brand, #0A8E6E);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(10,142,110,0.1);
  background-color: var(--glass-bg-header);
}
.form-select-sm {
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
  font-size: 0.8rem;
}

.form-check          { display: flex; align-items: center; gap: 0.4rem; min-height: 1.5rem; }
.form-check-input    { width: 1rem; height: 1rem; margin: 0; border: 1px solid var(--line, #dde3ed); border-radius: 0.25rem; appearance: none; background-color: var(--card); cursor: pointer; }
.form-check-input:checked { background-color: var(--brand, #0A8E6E); border-color: var(--brand, #0A8E6E); background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3e%3c/svg%3e"); background-size: 100%; background-position: center; }
.form-check-label    { cursor: pointer; font-size: 0.88rem; }

/* ── BUTTONS ─────────────────────────────────────────────── */
/* Base btn is defined in global.css — these are supplementary */
.btn-link {
  font-weight: 400;
  color: var(--brand, #0A8E6E);
  text-decoration: underline;
  background: none;
  border: none;
}
.btn-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e") center / 0.75em no-repeat;
  border: 0;
  border-radius: var(--radius-sm, 7px);
  opacity: 0.5;
  cursor: pointer;
}
.btn-close:hover { opacity: 0.75; }

/* ── TABLES ──────────────────────────────────────────────── */
.table {
  width: 100%;
  margin-bottom: 1rem;
  vertical-align: top;
  border-color: var(--line, #dde3ed);
}
.table > :not(caption) > * > * {
  padding: 0.5rem;
  border-bottom-width: 1px;
}
.table-sm > :not(caption) > * > * {
  padding: 0.25rem 0.4rem;
}
.table-bordered > :not(caption) > * > * {
  border-width: 1px;
}
.table-hover > tbody > tr:hover > * {
  background-color: rgba(0,0,0,0.02);
}
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── CARD ────────────────────────────────────────────────── */
/* card is already styled in global.css via .soft-card */
/* Provide minimal fallback for bare .card usage */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  word-wrap: break-word;
  background-color: var(--card, #fff);
  border: 1px solid var(--line, #dde3ed);
  border-radius: var(--radius, 10px);
}

/* Heading utilities used by semantic h2/h3 elements. Without this fallback,
   `.h6` kept the browser's much larger h2 defaults and added a top margin inside
   cards. */
h6,
.h6 {
  margin-top: 0;
  color: var(--t1, #1e1e4a);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
}

/* ── NAV ─────────────────────────────────────────────────── */
.nav {
  display: flex;
  flex-wrap: wrap;
  padding-inline-start: 0;
  margin-bottom: 0;
  list-style: none;
}

/* ── PROGRESS ────────────────────────────────────────────── */
.progress {
  display: flex;
  height: 1rem;
  overflow: hidden;
  font-size: 0.75rem;
  background-color: var(--line, #e9ecef);
  border-radius: var(--radius-sm, 7px);
}
.progress-bar {
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  color: #fff;
  text-align: center;
  white-space: nowrap;
  background-color: var(--brand, #0A8E6E);
  transition: width 0.6s ease;
}

/* ── MODAL (for transition period) ───────────────────────── */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2050;
  display: none;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  outline: 0;
  background: rgba(0,0,0,0.5);
}
.modal.show { display: flex; align-items: flex-start; justify-content: center; padding-top: 3rem; }
.modal-dialog { position: relative; width: auto; max-width: 500px; margin: 0.5rem; }
.modal-dialog-scrollable .modal-body { overflow-y: auto; max-height: 60vh; }
.modal-lg { max-width: 800px; }
.modal-content {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  background-color: var(--card, #fff);
  border: 1px solid var(--line, #dde3ed);
  border-radius: var(--radius, 10px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--line, #dde3ed);
}
.modal-title { margin: 0; font-weight: 600; font-size: 1.05rem; }
.modal-body { position: relative; flex: 1 1 auto; padding: 1rem; }
.fade { opacity: 0; transition: opacity 0.15s linear; }
.fade.show { opacity: 1; }

/* ── OVERFLOW ────────────────────────────────────────────── */
.overflow-auto { overflow: auto !important; }
.overflow-hidden { overflow: hidden !important; }

/* ── VISIBILITY ──────────────────────────────────────────── */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0,0,0,0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ── HR ──────────────────────────────────────────────────── */
hr {
  margin: 1rem 0;
  color: inherit;
  border: 0;
  border-top: 1px solid var(--line, #dde3ed);
  opacity: 0.25;
}

/* ═══════════════════════════════════════════════════════
   DARK MODE OVERRIDES  (Deep Navy theme)
   ═══════════════════════════════════════════════════════ */

/* ── Backgrounds ─────────────────────────────────────── */
html[data-theme="dark"] .bg-light { background-color: rgba(255,255,255,0.04) !important; }

/* ── Badges ──────────────────────────────────────────── */
html[data-theme="dark"] .text-bg-light {
  background-color: rgba(255,255,255,0.06) !important;
  color: #c0c4d4 !important;
}

/* ── Alerts ──────────────────────────────────────────── */
html[data-theme="dark"] .alert-danger {
  color: #f8a0a8;
  background-color: rgba(220,53,69,0.12);
  border-color: rgba(220,53,69,0.2);
}
html[data-theme="dark"] .alert-info {
  color: #7ed4e6;
  background-color: rgba(13,202,240,0.1);
  border-color: rgba(13,202,240,0.18);
}
html[data-theme="dark"] .alert-warning {
  color: #f5cf6e;
  background-color: rgba(255,193,7,0.1);
  border-color: rgba(255,193,7,0.18);
}
html[data-theme="dark"] .alert-secondary {
  color: #c0c4d4;
  background-color: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.08);
}
html[data-theme="dark"] .alert-light {
  color: #c0c4d4;
  background-color: rgba(255,255,255,0.03);
  border-color: rgba(255,255,255,0.06);
}

/* ── Forms ────────────────────────────────────────────── */
html[data-theme="dark"] .form-control {
  background-color: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.08);
  color: #e2e4ec;
}
html[data-theme="dark"] .form-control:focus {
  background-color: rgba(255,255,255,0.08);
  border-color: var(--brand, #0A8E6E);
}
html[data-theme="dark"] .form-control::placeholder {
  color: #505468;
}

html[data-theme="dark"] .form-select {
  background-color: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.08);
  color: #e2e4ec;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23a0a4b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
html[data-theme="dark"] .form-select:focus {
  background-color: rgba(255,255,255,0.08);
  border-color: var(--brand, #0A8E6E);
}
html[data-theme="dark"] .form-select option {
  background: #151826;
  color: #e2e4ec;
}

html[data-theme="dark"] .form-check-input {
  background-color: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.15);
}

/* ── Buttons ─────────────────────────────────────────── */
html[data-theme="dark"] .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}

/* ── Tables ──────────────────────────────────────────── */
html[data-theme="dark"] .table-hover > tbody > tr:hover > * {
  background-color: rgba(255,255,255,0.03);
}

/* ── Progress ────────────────────────────────────────── */
html[data-theme="dark"] .progress {
  background-color: rgba(255,255,255,0.06);
}

/* ── Modal ────────────────────────────────────────────── */
html[data-theme="dark"] .modal {
  background: rgba(0,0,0,0.7);
}
html[data-theme="dark"] .modal-content {
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
