/* ============================================================
 * 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;
  }
}

/* ---------- 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; }
}
