/* Responsive-phone — QUEUE5 ITEM 3, BATCH 1 (shared phone layer).
   ------------------------------------------------------------------
   Loaded globally after responsive-fit.css. Every rule is gated behind a PHONE
   media query (≤576px), so desktop and tablet rendering is byte-for-byte
   unchanged — this only reflows DOWN on a phone. It targets the desktop pages
   that the mobile app (/m) deep-links into via nav-parity, so a tile that opens
   a full module screen fits a 360px phone without a horizontal page scroll.

   Scope of batch 1 (safe, global, no per-template edits):
     1. no horizontal page scroll at 360px
     2. every table becomes its own horizontal scroll port (never widens the page)
     3. 44px minimum touch targets; 16px inputs (stops iOS focus-zoom)
     4. form grids collapse to a single column
     5. modals go full-screen
     6. toolbars / button rows wrap instead of overflowing
   Per-module refinements (stacked "card" tables, filter bottom-sheets, sticky
   action bars) are the later phased batches — see RESPONSIVE_AUDIT.md. */

/* belt-and-braces: never a page-level horizontal scrollbar (also set in responsive-fit) */
@media (max-width: 576px) {
  html, body { overflow-x: clip; max-width: 100%; }

  /* 1. reclaim padding so content uses the full narrow width */
  .container, .container-fluid { padding-inline: .55rem; }
  .col-md-10.page-fade, main .col-md-10 { padding: .6rem !important; }
  .card-body { padding: .8rem; }

  /* 2. tables: each becomes its own horizontal scroll port. display:block keeps the
     internal row layout while giving the element overflow-x, so a wide table scrolls
     inside its own box instead of forcing the whole page wider. */
  .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-responsive { -webkit-overflow-scrolling: touch; }
  .table { font-size: .85rem; }
  .table > :not(caption) > * > * { padding: .4rem .45rem; }

  /* B5 — a .freeze-first grid must keep NORMAL table layout on phones and scroll
     via its own wrapper (card-body / .table-responsive). The rule above turns a
     plain .table into a display:block scroll port, which would re-parent the
     sticky first column and break the freeze. Exempt freeze-first grids. */
  table.freeze-first { display: table; overflow: visible; }

  /* 3. touch targets — WCAG-ish 44px; ≥16px font on inputs stops iOS zoom-on-focus */
  .btn, .form-control, .form-select, .form-check-input,
  .nav-link, .page-link, .dropdown-item, .list-group-item-action {
    min-height: 44px;
  }
  .form-control, .form-select, .btn { font-size: 1rem; }
  .btn-sm, .form-control-sm, .form-select-sm { min-height: 38px; font-size: .9rem; }
  .form-check-input { width: 1.25rem; height: 1.25rem; }
  .form-control-color { min-height: 44px; }

  /* 4. form grids collapse to a single column (any Bootstrap col inside a form) */
  form .row > [class*="col-"] { flex: 0 0 100%; max-width: 100%; }
  .input-group { flex-wrap: wrap; }

  /* 5. modals full-screen on phones (like Bootstrap's modal-fullscreen, applied to all).
     QUEUE6 · B10 — make the header (title + close ✕) and footer (actions) STAY while
     only the body scrolls: a flex column with the body as the single scroll region.
     So on a long form the user can always see the title and reach ✕ / the CTA. */
  .modal-dialog { margin: 0; max-width: 100%; width: 100%; height: 100%; }
  .modal-content { min-height: 100vh; height: 100%; border: 0; border-radius: 0;
                   display: flex; flex-direction: column; }
  .modal-header, .modal-footer { flex: 0 0 auto; }
  .modal-body { overflow-y: auto; flex: 1 1 auto; min-height: 0; }

  /* 6. toolbars & inline button rows wrap instead of overflowing */
  .btn-toolbar, .d-flex.flex-wrap, .card-header .d-flex { flex-wrap: wrap; gap: .4rem; }
  .btn-group { flex-wrap: wrap; }

  /* 7. type scale */
  .page-title, h3.page-title { font-size: 1.15rem; }
  h1 { font-size: 1.4rem; } h2 { font-size: 1.25rem; }
}

/* ------------------------------------------------------------------ *
 * QUEUE6 · BATCH B2 — responsive card-table (shared list_table layer).
 * A wide data table (`table[data-list]` inside `.listview[data-delight]`)
 * reflows to stacked cards on phones: each row becomes a card, each cell a
 * "Label: value" line. list-delight.js stamps the column label onto every
 * cell as data-label (value wrapped in .ct-val); action/checkbox cells get
 * .ct-actions (full width, no label). Opt a screen out with
 * list_table(delight_no_cards=true) — e.g. mark grids that want a frozen
 * first column + horizontal scroll instead (B5). Desktop/tablet unchanged. */

/* .ct-val is layout-transparent above the phone breakpoint: the wrapper the
   JS adds around a cell's value must not change desktop/tablet rendering. */
