/* ─────────────────────────────────────────────────────────────────────
   SchoolOS brand stylesheet — overrides on top of Bootstrap 5 + AdminLTE 4.
   Copied from nhqa_frontend; token names kept (imperial = primary,
   pumpkin = accent) so the shared UI library works unchanged, values
   re-pointed to the OSARTech / SchoolOS logo palette.
   ───────────────────────────────────────────────────────────────────── */

:root {
  /* Brand colours */
  --brand-imperial:       #0b1f4b;
  --brand-imperial-dark:  #07153a;
  --brand-imperial-light: #1b3a7a;
  --brand-pumpkin:        #1e7bef;
  --brand-pumpkin-dark:   #1560c9;
  --brand-sky:            #29a3ff;
  --brand-sky-tint:       #dcecff;
  --brand-gold:           #f5a60a;   /* tassel gold — small highlights only */
  --brand-white:          #f7f9fc;

  /* Neutrals */
  --brand-text:           #212529;
  --brand-muted:          #6c757d;
  --brand-border:         #e2e8f0;
  --brand-surface:        #ffffff;
  --brand-surface-alt:    #f5f7fb;

  /* Bootstrap 5 overrides */
  --bs-primary:           var(--brand-imperial);
  --bs-primary-rgb:       11, 31, 75;
  --bs-link-color:        var(--brand-imperial);
  --bs-link-color-rgb:    11, 31, 75;
  --bs-link-hover-color:  var(--brand-pumpkin);
  --bs-body-bg:           var(--brand-white);
  --bs-body-color:        var(--brand-text);
}

/* ── Typography ────────────────────────────────────────────────────── */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--brand-white);
  color: var(--brand-text);
}

/* ── AdminLTE 4 sidebar — imperial-blue brand ─────────────────────── */
.app-sidebar {
  --lte-sidebar-bg:                  var(--brand-imperial);
  --lte-sidebar-color:               rgba(255, 255, 255, .82);
  --lte-sidebar-header-color:        rgba(255, 255, 255, .45);
  --lte-sidebar-hover-bg:            rgba(255, 255, 255, .06);
  --lte-sidebar-hover-color:         #ffffff;
  --lte-sidebar-active-color:        #ffffff;
  --lte-sidebar-menu-active-bg:      rgba(30, 123, 239, .18);
  --lte-sidebar-menu-active-color:   #ffffff;
  --lte-sidebar-submenu-bg:          rgba(0, 0, 0, .12);
  --lte-sidebar-submenu-color:       rgba(255, 255, 255, .7);
  --lte-sidebar-submenu-hover-bg:    rgba(255, 255, 255, .06);
  --lte-sidebar-submenu-hover-color: #ffffff;
  --lte-sidebar-submenu-active-bg:   rgba(30, 123, 239, .25);
  --lte-sidebar-submenu-active-color:#ffffff;
  background-color: var(--brand-imperial) !important;
  color: var(--lte-sidebar-color);
  border-right: 0;
  /* Provide a positioning context so the persona-foot can sit absolutely
     anchored to the bottom without disturbing AdminLTE's own sidebar
     layout (which expects sidebar-wrapper to drive its own scroll). */
  position: relative;
}
.app-sidebar .sidebar-wrapper {
  /* Reserve space for the persona-foot so the last menu item never sits
     beneath it (the foot is absolutely positioned over the sidebar). */
  padding-bottom: 64px;
}
.app-sidebar .sidebar-brand {
  /* No darker overlay — let the brand area share the same imperial
     surface as the rest of the sidebar so the logo blends in cleanly
     instead of sitting inside a visible "box". A faint underline still
     separates brand from nav items. */
  background: transparent;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  padding: 16px 18px;
}
.app-sidebar .brand-link {
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-size: 1.15rem;
  letter-spacing: .5px;
}
.app-sidebar .brand-link:hover { color: var(--brand-pumpkin); }
/* AdminLTE colours .brand-text itself, which beat the white above and left
   "SchoolOS" navy-on-navy. Inherit from the link instead. */
.app-sidebar .brand-link .brand-text { color: inherit; }
/* Logo blends naturally onto the sidebar — no white pill, no padding,
   no rounded background. Requires the uploaded logo PNG to have a
   transparent background (which the NH brand mark does). */
