/* ---------------------------------------------------------------------------
   responsive.css — mobile / tablet layout layer
   ---------------------------------------------------------------------------
   Hand written (NOT generated by Tailwind). static/css/output.css is a purged
   Tailwind build and cannot be regenerated here, so every responsive rule the
   templates need lives in this file and is loaded after output.css.

   Breakpoints used:
     <= 1023px app shell: sidebar becomes a drawer (phones + tablets)
     <= 767px  content: tables render as cards, m-full/m-hide helpers apply
     <= 639px  small phones (tighter spacing)
     >= 1024px desktop (unchanged original layout, docked sidebar)
--------------------------------------------------------------------------- */

:root {
  --app-primary: #082f58;
  --app-secondary: #1e40af;
  --app-sidebar-w: 16rem;
}

/* Nothing should ever push the page sideways. */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* ===========================================================================
   1. APP SHELL — sidebar drawer, overlay, topbar
   =========================================================================== */

.app-sidebar {
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.app-sidebar nav {
  flex: 1 1 auto;
}

/* ---- desktop: the nav list scrolls ------------------------------------
   The shell is `flex h-screen overflow-hidden`, so the sidebar is capped at
   the viewport and anything past the fold was simply clipped away — with no
   scrollbar to reveal it. Logout, as the last item, disappeared entirely once
   the list grew past the window height.

   The nav scrolls rather than the aside, so the brand block stays put. */
@media (min-width: 1024px) {
  .app-sidebar nav {
    /* `min-height: 0` is the whole fix. A flex item defaults to
       `min-height: auto`, which refuses to shrink below its content — so
       `overflow-y: auto` never had a constrained box to scroll inside and
       the list just overflowed into the parent's `overflow-hidden`. */
    min-height: 0;
    overflow-y: auto;
    /* Don't hand the scroll to the page when the list hits its end. */
    overscroll-behavior: contain;
  }

  /* The fly-out stays a fly-out. A scrolling ancestor would clip a panel
     positioned at `left: 100%`, so it switches to `position: fixed` — which
     is laid out against the viewport and therefore escapes the clip. The
     coordinates cannot be known in CSS (they depend on where the row has
     scrolled to), so `positionFlyout()` in _base.html sets them on hover. */
  .app-sidebar .nav-submenu {
    position: fixed !important;
    /* The template carries an inline `left: 100%`, which under `fixed` means
       100% of the VIEWPORT — i.e. off the right edge. This is the no-script
       fallback: park the panel against the sidebar's edge so it is still
       usable even if positionFlyout() never runs. JS then refines `top` and
       `left` per row (it must use setProperty(..., 'important') to win
       against this rule). */
    left: calc(var(--app-sidebar-w) + 4px) !important;
    margin-left: 0 !important;
  }
}

.sidebar-close {
  display: none;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.page-container {
  width: 100%;
}

/* Collapsible nav groups (Result / Fees). Desktop keeps the hover fly-out. */
.nav-group-caret {
  transition: transform 0.2s ease;
}

/* The app shell (sidebar drawer + topbar) switches to the mobile layout up to
   1023px so tablets get the drawer too. Table-as-cards stays at 767px — a
   tablet has the width for a real table, it just has no room for a permanently
   docked 16rem sidebar. Keep this breakpoint in step with MOBILE_BREAKPOINT in
   _base.html, which drives the same drawer from JS. */
@media (max-width: 1023px) {
  /* ---- drawer ---------------------------------------------------------- */
  aside.app-sidebar {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: fixed;
    top: 0;
    left: 0;
    width: 17rem;
    max-width: 85vw;
    height: 100%;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  }

  aside.app-sidebar.active {
    transform: translateX(0);
  }

  /* Clear the home-indicator bar so Logout stays tappable. */
  .app-sidebar > div:last-child {
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  }

  .sidebar-overlay.active {
    display: block;
    opacity: 1;
  }

  .sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    flex-shrink: 0;
  }

  .sidebar-brand {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
  }

  /* Bigger tap targets in the drawer. */
  .app-sidebar .nav-item {
    padding: 0.85rem 1.25rem;
    font-size: 0.95rem;
  }

  /* ---- nav groups become accordions ------------------------------------ */
  .app-sidebar .nav-submenu {
    position: static !important;
    margin: 0 !important;
    width: 100% !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: rgba(0, 0, 0, 0.18) !important;
    opacity: 1 !important;
    visibility: visible !important;
    display: none;
  }

  .app-sidebar .nav-group.open .nav-submenu {
    display: block;
  }

  .app-sidebar .nav-submenu a {
    color: #e5e7eb !important;
    padding-left: 3.25rem !important;
  }

  .app-sidebar .nav-group.open .nav-group-caret {
    transform: rotate(180deg);
  }

  /* ---- topbar ---------------------------------------------------------- */
  .topbar-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    height: auto !important;
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
  }

  .topbar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    flex: 1 1 auto;
  }

  .topbar-logo {
    width: 38px !important;
    height: 38px !important;
    margin-right: 0 !important;
  }

  .topbar-title-short {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: #1f2937;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-controls {
    flex: 1 1 100%;
    display: flex;
    gap: 0.5rem;
  }

  .topbar-controls > div {
    flex: 1 1 0;
    min-width: 0;
  }

  .topbar-controls select {
    width: 100%;
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
    font-size: 0.85rem;
  }

  #academic-year-container {
    display: flex;
    gap: 0.5rem;
    width: 100%;
  }

  #academic-year-container select {
    width: 100%;
  }

  /* ---- page gutters ---------------------------------------------------- */
  .page-container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    padding-top: 1rem;
    padding-bottom: 1rem;
  }
}