.ct-val { display: contents; }

@media (max-width: 576px) {
  /* card rows scroll with the PAGE — drop the viewport-tall/overflow scroll port
     (and, for list_table, its sticky first column), meaningless once rows are
     cards. Covers both the list_table wrapper and a plain .table-responsive
     (raw .js-cardify tables — B3). */
  .listview-scroll:has(> table.cardtable),
  .table-responsive:has(> table.cardtable) { max-height: none; overflow: visible; }

  table.cardtable,
  table.cardtable > tbody { display: block; }
  table.cardtable > thead { display: none; }
  table.cardtable > tbody > tr {
    display: block;
    margin-bottom: .6rem;
    padding: .5rem .7rem;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: .7rem;
    background: var(--bs-body-bg, #fff);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
  }
  /* zebra striping is meaningless once rows are cards */
  table.cardtable.table-striped > tbody > tr > td { background: transparent; }
  table.cardtable > tbody > tr > td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: .75rem;
    padding: .22rem 0;
    border: 0 !important;
    position: static !important;   /* undo .pin-first sticky first column */
    box-shadow: none !important;
    text-align: end;
    white-space: normal;
    min-height: 0;                 /* the 44px min-height is for tap targets, not cells */
  }
  table.cardtable > tbody > tr > td::before {
    content: attr(data-label);
    flex: 0 0 40%;
    font-weight: 600;
    color: var(--bs-secondary-color, #6c757d);
    text-align: start;
  }
  table.cardtable > tbody > tr > td .ct-val {
    display: block;
    min-width: 0;
    text-align: end;
  }
  /* action / checkbox / photo cells: full width, no label, start-aligned */
  table.cardtable > tbody > tr > td.ct-actions {
    justify-content: flex-start;
    text-align: start;
    padding-top: .4rem;
  }
  table.cardtable > tbody > tr > td.ct-actions::before { content: ""; display: none; }
  table.cardtable > tbody > tr > td.ct-actions .btn-group { width: 100%; }
  /* a hover/auto mini-card is pointless inside a card row */
  table.cardtable > tbody > tr .list-mini,
  table.cardtable > tbody > tr .stu-mini { display: none !important; }

  /* QUEUE6 · B4 — attendance register: the status toggles are the primary phone
     interaction and wrap to a 2x2 grid; give them the full 44px WCAG target
     (they use .btn-sm, which the shared layer otherwise slims to 38px). Covers
     the student register (attendance.html) and the staff grid (hr.html) — both
     mark rows carry tr[data-att-row]. */
  tr[data-att-row] .btn-group .btn { min-height: 44px; }

  /* QUEUE6 · B8 — multi-step wizard: pin the back/next bar to the bottom of the
     viewport on phones so the primary navigation is always reachable without
     scrolling to the end of a long step. Reusable via .wz-nav. */
  .wz-nav {
    position: sticky; bottom: 0; z-index: 5;
    background: var(--bs-body-bg, #fff);
    padding-block: .55rem; margin-block-end: 0 !important;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, .08);
  }

  /* QUEUE6 · B3 — pay/dialog CTA ergonomics on phones: stack modal footer
     buttons full-width with the PRIMARY action on top (column-reverse: the
     last button in the DOM — the submit/confirm — rises to the top). Serves
     the pay modal's "Record Payment" CTA and every dialog (pre-helps B10). */
  .modal-footer { flex-direction: column-reverse; align-items: stretch; gap: .4rem; flex-wrap: nowrap; }
  .modal-footer > .btn { width: 100%; margin: 0; }
}

/* ===================================================================== *
 * QUEUE8 · ITEM 1 — full-site mobile nav. On a phone the left sidebar
 * (#appSidebar) is a slide-in OFF-CANVAS drawer opened by the navbar
 * toggler, and the page content spans the full width (the drawer is fixed,
 * so it leaves the flow). Nav sub-menus stay Bootstrap `collapse` accordions
 * — they expand IN FLOW inside the drawer, never absolutely overlapping.
 * Bootstrap gives focus-trap, Esc, backdrop + scroll-lock for free.
 *
 * Specificity note: the base inline <style> loads AFTER this file, so its
 * `.sidebar { position:sticky; top:56px }` would otherwise beat Bootstrap's
 * responsive `.offcanvas-sm { position:fixed }`. We re-assert the drawer with
 * the `#appSidebar` id so it wins; Bootstrap's own transform/visibility
 * show-hide rules are not touched by `.sidebar`, so they still animate. */
@media (max-width: 576px) {
  #appSidebar.offcanvas-sm {
    position: fixed;
    top: 0;                       /* beat inline .sidebar{top:56px}: full-height drawer */
    --bs-offcanvas-width: 84vw;   /* never wider than a narrow phone */
    max-width: 330px;
    overflow-y: auto;             /* long nav scrolls inside the drawer */
    box-shadow: 0 0 24px rgba(0, 0, 0, .28);
    padding-bottom: env(safe-area-inset-bottom);
  }
  /* clear the notch/safe-area at the top of the drawer header */
  #appSidebar .offcanvas-header { padding-top: calc(.6rem + env(safe-area-inset-top)); }

  /* top-nav dropdowns must stay within the viewport on a phone */
  .navbar .dropdown-menu { max-width: calc(100vw - .8rem); }
}