.app-sidebar .brand-image {
  max-height: 42px;
  max-width: 100%;
  background: transparent;
  padding: 0;
  border-radius: 0;
}
.app-sidebar .brand-image-placeholder {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--brand-pumpkin);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.1rem;
}
.app-sidebar .nav-header {
  padding: 14px 16px 6px;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--lte-sidebar-header-color);
}
.app-sidebar .nav-link {
  color: var(--lte-sidebar-color);
  display: flex; align-items: center; gap: 10px;
  border-left: 3px solid transparent;
  border-radius: 0;
  padding: 10px 16px;
  transition: background .15s;
}
.app-sidebar .nav-link:hover {
  background: var(--lte-sidebar-hover-bg);
  color: var(--lte-sidebar-hover-color);
}
.app-sidebar .nav-link.active {
  background: var(--lte-sidebar-menu-active-bg);
  color: var(--lte-sidebar-menu-active-color);
  border-left-color: var(--brand-pumpkin);
  font-weight: 500;
}
.app-sidebar .nav-icon { font-size: 1.05rem; width: 20px; text-align: center; }
.app-sidebar .nav-link p { margin: 0; }

/* ── Student-name convention ─────────────────────────────────────────
   Counsellor / Finance / Admin surfaces display student names in
   uppercase so they read like a registry entry. Apply via .student-name
   on a wrapping element (typically the existing <strong>) so the
   convention can be flipped in one place if policy changes. */
.student-name { text-transform: uppercase; letter-spacing: .3px; }

/* Persona foot — absolutely pinned to the bottom of the sidebar so it
   never disturbs the AdminLTE sidebar-wrapper layout above. The wrapper
   reserves padding-bottom so the last menu item never sits under it.
   Smaller font, muted colour and a subtle dark overlay so it identifies
   the signed-in role without competing with the menu items above. */
.app-sidebar .sidebar-persona-foot {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 12px;
  /* Opaque (the same dark tint laid over the sidebar colour): menu items scroll beneath it
     and must not show through. */
  background: linear-gradient(rgba(0, 0, 0, .25), rgba(0, 0, 0, .25)), var(--brand-imperial);
  border-top: 1px solid rgba(255, 255, 255, .08);
  color: rgba(255, 255, 255, .82);
  font-size: .7rem;
  line-height: 1.25;
  letter-spacing: .2px;
  z-index: 2;
}
.app-sidebar .sidebar-persona-foot .persona-icon {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: rgba(30, 123, 239, .22);         /* pumpkin tint to echo the active-menu accent */
  color: var(--brand-pumpkin);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .82rem;
  flex: 0 0 auto;
}
.app-sidebar .sidebar-persona-foot .persona-meta {
  min-width: 0;                                /* allow text-overflow */
  flex: 1 1 auto;
}
.app-sidebar .sidebar-persona-foot .persona-title {
  color: #ffffff;
  font-weight: 600;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-sidebar .sidebar-persona-foot .persona-scope {
  color: rgba(255, 255, 255, .55);
  font-size: .66rem;
  font-style: italic;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── AdminLTE 4 header (topbar) ───────────────────────────────────── */
.app-header.navbar {
  background: #fff !important;
  border-bottom: 1px solid var(--brand-border);
  padding: 8px 0;
}
.app-page-title {
  font-size: 1.15rem; font-weight: 600;
  color: var(--brand-imperial);
  margin: 0;
}
.role-chip {
  background: var(--brand-sky-tint);
  color: var(--brand-imperial);
  font-size: .72rem; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .5px;
}
.app-header .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-imperial); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: .85rem;
}
.app-header .nav-link {
  color: var(--brand-text);
}
.app-header .dropdown-toggle::after { display: none; } /* avatar caret looks cleaner without */

/* ── AdminLTE 4 main / content / content-header ───────────────────── */
.app-content-header {
  padding: 12px 0 0;
}
.app-content {
  padding: 16px 0 24px;
}

