/* Exams: the hall drawing and the hall editor (owner, 2026-11-13; board
   E4-HallEditor), the exam timetable and its Publish dialog (boards
   E4-Timetable, E4-Publish), seating and "Fill the halls" (E4-Seating,
   E4-FillDialog), the student's Exams list and seat (E4-StudentExams,
   E4-StudentSeat), the Today "Next exam" card (E4-TodayExam) and the two
   printed sheets of a hall (E4-PrintHall, E4-PrintDoor).

   Loaded after admin.css (templates/base.html). Only rules in the declared
   layers, only tokens, only logical properties (tests/test_css_stylesheets.py,
   tests/test_css_rules.py, tests/ui/test_css_logical.py). The seat colours
   are measured in tests/exams/test_hall_look.py. */

@layer components {
  /* ----------------------------------------------------- The hall, drawn
     templates/exams/_hall_map.html: HTML, not SVG, so every label is text
     that scales with the reader's font size. The drawing is physical
     (dir="ltr" in Arabic too): the board at the top, seat 1 on the left, so
     "start" here always means the hall's left wall. */
  .xm-hall {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    inline-size: fit-content;
    padding: var(--space-3);
    border: 2px solid var(--attend-border-strong);
    border-radius: var(--r-md);
    background: var(--attend-surface);
    color: var(--attend-text);
  }

  /* The front and back walls: a door at either corner, the board between. */
  .xm-band {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: var(--space-2);
    min-block-size: 26px;
  }

  .xm-front {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    min-block-size: 26px;
    padding-inline: var(--space-6);
    border-radius: var(--r-xs);
    background: var(--attend-brand-tint);
    color: var(--attend-brand-text);
    font-size: 12px;
    font-weight: var(--weight-label);
    line-height: 16px;
    white-space: nowrap;
  }

  .xm-back {
    color: var(--attend-text-muted);
    font-size: 12px;
    font-weight: var(--weight-bold);
    line-height: 16px;
    text-align: center;
    white-space: nowrap;
  }

  .xm-mark {
    justify-self: start;
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    min-block-size: 24px;
    padding-inline: var(--space-2);
    border: 1px solid var(--attend-border-strong);
    border-radius: var(--r-xs);
    background: var(--attend-ground);
    color: var(--attend-text-strong);
    font-size: 12px;
    font-weight: var(--weight-bold);
    line-height: 16px;
    white-space: nowrap;
  }

  /* A door at a right-hand corner. */
  .xm-mark--end {
    justify-self: end;
  }

  .xm-mark .icon,
  .xm-front .icon,
  .xm-wall .icon {
    inline-size: 14px;
    block-size: 14px;
  }

  .xm-floor {
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    gap: var(--space-2);
  }

  .xm-rows {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  /* A row keeps its height while its number is still being typed. */
  .xm-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-block-size: 40px;
  }

  .xm-no {
    flex: none;
    min-inline-size: 50px;
    color: var(--attend-text-muted);
    font-size: 12px;
    font-weight: var(--weight-bold);
    line-height: 16px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  .xm-aisle {
    flex: none;
    inline-size: 14px;
  }

  .xm-seat {
    flex: none;
    box-sizing: border-box;
    display: grid;
    place-items: center;
    inline-size: 40px;
    block-size: 40px;
    border: 1px solid var(--attend-border-strong);
    border-radius: var(--r-xs);
    background: var(--attend-ground);
    color: var(--attend-text-strong);
    font-size: 13px;
    font-weight: var(--weight-bold);
    line-height: 1;
    font-variant-numeric: tabular-nums;
  }

  /* The reader's own seat: the brand fill, a ring around it and the word
     "You" in it, so it is never told by colour alone. */
  .xm-seat--you {
    border-color: var(--attend-brand);
    background: var(--attend-brand);
    color: var(--attend-on-brand);
    font-size: 12px;
    font-weight: var(--weight-label);
    outline: 2px solid var(--attend-brand);
    outline-offset: 1px;
  }

  /* A side wall with windows. */
  .xm-wall {
    flex: none;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    inline-size: 22px;
    border: 1px dashed var(--attend-border-strong);
    border-radius: var(--r-xs);
    background: var(--attend-ground);
    color: var(--attend-text-strong);
    font-size: 12px;
    font-weight: var(--weight-bold);
    line-height: 16px;
  }

  .xm-wall span {
    writing-mode: vertical-rl;
  }

  /* A hall wider than its place scrolls sideways inside this box, never the
     page; the ring sits inside the box so its edge is not cut. */
  .xm-scroll {
    max-inline-size: 100%;
    overflow-x: auto;
    padding-block: var(--space-1);
  }

  .xm-scroll:focus-visible {
    outline-offset: -2px;
  }

  /* ----------------------------------------------------- The hall editor
     templates/exams/halls/edit.html: the form, then the drawing; side by side
     from 1024px (board E4-HallEditor: 420px for the form). */
  .hall-editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: var(--space-8);
  }

  @media (min-width: 1024px) {
    .hall-editor {
      grid-template-columns: 420px minmax(0, 1fr);
    }
  }

  .hall-editor__names {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4);
  }

  .hall-editor__openings {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: var(--space-4);
  }

  .hall-doors > div {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 var(--space-4);
  }

  .hall-windows > div {
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0;
  }

  @media (max-width: 479px) {
    .hall-editor__names,
    .hall-editor__openings {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  .hall-drawing {
    min-inline-size: 0;
  }

  .hall-drawing__seats {
    color: var(--attend-text-strong);
  }

  .hall-drawing .xm-scroll {
    margin-block-start: var(--space-4);
  }

  .hall-drawing__words {
    margin-block-start: var(--space-3);
  }

  /* One line per row: its name, its number of seats, the word, Remove. */
  .he-rows {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: var(--space-2) 0 0;
    padding: 0;
    list-style: none;
  }

  .he-rows li {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }

  .he-rows label {
    flex: none;
    min-inline-size: 52px;
    color: var(--attend-text-strong);
    font-size: var(--text-small);
    font-weight: var(--weight-bold);
  }

  .he-rows input {
    flex: none;
    inline-size: 76px;
  }

  .he-rows .btn {
    margin-inline-start: auto;
  }

  /* The quick setup "Rows [ ] x Columns [ ]" (owner N7): one line that wraps. */
  .he-quick {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    margin-block-start: var(--space-2);
  }

  .he-quick label {
    color: var(--attend-text-strong);
    font-size: var(--text-small);
    font-weight: var(--weight-bold);
  }

  .he-quick input {
    flex: none;
    inline-size: 76px;
  }

  .he-quick__ask {
    margin-block-start: var(--space-3);
  }

  /* "Aisle after column": a ticked box drawn as a chip. The box itself is
     hidden from sight only, so the chip takes its focus ring and its tick. */
  .aisle-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-block-start: var(--space-2);
  }

  .aisle-chip {
    gap: var(--space-1);
    cursor: pointer;
  }

  .aisle-chip .icon {
    display: none;
    inline-size: 14px;
    block-size: 14px;
  }

  .aisle-chip:has(input:checked) {
    border-color: var(--attend-brand);
    background: var(--attend-brand);
    color: var(--attend-on-brand);
  }

  .aisle-chip:has(input:checked) .icon {
    display: block;
  }

  .aisle-chip:has(input:focus-visible) {
    outline: 2px solid var(--attend-focus);
    outline-offset: 3px;
  }

  /* The hall's exam columns in the editor's drawing (owner N11, 2026-11-15):
     a quiet tint and a heavier edge on the seats, the column number in the
     brand colour and underlined, so the mark is never colour alone. The
     ticks and the count say the same in words. */
  .xm-seat--exam {
    border-color: var(--attend-brand);
    background: var(--attend-brand-tint);
  }

  .xm-col--exam {
    color: var(--attend-brand-text);
    text-decoration: underline;
    text-underline-offset: 3px;
  }

  .hall-exam-count {
    margin-block-start: calc(-1 * var(--space-2));
  }

  /* Lists inside a banner: the hall editor's exams still on the hall's old
     layout, and the exam Edit page's halls that would lose seats. */
  .hall-old-layouts ul,
  .hall-drop ul {
    margin-block: var(--space-1);
    padding-inline-start: var(--space-4);
  }

  .hall-old-layouts li + li,
  .hall-drop li + li {
    margin-block-start: var(--space-1);
  }
}

