/* The teacher pages are Majordomo's own; the showcase links this file into their <head> (student.py, _banner),
   never into the student pages. It styles the read-only banner and fixes what breaks at phone width.
   Every rule is scoped to Majordomo's markup (.main-content, .table-wrapper, .rule-row-compact, ...). Apart from
   the banner and the rules list (fixed at every width), each sits inside a phone or tablet media query.
   Majordomo sets some widths inline (style="table-layout:fixed"), which only !important can beat.
   It also hides what is left of iLearn and sign-in in Majordomo's pages (see "leftovers" below). */

/* -- the banner ---------------------------------------------------------------------------------- */

.showcase-banner {
  position: relative;
  z-index: 1;
  margin: 0;
  padding: 6px 12px;
  background: #eef0f3;
  border-bottom: 1px solid #dee2e6;
  color: #1f2937;
  font: 500 13px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  text-align: center;
}
.showcase-banner a {
  display: inline-block;
  padding: 2px 0;
  color: #3730a3;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.showcase-banner a:focus-visible { outline: 2px solid #3730a3; outline-offset: 2px; border-radius: 2px; }
[data-bs-theme="dark"] .showcase-banner { background: #262637; border-color: #313244; color: #cdd6f4; }
[data-bs-theme="dark"] .showcase-banner a { color: #c7d2fe; }

/* Desktop: Majordomo's sidebar is fixed down the left, so the banner starts beside it. */
@media (min-width: 992px) {
  .showcase-banner { margin-left: var(--sidebar-w, 240px); }
}

/* Below 992px Majordomo shows a fixed 56px top bar and pads the content by 72px (66px on phones) to clear it.
   The banner sits just under the bar, and the content's top padding gives back what the banner takes. */
@media (max-width: 991.98px) {
  .showcase-banner { margin-top: 56px; }
  .showcase-banner ~ .main-content { padding-top: 16px; }
  /* A 44px touch target without a taller bar: the link's hit area runs from the bar's top edge down into the
     content's top padding, which is empty. */
  .showcase-banner { padding: 7px 12px; }
  .showcase-banner a { position: relative; padding: 0; }
  .showcase-banner a::after { content: ""; position: absolute; left: -8px; right: -8px; top: -7px; height: 44px; }
}
@media (max-width: 575.98px) {
  .showcase-banner ~ .main-content { padding-top: 12px; }
}

/* -- iLearn and sign-in leftovers, hidden at every width ------------------------------------------------
   Each selector matches one element of Majordomo's markup, by its href or id (tests/test_pages.py checks that
   against the served pages): the "iLearn Pipeline" and "Logout" menu entries (web/templates/base.html:111-114,
   :151-153), and on the Health page the "Check iLearn" button (health.html:58-60), the "iLearn Download" and
   "iLearn Upload" rows (:42-51) and the "Download Full Log" link (:10-12; /health/log is blocked, a 404).
   The button and the two rows stay in the page because health.html's script looks them up by id; display:none
   keeps them out of the tab order and the accessibility tree. showcase/pages.py also marks those two rows, and
   the three iLearn rows told apart only by their text, `hidden` in the HTML, so a browser without :has() hides
   them too. */
.sidebar-nav > a.sidebar-link[href$="/process"],
.sidebar-footer > a.sidebar-link[href$="/logout"],
#checkIlearnBtn,
tr:has(> td > #ilearn-download-badge),
tr:has(> td > #ilearn-upload-badge),
.page-header a[href$="/health/log"] { display: none !important; }

/* -- the rules list, at every width ---------------------------------------------------------------- */

/* Majordomo fixes the columns inline (table-layout:fixed, 25/10/8/8/49%), too narrow for the longer rule names
   and the badges at any laptop width: they print over each other. From 1200px: the columns size to their
   content, with the same widths in every topic's table so they line up down the page, and the description takes
   the rest. A name never splits mid-word (break-word does not shrink the column below the longest name). */
.topic-section .table-wrapper .table { table-layout: auto !important; }
.topic-section .table-wrapper .table th:first-child { width: 20rem !important; }
.topic-section .table-wrapper .table th:nth-last-child(4):not(:first-child) { width: 7.5rem !important; }  /* Level */
.topic-section .table-wrapper .table th:nth-last-child(3):not(:first-child),
.topic-section .table-wrapper .table th:nth-last-child(2) { width: 6rem !important; }                     /* Type, Status */
.topic-section .table-wrapper .table th:last-child { width: auto !important; }
/* Tables without a Level column: their Type column takes Level's space too, so Type and Status line up with the
   tables above and below. */
@media (min-width: 1200px) {
  .topic-section .table-wrapper .table th:nth-child(2):nth-last-child(3) { width: 13.5rem !important; }
  .topic-section .table-wrapper .table :is(th, td):nth-child(2):nth-last-child(3) { padding-left: calc(7.5rem + 14px); }
}
.topic-section .table-wrapper .table td:first-child { overflow-wrap: break-word; }
.topic-section .table-wrapper .table :is(th, td):not(:first-child):not(:last-child) { white-space: nowrap; }

/* 768-1199px: no room for a description column beside the badges, so each rule is a two-line row: the name and
   its badges in aligned columns, the description underneath. Columns are placed from the end, so Type and
   Status line up whether or not a table has a Level column. */
@media (min-width: 768px) and (max-width: 1199.98px) {
  .topic-section .table-wrapper .table,
  .topic-section .table-wrapper .table :is(thead, tbody) { display: block; width: 100%; min-width: 0; }
  .topic-section .table-wrapper .table tr {
    display: grid; grid-template-columns: minmax(0, 1fr) 7.5rem 6rem 6rem; align-items: center;
    border-bottom: 1px solid var(--border);
  }
  .topic-section .table-wrapper .table tbody tr:last-child { border-bottom: 0; }
  .topic-section .table-wrapper .table :is(th, td) { display: block; width: auto !important; border: 0; }
  .topic-section .table-wrapper .table :is(th, td):first-child { grid-column: 1; grid-row: 1; }
  .topic-section .table-wrapper .table :is(th, td):nth-last-child(4):not(:first-child) { grid-column: 2; grid-row: 1; }
  .topic-section .table-wrapper .table :is(th, td):nth-last-child(3):not(:first-child) { grid-column: 3; grid-row: 1; }
  .topic-section .table-wrapper .table :is(th, td):nth-last-child(2) { grid-column: 4; grid-row: 1; }
  .topic-section .table-wrapper .table td:last-child { grid-column: 1 / -1; grid-row: 2; padding-top: 0; }
  .topic-section .table-wrapper .table th:last-child {
    position: absolute; width: 1px !important; height: 1px; overflow: hidden; clip: rect(0 0 0 0); padding: 0;
  }
}

/* -- other tables below 992px --------------------------------------------------------------------- */

@media (max-width: 991.98px) {
  /* Student page, submissions table: the "Not taught" column wraps into a tall sliver at Majordomo's
     600px minimum; give the table room and let its card scroll sideways (Majordomo's own .table-wrapper rule). */
  .main-content:has(#dev-table) .table-wrapper .table { min-width: 880px; }

  /* Rule detail, Overview and PMD tables: two columns of label and value need no 600px minimum. */
  .dashboard-section .table-wrapper .table:not(:has(thead)) { min-width: 0; }
  .dashboard-section .table-wrapper .table:not(:has(thead)) td:first-child { width: 8rem !important; }
  .dashboard-section .table-wrapper .table:not(:has(thead)) code { overflow-wrap: anywhere; }

  /* Submission page, Detailed History: let the rule column fit the rule name; the table scrolls in its box. */
  .rule-group .table { table-layout: auto !important; }
  .rule-group .table td:first-child code { white-space: nowrap; }

  /* Submission page, flagged rules: the description wraps under the rule name instead of a narrow column. */
  .rule-row-compact { flex-wrap: wrap; row-gap: 2px; }
  .rule-row-compact > .ms-auto {
    flex: 1 1 100%;
    margin-left: 26px !important;
    overflow-wrap: anywhere;
  }

  /* Submission page, Student Rendered: the stored feedback scrolls in its own box if it is ever wider. */
  #tab-rendered .feedback-preview { overflow-x: auto; overflow-wrap: break-word; }
}

/* -- phones: the rules list as stacked cards ------------------------------------------------------- */

@media (max-width: 767.98px) {
  .topic-section .table-wrapper .table,
  .topic-section .table-wrapper .table tbody { display: block; min-width: 0; width: 100%; }
  .topic-section .table-wrapper .table thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .topic-section .table-wrapper .table tr {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
    padding: 10px 14px; border-bottom: 1px solid var(--border);
  }
  .topic-section .table-wrapper .table tr:last-child { border-bottom: 0; }
  .topic-section .table-wrapper .table td { display: block; padding: 0; border: 0; width: auto; }
  .topic-section .table-wrapper .table td:first-child { flex: 1 1 100%; overflow-wrap: anywhere; }
  .topic-section .table-wrapper .table td:not(:first-child):not(:last-child) { white-space: normal; }
  .topic-section .table-wrapper .table td:last-child { flex: 1 1 100%; line-height: 1.45; }
}
