/* ============================================================
 * admin_mobile_pages.css — Tier 2 page-specific mobile fixes.
 *
 * Companion to admin_mobile.css. This file targets bespoke
 * class names found in specific high-traffic admin pages
 * whose custom CSS overrode Bootstrap's responsive defaults.
 *
 * Scope: still inside body.admin-route only.
 * Breakpoint: ≤767.98px unless noted.
 * ============================================================ */

@media (max-width: 767.98px) {

  /* ============================================================
   * classes/list_v3.html — bespoke .classes-table
   * Has a "Card View" toggle but it's manual. On mobile the
   * table view is unusable — force the card grid to be the
   * default and hide the table. -------------------------------- */
  body.admin-route #tableView { display: none !important; }
  body.admin-route #cardView { display: block !important; }
  body.admin-route .cards-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.75rem;
  }
  body.admin-route .class-card {
    border-radius: 10px;
    overflow: hidden;
  }
  body.admin-route .class-card .card-image-container { height: 140px; }
  /* The view-mode toggle buttons are pointless on mobile. */
  body.admin-route .view-toggle,
  body.admin-route .view-mode-toggle { display: none !important; }

  /* ============================================================
   * classes/enrollments.html — bespoke .enrollment-table-mt
   * inside .table-wrap-mt. Force horizontal scroll and tighten. */
  body.admin-route .table-wrap-mt {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    margin-left: -4px; margin-right: -4px;
  }
  body.admin-route .enrollment-table-mt {
    font-size: 0.85rem;
    min-width: 560px;        /* keeps columns readable, scroll instead of squish */
  }
  body.admin-route .enrollment-table-mt th,
  body.admin-route .enrollment-table-mt td {
    padding: 0.45rem 0.55rem !important;
    white-space: nowrap;
  }
  body.admin-route .session-details-mt { padding: 0.5rem !important; }
  body.admin-route .empty-state-mt,
  body.admin-route .info-message-mt { padding: 0.75rem; font-size: 0.85rem; }
  body.admin-route .enrolled-badge-mt {
    font-size: 0.75rem; padding: 0.2rem 0.45rem;
  }
  body.admin-route .term-sessions-container { padding-top: 0.25rem !important; }
  /* The expandable session breakdown — no left indent on mobile. */
  body.admin-route .session-breakdown-container {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  /* ============================================================
   * families/detail.html, students/detail.html, classes/detail.html
   * --- Custom tabs (.student-tabs, .nav-tabs.flex-grow-1) need
   *     forced horizontal scroll. -------------------------------- */
  body.admin-route .nav-tabs.student-tabs,
  body.admin-route .nav.nav-tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  body.admin-route .nav-tabs .nav-item { flex-shrink: 0; }
  body.admin-route .nav-tabs .nav-link {
    white-space: nowrap;
    padding: 0.55rem 0.85rem !important;
    font-size: 0.875rem;
    min-height: 44px;
  }

  /* --- Tab pane padding tighter so content gets more space. --- */
  body.admin-route .tab-content { padding-top: 0.5rem; }
  body.admin-route .tab-pane > .row > [class*="col-md-"],
  body.admin-route .tab-pane > .row > [class*="col-lg-"] {
    width: 100%;
    flex: 0 0 100%;
    max-width: 100%;
    margin-bottom: 0.6rem;
  }

  /* ============================================================
   * families/detail.html — invoice modal inner grid
   * .invoice-details has 2-3 columns of detail-groups. Stack. -- */
  body.admin-route .invoice-details {
    display: block !important;
  }
  body.admin-route .invoice-details .detail-group {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.45rem 0;
    border-bottom: 1px solid #f1f3f5;
    margin: 0;
  }
  body.admin-route .invoice-details .detail-label {
    font-size: 0.8rem;
    color: #6b7280;
    flex: 0 0 40%;
  }
  body.admin-route .invoice-details .detail-value {
    font-size: 0.9rem;
    font-weight: 600;
    text-align: right;
    flex: 1;
  }

  /* ============================================================
   * notifications.html — subscribed user rows already use flex,
   * just tighten and make the delete button bigger. ------------- */
  body.admin-route .subscribed-group .d-flex.align-items-start {
    padding-bottom: 0.6rem !important;
  }
  body.admin-route .subscribed-group .btn.btn-sm.btn-danger {
    padding: 0.4rem 0.6rem !important;
    min-width: 38px;
    min-height: 38px;
    font-size: 0.85rem !important;
  }
  /* Subscribed users panel + Test panel stack via Bootstrap; just
     ensure the side panel doesn't get a 300px max-height that
     orphans content on phone. */
  body.admin-route #subscribedUsersList { max-height: none !important; }

  /* Messages tab — thread list & conversation panel stack via
     Bootstrap col-md-5/col-md-7. Cap heights. */
  body.admin-route .list-group.list-group-flush[style*="max-height"] {
    max-height: 360px !important;
  }
  body.admin-route .card-body[style*="min-height: 500px"] {
    min-height: 280px !important;
    max-height: 480px !important;
  }
  /* Message bubbles: widen on phone, was capped at 75% which is too narrow. */
  body.admin-route .tab-pane .d-inline-block[style*="max-width: 75%"] {
    max-width: 92% !important;
  }

  /* ============================================================
   * classes/detail.html — already has its own mobile @media.
   * Just one extra: the action dropdowns inside tab panes lose
   * their right-anchor on mobile and overflow off-screen. ------- */
  body.admin-route .tab-pane .dropdown-menu.dropdown-menu-end {
    right: 0 !important;
    left: auto !important;
    max-width: calc(100vw - 24px);
  }

  /* ============================================================
   * Generic "page header" block used across detail pages:
   * <div class="d-flex justify-content-between align-items-center">
   *   ...page title...   <buttons>
   * </div>
   * Tier 1 wraps it; here we ensure title + buttons each take
   * a clean full-width row. ----------------------------------- */
  body.admin-route .container-fluid > .d-flex.justify-content-between.align-items-center,
  body.admin-route .container > .d-flex.justify-content-between.align-items-center {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.6rem;
  }
  body.admin-route .container-fluid > .d-flex.justify-content-between.align-items-center > *,
  body.admin-route .container > .d-flex.justify-content-between.align-items-center > * {
    width: 100%;
  }
  body.admin-route .container-fluid > .d-flex.justify-content-between.align-items-center .btn,
  body.admin-route .container > .d-flex.justify-content-between.align-items-center .btn {
    width: 100%;
    justify-content: center;
  }

  /* ============================================================
   * Large pill rows / chip rows seen in attendance roster cards
   * and student detail header. Wrap and align. ----------------- */
  body.admin-route .student-meta,
  body.admin-route .family-status,
  body.admin-route .badge-row {
    flex-wrap: wrap !important;
    gap: 4px !important;
  }

  /* ============================================================
   * Sticky page-level toolbars (filter rows often have
   * position: sticky; top: 0) interact badly with the rail/nav.
   * Reset their top to 0 below 768px since the rail isn't there. */
  body.admin-route .sticky-top:not(.navbar-sticky) {
    position: relative !important;
  }

  /* ============================================================
   * attendance/session.html — Take Attendance page.
   * The per-student row has a 4-button cluster (Present / Absent /
   * Teacher Cancelled / Clear-X) that hits the right edge on phones
   * and the labels go off-screen. Reflow into a 2x2 grid with the
   * clear button as a small pinned action. ----------------------- */
  body.admin-route .attendance-page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  body.admin-route .attendance-page-title h1 {
    font-size: 1.25rem !important;
    margin-bottom: 0;
  }
  /* The roster table on phone: hide the family-name secondary text
     was crowding the name cell. Keep it but smaller. */
  body.admin-route .att-page-inner .student-name-cell .family-name {
    font-size: 0.75rem;
    color: #6b7280;
  }
  body.admin-route .att-page-inner .student-name-cell .student-name {
    font-size: 0.95rem;
    line-height: 1.2;
  }
  /* The 3-state status row + clear: 2-column grid, clear button on
     its own row at the end, full-width buttons with smaller padding. */
  body.admin-route .att-status-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    align-items: stretch;
  }
  body.admin-route .att-status-row .att-status-btn {
    width: 100%;
  }
  body.admin-route .att-status-row .att-status-btn .att-btn {
    width: 100%;
    padding: 0.4rem 0.45rem !important;
    font-size: 0.8rem !important;
    min-height: 40px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* Teacher Cancelled is the longest label — let it span full width
     on the second row. */
  body.admin-route .att-status-row .att-status-btn:nth-child(3) {
    grid-column: 1 / -1;
  }
  /* Clear button: small, right-aligned own row. */
  body.admin-route .att-status-row > .att-btn-clear {
    grid-column: 1 / -1;
    justify-self: end;
    min-width: 40px;
    min-height: 36px;
    padding: 0.3rem 0.6rem !important;
  }
  /* Make the attendance roster table genuinely scrollable side-to-
     side rather than overflowing the page. The roster is rendered
     as a real <table> inside _session_card.html. */
  body.admin-route .att-page .table-responsive,
  body.admin-route .att-page .att-roster-table-wrapper {
    -webkit-overflow-scrolling: touch;
    margin-left: -4px;
    margin-right: -4px;
  }

  /* ============================================================
   * hub.html — tighten container/section padding and let alert
   * details wrap. The 2-column stats-grid override is in a
   * separate (min-width:577px) query below so we DO NOT clobber
   * hub.html's own ≤576px single-column rule for narrow phones. - */
  body.admin-route .hub-container { padding: 0.75rem !important; }
  body.admin-route .hub-section { padding: 0.85rem !important; }
  body.admin-route .hub-container .stat-card {
    padding: 0.85rem;
  }
  body.admin-route .hub-container .stat-card .stat-value {
    font-size: 1.65rem;
    line-height: 1.1;
  }
  body.admin-route .hub-container .stat-card .stat-label {
    font-size: 0.78rem;
  }
  /* The waitlist class stats row inside hub-section can wrap. */
  body.admin-route .waitlist-class-stats {
    flex-wrap: wrap;
    gap: 4px !important;
  }
  /* Section headers (title + actions) stack. */
  body.admin-route .hub-section .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  /* Alert items inside the right column: tighten and let icon stay
     compact so text gets more width. */
  body.admin-route .admin-hub-section-alerts .alert-item {
    flex-wrap: wrap;
    gap: 0.4rem;
  }
  body.admin-route .admin-hub-section-alerts .alert-details .alert-detail-item {
    flex-wrap: wrap;
  }

  /* ============================================================
   * invoices/list.html — the bottom summary row uses col-md-3
   * which stacks to 4 tall cards on mobile. Convert to a 2x2 grid
   * so it fits on one phone screen. The row has no unique parent
   * class, so we match the col directly via :has() on the bespoke
   * coloured summary cards (.card.bg-primary/success/warning/info
   * with text-white).
   *
   * Cross-page note: this same coloured-summary-card pattern is
   * also used in templates/admin/shop/dashboard.html and
   * templates/admin/shop/orders.html. The 2x2 reflow is the same
   * UX win there, so the broader scope is intentional. ----------- */
  body.admin-route .col-md-3:has(> .card.bg-primary.text-white),
  body.admin-route .col-md-3:has(> .card.bg-success.text-white),
  body.admin-route .col-md-3:has(> .card.bg-warning.text-white),
  body.admin-route .col-md-3:has(> .card.bg-info.text-white) {
    flex: 0 0 50% !important;
    max-width: 50% !important;
    padding-left: 4px;
    padding-right: 4px;
    margin-bottom: 0.5rem;
  }
  body.admin-route .col-md-3 > .card.bg-primary.text-white .card-body h3,
  body.admin-route .col-md-3 > .card.bg-success.text-white .card-body h3,
  body.admin-route .col-md-3 > .card.bg-warning.text-white .card-body h3,
  body.admin-route .col-md-3 > .card.bg-info.text-white .card-body h3 {
    font-size: 1.1rem;
  }
  body.admin-route .col-md-3 > .card.bg-primary.text-white .card-body h5,
  body.admin-route .col-md-3 > .card.bg-success.text-white .card-body h5,
  body.admin-route .col-md-3 > .card.bg-warning.text-white .card-body h5,
  body.admin-route .col-md-3 > .card.bg-info.text-white .card-body h5 {
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
  }
  body.admin-route .col-md-3 > .card.bg-primary.text-white .card-body,
  body.admin-route .col-md-3 > .card.bg-success.text-white .card-body,
  body.admin-route .col-md-3 > .card.bg-warning.text-white .card-body,
  body.admin-route .col-md-3 > .card.bg-info.text-white .card-body {
    padding: 0.6rem !important;
  }

  /* ============================================================
   * Generic Bootstrap btn-group with dropdown-toggle-split (used in
   * invoices/list, classes/list, etc.) — keep the View button + the
   * caret tightly together on mobile rather than wrapping to two
   * lines. Override Tier 1's flex-wrap for this specific pattern. */
  body.admin-route .btn-group:has(> .dropdown-toggle-split) {
    flex-wrap: nowrap;
    width: auto;
  }
  body.admin-route .btn-group:has(> .dropdown-toggle-split) > .btn {
    flex: 0 1 auto;
  }
}