@layer components {
  /* ------------------------------------------------- The exam timetable
     templates/exams/timetable/: the stage tabs (the roster's tab track, with
     no count pills), the stage's table and its warning rows, "Add an exam". */
  .tt-stages {
    margin-block-end: var(--space-5);
  }

  .tt-stages .btn--plain {
    padding-inline: var(--space-4);
  }

  .tt-when {
    color: var(--attend-text-strong);
    font-weight: var(--weight-bold);
    white-space: nowrap;
  }

  .tt-sub {
    color: var(--attend-text-muted);
    white-space: nowrap;
  }

  .tt-actions {
    text-align: end;
  }

  .tt-actions .tt-link + .tt-link {
    margin-inline-start: var(--space-4);
  }

  .tt-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    white-space: nowrap;
  }

  /* On a touch screen the timetable's links (Edit, Open seating) and the two
     print links are 44px tall targets. The seats keep the board's 40px. */
  @media (pointer: coarse) {
    .tt-link,
    .seating-print a {
      min-block-size: 44px;
    }
  }

  /* A row's warnings: a row of their own under it, joined to it (no rule
     between them), each with the warning icon and what to do about it. */
  .tt-note td {
    block-size: auto;
    padding-block: 0 var(--space-3);
    border-block-start: 0;
  }

  .tt-note__line {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    color: var(--attend-text);
  }

  .tt-note__line + .tt-note__line {
    margin-block-start: var(--space-2);
  }

  .tt-note__line .icon {
    flex: none;
    margin-block-start: 1px;
    color: var(--attend-warning-text);
  }

  .table tr.tt-note td a:not(.btn) {
    color: var(--attend-brand-text);
    text-decoration: underline;
  }

  .tt-students summary {
    inline-size: fit-content;
    color: var(--attend-brand-text);
    text-decoration: underline;
    cursor: pointer;
  }

  .tt-students ul {
    margin: var(--space-2) 0 0;
    padding: 0;
    list-style: none;
  }

  /* "Add an exam": one row of fields where there is room, stacked on a phone. */
  .tt-add,
  .tt-edit {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
  }

  @media (min-width: 900px) {
    .tt-add {
      grid-template-columns:
        minmax(0, 1.6fr) minmax(0, 1.1fr) minmax(0, 1.2fr) minmax(0, 1.4fr)
        minmax(0, 1.4fr) minmax(0, 1.4fr);
    }

    .tt-edit {
      grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) minmax(0, 1fr);
      max-inline-size: 560px;
    }
  }

  /* ------------------------------------------------- The Publish dialog */
  .tt-publish {
    inline-size: min(540px, calc(100vw - 2 * var(--space-4)));
  }

  .tt-publish__list {
    margin-block-end: 0;
  }

  .tt-publish__list .icon {
    flex: none;
    margin-block-start: 1px;
    color: var(--attend-positive-text);
  }

  .tt-publish__missing {
    margin-block-end: 0;
  }

  .tt-publish__missing p + p {
    margin-block-start: var(--space-1);
  }

  .tt-publish__who {
    margin-block-start: var(--space-2);
  }

  /* ------------------------------------------------- The student's Exams list
     templates/exams/student/exams.html: the Lectures section's agenda rows,
     plus one line for the seat's state (and what changed). */
  .exam-state {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
    margin: var(--space-2) 0 0;
  }
}

