/* Exam results (apps.exams.results): the New result sheet page, a subject's
   list of sheets, the list a lecturer types the marks in and the check of a
   pasted or uploaded sheet (boards R5-NewSheet, R5-Grid, R5-GridPhone,
   R5-Preview); the Exam committee's pages, a published sheet's "More" menu and
   "Correct a mark" (boards R5-Correct, R5-Withdraw), the objections (board
   R5-Objections); the student's own results with "Object" and its answer
   (boards R5-StudentResults, R5-SubjectResults, R5-Objection,
   R5-ObjectionStates) and the Today card "New result".

   Loaded after subjects.css (templates/base.html). Only rules in the declared
   layers, only tokens, only logical properties. */

@layer components {
  /* --- New result sheet --------------------------------------------------- */
  .new-sheet {
    max-inline-size: 840px;
  }

  .new-sheet__exams {
    display: flex;
    flex-direction: column;
  }

  /* "Another exam" with its kind and name on one line, wrapping on a phone. */
  .new-sheet__other {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-4);
  }

  .new-sheet__other select {
    flex: 0 1 190px;
    inline-size: auto;
  }

  .new-sheet__other input[type="text"] {
    flex: 1 1 220px;
    max-inline-size: 280px;
  }

  .new-sheet__full {
    max-inline-size: 280px;
  }

  /* The ways to enter the marks: one card each, the chosen one outlined. */
  .new-sheet__ways {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
  }

  .new-sheet__way {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-4);
    border: 1px solid var(--attend-border-strong);
    border-radius: var(--r-md);
    background: var(--attend-surface);
    cursor: pointer;
  }

  .new-sheet__way:has(input:checked) {
    border-color: var(--attend-brand);
    background: var(--attend-row-selected);
    outline: 1px solid var(--attend-brand);
  }

  .new-sheet__way input[type="radio"] {
    position: absolute;
    inset-block-start: var(--space-4);
    inset-inline-end: var(--space-4);
  }

  .new-sheet__way-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inline-size: 40px;
    block-size: 40px;
    border-radius: 50%;
    background: var(--attend-brand-tint);
    color: var(--attend-brand-text);
  }

  .new-sheet__way-label {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
  }

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

    /* "Add from Excel": the three ways that read rows. */
    .new-sheet__ways--three {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  /* --- The rows: pasted, or a file (board R5-NewSheet) -------------------- */
  .marks-source {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }

  /* The label, and beside it how many lines were pasted. */
  .marks-source__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
  }

  /* Rows as a spreadsheet gives them: one line each, columns kept apart. */
  .marks-source__paste {
    block-size: 196px;
    font-family: var(--font-mono);
    font-size: var(--text-small);
    line-height: 22px;
    tab-size: 22;
    white-space: pre;
    overflow: auto;
  }

  /* --- Check the marks (board R5-Preview) --------------------------------- */
  /* "Skipped rows" with its count beside it. */
  .check-skipped__head {
    justify-content: flex-start;
    gap: var(--space-2);
  }

  .check-columns {
    max-inline-size: 520px;
  }

  /* A row's number is under the heading "Row" on a wide screen; on a phone
     each row is a card and the word comes with the number. */
  @media (min-width: 768px) {
    .check-table__word {
      display: none;
    }
  }

  /* On a phone the reason is the card's last line, read from its start. */
  @media (max-width: 767px) {
    .check-table .check-table__why {
      justify-content: flex-start;
      text-align: start;
    }
  }

  /* --- A subject's result sheets ------------------------------------------ */
  .sheet-table__kind {
    display: block;
  }

  .sheet-table__note {
    margin-block-start: var(--space-1);
    color: var(--attend-text-secondary);
  }

  /* --- The typed list: what to show, the order, find by ID ---------------- */
  .mark-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3) var(--space-4);
  }

  .mark-show {
    flex: none;
  }

  .mark-sort {
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }

  .mark-sort .btn--plain {
    justify-content: center;
    padding-inline: var(--space-4);
  }

  .mark-sort__narrow {
    display: none;
  }

  .mark-find {
    flex: 1 1 220px;
    max-inline-size: 300px;
    margin-inline-start: auto;
  }

  /* --- The typed list: one row for each student --------------------------- */
  /* Not clipped: a row's menu opens over the rows under it. */
  .mark-wrap {
    overflow: visible;
  }

  .mark-wrap__none {
    padding: var(--space-4);
    color: var(--attend-text-secondary);
  }

  .mark-row__name {
    color: var(--attend-text-strong);
    font-weight: var(--weight-medium);
  }

  .mark-cell {
    inline-size: 96px;
    padding-inline: var(--space-2);
    font-variant-numeric: tabular-nums;
    text-align: center;
  }

  .mark-row__value {
    display: inline-block;
    min-inline-size: 96px;
    color: var(--attend-text-strong);
    font-weight: var(--weight-medium);
    text-align: center;
  }

  /* Saved or not, with "Saving…" laid over it while the row is on its way
     (it shows after 300ms, as every htmx indicator does). */
  .mark-row__state {
    position: relative;
  }

  .mark-saved,
  .mark-none {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--attend-text-muted);
    font-size: var(--text-small);
  }

  .mark-saved .icon {
    inline-size: 16px;
    block-size: 16px;
  }

  .mark-saving {
    position: absolute;
    inset-block: 0;
    inset-inline: var(--space-4) 0;
    background: var(--attend-surface);
  }

  .mark-row__state .field__error {
    margin: 0;
  }

  /* A mark changed since a quiz handed it over (CONTRACTS.md §10). */
  .mark-from-quiz {
    display: block;
    margin-block-start: var(--space-1);
  }

  .mark-row__menu {
    text-align: end;
  }

  .mark-menu {
    display: inline-block;
  }

  /* The three dots say "more": no disclosure chevron beside them. */
  .mark-menu > summary::after {
    content: none;
  }

  /* Under its button, at the row's end (the live card's menu opens upward). */
  .mark-menu .tools-more__panel {
    inset-block: calc(100% + var(--space-1)) auto;
    inset-inline: auto 0;
    min-inline-size: 13rem;
    text-align: start;
  }

  .mark-menu__title {
    padding: var(--space-1) var(--space-3);
  }

  .mark-menu .btn[aria-current="true"] {
    border-color: transparent;
    background: var(--attend-row-selected);
  }

  /* --- The foot: the count and Send, always in reach ---------------------- */
  .mark-foot {
    position: sticky;
    inset-block-end: 0;
    z-index: 4;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3) var(--space-6);
    padding-block: var(--space-3);
    border-block-start: 1px solid var(--attend-edge);
    background: var(--attend-ground);
  }

  /* The list ends on the foot: no gap for a row to show through. */
  .content__body > .mark-foot {
    margin-block-start: 0;
  }

  .mark-foot__line {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
  }

  .mark-foot__link {
    display: none;
    align-items: center;
    min-block-size: var(--touch);
  }

  /* At the end of the foot, also when the "not saved" line pushes it to a
     line of its own. */
  .mark-foot__form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2) var(--space-4);
    margin-inline-start: auto;
  }

  /* Compact for a mouse only (tests/test_css_touch.py): the board's 36px field. */
  @media (min-width: 768px) and (pointer: fine) {
    input.mark-cell {
      min-height: 36px;
      block-size: 36px;
      padding-block: 0;
    }
  }

  /* Phone (board R5-GridPhone): find first, then the order; each student is
     two lines (the name; the ID and whether it is saved) beside the field and
     the menu; a refusal takes a line of its own. "No mark yet" is the foot's
     link, which stands above the tab bar. */
  @media (max-width: 767px) {
    .mark-show,
    .mark-sort__label,
    .mark-sort__wide,
    .mark-foot__hint {
      display: none;
    }

    .mark-sort__narrow {
      display: inline;
    }

    .mark-find {
      order: -1;
      flex-basis: 100%;
      max-inline-size: none;
      margin-inline-start: 0;
    }

    .mark-sort,
    .mark-sort .roster-tabs {
      flex: 1 1 100%;
    }

    .mark-sort .roster-tabs {
      display: flex;
    }

    .mark-sort .btn--plain {
      flex: 1 1 0;
      padding-inline: var(--space-2);
    }

    .mark-table,
    .mark-table tbody {
      display: block;
    }

    .mark-table thead {
      position: absolute;
      inline-size: 1px;
      block-size: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }

    .mark-row {
      display: grid;
      grid-template-columns: auto minmax(0, 1fr) auto auto;
      grid-template-areas:
        "who who mark menu"
        "id state mark menu"
        "error error error error";
      align-items: center;
      column-gap: var(--space-2);
      padding: var(--space-3) var(--space-4);
      border-block-start: 1px solid var(--attend-border);
    }

    .mark-row:first-child {
      border-block-start: 0;
    }

    .mark-table .mark-row > td {
      padding: 0;
      border: 0;
    }

    .mark-row__who {
      grid-area: who;
      min-inline-size: 0;
      overflow-wrap: anywhere;
    }

    .mark-row__name {
      font-weight: var(--weight-strong);
    }

    .mark-row__id {
      grid-area: id;
      color: var(--attend-text-muted);
    }

    .mark-row__state {
      grid-area: state;
    }

    .mark-row__mark {
      grid-area: mark;
    }

    .mark-row__menu {
      grid-area: menu;
    }

    .mark-row--error .mark-row__state {
      grid-area: error;
      padding-block-start: var(--space-2);
    }

    .mark-saving {
      inset-inline-start: 0;
    }

    .mark-cell,
    .mark-row__value {
      inline-size: 80px;
      min-inline-size: 80px;
    }

    input.mark-cell {
      min-height: 48px;
    }

    .mark-foot {
      flex-direction: column;
      align-items: stretch;
      gap: var(--space-2);
    }

    .shell--bottom-nav .mark-foot {
      inset-block-end: var(--bottom-nav-room);
    }

    .mark-foot__count {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: 0 var(--space-4);
    }

    .mark-foot__link {
      display: inline-flex;
    }

    .mark-foot__form {
      flex-direction: column;
      align-items: stretch;
      margin-inline-start: 0;
    }

    .mark-foot__send {
      inline-size: 100%;
    }
  }

  /* --- The Exam committee: the queue and one sheet to review ---------------
     (boards R5-Queue, R5-Review, R5-ReviewPublish) */
  /* The lists (Waiting, Published, Returned; All, No mark, ...) at the start,
     the find field at the end; they wrap under each other on a phone. */
  .review-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3) var(--space-5);
  }

  .review-tools .roster-tabs {
    flex: none;
    max-inline-size: 100%;
  }

  .report-headline + .review-tools {
    margin-block-start: var(--space-6);
  }

  .review-find {
    flex: 1 1 220px;
    max-inline-size: 300px;
  }

  .review-find input[type="search"] {
    min-block-size: 40px;
  }

  /* "Staff only." under the figures: the lock, then the sentence. */
  .review-note {
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }

  .review-note .icon {
    flex: none;
  }

  .review-table__mark {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
  }

  .queue-table__subject {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
  }

  /* The second line of a cell: the code and stage, the exam's day, the note. */
  .queue-table__under {
    display: block;
  }

  .queue-table__short {
    white-space: nowrap;
  }

  .queue-table__go {
    text-align: end;
    white-space: nowrap;
  }

  .queue-note {
    max-inline-size: 70ch;
  }

  /* --- The student's results (boards R5-StudentResults, R5-SubjectResults) ---
     One row for each result: the exam and its day, the mark out of the full
     mark with the grade word under it, ONE chip at the row's end. */
  .result-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
  }

  .result-line__words {
    flex: 1 1 0;
    min-inline-size: 0;
  }

  .result-mark {
    color: var(--attend-text-strong);
    font-family: var(--font-display);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  .result-mark__n {
    font-size: 30px;
    line-height: 34px;
    font-weight: var(--weight-display);
    letter-spacing: var(--tracking-h1);
  }

  .result-mark__of {
    color: var(--attend-text-muted);
    font-family: var(--font-body);
    font-size: var(--text-num-m);
    line-height: var(--leading-num-m);
    font-weight: var(--weight-num-m);
  }

  .result-grade {
    color: var(--attend-text);
    font-weight: var(--weight-medium);
  }

  /* "New": a dot and the word beside the exam's name, until the page was opened. */
  .result-new {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    margin-inline-start: var(--space-2);
    color: var(--attend-brand-text);
    font-size: var(--text-label);
    line-height: var(--leading-label);
    font-weight: var(--weight-label);
    letter-spacing: var(--tracking-label);
    vertical-align: middle;
  }

  .result-new::before {
    content: "";
    inline-size: 6px;
    block-size: 6px;
    border-radius: 50%;
    background: var(--attend-accent);
  }

  /* "Corrected on ...": a muted line under the mark. */
  .result-note {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    color: var(--attend-text-muted);
    font-size: var(--text-small);
    line-height: var(--leading-small);
  }

  .result-note .icon {
    flex: none;
    margin-block-start: 2px;
  }

  /* A subject's section starts with its list: the room the row of sections leaves. */
  .subject-results {
    margin-block-start: var(--space-4);
  }

  /* Earlier terms: closed under the running term's results. */
  .results-earlier {
    margin-block-start: var(--space-6);
  }

  .results-earlier > summary {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
  }

  .results-earlier__term + .results-earlier__term {
    margin-block-start: var(--space-6);
  }

  /* --- Today: "New result" (board F2-TodayFilesA) --------------------------
     The award in a tinted circle, then the words; the whole row is the link. */
  .today-result__row {
    flex-wrap: nowrap;
    justify-content: flex-start;
  }

  .today-result__icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    inline-size: 44px;
    block-size: 44px;
    border-radius: 50%;
    background: var(--attend-brand-tint);
    color: var(--attend-brand-text);
  }

  .today-result__body {
    min-inline-size: 0;
  }

  /* --- A published sheet: "More" and "Correct a mark" (boards R5-Withdraw,
     R5-Correct) ------------------------------------------------------------
     The menu opens under its button, at the header's end, wide enough for the
     withdraw form. */
  .sheet-more {
    position: relative;
  }

  .sheet-more .tools-more__panel {
    inset-block: calc(100% + var(--space-1)) auto;
    inset-inline: auto 0;
    inline-size: min(24rem, calc(100vw - 2 * var(--space-4)));
    padding: var(--space-3);
    text-align: start;
  }

  .sheet-more__form {
    gap: var(--space-3);
  }

  /* Below "Export CSV" (board R5-Withdraw): the withdraw part is set apart. */
  .sheet-more__export ~ .sheet-more__form,
  .sheet-more__export ~ .sheet-more__danger {
    margin-block-start: var(--space-2);
    padding-block-start: var(--space-3);
    border-block-start: 1px solid var(--attend-border);
  }

  .sheet-more__title,
  .sheet-more__danger {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--attend-danger-text);
    font-weight: var(--weight-button);
  }

  .sheet-more .actions .btn {
    inline-size: auto;
  }

  /* "Mark now" beside "New mark". */
  .correct-marks {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: var(--space-4);
  }

  /* --- Objections (board R5-Objections): the list, and the opened one ------ */
  .objections {
    display: grid;
    gap: var(--space-5);
    align-items: start;
    margin-block-start: var(--space-4);
  }

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

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

  .objection-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }

  .objection-panel__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
  }

  .objection-panel__id {
    margin-inline-start: var(--space-2);
    color: var(--attend-text-muted);
    font-family: var(--font-body);
    font-size: var(--text-small);
    font-weight: var(--weight-medium);
  }

  .objection-panel__mark {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
  }

  .objection-words {
    margin: 0;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--r-md);
    background: var(--attend-brand-tint);
    color: var(--attend-text);
    white-space: pre-line;
    overflow-wrap: anywhere;
  }

  /* The way from the Results page: "Objections waiting for an answer  3  >". */
  .objections-link {
    gap: var(--space-2);
  }

  /* --- The student's "Object" line and the objection's answer (boards
     R5-Objection, R5-ObjectionStates) --------------------------------------- */
  .result-object {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-block-end: calc(-1 * var(--space-3));
    padding-block: var(--space-2);
    border-block-start: 1px solid var(--attend-border);
  }

  .result-object p {
    flex: 1 1 0;
    min-inline-size: 0;
    line-height: var(--leading-small);
  }

  .result-object .btn {
    flex: none;
  }

  .object-steps {
    margin: 0;
    padding-inline-start: var(--space-5);
  }
  /* --- The Super Admin's grade scale (board R5-GradeScale) ---------------- */
  .grade-scale-page {
    display: grid;
    gap: var(--space-8);
    align-items: start;
  }

  @media (min-width: 1024px) {
    .grade-scale-page {
      grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
    }
  }

  .grade-scale__help {
    margin-block: var(--space-1) var(--space-3);
  }

  .grade-scale__grade {
    color: var(--attend-text-strong);
    font-weight: var(--weight-strong);
    text-align: start;
  }

  .grade-scale__pass {
    font-weight: var(--weight-medium);
  }

  .grade-scale__ar {
    font-family: var(--font-arabic);
  }

  .grade-scale__limit {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
  }

  .grade-scale__limit input {
    inline-size: 72px;
    min-block-size: 44px;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }

  .grade-scale__days {
    max-inline-size: 360px;
  }
}