/* ---------- Phone-only (≤575.98px) extra-tight tweaks ---------- */
@media (max-width: 575.98px) {

  /* enrollment-table-mt min-width drops a bit so it doesn't scroll
     too far for phones with narrow viewports. */
  body.admin-route .enrollment-table-mt { min-width: 480px; }

  /* Detail-page tab labels can shrink to icon+short on tiny screens. */
  body.admin-route .nav-tabs .nav-link .tab-label-long { display: none; }

  /* Invoice details label / value swap to stacked rather than
     justify-between — space is too tight. */
  body.admin-route .invoice-details .detail-group {
    flex-direction: column;
    gap: 2px;
  }
  body.admin-route .invoice-details .detail-label { flex: 1 1 auto; }
  body.admin-route .invoice-details .detail-value { text-align: left; }
}

/* ---------- Landscape phones / small tablets (577–767.98px) ---------- *
 * Banded so we don't clobber narrower-phone overrides defined in the
 * page templates themselves (e.g. hub.html ≤576px single-column).      */
@media (min-width: 577px) and (max-width: 767.98px) {

  /* hub.html: at this width the auto-fit minmax(200px,1fr) gives a
     ragged 2–3 column layout. Lock to a clean 2-column grid. */
  body.admin-route .hub-container .stats-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.75rem;
  }
}