@layer components {
  /* ------------------------------------------------- Seating (board E4-Seating)
     templates/exams/seating/: the hall tabs and the counts, then the hall
     drawn with who sits where beside the students without a seat. The
     drawing is the hall's own (.xm-*); a seat here is a seated student, a
     free seat or one another exam uses, told by its edge and its word or
     icon, never by colour alone. */
  .seating-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3) var(--space-6);
    margin-block-end: var(--space-6);
  }

  /* The hall picker. Its labels are long ("A-1-06 (A2) · 77 of 176"): on a
     phone the roster's two tabs a row ran them over each other (owner P2,
     2026-11-15), so each hall has its own full-width row, and a label that
     still does not fit wraps inside its tab. */
  @media (max-width: 479px) {
    .roster-tabs.roster-tabs--halls {
      display: grid;
      grid-template-columns: minmax(0, 1fr);
    }

    .roster-tabs--halls .btn--plain {
      flex-wrap: wrap;
      justify-content: flex-start;
      min-inline-size: 0;
      white-space: normal;
      text-align: start;
    }
  }

  .seating-top__counts {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
  }

  /* "N without a seat": the warning's icon and its words, not a status chip. */
  .seating-top__missing {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--attend-warning-text);
    font-weight: var(--weight-strong);
  }

  .seating {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: var(--space-6);
  }

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

  /* "Choose a free seat for ..." and "the layout changed": the words, then
     what can be done, on one line where there is room. */
  .seating-pick {
    flex-wrap: wrap;
    align-items: center;
    margin-block: var(--space-4);
  }

  .seating-pick > div {
    flex: 1 1 12rem;
  }

  .seating-pick > .icon,
  .seating-pick .btn .icon {
    margin-block-start: 0;
  }

  .seating-pick .btn .icon {
    color: inherit;
  }

  /* The seat numbers over the drawing. */
  .xm-row--cols {
    min-block-size: 0;
  }

  .xm-col {
    flex: none;
    inline-size: 40px;
    color: var(--attend-text-muted);
    font-size: 12px;
    font-weight: var(--weight-bold);
    line-height: 16px;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }

  /* A seated student's seat that can be chosen, and a free seat that can be given. */
  a.xm-seat,
  button.xm-seat {
    padding: 0;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
  }

  /* Only a seat that is a link or a button takes the focus. */
  .xm-seat:focus-visible {
    outline: 2px solid var(--attend-focus);
    outline-offset: 2px;
  }

  @media (hover: hover) and (pointer: fine) {
    a.xm-seat:hover,
    button.xm-seat:hover {
      border-color: var(--attend-brand);
      border-width: 2px;
    }
  }

  .xm-seat--free {
    border: 2px dashed var(--attend-brand-text);
    background: var(--attend-brand-tint);
    color: var(--attend-brand-text);
    font-size: 12px;
  }

  /* The chosen student's own seat while a new one is picked: the ring of "You". */
  .xm-seat--chosen {
    border-color: var(--attend-brand);
    background: var(--attend-brand);
    color: var(--attend-on-brand);
    outline: 2px solid var(--attend-brand);
    outline-offset: 1px;
  }

  /* A seat another exam uses at this time: nobody of this exam sits there. */
  .xm-seat--other {
    border-style: dotted;
    background: var(--attend-surface);
    color: var(--attend-text-muted);
  }

  .xm-seat--other .icon {
    inline-size: 14px;
    block-size: 14px;
  }

  /* A seating-page seat's number in the hall, in its corner (owner N1, N4): the
     seat's own content (the ID digits, "Free", the cross) stays in the middle. */
  .xm-hall--seating .xm-seat {
    position: relative;
  }

  .xm-seat__no {
    position: absolute;
    inset-block-start: 2px;
    inset-inline-start: 3px;
    font-size: 10px;
    font-weight: var(--weight-medium);
    line-height: 1;
  }

  .seat-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-5);
    margin-block-start: var(--space-3);
  }

  .seat-legend > span {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
  }

  .seat-key {
    box-sizing: border-box;
    display: inline-grid;
    place-items: center;
    min-inline-size: 36px;
    block-size: 24px;
    padding-inline: var(--space-1);
    border: 1px solid var(--attend-border-strong);
    border-radius: var(--r-xs);
    background: var(--attend-ground);
    color: var(--attend-text-strong);
    font-size: 12px;
    font-weight: var(--weight-bold);
  }

  .seat-key--free {
    border: 2px dashed var(--attend-brand-text);
    background: var(--attend-brand-tint);
    color: var(--attend-brand-text);
  }

  .seat-key--other {
    border-style: dotted;
    background: var(--attend-surface);
    color: var(--attend-text-muted);
  }

  .seat-key .icon {
    inline-size: 14px;
    block-size: 14px;
  }

  /* The students without a seat: a name and ID, then "Choose a seat". */
  .seating-list {
    margin-block-start: var(--space-4);
    overflow: hidden;
  }

  .seating-list .row {
    flex-wrap: nowrap;
  }

  .seating-list .row.is-chosen {
    border-inline-start: 3px solid var(--attend-brand);
    background: var(--attend-row-selected);
  }

  .seating-list__who {
    min-inline-size: 0;
  }

  .seating-list .btn {
    flex: none;
    padding-inline: var(--space-4);
  }

  .seating-note {
    margin-block-start: var(--space-3);
  }

  .seating-apart {
    margin-block-start: var(--space-8);
  }
}