/* The short title only exists for mobile. */
.topbar-title-short {
  display: none;
}

/* ===========================================================================
   2. SHARED MOBILE HELPERS
   =========================================================================== */

/* A button/link that goes full width on phones. */
@media (max-width: 767px) {
  .m-full {
    width: 100%;
    justify-content: center;
  }

  .m-stack {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }

  .m-hide {
    display: none !important;
  }
}

@media (min-width: 768px) {
  .d-hide {
    display: none !important;
  }
}

/* ===========================================================================
   3. GENERAL REGISTER — list page
   =========================================================================== */

.gr-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.gr-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.gr-import-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.gr-search-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.gr-table-wrap {
  /* Leaves room for the toolbar, the school-level tabs and the search row
     above it so the page itself does not also need to scroll. */
  max-height: calc(100vh - 24rem);
  min-height: 22rem;
}

.gr-card-more,
.gr-card-open {
  display: none;
}

.pagination-bar {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

@media (max-width: 767px) {
  .gr-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .gr-toolbar-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .gr-toolbar-actions > div,
  .gr-toolbar-actions > select,
  .gr-toolbar-actions button {
    width: 100%;
  }

  .gr-toolbar-actions #exportExcel {
    justify-content: center;
  }

  .gr-import-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
  }

  .gr-import-form {
    flex: 1 1 auto;
    gap: 0.5rem;
  }

  .gr-import-form label {
    flex: 1 1 auto;
    margin-right: 0 !important;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .gr-import-form button {
    flex: 0 0 auto;
    width: auto !important;
  }

  #grImportModeSelect {
    margin-right: 0 !important;
  }

  .gr-search-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }

  .gr-search-row select {
    width: 100%;
  }

  .gr-search-hint {
    font-size: 0.75rem;
  }

  /* ---- table -> cards -------------------------------------------------- */
  .gr-table-wrap {
    max-height: none;
    min-height: 0;
    overflow: visible;
    border: 0 !important;
    box-shadow: none !important;
    background: transparent;
  }

  .gr-table,
  .gr-table tbody,
  .gr-table tr,
  .gr-table td {
    display: block;
    width: 100%;
  }

  .gr-table thead {
    display: none;
  }

  .gr-table tbody {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .gr-table tr {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    padding: 0.25rem 0 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
    position: relative;
  }

  .gr-table td {
    position: static !important;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.4rem 0.9rem !important;
    white-space: normal !important;
    font-size: 0.85rem;
    text-align: right;
  }

  .gr-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    font-size: 0.75rem;
    text-align: left;
    flex: 0 0 45%;
    line-height: 1.35;
  }

  /* Headline row of each card: GR number. */
  .gr-table td.gr-col-grno {
    background: #f8fafc;
    border-bottom: 1px solid #eef2f7;
    border-radius: 0.75rem 0.75rem 0 0;
    padding: 0.6rem 0.9rem !important;
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
  }

  .gr-table td.gr-col-grno::before {
    font-size: 0.75rem;
    align-self: center;
  }

  /* Secondary columns stay hidden until the card is expanded. */
  .gr-table td.gr-col-extra {
    display: none;
  }

  .gr-table tr.expanded td.gr-col-extra {
    display: flex;
  }

  .gr-table td.gr-col-actions {
    justify-content: flex-end;
    border-top: 1px solid #eef2f7;
    margin-top: 0.25rem;
    padding-top: 0.6rem !important;
  }

  .gr-table td.gr-col-actions::before {
    content: "";
    flex: 0 0 auto;
  }

  /* Finger-sized edit / delete targets. */
  .gr-table td.gr-col-actions .flex {
    gap: 0.5rem;
  }

  .gr-table td.gr-col-actions a,
  .gr-table td.gr-col-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
  }

  .gr-table td.gr-col-actions svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  .gr-card-more,
  .gr-card-open {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.45rem 0.8rem;
    border-radius: 0.5rem;
    border: 1px solid #dbeafe;
    background: #eff6ff;
    color: #1d4ed8;
  }

  .gr-table td.gr-card-footer {
    display: flex;
    gap: 0.5rem;
    padding: 0.25rem 0.9rem 0.4rem !important;
    justify-content: stretch;
  }

  .gr-table td.gr-card-footer::before {
    content: none;
  }

  .gr-table td.gr-card-footer > * {
    flex: 1 1 0;
    justify-content: center;
  }

  .gr-card-open {
    border-color: #e5e7eb;
    background: #f9fafb;
    color: #374151;
  }

  /* ---- pagination ------------------------------------------------------ */
  .pagination-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    text-align: center;
  }

  .pagination-bar > div {
    margin: 0 !important;
    display: flex;
    justify-content: center;
  }

  .pagination-bar nav {
    width: 100%;
    justify-content: center;
  }

  /* Modals: let them use the full screen height on a phone. */
  #grImportInfoModal > div,
  #linkedGrImportInfoModal > div {
    margin: 0.75rem !important;
    max-height: 88vh !important;
  }

  #grImportInfoModal table,
  #linkedGrImportInfoModal table {
    font-size: 0.72rem !important;
  }

  #grImportInfoModal td,
  #grImportInfoModal th,
  #linkedGrImportInfoModal td,
  #linkedGrImportInfoModal th {
    padding: 6px 8px !important;
  }

  .modal-scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ===========================================================================
   4. GENERAL REGISTER — add / edit form
   =========================================================================== */

.form-tabs {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
  gap: 1rem;
}

.form-grid > .span-1 {
  grid-column: span 1 / span 1;
}

.form-grid > .span-2 {
  grid-column: span 2 / span 2;
}

.form-grid > .span-3 {
  grid-column: span 3 / span 3;
}