/* very small phones (≤360px): one more notch of tightening, still no reflow to cards */
@media (max-width: 360px) {
  .col-md-10.page-fade, main .col-md-10 { padding: .45rem !important; }
  .card-body { padding: .65rem; }
  .table { font-size: .8rem; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   qF · 0.2 — AUTHENTICATED full-site mobile QUALITY (owner screenshots: /fees,
   /students, /hr). All ≤576px; desktop ≥577px byte-for-byte unchanged. Fixes:
   (a) ragged button/control clusters → clean aligned equal-width blocks;
   (b) the EMPTY SIDE BAND → content column full width (no reserved sidebar slot).
   Uses :has() (modern mobile Chrome/Safari); unsupported browsers ignore it and
   fall back to the already-usable wrapping layout. RTL-safe (logical properties).
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 576px) {
  /* (b) EMPTY SIDE BAND — root cause: responsive-fit.css pins the content column to
     86% (sidebar's 14% slot) at ≤1440px with no lower bound, so on a phone — where the
     sidebar is an off-canvas drawer (position:fixed, out of flow) — that 14% is dead
     space down the inline-start. Reclaim it: content spans the full row. */
  body.rl-fit .container-fluid > .row > .col-md-10.page-fade,
  .container-fluid > .row > .col-md-10.page-fade,
  .col-md-10.page-fade, main .col-md-10 {
    flex: 0 0 100% !important; max-width: 100% !important; width: 100% !important;
  }
  /* the sidebar column must never hold flow width on a phone (it is the drawer) */
  body.rl-fit .container-fluid > .row > .col-md-2.sidebar,
  .container-fluid > .row > .col-md-2.sidebar {
    flex: 0 0 auto !important; max-width: none !important;
  }

  /* (a1) PAGE-HEADER action bar — the `d-flex justify-content-between` that holds the
     page title: stack the title, and lay its action cluster out as an EVEN grid of
     equal-width blocks (auto-fit → 2-up, a lone action fills the row) instead of a
     ragged right-aligned wrap of mixed widths. Scoped by :has(.page-title) so only a
     real page header is touched, never a mid-page justify-between row. */
  .d-flex.justify-content-between:has(.page-title) {
    flex-wrap: wrap; row-gap: .5rem; align-items: stretch;
  }
  .d-flex.justify-content-between:has(.page-title) > :first-child { width: 100%; }
  .d-flex.justify-content-between:has(.page-title)
      > :last-child:not(.page-title):not(:has(.page-title)) {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(45%, 1fr));
    gap: .4rem; width: 100%; margin: 0 !important;
  }
  .d-flex.justify-content-between:has(.page-title)
      > :last-child:not(.page-title):not(:has(.page-title)) > * {
    width: 100%; margin: 0 !important;
  }

  /* (a2) LIST VIEW-MODE TOGGLE (column-set presets) → even full-width segmented control */
  .btn-group[aria-label="Column presets"] { display: flex; width: 100%; }
  .btn-group[aria-label="Column presets"] > .btn { flex: 1 1 0; padding-inline: .25rem; }

  /* (a3) SAVED VIEWS + PER-PAGE + presets sit in an `ms-auto` sub-group on the filter
     action row; on a phone stop it hugging the inline-end — drop to its own full-width
     left-aligned row with even spacing. Scoped by the saved-views widget id. */
  .d-flex:has(> [id^="sv-"]) {
    margin-inline-start: 0 !important; width: 100%;
    justify-content: flex-start; flex-wrap: wrap; gap: .4rem !important;
  }
  .btn-group[id^="sv-"] { display: flex; }
  .btn-group[id^="sv-"] > .btn { flex: 1 1 auto; }

  /* (a4) FILTER ACTION ROW — the row that carries Apply: make the primary Apply button
     full-width, secondary controls wrap tidily beneath it. Scoped to a flex-wrap row
     that contains the saved-views group (i.e. a listview filter action row). */
  form .d-flex.flex-wrap:has([id^="sv-"]) { row-gap: .5rem; }
  form .d-flex.flex-wrap:has([id^="sv-"]) > .btn-brand:first-child,
  form .d-flex.flex-wrap:has([id^="sv-"]) > button.btn:first-child { flex: 1 1 100%; }

  /* (a5) STAT / SUMMARY BADGES + status chips — even wrapping rows, consistent size */
  .listview-stats { gap: .4rem !important; }
  .listview-stats .badge { font-size: .8rem; padding: .4em .6em; }
}