@layer components {
  /* ------------------------------------------------- Fill the halls
     templates/exams/seating/_fill_dialog.html (board E4-FillDialog): the
     order and the halls one under the other, then what the fill would do. */
  .seat-fill {
    inline-size: min(520px, calc(100vw - 2 * var(--space-4)));
  }

  .seat-fill .seat-fill__choices {
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0;
  }

  .seat-fill__preview {
    display: grid;
    gap: var(--space-4);
  }

  .seat-fill__preview .banner {
    margin-block-end: 0;
  }

  .seat-fill__preview p + p {
    margin-block-start: var(--space-1);
  }
}

@layer components {
  /* ------------------------------------------------- The student's seat
     templates/exams/student/: a row of the Exams list that opens the seat
     (board E4-StudentExams), then the seat page (boards E4-StudentSeat,
     E4-StudentSeatAr, E4-StudentSeatDark). */
  .agenda-row.exam-row {
    grid-template-columns: minmax(var(--time-tile), auto) minmax(0, 1fr) auto;
  }

  /* The whole row opens the seat: the subject's link covers it. */
  .exam-row .agenda-row__title a {
    color: inherit;
    text-decoration: none;
  }

  .exam-row .agenda-row__title a::after {
    content: "";
    position: absolute;
    inset: 0;
  }

  .exam-row > .icon {
    color: var(--attend-text-muted);
  }

  .exam-seat {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: var(--space-1) 0 0;
    color: var(--attend-text-strong);
    font-size: var(--text-small);
    font-weight: var(--weight-strong);
    line-height: var(--leading-small);
  }

  .exam-seat .icon {
    flex: none;
    color: var(--attend-text-muted);
  }

  /* The seat in words, first on the page. */
  .seat-hero .section-label {
    margin: 0 0 var(--space-2);
  }

  .seat-hero__place {
    margin: 0;
    color: var(--attend-text-strong);
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: var(--weight-display);
    letter-spacing: var(--tracking-h1);
    line-height: 30px;
  }

  :lang(ar) .seat-hero__place {
    letter-spacing: 0;
    line-height: 36px;
  }

  .seat-hero__facts {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin-block-start: var(--space-3);
  }

  .seat-early {
    margin-block: var(--space-4) 0;
  }

  .seat-map {
    margin-block-start: var(--space-6);
  }

  /* The student's hall zoomed in ("Zoom in", data-zoomed on .xm-fit): smaller
     seats with their numbers and the row's number before each row, so eight
     seats, two aisles and a window wall fit a 360px phone; a wider hall
     scrolls inside its box (.xm-scroll). Not zoomed in, the hall is fitted to
     the screen's width (below). */
  .xm-hall--own {
    padding: var(--space-3) var(--space-2);
  }

  .xm-hall--own .xm-front {
    padding-inline: var(--space-4);
  }

  .xm-hall--own .xm-rows {
    gap: 5px;
  }

  .xm-hall--own .xm-row {
    gap: 3px;
    min-block-size: 28px;
  }

  .xm-hall--own .xm-row--cols {
    min-block-size: 0;
  }

  .xm-hall--own .xm-no {
    min-inline-size: 22px;
    text-align: center;
  }

  .xm-hall--own .xm-col,
  .xm-hall--own .xm-seat {
    inline-size: 28px;
  }

  /* Room for a three-digit seat number ("176") in the small seat. */
  .xm-hall--own .xm-seat {
    block-size: 28px;
    font-size: 11px;
  }

  .xm-hall--own .xm-aisle {
    inline-size: 8px;
  }

  .xm-hall--own .xm-wall {
    inline-size: 20px;
  }

  @media (max-width: 379px) {
    .xm-hall--own .xm-row {
      gap: 2px;
      min-block-size: 26px;
    }

    .xm-hall--own .xm-col,
    .xm-hall--own .xm-seat {
      inline-size: 26px;
    }

    .xm-hall--own .xm-seat {
      block-size: 26px;
    }

    .xm-hall--own .xm-seat--you {
      font-size: 11px;
    }
  }

  /* An empty place at the end of a short row: it keeps the row's seats under
     their columns when the hall is fitted to the screen. */
  .xm-pad {
    flex: none;
    visibility: hidden;
  }

  .xm-hall--own .xm-pad {
    inline-size: 28px;
  }

  /* The whole hall in the screen's width (owner N9, 2026-11-14): each seat
     starts at its zoomed size and every seat and aisle shrinks alike (flex
     basis, no minimum), square by aspect-ratio, so up to 40 x 40 seats fit a
     phone; no row or column numbers. Each seat is a container: its text (the
     hall's number, "You") shows only while the seat is wide enough to read it;
     smaller, the reader's seat is the filled, ringed box and the others plain
     boxes. Students only: staff drawings keep their size (owner N10). */
  .xm-fit:not([data-zoomed]) .xm-hall--own {
    max-inline-size: 100%;
  }

  .xm-fit:not([data-zoomed]) .xm-hall--own .xm-floor {
    min-inline-size: 0;
  }

  .xm-fit:not([data-zoomed]) .xm-hall--own .xm-rows {
    flex: 0 1 auto;
    min-inline-size: 0;
    gap: 2px;
  }

  .xm-fit:not([data-zoomed]) .xm-hall--own .xm-row {
    gap: 2px;
    min-block-size: 0;
  }

  .xm-fit:not([data-zoomed]) .xm-hall--own .xm-row--cols,
  .xm-fit:not([data-zoomed]) .xm-hall--own .xm-no {
    display: none;
  }

  .xm-fit:not([data-zoomed]) .xm-hall--own .xm-seat,
  .xm-fit:not([data-zoomed]) .xm-hall--own .xm-pad {
    flex: 0 1 28px;
    min-inline-size: 0;
    inline-size: 28px;
    block-size: auto;
    border-radius: 0;
    aspect-ratio: 1;
    container: xm-seat / inline-size;
  }

  .xm-fit:not([data-zoomed]) .xm-hall--own .xm-aisle {
    flex: 0 1 8px;
    min-inline-size: 0;
  }

  @container xm-seat (max-width: 25.98px) {
    .xm-seat__text {
      display: none;
    }
  }

  /* With JavaScript a tap on the fitted drawing zooms in, and on the zoomed
     one goes back (static/js/exams/seat-scroll.js). */
  .xm-fit[data-zoomable] {
    cursor: zoom-in;
  }

  .xm-fit[data-zoomable][data-zoomed] {
    cursor: zoom-out;
  }

  /* The number of the reader's own row and of their seat's column. */
  .xm-on {
    border-radius: var(--r-pill);
    background: var(--attend-brand-tint);
    color: var(--attend-brand-text);
  }

  /* The section's name, and "Zoom in" at its end (a toggle: aria-pressed). */
  .seat-map__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
  }

  .seat-map__head .section-label {
    margin: 0;
  }

  .seat-zoom {
    flex: none;
  }

  .seat-zoom[aria-pressed="true"] {
    background: var(--attend-brand-tint);
  }

  .seat-zoom[aria-pressed="true"] .seat-zoom__in,
  .seat-zoom:not([aria-pressed="true"]) .seat-zoom__out {
    display: none;
  }

  .seat-zoom__in,
  .seat-zoom__out {
    display: inline-flex;
  }

  /* The seat in words, large, right under the drawing (owner N9). */
  .seat-map__place {
    margin: var(--space-3) 0 0;
    color: var(--attend-text-strong);
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: var(--weight-display);
    letter-spacing: var(--tracking-h1);
    line-height: 28px;
  }

  :lang(ar) .seat-map__place {
    letter-spacing: 0;
    line-height: 34px;
  }

  /* Under the drawing: what the filled seat means, in words. */
  .seat-own {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-4);
    margin: var(--space-3) 0 0;
    font-size: var(--text-small);
  }

  .seat-own__you {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-block-size: 28px;
    padding-inline: var(--space-2) var(--space-3);
    border-radius: var(--r-pill);
    background: var(--attend-brand);
    color: var(--attend-on-brand);
    font-weight: var(--weight-strong);
  }

  .seat-own__others {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--attend-text-muted);
  }

  .seat-own__key {
    box-sizing: border-box;
    inline-size: 16px;
    block-size: 16px;
    border: 1px solid var(--attend-border-strong);
    border-radius: 0;
    background: var(--attend-ground);
  }

  .seat-map__words {
    margin-block-start: var(--space-3);
  }
}