.form-grid > .span-full {
  grid-column: 1 / -1;
}

/* Tablets: never more than two columns. */
@media (max-width: 1023px) {
  .form-grid {
    grid-template-columns: repeat(min(var(--cols, 4), 2), minmax(0, 1fr));
  }

  .form-grid > .span-3,
  .form-grid > .span-2 {
    grid-column: 1 / -1;
  }
}

@media (max-width: 639px) {
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .form-grid > .span-1,
  .form-grid > .span-2,
  .form-grid > .span-3,
  .form-grid > .span-full {
    grid-column: 1 / -1;
  }
}

@media (max-width: 767px) {
  .form-header {
    padding: 1rem !important;
  }

  .form-header h2 {
    font-size: 1.35rem !important;
    margin-bottom: 0.9rem !important;
  }

  /* Tabs scroll sideways instead of wrapping into a tall stack. */
  .form-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.5rem;
    padding-bottom: 0.35rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .form-tabs::-webkit-scrollbar {
    display: none;
  }

  .form-tabs li {
    flex: 0 0 auto;
  }

  .form-tabs .tab-button {
    padding: 0.55rem 0.9rem !important;
    font-size: 0.82rem !important;
    white-space: nowrap;
  }

  .form-body {
    padding: 1rem !important;
  }

  /* Comfortable touch targets for every input crispy renders. */
  .form-body input[type="text"],
  .form-body input[type="number"],
  .form-body input[type="date"],
  .form-body input[type="email"],
  .form-body input[type="tel"],
  .form-body select,
  .form-body textarea {
    font-size: 16px; /* stops iOS Safari zooming on focus */
    min-height: 2.75rem;
  }

  .form-body .select2-container {
    width: 100% !important;
  }

  /* overflow-hidden on the card would kill `position: sticky` below. */
  .form-card {
    overflow: visible !important;
  }

  /* Sticky save bar so the admin never has to scroll back up. */
  .form-actions {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    padding: 0.75rem 1rem;
    margin: 0 -1rem -1rem;
    display: flex;
    gap: 0.6rem;
    z-index: 20;
  }

  .form-actions button {
    flex: 1 1 0;
    padding: 0.8rem 0.5rem !important;
  }

  .copy-info-panel-results {
    max-height: 40vh;
    overflow-y: auto;
  }
}

/* ===========================================================================
   5. DASHBOARD / HOME
   =========================================================================== */

.quick-actions-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

@media (min-width: 640px) {
  .quick-actions-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 768px) {
  .quick-actions-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .quick-actions-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

.reports-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem;
}

@media (min-width: 640px) {
  .reports-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .reports-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  .page-title {
    font-size: 1.75rem !important;
    margin-bottom: 1rem !important;
  }

  .card-pad {
    padding: 1rem !important;
  }

  .section-title {
    font-size: 1.15rem !important;
  }

  .quick-actions-grid {
    gap: 0.6rem;
  }

  .quick-actions-grid a {
    padding: 0.85rem 0.4rem !important;
  }

  .quick-actions-grid svg {
    width: 1.6rem !important;
    height: 1.6rem !important;
  }

  .quick-actions-grid span {
    font-size: 0.78rem !important;
    line-height: 1.25;
  }

  .reports-grid {
    gap: 0.85rem;
  }

  .reports-grid > div {
    padding: 1.1rem !important;
  }

  .reports-grid h3 {
    font-size: 1.05rem !important;
  }

  .reports-grid p {
    font-size: 0.85rem;
    margin-bottom: 0.9rem !important;
  }

  .reports-grid svg {
    width: 1.6rem !important;
    height: 1.6rem !important;
  }
}

/* ===========================================================================
   6. CLASS LIST (/student/)
   =========================================================================== */

/* The standard pills used `flex-auto`, which stretched a lone trailing pill
   across the whole row. Size them to their content instead. */
.std-tabs li {
  flex: 0 1 auto;
}

.std-tabs .tab {
  min-width: 4rem;
}

