/* ============================================================================
   result.css — the published score table and a taker's marked answer sheet.

   Both audiences share the table, so it is styled once. The sheet is only
   ever seen by the person who wrote it.
   ========================================================================= */

/* --- filter bar ---------------------------------------------------------- */

.result-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.result-filter { width: auto; min-width: 160px; }
.result-search { flex: 1 1 200px; min-width: 160px; }

.result-bar .dataset-count {
  margin-left: auto;
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
}

/* --- the table ----------------------------------------------------------- */

/* Long shop and staff names on a phone would push the page sideways; the
   table scrolls inside its own box instead. */
.result-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.result-table th,
.result-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.result-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-alt);
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.result-table tbody tr:last-child td { border-bottom: 0; }
.result-table tbody tr:hover { background: var(--surface-alt); }

.result-table .is-num  { text-align: right; }
.result-table .is-mono { font-family: var(--font-mono); font-weight: 600; }

/* A taker reading a long roll should find their own line without hunting. */
.result-table tr.is-self td {
  background: var(--accent-soft);
  font-weight: 700;
}
.result-table tr.is-self:hover td { background: var(--accent-soft); }

.result-empty {
  padding: 24px 14px;
  text-align: center;
}

/* --- pass / fail --------------------------------------------------------- */

.verdict {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.verdict.is-pass { background: var(--success-soft); color: #0C7150; }
.verdict.is-fail { background: var(--danger-soft);  color: #A5271F; }

.verdict.is-lg { font-size: 15px; padding: 6px 16px; }

/* --- the taker's own score ---------------------------------------------- */

.result-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 22px 16px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.result-hero-label {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.result-hero-score {
  margin: 0;
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--ink);
}

/* --- the marked answer sheet -------------------------------------------- */

.sheet {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* A stripe down the edge says right or wrong at a glance while scrolling,
   without colouring the whole card and making the text hard to read. */
.sheet-q {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius-md);
}

.sheet-q.is-correct { border-left-color: var(--success); }
.sheet-q.is-wrong   { border-left-color: var(--danger); }

.sheet-q-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

.sheet-q-no {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--ink-soft);
}

.sheet-q-text {
  flex: 1;
  font-weight: 600;
  line-height: 1.5;
}

.sheet-q-mark {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.sheet-q-mark.is-pass { background: var(--success-soft); color: #0C7150; }
.sheet-q-mark.is-fail { background: var(--danger-soft);  color: #A5271F; }

.sheet-options {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sheet-option {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.5;
}

/* The right answer is always marked, whether or not it was the one chosen —
   a wrong answer is only useful next to the right one. */
.sheet-option.is-right {
  background: var(--success-soft);
  border-color: var(--success);
}

.sheet-option.is-given-wrong {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.sheet-option-letter {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-alt);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}

.sheet-option-text { flex: 1; }

.sheet-tag {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  white-space: nowrap;
}

.sheet-tag.is-right { color: #0C7150; }

.sheet-blank {
  margin: 8px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--warning);
}

@media (max-width: 560px) {
  .result-bar .dataset-count { margin-left: 0; width: 100%; }
  .result-hero-score { font-size: 34px; }
  .sheet-q-head { flex-wrap: wrap; }
}

/* ============================================================================
   Past papers — the history list and the dialog that shows one
   ========================================================================= */

.paper-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.paper-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.paper-row-main { flex: 1; min-width: 0; }

.paper-row-title {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 700;
}

.paper-row-meta {
  margin: 0;
  font-size: 12px;
  color: var(--ink-soft);
}

/* --- the dialog ---------------------------------------------------------- */

/* Sized against the viewport rather than the content: a forty-question paper
   should scroll inside the dialog, not push it off the screen. */
.paper-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.paper-dialog::backdrop {
  background: rgba(16, 32, 58, 0.45);
}

.paper-dialog-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.paper-dialog-head > div:first-child { flex: 1; min-width: 0; }

.paper-dialog-title {
  margin: 0 0 2px;
  font-size: 17px;
  font-weight: 700;
}

.paper-dialog-body {
  padding: 16px 20px 20px;
  overflow-y: auto;
  max-height: calc(100vh - 190px);
}

.paper-dialog .import-message { margin: 0 20px; }

.paper-questions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.paper-q {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.paper-q-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

@media (max-width: 560px) {
  .paper-row { flex-wrap: wrap; }
  .paper-dialog-head { flex-wrap: wrap; }
  .paper-dialog-body { max-height: calc(100vh - 230px); }
}

/* Sortable headers. The whole cell is the target, not a small icon in it —
   on a phone a header is already a thin strip. */
.result-table th.is-sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.result-table th.is-sortable:hover { color: var(--ink); }
.result-table th.is-sorted { color: var(--accent-deep); }

.result-table th.is-sortable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Open, and — for whoever may write exams — delete. */
.paper-row-actions { display: flex; flex: none; gap: 6px; align-items: center; }
.result-table td.is-end { text-align: right; white-space: nowrap; }
@media (max-width: 480px) {
  .paper-row { flex-wrap: wrap; }
  .paper-row-actions { width: 100%; justify-content: flex-end; }
}

/* The score list on a phone: one card a person — name and pass/fail on top,
   shop and score under them. A five-column table pushed the delete button
   off the edge. The order is a select, since cards have no headings. */
.result-sort { display: none; }
@media (max-width: 640px) {
  .result-bar .result-filter, .result-bar .result-sort { display: block; width: 100%; }
  .result-bar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .result-bar .result-search { grid-column: 1 / -1; }
  .result-bar .dataset-count { grid-column: 1 / -1; }
  .result-table-wrap:has(> .result-table--scores) { overflow: visible; border: 0; background: none; }
  .result-table--scores, .result-table--scores tbody { display: block; }
  .result-table--scores thead { display: none; }
  .result-table--scores tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name verdict" "shop score" "del del";
    align-items: center;
    gap: 2px 12px;
    margin-bottom: 8px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
  }
  .result-table--scores td { padding: 0; border: 0; white-space: normal; min-width: 0; }
  .result-table--scores .rt-name { grid-area: name; font-weight: 700; font-size: 15px; }
  .result-table--scores .rt-shop { grid-area: shop; font-size: 13px; color: var(--ink-soft); }
  .result-table--scores .rt-score { grid-area: score; font-size: 15px; }
  .result-table--scores .rt-verdict { grid-area: verdict; justify-self: end; }
  .result-table--scores .rt-del { grid-area: del; justify-self: end; margin-top: 4px; }
  .result-table--scores tr.is-self { border-color: var(--accent); background: var(--accent-soft); }
  .result-table--scores tr.is-self td { background: none; }
}

/* Who logged in, on a phone: a card each — name and when, then shop and
   exam, then the device. */
@media (max-width: 640px) {
  .result-table-wrap:has(> .result-table--logins) { overflow: visible; border: 0; background: none; }
  .result-table--logins, .result-table--logins tbody { display: block; }
  .result-table--logins thead { display: none; }
  .result-table--logins tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name at" "shop exam" "device device";
    gap: 2px 12px;
    margin-bottom: 8px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
  }
  .result-table--logins td { padding: 0; border: 0; white-space: normal; min-width: 0; }
  .result-table--logins td:nth-child(1) { grid-area: shop; font-size: 13px; color: var(--ink-soft); }
  .result-table--logins td:nth-child(2) { grid-area: name; font-weight: 700; font-size: 15px; }
  .result-table--logins td:nth-child(3) { grid-area: exam; font-size: 13px; text-align: right; }
  .result-table--logins td:nth-child(4) { grid-area: at; font-size: 12.5px; color: var(--ink-soft); text-align: right; }
  .result-table--logins td:nth-child(5) { grid-area: device; font-size: 12px; color: var(--ink-faint); }
}

/* The results table is read once; this asks for it again. */
.result-refresh-row { display: flex; justify-content: flex-end; margin: 0 0 8px; }
.state-box .result-refresh { margin-top: 12px; }