/* ── AdminLTE 4 footer ────────────────────────────────────────────── */
.app-footer {
  background: #fff;
  border-top: 1px solid var(--brand-border);
  padding: 12px 24px;
  font-size: .9rem;
}
.app-footer .text-brand { color: var(--brand-imperial) !important; font-weight: 700; }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn-brand        { background: var(--brand-imperial); border-color: var(--brand-imperial); color: #fff; }
.btn-brand:hover,
.btn-brand:focus  { background: var(--brand-imperial-dark); border-color: var(--brand-imperial-dark); color: #fff; }
.btn-accent       { background: var(--brand-pumpkin); border-color: var(--brand-pumpkin); color: #fff; }
.btn-accent:hover,
.btn-accent:focus { background: var(--brand-pumpkin-dark); border-color: var(--brand-pumpkin-dark); color: #fff; }
.btn-outline-brand        { color: var(--brand-imperial); border-color: var(--brand-imperial); }
.btn-outline-brand:hover  { background: var(--brand-imperial); color: #fff; }

/* ── Utilities ────────────────────────────────────────────────────── */
.text-brand     { color: var(--brand-imperial) !important; }
.text-accent    { color: var(--brand-pumpkin)  !important; }
.text-info-brand{ color: var(--brand-sky)      !important; }
.bg-brand       { background: var(--brand-imperial); color: #fff; }
.bg-mist        { background: var(--brand-sky-tint); }
.border-brand   { border-color: var(--brand-imperial) !important; }

/* ── KPI / dashboard cards (QA dashboard hero numbers) ────────────── */
.kpi-card {
  background: #fff; border: 1px solid var(--brand-border); border-radius: 10px;
  padding: 18px; height: 100%;
}
.kpi-card .kpi-label { color: var(--brand-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; }
.kpi-card .kpi-value { color: var(--brand-pumpkin); font-size: 2rem; font-weight: 700; line-height: 1.1; margin-top: 4px; }
.kpi-card .kpi-sub   { color: var(--brand-muted); font-size: .85rem; margin-top: 4px; }

/* ── Cards & forms (generic polish) ───────────────────────────────── */
.card                  { border: 1px solid var(--brand-border); }
.card-header           { background: var(--brand-surface-alt); border-bottom: 1px solid var(--brand-border); }
.card-header strong    { color: var(--brand-imperial); }

/* ── 2026-06-28 — Global card-content safety rules ─────────────────
 * Stops text from spilling outside cards (KPI tiles, dashboard
 * stats, badges, etc.) by giving every card body + table-cell a
 * sensible default min-width and overflow-wrap behaviour.
 *
 * Why each rule:
 *  - .card { min-width:0 } lets flex/grid children shrink instead
 *    of forcing the card to widen with their text.
 *  - .card-body word-wrap covers long URLs and unbroken emails.
 *  - .text-truncate-2 / -3 are reusable line-clamps for descriptive
 *    text that should stay within one card height (e.g. course
 *    descriptions on a tile).
 *  - .stat-card sizing keeps tile values readable while the label
 *    truncates with an ellipsis if the persona name is long.
 *  - Table cells inside cards never exceed the card; long strings
 *    wrap or ellipsis based on `.text-truncate` opt-in.
 */
.card,
.card-body,
.card-header { min-width: 0; }
/* 2026-09-16 — Retired the blanket `overflow-wrap: anywhere` +
 * `word-break: break-word` on card bodies and table cells. Combined
 * with narrow columns on mobile it forced character-by-character
 * wrapping ("CE NT RE S"). Tables now use ui_table() (Tabulator with
 * responsiveLayout: 'collapse') which hides low-priority columns
 * into an expandable row drawer instead of squishing text. */
.card-header .badge { vertical-align: middle; }
.card .table              { table-layout: auto; }
.card .table td,
.card .table th           { vertical-align: middle; }
.card .table td.text-truncate,
.card .table th.text-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0; }
/* Compact KPI tile — used by the rich dashboards. */
.stat-card                { border-left: 4px solid var(--brand-pumpkin, #1e7bef); transition: transform .12s ease; }
.stat-card:hover          { transform: translateY(-1px); }
.stat-card .stat-value    { font-size: 1.5rem; font-weight: 700; line-height: 1.1; word-break: break-word; }
.stat-card .stat-label    { font-size: .78rem; color: #6c757d; text-transform: uppercase; letter-spacing: .35px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-card .stat-icon-wrap{ width: 38px; height: 38px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
/* Line-clamp helpers for descriptive cells. */
.text-clamp-1, .text-clamp-2, .text-clamp-3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.text-clamp-1 { -webkit-line-clamp: 1; line-clamp: 1; }
.text-clamp-2 { -webkit-line-clamp: 2; line-clamp: 2; }
.text-clamp-3 { -webkit-line-clamp: 3; line-clamp: 3; }
/* Section heading + sub-text combo used on dashboards. */
.dash-section-h           { font-size: .82rem; text-transform: uppercase; letter-spacing: .6px; color: #6c757d; font-weight: 600; }
.dash-empty               { padding: 2rem 1rem; text-align: center; color: #6c757d; font-size: .9rem; }
.dash-empty .bi           { font-size: 1.6rem; display: block; margin-bottom: .35rem; opacity: .7; }
/* Tighter chart canvas defaults. */
.dash-chart               { width: 100%; height: 220px; }
.dash-chart-sm            { width: 100%; height: 130px; }
.form-label.fw-semibold{ color: var(--brand-imperial); }
.form-control:focus,
.form-select:focus     { border-color: var(--brand-imperial-light); box-shadow: 0 0 0 .2rem rgba(11,31,75,.15); }

/* ── DataTables / Select2 polish ──────────────────────────────────── */
table.dataTable thead th { background: var(--brand-surface-alt); color: var(--brand-imperial); border-bottom: 2px solid var(--brand-border); }
.select2-container--bootstrap-5 .select2-selection { border-color: var(--brand-border); }
.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered { color: var(--brand-text); }

/* ── Logo upload preview (SuperAdmin Settings) ────────────────────── */
.company-logo-preview {
  border: 2px dashed var(--brand-border); border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-surface-alt); padding: 16px;
}
.company-logo-preview.has-logo { border-style: solid; background: #fff; }

/* ── Phase 4: Materials viewer + DRM watermark ────────────────────── */

/* Lesson type icons */
.lesson-type-icon {
  width: 32px; height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-imperial); color: #fff; font-size: 1rem;
  flex-shrink: 0;
}
.lesson-type-icon.type-pdf    { background: #d9534f; }
.lesson-type-icon.type-video  { background: var(--brand-imperial); }
.lesson-type-icon.type-slides { background: var(--brand-pumpkin); }
.lesson-type-icon.type-text   { background: var(--brand-sky); color: #0b1f4b; }

/* Lesson list rows on /client/materials */
.lesson-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: 8px;
  background: #fff; border: 1px solid var(--brand-border);
  text-decoration: none; color: var(--brand-text); transition: background .12s;
}
.lesson-row:hover { background: var(--brand-surface-alt); color: var(--brand-text); }
.lesson-row.locked {
  opacity: .6; cursor: not-allowed; pointer-events: none;
  background: var(--brand-surface-alt);
}
.lesson-row .lesson-meta { flex: 1; min-width: 0; }
.lesson-row .lesson-title { font-weight: 600; color: var(--brand-imperial); }
.lesson-row .lesson-sub   { color: var(--brand-muted); font-size: .85rem; margin-top: 2px; }

.locked-module-card {
  border: 2px dashed var(--brand-border); background: var(--brand-surface-alt);
  border-radius: 10px; padding: 24px; text-align: center;
}
.locked-module-card .lock-icon {
  font-size: 2.5rem; color: var(--brand-pumpkin); display: block; margin-bottom: 8px;
}

/* ── DRM viewer page (full-screen with watermark) ─────────────────── */
.viewer-shell {
  position: relative; min-height: 100vh; background: #061233;
  color: #fff; overflow: hidden;
}
.viewer-shell .viewer-topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(6, 18, 51, .96); backdrop-filter: blur(6px);
  padding: 10px 16px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.viewer-shell .viewer-topbar .v-title { color: #fff; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-shell .viewer-topbar .v-meta  { color: rgba(255,255,255,.55); font-size: .8rem; }
.viewer-shell .viewer-content {
  position: relative; padding: 24px 16px; max-width: 1100px; margin: 0 auto;
}
.viewer-shell .pdf-pages canvas {
  display: block; margin: 0 auto 14px; background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,.5);
  max-width: 100%; height: auto;
}
.viewer-shell .markdown-body {
  background: #fff; color: var(--brand-text);
  border-radius: 8px; padding: 32px; line-height: 1.6;
  box-shadow: 0 2px 12px rgba(0,0,0,.5);
}
.viewer-shell .markdown-body h1 { color: var(--brand-imperial); margin-top: 0; }
.viewer-shell .markdown-body h2,
.viewer-shell .markdown-body h3 { color: var(--brand-imperial); }
.viewer-shell .markdown-body code {
  background: var(--brand-surface-alt); color: var(--brand-pumpkin-dark);
  padding: 2px 5px; border-radius: 3px; font-size: .92em;
}
.viewer-shell .markdown-body pre {
  background: #f1f5f9; padding: 14px; border-radius: 6px; overflow-x: auto;
}
.viewer-shell video {
  display: block; max-width: 100%; margin: 0 auto; border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,.5);
}

/* Watermark overlay — diagonal grid behind the content.
 * Tuned to be visible-on-inspection but unobtrusive while reading:
 *   3×4 grid (12 cells, fewer than before so spacing is wider)
 *   ~6% opacity (down from 14%) — readable text wins, watermark recedes
 *   400 weight (was 500) — thinner strokes
 *   no text-shadow (was making letters thicker against the dark viewer bg)
 */
/* Watermark v2 — varied per-cell rotation + mix-blend-mode so the
 * text stays legible on EVERY background (dark PDF viewer chrome AND
 * white PDF page surfaces). The varied angles make the watermark
 * harder to crop or OCR-erase. */
.viewer-watermark {
  position: fixed; inset: 0; pointer-events: none; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(5, 1fr);
  font-family: 'Inter', sans-serif; font-size: 12px; font-weight: 600;
  color: rgba(110, 110, 130, .18);
  mix-blend-mode: multiply;
  user-select: none; letter-spacing: .4px;
}
/* Dense variant (6×5 = 30 cells) used by the server-randomized
 * watermark. Each cell sets its own rotation+opacity inline so
 * the .viewer-watermark span nth-child rules below don't apply. */
.viewer-watermark--dense {
  grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(5, 1fr);
  font-size: 11px;
}
.viewer-watermark--dense span { transform: none; }
.viewer-watermark span {
  display: flex; align-items: center; justify-content: center;
  white-space: nowrap;
}
/* 20 cells (4×5) — each picks a distinct rotation so the diagonal
 * pattern doesn't repeat. nth-child(20n) cycles for safety on browsers
 * that render a few extra grid items. */
.viewer-watermark span:nth-child(20n+1)  { transform: rotate(-32deg); }
.viewer-watermark span:nth-child(20n+2)  { transform: rotate(  18deg); }
.viewer-watermark span:nth-child(20n+3)  { transform: rotate( -12deg); }
.viewer-watermark span:nth-child(20n+4)  { transform: rotate(  42deg); }
.viewer-watermark span:nth-child(20n+5)  { transform: rotate( -25deg); }
.viewer-watermark span:nth-child(20n+6)  { transform: rotate(  35deg); }
.viewer-watermark span:nth-child(20n+7)  { transform: rotate( -45deg); }
.viewer-watermark span:nth-child(20n+8)  { transform: rotate(   8deg); }
.viewer-watermark span:nth-child(20n+9)  { transform: rotate( -20deg); }
.viewer-watermark span:nth-child(20n+10) { transform: rotate(  28deg); }
.viewer-watermark span:nth-child(20n+11) { transform: rotate( -38deg); }
.viewer-watermark span:nth-child(20n+12) { transform: rotate(  15deg); }
.viewer-watermark span:nth-child(20n+13) { transform: rotate( -8deg); }
.viewer-watermark span:nth-child(20n+14) { transform: rotate(  48deg); }
.viewer-watermark span:nth-child(20n+15) { transform: rotate( -29deg); }
.viewer-watermark span:nth-child(20n+16) { transform: rotate(  22deg); }
.viewer-watermark span:nth-child(20n+17) { transform: rotate( -15deg); }
.viewer-watermark span:nth-child(20n+18) { transform: rotate(  39deg); }
.viewer-watermark span:nth-child(20n+19) { transform: rotate( -42deg); }
.viewer-watermark span:nth-child(20n+20) { transform: rotate(  11deg); }
/* On the white markdown / PDF backgrounds the white text would disappear
 * entirely — switch to dark-on-light where the underlying content is light. */
.viewer-shell .markdown-body { position: relative; }
.viewer-shell .pdf-pages canvas,
.viewer-shell .markdown-body { /* let the watermark layer above any white content */ }

/* Print-blocking for a protected document viewer only (it used to hide body, so every Print came out blank). */
@media print {
  .viewer-shell { display: none !important; }
}

/* No-context-menu feedback (optional visual hint) */
.viewer-shell, .viewer-shell * { -webkit-user-drag: none; }

/* ─────────────────────────────────────────────────────────────
 * 2026-07-03 — Mobile-safety pass.
 *
 * Priorities:
 *   1) Cards never let text spill outside their rounded box.
 *   2) KPI values shrink instead of pushing the card wider.
 *   3) Stat labels wrap onto two lines instead of ellipsis on tiny
 *      screens (a truncated label reads worse than a wrapped one).
 *   4) Any <table> inside a card is horizontally scrollable if it
 *      would otherwise overflow (belt-and-braces for pages that
 *      forgot the .table-responsive wrapper).
 *   5) Card headers can wrap: strong + badge + count + action button
 *      all sit on the same row on desktop, stack cleanly on mobile.
 *   6) Buttons + button groups on card headers wrap instead of
 *      pushing the h6 title off the row.
 * ───────────────────────────────────────────────────────────── */

/* KPI value: fluid font-size + wrap fallback so ₦1,000,000 or
 * long emails fit inside a 45vw card at 360px viewport. */
.stat-card .stat-value {
  font-size: clamp(1.1rem, 3.6vw, 1.5rem);
  line-height: 1.15;
  overflow-wrap: anywhere;
  word-break: break-word;
}
/* Stat labels: prefer wrap over truncation on small screens.
 * On desktop they can still be truncated if a persona name gets long. */
.stat-card .stat-label {
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  min-height: 1.6em;                  /* keep tile heights aligned */
}
/* Any table inside a card gets a horizontal scrollbar rescue. Kept
 * off .table-responsive elements so the double-scroll doesn't appear. */
.card > .table:not(.table-responsive),
.card > .card-body > .table:not(.table-responsive) {
  display: block;
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}
/* Card headers on mobile: let strong + badges + buttons wrap. */
.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem;
  row-gap: .35rem;
}
.card-header > strong,
.card-header > .fw-semibold {
  min-width: 0;
  flex: 1 1 auto;
}
.card-header .btn,
.card-header .btn-sm,
.card-header .badge {
  flex: 0 0 auto;
}

/* Badges: allow wrap if very long, but on WORD boundaries only —
 * never per-character (which produced the "AC TI VE" bug). */
.badge {
  white-space: normal;
  overflow-wrap: break-word;
}

/* Compact stat-strip tile: shrink icon on mobile. */
@media (max-width: 575.98px) {
  .stat-card .stat-icon-wrap { width: 32px; height: 32px; }
  .stat-card .stat-value     { font-size: clamp(1rem, 5.5vw, 1.35rem); }
  .stat-card                 { padding: .5rem .75rem; }
  h1, .h1 { font-size: 1.5rem; }
  h2, .h2 { font-size: 1.3rem; }
  h3, .h3 { font-size: 1.15rem; }
  h4, .h4 { font-size: 1.05rem; }
  h5, .h5 { font-size: 1rem; }
  h6, .h6 { font-size: .95rem; }
}

/* Datatables often force wide layouts — ensure their wrapper
 * scrolls instead of blowing out the page on mobile. */
.dataTables_wrapper,
.dataTables_scroll,
.dataTables_scrollBody {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Long emails, tokens, and codes inside table cells: force wrap
 * (word-break: break-word already applied at .card .table td, but
 * a bare table outside a card wouldn't get it — add here too). */
.table td, .table th {
  overflow-wrap: anywhere;
}

/* Prevent buttons inside card-body from pushing the card wider than
 * its parent col (long "Open Full Asset Page" style labels wrap). */
.card-body .btn,
.card-body .btn-sm {
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
}

/* Nav tabs on Auditor / drill pages: allow horizontal scroll on
 * very narrow screens instead of squishing labels illegibly. */
.nav-tabs {
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.nav-tabs .nav-link { white-space: nowrap; }

/* Modal on mobile: fill viewport with a small side gutter. */
@media (max-width: 575.98px) {
  .modal-dialog { margin: .5rem; }
  .modal-body   { padding: .75rem; }
  .modal-footer { flex-wrap: wrap; }
}

/* App-content on mobile: less horizontal padding so cards get the
 * full width and their KPI grids don't get squeezed. */
@media (max-width: 575.98px) {
  .app-content .container-fluid { padding-left: .5rem; padding-right: .5rem; }
  .card-body { padding: .75rem; }
}

/* ─────────────────────────────────────────────────────────────
 * 2026-07-04 — Anchor-wrapped card fix.
 *
 * Common pattern in the codebase:
 *   <div class="col-md-4">
 *     <a class="text-decoration-none text-reset" href="...">
 *       <div class="card ...">…</div>
 *     </a>
 *   </div>
 *
 * By default <a> is inline. Its child .card then intrinsic-sizes to
 * its content instead of filling the col. `.text-truncate` inside
 * the card can't clamp against a defined width, so long names bleed
 * past the card boundary (Centre folders / cohort cards / student
 * lists / etc). Force the anchor to fill its grid cell and pin its
 * `min-width: 0` so nested flex items shrink correctly.
 * ───────────────────────────────────────────────────────────── */
[class*="col-"] > a,
[class*="col-"] > a.text-decoration-none,
.col > a,
.col > a.text-decoration-none {
  display: block;
  width: 100%;
  min-width: 0;
}
[class*="col-"] > a > .card,
.col > a > .card {
  width: 100%;
  max-width: 100%;
}

/* Universal card overflow safety. Even when no anchor wraps the card
 * (e.g. dashboard-alerts partial uses bare .col with .row-cols-*), any
 * descendant that tries to exceed the col width clips at the card edge
 * rather than bleeding past. Pair with .text-truncate + min-width:0 on
 * the flex chain below so the ellipsis actually shows. */
.card { overflow: hidden; }

/* Every .d-flex directly inside a card-body must span the full body
 * width AND allow its children to shrink. Without min-width:0 the flex
 * algorithm treats each flex item's min as `auto` (= content), and a
 * long label pushes the whole flex row past the card border. */
.card-body > .d-flex,
.card-body .d-flex {
  width: 100%;
  min-width: 0;
}

/* ── 2026-07-15 — Alert / KPI card readability ───────────────────
 * Used by inc/dashboard_alerts.php and can be applied to any
 * new KPI card that pairs a label + big number + detail line.
 * Labels can wrap onto two lines (no more "Students at atten…"
 * ellipsis) while the card heights stay aligned across the row
 * thanks to the fixed min-heights on the label + detail slots. */
.alert-card                    { border-left-width: 4px; }
.alert-card-label {
  white-space: normal;
  line-height: 1.25;
  font-weight: 500;
  min-height: 2.5em;                         /* room for 2 lines */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: #4a4a55;
  margin-bottom: 2px;
}
.alert-card-count              { font-weight: 700; line-height: 1.1; }
.alert-card-detail {
  white-space: normal;
  line-height: 1.2;
  min-height: 1.4em;                         /* single line, but keeps alignment */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 2px;
}

/* Every .text-truncate inside a card gets a hard upper bound so the
 * ellipsis actually renders (Bootstrap's utility relies on the
 * parent constraining width — this makes sure it does). */
.card .text-truncate,
.card-body .text-truncate {
  max-width: 100%;
  min-width: 0;
}

/* Flex-item shrink safety: every .flex-grow-1 inside a card gets
 * `min-width: 0` so its children (typically <div class="text-truncate">)
 * can actually truncate. Without this, the flex algorithm honours the
 * intrinsic content width and shoves the truncate parent past the card. */
.card .flex-grow-1,
.card-body .flex-grow-1 {
  min-width: 0;
}

/* Bootstrap's `.row-cols-*` grids: force each generated col to have
 * min-width:0 (Bootstrap sets flex-basis by percentage but doesn't
 * clamp min-width, so a wide child can still push the col wider). */
[class*="row-cols-"] > .col,
[class*="row-cols-"] > [class*="col-"] {
  min-width: 0;
}

/* Row itself: prevent horizontal overflow when a stray content item
 * exceeds its column. The container clips instead of the whole card
 * blowing out. */
.card-body > .row { min-width: 0; }

/* ══════════════════════════════════════════════════════════════════════
 * MOBILE-FIRST OVERRIDES — 2026-08-07
 * Sweeping fixes for the "not mobile-friendly" regression: modals go
 * fullscreen on phones, DataTables scrollX gets a light coat of paint,
 * KPI strips wrap instead of overflowing, buttons wrap, and the app
 * sidebar becomes an off-canvas drawer under 992px.
 * ══════════════════════════════════════════════════════════════════════ */

/* Every modal-dialog behaves like Bootstrap's modal-fullscreen-sm-down
 * on phones — no more thin narrow cards floating over a dim overlay. */
@media (max-width: 575.98px) {
  .modal-dialog {
    width: 100%;
    max-width: none;
    height: 100%;
    margin: 0;
  }
  .modal-content {
    height: 100%;
    border: 0;
    border-radius: 0;
  }
  .modal-body {
    overflow-y: auto;
  }
}

/* DataTables toolbar (Show N + Search) stacks cleanly on mobile
 * instead of squishing the search box into a sliver. */
@media (max-width: 767.98px) {
  .dataTables_wrapper .row {
    flex-direction: column;
  }
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter {
    text-align: left !important;
    margin-bottom: .5rem;
  }
  .dataTables_wrapper .dataTables_filter input {
    width: 100%;
  }
}

/* The real fix for wide tables on mobile: force a min-width so
 * Bootstrap's `.table { width: 100% }` can't shrink the table to
 * viewport width and crush every column vertically. The parent
 * `.table-responsive` wrapper then has something wider than itself
 * to scroll over, which is exactly its whole point. Same rule
 * covers every DataTables-generated `.dataTable` class too. */
@media (max-width: 991.98px) {
  .table-responsive > table.datatable,
  .table-responsive > table.dataTable,
  .dataTables_wrapper table.dataTable {
    min-width: 720px !important;
  }
}

/* Any table that missed the .table-responsive wrapper still shouldn't
 * blow the page horizontally — clip inside its card body instead. */
@media (max-width: 767.98px) {
  .card-body > table:not(.no-scroll),
  .card > table:not(.no-scroll) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
}

/* KPI tile strips (row-cols-2 row-cols-md-4 etc.) already wrap by
 * grid rules, but the numeric value (h5) can overflow on narrow
 * screens — cap it and add ellipsis. */
@media (max-width: 575.98px) {
  .card .h5, .card .h4, .card .h3 {
    font-size: 1rem;
    line-height: 1.2;
  }
  .card-body .text-truncate {
    max-width: 100%;
  }
}

/* Button rows: ".d-flex gap-2" of pill actions must wrap on mobile
 * instead of getting horizontally clipped. */
@media (max-width: 575.98px) {
  .card .d-flex.gap-2,
  .card .d-flex.gap-3 {
    flex-wrap: wrap;
  }
  .btn-group-sm > .btn,
  .btn-toolbar .btn {
    margin-bottom: .25rem;
  }
}

/* Forms: labels + inputs stack, help text gets breathing room. */
@media (max-width: 575.98px) {
  .form-label {
    margin-bottom: .25rem;
  }
  .row.g-3 > [class*="col-"] {
    margin-bottom: .5rem;
  }
}

/* Nav-tabs (Ongoing / Upcoming / All etc.) — allow horizontal scroll
 * instead of wrapping into a stacked ugly mess. */
@media (max-width: 575.98px) {
  .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .nav-tabs .nav-link {
    white-space: nowrap;
  }
}

/* Canvas charts inside cards — cap height on mobile so a
 * height=250 canvas doesn't dominate the viewport. */
@media (max-width: 575.98px) {
  canvas.dash-chart,
  .card-body > canvas {
    max-height: 220px !important;
  }
}