@media (max-width: 767px) {
  .class-head,
  .class-body {
    padding: 1rem !important;
  }

  .class-head h3 {
    font-size: 1.05rem !important;
  }

  /* One swipeable strip beats five stacked rows of pills. */
  .std-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.4rem;
    padding-bottom: 0.35rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .std-tabs::-webkit-scrollbar {
    display: none;
  }

  .std-tabs li {
    flex: 0 0 auto;
  }

  .std-tabs .tab {
    padding: 0.5rem 0.9rem !important;
    font-size: 0.875rem;
    min-width: 3rem;
  }

  /* Stat cards: one compact label/number row each. */
  .class-stats {
    gap: 0.6rem !important;
  }

  .class-stats > div {
    padding: 0.85rem 1rem !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .class-stats > div > span {
    font-size: 0.9rem !important;
  }

  .class-stats > div > p {
    font-size: 1.5rem !important;
    margin-top: 0 !important;
  }

  /* ---- toolbar --------------------------------------------------------- */
  .class-toolbar {
    align-items: stretch !important;
    gap: 0.6rem !important;
  }

  .class-toolbar > a,
  .class-toolbar > button {
    width: 100%;
    text-align: center;
  }

  .class-toolbar form {
    width: 100%;
    flex-wrap: wrap;
  }

  .class-filter-form select {
    flex: 1 1 auto;
    min-height: 2.6rem;
  }

  .class-filter-form button {
    flex: 0 0 auto;
  }

  .class-import-form input[type="file"] {
    flex: 1 1 100%;
    font-size: 0.8rem;
  }

  .class-import-form button[type="submit"] {
    flex: 1 1 auto;
  }

  /* ---- DataTables chrome ---------------------------------------------- */
  .dataTables_wrapper .dt-buttons {
    float: none !important;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    width: 100%;
  }

  .dataTables_wrapper .dt-button {
    margin: 0 !important;
    flex: 1 1 auto;
    text-align: center;
  }

  .dataTables_wrapper .dataTables_filter {
    float: none !important;
    text-align: left !important;
    width: 100%;
    margin-top: 0.6rem;
  }

  .dataTables_wrapper .dataTables_filter label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    font-size: 0.85rem;
  }

  .dataTables_wrapper .dataTables_filter input {
    flex: 1 1 auto;
    margin-left: 0 !important;
    min-height: 2.6rem;
    font-size: 16px; /* no iOS zoom-on-focus */
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    padding: 0 0.6rem;
    width: auto;
  }

  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    float: none !important;
    text-align: center !important;
    width: 100%;
  }

  .dataTables_wrapper .dataTables_paginate {
    padding-top: 0.5rem;
  }

  .dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.4rem 0.7rem !important;
  }

  /* ---- table -> cards -------------------------------------------------- */
  .st-table-wrap {
    overflow: visible !important;
  }

  .st-table {
    width: 100% !important;
    box-shadow: none !important;
    background: transparent !important;
  }

  .st-table,
  .st-table tbody,
  .st-table tr {
    display: block;
    width: 100% !important;
  }

  .st-table thead {
    display: none !important;
  }

  .st-table tbody {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .st-table tr {
    display: flex;
    flex-wrap: wrap;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
    overflow: hidden;
  }

  .st-table td {
    position: static !important;
    display: flex;
    flex: 0 0 100%;
    /* DataTables' stylesheet forces content-box on cells, which makes a
       flex-basis of 100% overflow by the cell's own padding */
    box-sizing: border-box !important;
    /* without this the cell refuses to shrink below its min-content width
       and the value overflows the card */
    min-width: 0;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.4rem 0.9rem !important;
    text-align: right !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
    font-size: 0.85rem;
  }

  .st-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    font-size: 0.75rem;
    text-align: left;
    flex: 0 1 45%;
    min-width: 0;
    line-height: 1.35;
  }

  /* Card header — tap anywhere on it to reveal the rest. */
  .st-table td.st-col-grno {
    background: #f8fafc;
    border-bottom: 1px solid #eef2f7;
    padding: 0.65rem 0.9rem !important;
    font-size: 1rem;
    font-weight: 700;
    align-items: center;
    cursor: pointer;
  }

  .st-table td.st-col-grno::before {
    font-size: 0.75rem;
  }

  .st-table td.st-col-grno::after {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    margin-left: 0.6rem;
    flex: 0 0 auto;
    border-right: 2px solid #9ca3af;
    border-bottom: 2px solid #9ca3af;
    transform: translateY(-2px) rotate(45deg);
    transition: transform 0.2s ease;
  }

  .st-table tr.expanded td.st-col-grno::after {
    transform: translateY(2px) rotate(225deg);
  }

  .st-table td.st-col-extra {
    display: none;
  }

  .st-table tr.expanded td.st-col-extra {
    display: flex;
  }

  /* Edit / Delete share one footer row. */
  .st-table td.st-col-action {
    flex: 1 1 0;
    justify-content: center;
    border-top: 1px solid #eef2f7;
    background: #fafbfc;
    padding: 0.7rem 0.5rem !important;
    font-weight: 600;
  }

  .st-table td.st-col-action::before {
    content: none;
  }

  .st-table td.st-col-action + td.st-col-action {
    border-left: 1px solid #eef2f7;
  }

  /* ---- modals ---------------------------------------------------------- */
  #importInfoModal > div,
  #promoteModal > div {
    margin: 0.6rem !important;
    max-height: 92vh !important;
  }

  #importInfoModal table {
    font-size: 0.72rem !important;
  }

  #importInfoModal td,
  #importInfoModal th {
    padding: 6px 8px !important;
  }

  #promoteModal #modalFooter {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 12px 16px !important;
  }

  #promoteModal #modalFooter > div:last-child {
    flex: 1 1 100%;
  }

  #promoteModal #modalFooter > div:last-child button {
    flex: 1 1 0;
  }
}

/* ===========================================================================
   7. CLASS ENROLMENT FORM (/student/add/)
   =========================================================================== */

