/* Responsive-fit — reusable adapt-to-viewport pattern (RTL-aware).
   Opt-in via <body class="rl-fit"> on the page template (set in the
   template's `content` block via a small script or via {% block body_class %}
   if the shell supports it). Anything under this rule is SAFE on all screens:
   it only *tightens* spacing and prevents overflow. It never hides content
   and never reflows to cards.

   The one shell-wide safety rule is the `min-width:0` on the content column:
   without it, a wide child (a long table, a long token) forces its parent
   flex column to grow past the row, which is what produces a page-level
   horizontal scrollbar even when the inner .table-responsive already has
   its own overflow-x:auto. This is standard flexbox — safe everywhere.
*/

/* --- 1. Shell safety (applies globally) ------------------------------ */
.container-fluid > .row > .col-md-10.page-fade { min-width: 0; }
/* belt-and-braces: no page-level horizontal scroll, ever */
html, body { overflow-x: clip; }

/* --- 2. Fit pattern (opt-in per page via body.rl-fit) ---------------- */

/* On typical laptop screens (≤1440), reclaim wasted padding on the
   content column and slim the sidebar so wide tables fit before their
   internal scrollbar kicks in. */
@media (max-width: 1440px) {
  body.rl-fit .col-md-10.page-fade { padding: 1rem !important; }
  body.rl-fit .sidebar { padding: .35rem !important; }
  body.rl-fit .sidebar .nav-link { padding: .3rem .5rem; font-size: .82rem; }
  body.rl-fit .sidebar .nav-group-toggle { font-size: .78rem; padding: .35rem .55rem; }
  /* Slightly slimmer sidebar column: Bootstrap col-md-2 = 16.67% → 12.5%
     using its own flex-basis, no grid override needed elsewhere. */
  body.rl-fit .container-fluid > .row > .col-md-2.sidebar {
    flex: 0 0 14%;
    max-width: 14%;
  }
  body.rl-fit .container-fluid > .row > .col-md-10.page-fade {
    flex: 0 0 86%;
    max-width: 86%;
  }
  /* Page title / header row: scale down type + gap so the header wraps
     less often on 1366. */
  body.rl-fit .page-title { font-size: clamp(1rem, 1.2vw + .5rem, 1.35rem); }
  body.rl-fit .btn { font-size: .82rem; }
  body.rl-fit .btn i, body.rl-fit .btn .bi { font-size: .95em; }
}

/* Narrower screens (≤1280): tighten further, still no reflow. */
@media (max-width: 1280px) {
  body.rl-fit .col-md-10.page-fade { padding: .75rem !important; }
  body.rl-fit .table { font-size: .82rem; }
  body.rl-fit .table > :not(caption) > * > * { padding: .35rem .4rem; }
}

/* --- 3. Table scroll container (already provided by list_table via
       .table-responsive). We just make sure it's RTL-correct and that
       sticky headers inside it keep working. --- */
body.rl-fit .table-responsive { max-width: 100%; }
html[dir="rtl"] body.rl-fit .table-responsive { direction: rtl; }

/* --- QUEUE6 · B5 — reusable frozen first column for wide mark/data grids ---
   A wide grid (student × subjects) scrolls horizontally inside its own wrapper
   (card-body overflow-x:auto, or the shared phone layer's table scroll port);
   the first column (the student/class name) stays pinned so you never lose track
   of whose row you're on. RTL-SAFE (inset-inline-start, not left:0 — the old
   inline styles pinned to the physical left, which is the WRONG side in Arabic).
   Covers both a <td> and a <th> first cell (timetables use a row-header <th>).
   A logical inline-end divider is the scroll affordance. No-op when the grid
   isn't actually scrolling, so it's safe at any width. */
.table.freeze-first > thead > tr > th:first-child,
.table.freeze-first > tbody > tr > td:first-child,
.table.freeze-first > tbody > tr > th:first-child {
  position: sticky;
  inset-inline-start: 0;
  z-index: 2;
  background: var(--bs-body-bg, #fff);
  border-inline-end: 2px solid var(--bs-border-color, #dee2e6);
}
.table.freeze-first > thead > tr > th:first-child {
  z-index: 3;
  background: var(--bs-tertiary-bg, #f8f9fa);
}

/* --- 4. Print: undo the fit tightening so paper renders full-size --- */
@media print {
  body.rl-fit .col-md-10.page-fade,
  body.rl-fit .sidebar,
  body.rl-fit .container-fluid > .row > .col-md-2.sidebar,
  body.rl-fit .container-fluid > .row > .col-md-10.page-fade {
    padding: initial !important;
    flex: initial !important;
    max-width: initial !important;
  }
}
