/* public/assets/css/responsive-tables.css
 *
 * Turns ordinary data-listing tables into stacked "cards" on small screens
 * instead of forcing the user to scroll a squeezed table sideways. Desktop
 * and tablet views are untouched — the table renders exactly as it always
 * has above the breakpoint.
 *
 * How it's applied: responsive-tables.js scans the page on load, decides
 * which <table> elements are safe to transform (plain single-row headers,
 * no data-no-responsive opt-out), and tags them with the `.rtable` class
 * plus a `data-label` attribute on every <td> copied from its column's
 * header. This file only styles tables carrying that `.rtable` class, so a
 * table the script skipped (e.g. a multi-row pivot/results grid) keeps its
 * normal horizontal-scroll fallback automatically — nothing here can break
 * markup it never touched.
 *
 * Card visuals intentionally reuse the app's existing tokens: the same
 * --primary-color/--secondary-color CSS vars every layout already defines,
 * and the same white/rounded/shadow language as .stat-card in dashboard.php.
 */

@media (max-width: 768px) {
  table.rtable,
  table.rtable tbody,
  table.rtable tbody tr,
  table.rtable tbody td {
    box-sizing: border-box !important;
  }

  table.rtable {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    border: none !important;
    border-collapse: separate;
  }

  table.rtable thead {
    display: none !important;
  }

  table.rtable tbody {
    display: block;
    width: 100% !important;
  }

  table.rtable tbody tr {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-bottom: 12px;
    overflow: hidden;
    box-sizing: border-box !important;
  }

  table.rtable tbody tr:last-child {
    margin-bottom: 0;
  }

  /* Card Header / First Column (e.g. Student Name & Avatar) */
  table.rtable tbody td:first-child {
    display: block !important;
    width: 100% !important;
    background-color: #f8fafc !important;
    border-bottom: 1px solid #e2e8f0 !important;
    padding: 12px 14px !important;
    text-align: left !important;
    box-sizing: border-box !important;
  }

  /* Hide duplicate label on card header (first child) */
  table.rtable tbody td:first-child[data-label]::before {
    display: none !important;
  }

  /* Regular field rows inside the card (data-label fields) */
  table.rtable tbody td:not(:first-child) {
    position: relative;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 2.5rem;
    padding: 10px 14px !important;
    border-bottom: 1px solid #f0f2f1;
    font-size: 0.8125rem;
    box-sizing: border-box !important;
  }

  table.rtable tbody td:last-of-type {
    border-bottom: none;
  }

  /* Field label on the left */
  table.rtable tbody td:not(:first-child)[data-label]::before {
    content: attr(data-label);
    position: static !important;
    display: inline-block !important;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--secondary-color, #164346);
    text-align: left;
    white-space: normal;
    min-width: 90px;
    max-width: 45%;
    margin-right: 8px;
    flex-shrink: 0;
  }

  /* Field value on the right */
  table.rtable tbody td:not(:first-child) {
    text-align: right;
  }

  table.rtable tbody td:not(:first-child) > * {
    max-width: 100%;
  }

  /* Actions Footer Strip */
  table.rtable tbody td.rtable-actions {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 8px;
    background: #f8faf9;
    padding: 10px 14px !important;
    text-align: right !important;
    border-top: 1px solid #e2e8f0;
  }

  table.rtable tbody td.rtable-actions::before {
    content: none !important;
    display: none !important;
  }

  table.rtable tbody tr.opacity-60 {
    opacity: 0.7;
  }
}