@media (max-width: 767px) {
  .student-form-body {
    padding: 1rem !important;
  }

  /* The fields sit in a centred w-3/4 box — too narrow on a phone. */
  .student-field > div {
    width: 100% !important;
  }

  .student-form-body input[type="text"],
  .student-form-body input[type="number"],
  .student-form-body input[type="date"],
  .student-form-body select,
  .student-form-body textarea {
    font-size: 16px;
    min-height: 2.75rem;
  }

  .student-form-body .select2-container {
    width: 100% !important;
  }

  .student-form-actions {
    padding: 0.85rem 1rem !important;
    gap: 0.6rem;
  }

  .student-form-actions button {
    width: 100% !important;
    padding-top: 0.8rem !important;
    padding-bottom: 0.8rem !important;
    /* the card uses space-x-4; gap already separates them */
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

/* ===========================================================================
   8. EXAM MODULE  (/exam/, /result9–12/, /result-notes/, subject selection)
   ---------------------------------------------------------------------------
   Every screen template under student/templates/exam/ sets
   {% block page_class %}exam-page{% endblock %}, so these rules are scoped to
   the module. The standalone print/PDF layouts (bulk sheets, certificates,
   *-result.html) do not extend _base.html and are deliberately untouched —
   they are fixed A4 pages.

   Mark-entry and mark-list grids stay TABLES on mobile. Entering marks means
   running along a row of subjects, so a card layout would break the task;
   instead the table scrolls sideways with the roll-no/name column pinned.
   =========================================================================== */

/* Pinned first column needs an opaque background and a stacking order, or the
   inputs in the columns scrolling underneath paint on top of it. Tailwind's
   `z-10` is not in the purged build, so set it here. */
.exam-page table td.sticky,
.exam-page table th.sticky {
  background-color: #fff;
  z-index: 3;
}

.exam-page table thead th.sticky {
  z-index: 4;
}

@media (max-width: 767px) {
  /* ---- page chrome ----------------------------------------------------- */
  .exam-page .container,
  .exam-page .container-fluid {
    padding-left: 0 !important;
    padding-right: 0 !important;
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
    margin-top: 0 !important;
  }

  .exam-page h1 {
    font-size: 1.4rem !important;
  }

  .exam-page h2 {
    font-size: 1.2rem !important;
    margin-bottom: 1rem !important;
  }

  .exam-page h3 {
    font-size: 1.05rem !important;
  }

  .exam-page h4,
  .exam-page h5 {
    font-size: 0.95rem !important;
  }

  /* Cards that were sized to content or to a fraction of the page. */
  .exam-page .w-2\/3,
  .exam-page .w-3\/4,
  .exam-page .w-1\/2,
  .exam-page .max-w-3xl,
  .exam-page .max-w-2xl,
  .exam-page .max-w-xl {
    width: 100% !important;
    max-width: 100% !important;
  }

  .exam-page .p-6 {
    padding: 1rem !important;
  }

  .exam-page .py-8 {
    padding-top: 1rem !important;
    padding-bottom: 1rem !important;
  }

  /* ---- toolbars -------------------------------------------------------- */
  .exam-page .flex.justify-between,
  .exam-page .flex.justify-end {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* …but button clusters inside a table cell stay on one line. */
  .exam-page td .flex,
  .exam-page th .flex {
    flex-wrap: nowrap;
  }

  .exam-page .mb-8 {
    margin-bottom: 1rem !important;
  }

  /* ---- layout grids collapse; small stat tiles keep two columns -------- */
  .exam-page .grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 0.75rem !important;
    /* several of these grids are flex items, which would otherwise shrink to
       their content and leave a ragged right gutter */
    width: 100%;
  }

  .exam-page .stat-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .exam-page .stat-tiles > div {
    padding: 0.6rem !important;
  }

  /* ---- wide tables ----------------------------------------------------- */
  .exam-page .overflow-x-auto,
  .exam-page .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* A thin always-visible scrollbar: otherwise there is no hint that the
     table scrolls sideways. */
  .exam-page .overflow-x-auto::-webkit-scrollbar,
  .exam-page .table-container::-webkit-scrollbar {
    height: 6px;
  }

  .exam-page .overflow-x-auto::-webkit-scrollbar-thumb,
  .exam-page .table-container::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 3px;
  }

  .exam-page table {
    font-size: 0.78rem;
  }

  .exam-page table th,
  .exam-page table td {
    padding: 0.4rem 0.5rem !important;
  }

  .exam-page table th {
    font-size: 0.68rem;
  }

  /* ---- mark inputs: tappable, and no iOS zoom-on-focus ----------------- */
  .exam-page input[type="text"],
  .exam-page input[type="number"],
  .exam-page input[type="date"],
  .exam-page select,
  .exam-page textarea {
    font-size: 16px;
    min-height: 2.5rem;
  }

  .exam-page table input[type="text"],
  .exam-page table input[type="number"] {
    min-height: 2.25rem;
    min-width: 3.5rem;
    padding: 0.2rem 0.35rem !important;
    text-align: center;
  }

  .exam-page .select2-container {
    width: 100% !important;
  }

  /* ---- buttons --------------------------------------------------------- */
  .exam-page button,
  .exam-page a.inline-flex,
  .exam-page a[class*="rounded"] {
    min-height: 2.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Submit bars that were right- or centre-aligned become full width. */
  .exam-page .text-right > button[type="submit"],
  .exam-page .text-center > button[type="submit"],
  .exam-page .text-right > button[form],
  .exam-page .text-center > button[form] {
    width: 100%;
    margin-right: 0 !important;
  }

  /* Icon-only links inside tables must not inherit the min-height block. */
  .exam-page table a[class*="rounded"] {
    min-height: 0;
    display: inline;
  }

  /* ---- standards index (/exam/result-standard-list/) ------------------- */
  .exam-page .divide-y > li {
    flex-direction: column;
    align-items: stretch !important;
    gap: 0.6rem !important;
    padding: 0.85rem 1rem !important;
    overflow: visible !important;
  }

  .exam-page .divide-y > li > span {
    font-weight: 700;
    font-size: 1rem;
  }

  .exam-page .divide-y > li > div {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.5rem !important;
    width: 100%;
  }

  .exam-page .divide-y > li > div > a {
    width: 100%;
    justify-content: center;
  }
}

/* The standards index card is centred and sized to its content; let it fill
   the screen on a phone. */
@media (max-width: 767px) {
  .exam-page > .flex.justify-center {
    display: block;
  }

  .exam-page > .flex.justify-center > div {
    width: 100%;
  }
}

/* ===========================================================================
   8b. EXAM LIST (/exam/) — table becomes cards
   =========================================================================== */

.ex-card-head {
  display: none;
}

@media (max-width: 767px) {
  .ex-table-wrap {
    overflow: visible !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  .ex-table,
  .ex-table tbody,
  .ex-table tr {
    display: block;
    width: 100%;
  }

  .ex-table thead {
    display: none;
  }

  .ex-table tbody {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .ex-table tr {
    display: flex;
    flex-wrap: wrap;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
    overflow: hidden;
  }

  .ex-table td {
    box-sizing: border-box !important;
    display: flex;
    flex: 0 0 100%;
    min-width: 0;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.4rem 0.9rem !important;
    text-align: right !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
    font-size: 0.85rem;
  }

  .ex-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    font-size: 0.75rem;
    text-align: left;
    flex: 0 1 45%;
    min-width: 0;
    line-height: 1.35;
  }

  .ex-table td.ex-col-id {
    background: #f8fafc;
    border-bottom: 1px solid #eef2f7;
    padding: 0.6rem 0.9rem !important;
    font-size: 0.95rem;
    font-weight: 700;
    align-items: center;
  }

  .ex-table td.ex-col-action {
    flex: 1 1 0;
    justify-content: center;
    border-top: 1px solid #eef2f7;
    background: #fafbfc;
    padding: 0.6rem 0.5rem !important;
  }

  .ex-table td.ex-col-action::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 0.72rem;
    margin-right: 0.4rem;
  }

  .ex-table td.ex-col-action + td.ex-col-action {
    border-left: 1px solid #eef2f7;
  }

  /* The action cluster mixes bare links, a form-wrapped button and differently
     sized icons — normalise them into one evenly spaced row. */
  .ex-table td.ex-col-action .flex {
    justify-content: center;
    align-items: center;
    gap: 0.6rem;
  }

  .ex-table td.ex-col-action .flex > a,
  .ex-table td.ex-col-action .flex button {
    width: 1.75rem !important;
    height: 1.75rem;
    margin: 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
  }

  .ex-table td.ex-col-action .flex form {
    margin: 0;
    display: inline-flex;
    align-items: center;
  }

  .ex-table td.ex-col-action svg {
    width: 1.25rem !important;
    height: 1.25rem !important;
  }
}

/* ===========================================================================
   9. STANDARD REPORT (/reports/standard/)
   =========================================================================== */

/* The total card is a hard w-1/2. That is fine on a desktop but cramped on a
   tablet, so cap it below lg; desktop keeps the original 50%. */
@media (max-width: 1023px) {
  .report-total-card {
    max-width: 32rem;
  }
}

@media (max-width: 767px) {
  .report-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: #1f2937;
  }

  .report-shell {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .report-shell > .p-4,
  .report-std-grid {
    padding: 0.75rem !important;
  }

  .report-title {
    padding-top: 0.9rem !important;
  }

  .report-total-card {
    width: 100% !important;
    max-width: 100%;
    margin-top: 0 !important;
    padding: 0.9rem !important;
  }

  .report-std-grid {
    gap: 0.75rem !important;
  }

  .report-std-grid > div {
    padding: 0.9rem !important;
  }

  .report-page h3 {
    font-size: 1rem !important;
  }

  /* Three compact figures still read fine side by side at phone width. */
  .report-page .grid-cols-3 > div > span {
    font-size: 0.72rem !important;
    display: block;
    line-height: 1.2;
  }

  .report-page .grid-cols-3 > div > p {
    font-size: 1.15rem !important;
  }

  /* Chart.js keeps its own 2:1 ratio; just stop the canvas overflowing. */
  .report-page canvas {
    max-width: 100% !important;
    height: auto !important;
  }
}

/* ===========================================================================
   10. PAYMENT (/payment/)
   =========================================================================== */

/* Was a hard-coded w-[700px], which overflowed every phone. */
.pay-filter-card {
  width: 100%;
  max-width: 700px;
}

@media (max-width: 767px) {
  .pay-shell {
    padding: 0.75rem 0 !important;
  }

  .pay-header {
    font-size: 1.15rem !important;
    padding: 0.9rem 1rem !important;
  }

  .pay-body,
  .pay-history {
    padding: 1rem !important;
  }

  /* This page nests a second .container inside the card — drop its padding
     rather than paying for the gutter twice. */
  .pay-history-inner {
    padding: 0 !important;
  }

  .pay-title {
    font-size: 1.3rem !important;
    margin-bottom: 1rem !important;
  }

  /* ---- GR search ------------------------------------------------------- */
  .pay-search-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }

  .pay-search-row > div {
    margin-left: 0 !important;
  }

  .pay-search-btn {
    width: 100%;
    justify-content: center;
  }

  /* ---- date filter ----------------------------------------------------- */
  .pay-filter-card {
    padding: 0.85rem !important;
    margin-bottom: 1.25rem !important;
  }

  .pay-filter-form {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
  }

  .pay-filter-form > * {
    margin-left: 0 !important;
  }

  .pay-filter-form > div.flex-grow {
    grid-column: 1 / -1;
  }

  .pay-filter-sep {
    display: none; /* the two date fields are stacked and self-evident */
  }

  .pay-filter-form button {
    justify-content: center;
  }

  /* ---- the fee rows jQuery builds after a GR search -------------------- */
  .pay-body #fees_form .w-3\/5 {
    width: 60%;
  }

  .pay-body #fees_form .w-2\/5 {
    width: 40%;
  }

  .pay-body input[type="text"],
  .pay-body input[type="date"] {
    font-size: 16px; /* no iOS zoom-on-focus */
    min-height: 2.6rem;
  }

  /* ---- fee history table -> cards -------------------------------------- */
  .pay-table-wrap {
    overflow: visible !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  .pay-table,
  .pay-table tbody,
  .pay-table tr {
    display: block;
    width: 100%;
  }

  .pay-table thead {
    display: none;
  }

  .pay-table tbody {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .pay-table tr {
    display: flex;
    flex-wrap: wrap;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
    overflow: hidden;
  }

  .pay-table td {
    box-sizing: border-box !important;
    display: flex;
    flex: 0 0 100%;
    min-width: 0;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    border: 0 !important;
    padding: 0.4rem 0.9rem !important;
    text-align: right !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
    font-size: 0.85rem;
  }

  .pay-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    font-size: 0.75rem;
    text-align: left;
    flex: 0 1 45%;
    min-width: 0;
    line-height: 1.35;
  }

  .pay-table td.pay-col-date {
    background: #f8fafc;
    border-bottom: 1px solid #eef2f7 !important;
    padding: 0.6rem 0.9rem !important;
    font-size: 0.95rem;
    font-weight: 700;
    align-items: center;
  }

  .pay-table td.pay-col-amount {
    font-weight: 700;
    color: #065f46;
  }

  .pay-table td.pay-col-action {
    flex: 1 1 0;
    justify-content: center;
    border-top: 1px solid #eef2f7 !important;
    background: #fafbfc;
    padding: 0.55rem 0.5rem !important;
  }

  .pay-table td.pay-col-action::before {
    content: none;
  }

  .pay-table td.pay-col-action + td.pay-col-action {
    border-left: 1px solid #eef2f7 !important;
  }

  .pay-table td.pay-col-action a {
    font-weight: 600;
  }

  .pay-table td.pay-col-action button {
    padding: 0.35rem 1rem !important;
    width: 100%;
  }
}

