/* ============================================================
   BBS — ملاءمة الهاتف: كل المعلومات داخل الشاشة بلا تمرير جانبي
   يُحمَّل بعد app.css. الجداول تتحول على الهاتف إلى بطاقات
   (الأسماء تأتي من رؤوس الأعمدة عبر mobile-fit.js).
   لإبقاء جدول معيّن كما هو أضف إليه الصنف no-stack.
   ============================================================ */

img, video, canvas, svg { max-width: 100%; }
img, video { height: auto; }
input, select, textarea, button { max-width: 100%; }
.content, .sheet, .card, .stat { min-width: 0; }
td, th, .badge, .btn, h1, h2, h3, p, a { overflow-wrap: break-word; }

@media (max-width: 48rem) {
  html, body { max-width: 100%; overflow-x: hidden; }
  .shell { padding-inline: 0.7rem; align-items: stretch; }
  .content { width: 100%; }
  .table-wrap { overflow: visible; }
  pre, pre.trace { white-space: pre-wrap; word-break: break-word; }

  /* ── الجدول العادي → بطاقات ── */
  table:not(.no-stack),
  table:not(.no-stack) tbody,
  table:not(.no-stack) tr,
  table:not(.no-stack) td { display: block; width: 100%; }

  table:not(.no-stack) thead {
    position: absolute; inline-size: 1px; block-size: 1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  table:not(.no-stack) tr {
    background: var(--surface, #fff);
    border: 1px solid var(--line, #dfe5e3);
    border-radius: var(--radius, 10px);
    margin-block-end: 0.7rem;
    padding: 0.2rem 0;
  }
  table:not(.no-stack) tbody tr:hover { background: var(--surface, #fff); }
  table:not(.no-stack) td {
    display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
    gap: 0.3rem 0.8rem;
    padding: 0.45rem 0.8rem;
    border: 0;
    border-block-end: 1px dashed var(--line, #dfe5e3);
    text-align: end;
    white-space: normal;
  }
  table:not(.no-stack) td { unicode-bidi: plaintext; }
  table:not(.no-stack) td:last-child { border-block-end: 0; }
  table:not(.no-stack) td::before {
    content: attr(data-label);
    flex: none; max-width: 48%;
    color: var(--ink-3, #6b7a77); font-size: 0.76rem; font-weight: 500; text-align: start;
  }
  table:not(.no-stack) td[data-label=""]::before, table:not(.no-stack) td:not([data-label])::before { display: none; }
  table:not(.no-stack) td[data-label=""], table:not(.no-stack) td:not([data-label]) { justify-content: flex-end; }
  table:not(.no-stack) td[colspan] { justify-content: center; text-align: center; }

  /* ── جداول النتائج (الشبكة) → بطاقة لكل طالب، عمودان ── */
  table.grid-table:not(.no-stack) tr {
    display: grid; grid-template-columns: 1fr 1fr; padding: 0; overflow: hidden;
  }
  table.grid-table:not(.no-stack) td {
    border: 0; border-block-end: 1px solid var(--line-2, #dfe5e3);
    border-inline-end: 1px solid var(--line-2, #dfe5e3);
    padding: 0.4rem 0.6rem; text-align: center; justify-content: space-between;
    background: transparent !important;
  }
  table.grid-table:not(.no-stack) td:nth-child(even) { border-inline-end: 0; }
  table.grid-table:not(.no-stack) td.cell-name {
    grid-column: 1 / -1; display: block; text-align: start; font-weight: 600;
    background: var(--primary-soft, #E3EFEC) !important; color: var(--primary, #134E48);
  }
  table.grid-table:not(.no-stack) td.cell-name::before { display: none; }
  table.grid-table:not(.no-stack) td.cell-avg { font-size: 0.9rem; }
  table.grid-table:not(.no-stack) td input[type="number"],
  table.grid-table:not(.no-stack) td input[type="text"] { width: 5.4rem; max-width: 60%; padding-inline: 0.3rem; text-align: center; }
  table:not(.no-stack) td input,
  table:not(.no-stack) td select { min-width: 0; }
}