@layer components {
  /* ------------------------------------------------- Today: the next exam
     templates/exams/_today_card.html (board E4-TodayExam): the class card's
     own look; the seat's words stand out among the card's facts. */
  .today-exam {
    margin-block-end: var(--space-6);
  }

  .today-exam__seat > span {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
  }
}

/* ------------------------------------------------- The printed sheets
   templates/exams/print/ (boards E4-PrintHall, E4-PrintDoor): the hall seating
   sheet and the door list. The page is the paper: each .exam-sheet is one A4
   sheet with a 10mm margin, drawn on screen as the paper (its margin as
   padding) and printed as the page itself; the bar above never prints. Every
   sheet is upright and fits the printable area of A4 and Letter alike (190mm
   wide, 257mm high: owner P1, P3, 2026-11-15); a wide hall is cut at its
   aisles on the server (apps/exams/print_blocks.py). Always light (the view
   sets the theme). Millimetres only for the paper; type sizes
   are the boards' own, fixed for paper. */
@layer components {
  body.exam-print {
    background: var(--attend-ground);
  }

  .exam-print__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-4);
    max-inline-size: 210mm;
    margin: 0 auto;
    padding: var(--space-6) var(--space-4);
  }

  .exam-print__text {
    flex: 1 1 320px;
    min-inline-size: 0;
  }

  .exam-print__text p {
    margin: 0;
  }

  .exam-print__what {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
  }

  /* "Students see these seats only after the stage is published." */
  .exam-print__draft {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding-block-start: var(--space-2);
    color: var(--attend-warning-text);
    font-weight: var(--weight-strong);
  }

  /* The three print links in a hall's head on the seating page. */
  .seating-print {
    display: inline-flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
    font-size: var(--text-small);
    line-height: var(--leading-small);
  }

  /* On a screen narrower than the paper the sheets scroll sideways in here,
     never the page. */
  .exam-sheets {
    overflow-x: auto;
    padding: 0 var(--space-4) var(--space-8);
  }

  .exam-sheets:focus-visible {
    outline-offset: -2px;
  }

  /* position: the hidden table captions stay inside the sheet (and so inside
     the scrolling box), or they would widen the page on a phone. */
  .exam-sheet {
    position: relative;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    inline-size: 210mm;
    min-block-size: 297mm;
    margin: 0 auto var(--space-8);
    padding: 10mm;
    background: var(--attend-surface);
    color: var(--attend-text-strong);
    box-shadow: var(--attend-shadow-card);
    font-size: 13px;
    line-height: 18px;
    break-after: page;
    print-color-adjust: exact;
  }

  .exam-sheet:last-child {
    break-after: auto;
  }

  .exam-sheet p,
  .exam-sheet dl,
  .exam-sheet dt,
  .exam-sheet dd {
    margin: 0;
  }

  .exam-sheet__head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-6);
    padding-block-end: var(--space-3);
    border-block-end: 2px solid var(--attend-text-strong);
  }

  .exam-sheet__hall {
    margin: var(--space-1) 0 0;
    font-size: 28px;
    line-height: 32px;
  }

  /* The part of a cut hall on this sheet: "Columns 1–5 of 16". */
  .exam-sheet__part {
    color: var(--attend-text-strong);
    font-size: 16px;
    font-weight: var(--weight-strong);
    line-height: 20px;
  }

  .exam-sheet__owner {
    color: var(--attend-text);
    font-size: 12px;
    line-height: 16px;
    text-align: end;
  }

  .exam-sheet__facts {
    display: grid;
    grid-template-columns: 2fr 1fr 1.4fr 1.5fr 0.7fr;
    gap: var(--space-4);
    padding-block: var(--space-3);
  }

  .ps-label {
    color: var(--attend-text-muted);
    font-size: 11px;
    font-weight: var(--weight-label);
    letter-spacing: var(--tracking-label);
    line-height: 14px;
  }

  .ps-value {
    color: var(--attend-text-strong);
    font-size: 15px;
    font-weight: var(--weight-strong);
    line-height: 20px;
  }

  /* "Not published yet", on the paper itself: a framed word, not a colour. */
  .ps-draft {
    display: inline-block;
    margin-inline-start: var(--space-2);
    padding: 0 var(--space-2);
    border: 1px solid var(--attend-text-strong);
    border-radius: var(--r-xs);
    color: var(--attend-text-strong);
  }

  .exam-sheet__note {
    padding-block-start: var(--space-3);
    color: var(--attend-text);
    font-size: 12px;
    line-height: 16px;
  }

  .exam-sheet__note--centre {
    text-align: center;
  }

  .exam-sheet__foot {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    margin-block-start: auto;
    padding-block-start: var(--space-3);
    border-block-start: 1px solid var(--attend-border-strong);
    color: var(--attend-text-muted);
    font-size: 11px;
    line-height: 14px;
  }

  /* The hall on paper: as wide as the sheet, every seat a share of its row
     (at most 34mm: a block of 5 fills the sheet), so up to 9 seats fit
     upright. A shorter
     row ends in empty places, which keeps the seats in columns. */
  .xm-hall.ps-hall {
    display: block;
    inline-size: 100%;
    padding: 6px 10px;
    border-color: var(--attend-text-strong);
    border-radius: var(--r-sm);
    color: var(--attend-text-strong);
  }

  .ps-hall .xm-band + .xm-floor,
  .ps-hall .xm-floor + .xm-band {
    margin-block-start: var(--space-2);
  }

  .ps-hall .xm-front,
  .ps-hall .xm-mark {
    border-color: var(--attend-text-strong);
    background: var(--attend-surface);
    color: var(--attend-text-strong);
  }

  .ps-hall .xm-wall {
    inline-size: 18px;
    border-color: var(--attend-text-strong);
    background: var(--attend-surface);
    font-size: 11px;
    line-height: 14px;
  }

  .ps-hall .xm-rows {
    flex: 1 1 auto;
    display: block;
    min-inline-size: 0;
  }

  .ps-hall .xm-row {
    align-items: stretch;
    justify-content: center;
    gap: var(--space-1);
    min-block-size: 0;
    break-inside: avoid;
  }

  .ps-hall .xm-row + .xm-row {
    margin-block-start: 3px;
  }

  .ps-hall .xm-no {
    align-self: center;
    inline-size: 26px;
    min-inline-size: 0;
    color: var(--attend-text-strong);
    font-size: 14px;
    font-weight: var(--weight-label);
    line-height: 18px;
    text-align: center;
  }

  .ps-hall .xm-aisle {
    inline-size: var(--space-2);
  }

  /* The column numbers over the seats, each as wide as its column's seats. */
  .ps-col {
    flex: 1 1 0;
    min-inline-size: 0;
    max-inline-size: 34mm;
    color: var(--attend-text-muted);
    font-size: 11px;
    font-weight: var(--weight-label);
    line-height: 14px;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }

  /* A seat: its number and the University ID on the top line (the ID drops
     under the number when the seat is too narrow for both), the student's
     first two names under them, one a line, wrapping rather than cut. */
  .ps-seat {
    flex: 1 1 0;
    box-sizing: border-box;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    align-items: baseline;
    justify-content: space-between;
    gap: 0 var(--space-1);
    min-inline-size: 0;
    max-inline-size: 34mm;
    min-block-size: 42px;
    padding: 1px 3px;
    border: 1px solid var(--attend-border-strong);
    border-radius: var(--r-xs);
    background: var(--attend-surface);
    text-align: center;
    overflow: hidden;
  }

  .ps-seat--none {
    visibility: hidden;
  }

  /* A seat another exam uses at this time: dashed, with that subject. */
  .ps-seat--other {
    border-style: dashed;
  }

  .ps-no {
    color: var(--attend-text-strong);
    font-size: 10px;
    font-weight: var(--weight-strong);
    line-height: 12px;
    font-variant-numeric: tabular-nums;
  }

  .ps-name,
  .ps-other {
    order: 2;
    flex: 1 0 100%;
    max-inline-size: 100%;
    color: var(--attend-text-strong);
    font-size: 11px;
    font-weight: var(--weight-bold);
    line-height: 13px;
  }

  .ps-name span {
    display: block;
    overflow-wrap: anywhere;
  }

  .ps-other {
    color: var(--attend-text);
    font-weight: var(--weight-medium);
    overflow-wrap: anywhere;
  }

  .ps-id {
    order: 1;
    min-inline-size: 0;
    margin-inline-start: auto;
    color: var(--attend-text);
    font-size: 10px;
    font-weight: var(--weight-medium);
    line-height: 12px;
    overflow-wrap: anywhere;
    font-variant-numeric: tabular-nums;
  }

  /* Three columns of two lines: Present over Absent, then each invigilator
     over the signature (two rows, so the last sheet still fits Letter). */
  .ps-sign {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, auto);
    grid-auto-flow: column;
    gap: var(--space-6) var(--space-8);
    padding-block: var(--space-5) var(--space-2);
    break-inside: avoid;
  }

  .ps-sign p {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
  }

  .ps-line {
    flex: 1 1 auto;
    min-inline-size: 60px;
    border-block-end: 1px solid var(--attend-text-strong);
  }

  /* The door list: two columns of names, each against its ID, side by side
     inside the printable width of A4 and Letter (owner P3, 2026-11-15): fixed
     tables whose columns are shares of their half (the colgroup), a long name
     wrapping inside its own cell, a clear gap between the halves. */
  .pd-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 8mm;
  }

  .pd {
    inline-size: 100%;
    border-collapse: collapse;
    font-size: 13px;
    line-height: 18px;
  }

  .pd--fixed {
    table-layout: fixed;
  }

  .pd__name {
    inline-size: 45%;
  }

  .pd__id {
    inline-size: 22%;
  }

  .pd__seat {
    inline-size: 11%;
  }

  .pd__column {
    inline-size: 13%;
  }

  .pd__row {
    inline-size: 9%;
  }

  /* Headings wrap between their words only ("University ID" on two lines). */
  .pd th {
    block-size: 26px;
    padding: 0 3px;
    border-block-end: 2px solid var(--attend-text-strong);
    color: var(--attend-text-strong);
    font-size: 10px;
    font-weight: var(--weight-label);
    line-height: 12px;
    text-align: start;
  }

  /* 24 lines of two-line names still fit Letter's height (31px a line). */
  .pd td {
    block-size: 26px;
    padding: 0 3px;
    border-block-end: 1px solid var(--attend-border);
    color: var(--attend-text-strong);
    white-space: nowrap;
    overflow: hidden;
  }

  .pd td:first-child {
    padding-block: 1px;
    font-size: 12px;
    font-weight: var(--weight-bold);
    line-height: 14px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .pd td:nth-child(2) {
    font-size: 12px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  /* The name keeps its own direction and its own cell. */
  .pd td:first-child bdi {
    display: block;
    unicode-bidi: isolate;
  }

  /* On a left-to-right page the names stand against the ID beside them. */
  .pd--names-end th:first-child,
  .pd--names-end td:first-child {
    text-align: end;
  }

  .pd th:nth-child(n + 3),
  .pd td:nth-child(n + 3) {
    padding-inline: 1px;
    text-align: center;
  }

  .pd td:nth-child(n + 3) {
    font-weight: var(--weight-label);
  }

  /* The attendance list: two halves of 25 students side by side (owner,
     2026-11-15), 11px, in the door list's columns (.pd-columns): the running
     number, the University ID, the full name (wrapping in its own cell, two
     lines still fit a row) and an empty cell to sign in, ruled off from the name. */
  .pa {
    inline-size: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 11px;
    line-height: 13px;
  }

  .pa__no {
    inline-size: 7%;
  }

  .pa__id {
    inline-size: 20%;
  }

  .pa__name {
    inline-size: 46%;
  }

  .pa__sign {
    inline-size: 27%;
  }

  .pa th {
    block-size: 26px;
    padding: 0 4px 4px;
    border-block-end: 2px solid var(--attend-text-strong);
    color: var(--attend-text-strong);
    font-size: 10px;
    font-weight: var(--weight-label);
    line-height: 12px;
    text-align: start;
    vertical-align: bottom;
  }

  /* Every row the same height, a two-line name included (7.4mm, room to sign). */
  .pa td {
    block-size: 28px;
    padding: 1px 4px;
    border-block-end: 1px solid var(--attend-border);
    color: var(--attend-text-strong);
    font-weight: var(--weight-label);
  }

  .pa th:first-child,
  .pa td:first-child {
    padding-inline: 1px;
    color: var(--attend-text-muted);
    text-align: center;
  }

  /* A long University ID (up to 32 characters) wraps in its own cell, as on the
     door list, never over the name. */
  .pa td:nth-child(2) {
    overflow-wrap: anywhere;
  }

  .pa td:nth-child(3) {
    font-weight: var(--weight-bold);
    overflow-wrap: anywhere;
  }

  /* The name keeps its own direction but lines up with the page's start (an
     inline isolate, not a block): on an English page an Arabic name stands
     against the ID, not the signature. */
  .pa td:nth-child(3) bdi {
    unicode-bidi: isolate;
  }

  .pa th:last-child,
  .pa td:last-child {
    border-inline-start: 1px solid var(--attend-border);
  }

  /* The list's last sheet: the same lines, closer to a full page of names. */
  .ps-sign--list {
    gap: var(--space-5) var(--space-8);
    padding-block: var(--space-4) var(--space-2);
  }

  @media print {
    @page exam-sheet {
      size: A4 portrait;
      margin: 10mm;
    }

    /* Paper is white to its edge: below a short last sheet too. */
    :root:has(> body.exam-print),
    body.exam-print {
      background: var(--attend-surface);
    }

    .exam-print__bar {
      display: none;
    }

    .exam-sheets {
      overflow: visible;
      padding: 0;
    }

    /* The sheet is the printable area: the page's margin is the paper's. At
       most Letter's printable height (259mm), so a sheet printed on Letter is
       still one page. */
    .exam-sheet {
      page: exam-sheet;
      inline-size: auto;
      min-block-size: 257mm;
      margin: 0;
      /* A hair at the top, so the first line's frames ("Not published yet")
         never bleed into the sheet before. */
      padding: 1px 0 0;
      box-shadow: none;
    }
  }
}