/* ===========================================================================
   11. SETTINGS MODULE (/settings/ and everything under it)
   ---------------------------------------------------------------------------
   All 11 screens set {% block page_class %}settings-page{% endblock %}.
   The lists are small (3-5 columns) so they become cards on a phone rather
   than scrolling sideways.
   =========================================================================== */

/* The delete-user modal was a hard w-96 (384px) — wider than a small phone. */
.set-modal-box {
  width: 100%;
  max-width: 24rem;
}

@media (max-width: 767px) {
  /* ---- page chrome ----------------------------------------------------- */
  .set-shell,
  .set-form-shell {
    padding-left: 0 !important;
    padding-right: 0 !important;
    padding-top: 0.5rem !important;
    padding-bottom: 1rem !important;
  }

  .settings-page h1 {
    font-size: 1.5rem !important;
    margin-bottom: 1rem !important;
  }

  .settings-page h2 {
    font-size: 1.2rem !important;
    margin-bottom: 0.75rem !important;
  }

  .settings-page h3 {
    font-size: 1.05rem !important;
  }

  /* Title + action button on one line is too tight at phone width. */
  .set-head,
  .set-card-head {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.75rem;
    margin-bottom: 1.25rem !important;
  }

  .set-head > a,
  .set-head > a > button,
  .set-card-head > button {
    width: 100%;
    justify-content: center;
  }

  .set-card-head {
    padding: 1rem !important;
  }

  /* ---- hub cards ------------------------------------------------------- */
  .set-cards {
    gap: 0.75rem !important;
    margin-bottom: 1.25rem !important;
  }

  .set-cards > div {
    padding: 1rem !important;
  }

  .set-cards p {
    font-size: 0.85rem;
    margin-bottom: 0.9rem !important;
  }

  .set-cards a,
  .set-cards button {
    width: 100%;
  }

  .set-add-user {
    justify-content: stretch;
  }

  .set-add-user > a,
  .set-add-user button {
    width: 100%;
  }

  .settings-page .bg-white.rounded-lg.shadow-md.p-6 {
    padding: 1rem !important;
  }

  /* ---- standard-subject filters --------------------------------------- */
  /* One swipeable strip of standard pills beats five stacked rows. */
  .settings-page .flex-grow.flex.flex-wrap.gap-2 {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.4rem;
    padding-bottom: 0.35rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .settings-page .flex-grow.flex.flex-wrap.gap-2::-webkit-scrollbar {
    display: none;
  }

  .settings-page .flex-grow.flex.flex-wrap.gap-2 > a {
    flex: 0 0 auto;
    padding: 0.4rem 0.85rem !important;
  }

  .settings-page .justify-end.gap-6 {
    justify-content: flex-start !important;
    flex-wrap: wrap;
    gap: 0.75rem !important;
    padding: 0.75rem !important;
  }

  /* ---- list tables -> cards ------------------------------------------- */
  .set-table-wrap {
    overflow: visible !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  .set-table,
  .set-table tbody,
  .set-table tr {
    display: block;
    width: 100%;
    min-width: 0 !important;
  }

  .set-table thead {
    display: none;
  }

  .set-table tbody {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .set-table tr {
    display: flex;
    flex-wrap: wrap;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
    overflow: hidden;
  }

  .set-table td {
    box-sizing: border-box !important;
    display: flex;
    flex: 0 0 100%;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.45rem 0.9rem !important;
    text-align: right !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  .set-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    font-size: 0.75rem;
    text-align: left;
    flex: 0 1 45%;
    min-width: 0;
    line-height: 1.35;
  }

  .set-table td.set-col-main {
    background: #f8fafc;
    border-bottom: 1px solid #eef2f7;
    padding: 0.6rem 0.9rem !important;
    font-size: 0.95rem;
    font-weight: 700;
  }

  .set-table td.set-col-action {
    justify-content: flex-end;
    border-top: 1px solid #eef2f7;
    background: #fafbfc;
    padding: 0.55rem 0.9rem !important;
  }

  .set-table td.set-col-action::before {
    content: none;
  }

  .set-table td.set-col-action > div,
  .set-table td.set-col-action .flex {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: nowrap;
  }

  .set-table td.set-col-action form {
    display: inline-flex;
    align-items: center;
    margin: 0 !important;
  }

  .set-table td.set-col-action button {
    width: auto !important;
    margin: 0 !important;
  }

  .set-table td.set-col-action svg {
    width: 1.15rem;
    height: 1.15rem;
  }

  .set-table td.set-col-empty {
    justify-content: center;
    text-align: center !important;
  }

  .set-table td.set-col-empty::before {
    content: none;
  }

  /* ---- forms ----------------------------------------------------------- */
  .set-form-title {
    font-size: 1.5rem !important;
    margin-bottom: 1rem !important;
  }

  .set-form-card {
    padding: 1rem !important;
    max-width: 100% !important;
  }

  .set-form-banner {
    padding: 1rem !important;
  }

  .settings-page input[type="text"],
  .settings-page input[type="email"],
  .settings-page input[type="password"],
  .settings-page input[type="number"],
  .settings-page select,
  .settings-page textarea {
    font-size: 16px; /* stops iOS Safari zooming on focus */
    min-height: 2.75rem;
  }

  .settings-page form button[type="submit"] {
    padding-top: 0.8rem !important;
    padding-bottom: 0.8rem !important;
    font-size: 1rem !important;
  }

  /* ---- user permissions ------------------------------------------------ */
  .set-perm-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }

  .set-perm-actions button {
    width: 100%;
  }

  .set-modal-box {
    top: 1.5rem !important;
    margin-left: 0.75rem !important;
    margin-right: 0.75rem !important;
    width: auto !important;
    padding: 1rem !important;
  }

  .set-modal-box .flex.justify-end {
    flex-direction: column-reverse;
    gap: 0.5rem;
  }

  .set-modal-box .flex.justify-end > button {
    width: 100%;
    margin: 0 !important;
  }
}

/* ===========================================================================
   12. CERTIFICATE SEARCH (/certificate/)
   ---------------------------------------------------------------------------
   Only the search screen. The certificates it links to (school/birth.html and
   school/bonafide.html) are standalone print documents that do not extend
   _base.html, never load this stylesheet, and are deliberately untouched.
   =========================================================================== */

@media (max-width: 767px) {
  .cert-shell {
    padding-left: 0 !important;
    padding-right: 0 !important;
    padding-top: 0.5rem !important;
    padding-bottom: 1rem !important;
  }

  .cert-title {
    font-size: 1.5rem !important;
    margin-bottom: 1rem !important;
  }

  .cert-card {
    padding: 1rem !important;
    margin-bottom: 1rem !important;
  }

  .certificate-page h2 {
    font-size: 1.05rem !important;
    margin-bottom: 0.75rem !important;
  }

  .certificate-page .step {
    align-items: flex-start;
    margin-bottom: 0.75rem;
  }

  .certificate-page .step-number {
    width: 26px;
    height: 26px;
    font-size: 0.85rem;
    margin-right: 0.7rem;
    flex: 0 0 auto;
  }

  .certificate-page .step-text {
    font-size: 0.875rem;
    line-height: 1.4;
  }

  /* Language on its own row, then the three name positions two-up. */
  .cert-options-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.6rem !important;
  }

  .cert-options-grid > div:first-child {
    grid-column: 1 / -1;
  }

  .cert-options-grid label {
    font-size: 0.78rem;
    margin-bottom: 0.25rem;
  }

  .certificate-page select,
  .certificate-page input[type="text"] {
    font-size: 16px; /* stops iOS Safari zooming on focus */
    min-height: 2.75rem;
  }

  .certificate-page .text-sm.text-gray-500 {
    font-size: 0.78rem;
  }

  /* ---- results table -> cards ----------------------------------------- */
  .cert-table-wrap {
    overflow: visible !important;
    box-shadow: none !important;
  }

  /* The table starts hidden and jQuery toggles `hidden`; this rule set is
     later in the cascade than Tailwind's .hidden, so restore it explicitly. */
  .cert-table.hidden {
    display: none !important;
  }

  .cert-table,
  .cert-table tbody,
  .cert-table tr {
    display: block;
    width: 100%;
  }

  .cert-table thead {
    display: none;
  }

  .cert-table tbody {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .cert-table tr {
    display: block;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
    overflow: hidden;
  }

  .cert-table td {
    box-sizing: border-box !important;
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.5rem 0.9rem !important;
    text-align: right;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .cert-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    font-size: 0.75rem;
    text-align: left;
    flex: 0 1 40%;
    min-width: 0;
  }

  .cert-table td.cert-col-grno {
    background: #f8fafc;
    border-bottom: 1px solid #eef2f7;
    font-size: 0.95rem;
    font-weight: 700;
  }

  /* Two full-width certificate buttons, stacked. */
  .cert-table td.cert-col-action {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    border-top: 1px solid #eef2f7;
    background: #fafbfc;
    padding: 0.7rem 0.9rem !important;
  }

  .cert-table td.cert-col-action::before {
    content: none;
  }

  .cert-table td.cert-col-action > a {
    display: block;
    width: 100%;
  }

  .cert-table td.cert-col-action button {
    width: 100%;
    margin: 0 !important;
    padding-top: 0.7rem !important;
    padding-bottom: 0.7rem !important;
  }
}

/* ===========================================================================
   13. BACK BUTTONS
   ---------------------------------------------------------------------------
   Added to the drill-down pages that had none. Top-level pages reachable from
   the sidebar (Home, General Register, Class, Exam, Settings, Payment) keep no
   back button — the sidebar is their navigation.
   =========================================================================== */

.page-back {
  min-height: 2.5rem;
}

/* Line the report's back button up with its card, which is inset by ml-10. */
.report-page .page-back {
  margin-left: 2.5rem;
}

@media (max-width: 767px) {
  .page-back {
    width: 100%;
    justify-content: center;
  }

  .report-page .page-back {
    margin-left: 0;
  }
}
