/* ================================================================
   CAMNAT Marker — Design System
   Aesthetic: Refined educational tool. Deep navy accent, warm white
   surfaces, crisp typography. Professional without being sterile.
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;0,9..40,800;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

/* ── Tokens ─────────────────────────────────────────────────── */
:root {
  --bg:          #f7f8fa;
  --surface:     #ffffff;
  --text:        #111827;
  --muted:       #6b7280;
  --border:      #e5e7eb;
  --border-mid:  #d1d5db;
  --card:        #ffffff;

  /* Brand */
  --primary:         #1e3a5f;
  --primary-hover:   #162e4d;
  --primary-light:   #e8eef6;
  --primaryText:     #ffffff;
  --accent:          #2563eb;

  /* Semantic */
  --chip:    #f3f4f6;
  --danger:  #dc2626;
  --warn:    #d97706;
  --ok:      #16a34a;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg:  0 10px 30px rgba(0,0,0,.09), 0 4px 8px rgba(0,0,0,.04);

  /* Radii */
  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   18px;
  --r-xl:   24px;
  --r-pill: 999px;
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  overflow-x: hidden;
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
h1, h2, h3 { margin: 0; font-family: 'DM Sans', sans-serif; }

/* ── Page fade-in ────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.container, .container-wide {
  animation: fadeUp 0.35s ease both;
}

/* ── Layout ──────────────────────────────────────────────────── */
.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 24px;
}
.container-wide {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px;
}

/* ── Header ──────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.brand {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary);
}

.app-logo {
  height: 30px;
  width: auto;
  display: block;
}

.page-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--muted);
  letter-spacing: 0;
}

/* Header nav links */
.header .row a.small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  transition: background 0.15s, color 0.15s;
}
.header .row a.small:hover {
  background: var(--primary-light);
  color: var(--primary);
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 24px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s;
}
.card + .card { margin-top: 16px; }

/* ── Typography helpers ──────────────────────────────────────── */
.h2 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.3px;
  margin-bottom: 6px;
  color: var(--text);
}

.label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.small {
  font-size: 13px;
  color: var(--muted);
}

/* ── Row / flex helpers ──────────────────────────────────────── */
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

/* ── Inputs ──────────────────────────────────────────────────── */
.input, select {
  border: 1.5px solid var(--border-mid);
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  min-width: 220px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
select { cursor: pointer; }

/* Marking tables — no forced 220px */
.markingTable .evidence-input,
.markingTable textarea.evidence-input,
.markingTable select.markSelect,
.markingTable .markWrap select,
.markingTable input:not([type="checkbox"]) {
  min-width: 0 !important;
  width: 100%;
}
.markingTable .markWrap { display: flex; align-items: center; gap: 8px; }
.markingTable .markWrap .small { white-space: nowrap; }

/* ── Buttons ─────────────────────────────────────────────────── */
button {
  border: 1.5px solid var(--border-mid);
  border-radius: var(--r-md);
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  background: #fff;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  line-height: 1.3;
}
button:hover {
  background: var(--chip);
  border-color: var(--border-mid);
}
button:active { transform: translateY(1px); }

button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primaryText);
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(30,58,95,0.20);
}
button.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 4px 10px rgba(30,58,95,0.28);
}

button.ghost {
  background: #fff;
  border-color: var(--border-mid);
}
button.ghost:hover {
  background: var(--chip);
}

button.danger {
  background: #fff;
  border-color: #fecaca;
  color: #b91c1c;
}
button.danger:hover {
  background: #fef2f2;
}

/* Anchor-as-button */
a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--border-mid);
  border-radius: var(--r-md);
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  background: #fff;
  color: inherit;
  text-decoration: none;
  line-height: 1.3;
  transition: background 0.15s, border-color 0.15s;
}
a.button.ghost { background: #fff; }
a.button:hover { background: var(--chip); }
a.button:active { transform: translateY(1px); }
a.button[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

.btn-secondary { background: #fff; border-color: var(--border-mid); color: var(--text); }
.btn-secondary:hover { background: var(--chip); }

/* ── Pills / Chips ───────────────────────────────────────────── */
.pill {
  display: inline-block;
  padding: 4px 11px;
  border-radius: var(--r-pill);
  font-weight: 700;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--chip);
  letter-spacing: 0.2px;
}
.pill.red   { border-color: #fecaca; background: #fee2e2; color: #991b1b; }
.pill.amber { border-color: #fde68a; background: #fef3c7; color: #92400e; }
.pill.green { border-color: #bbf7d0; background: #dcfce7; color: #166534; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 4px 11px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  line-height: 1;
  white-space: nowrap;
}
.badge.green { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.badge.amber { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.badge.red   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ── Tables ──────────────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-top: 12px;
}
.table th, .table td {
  border-top: 1px solid var(--border);
  padding: 12px 10px;
  vertical-align: top;
}
.table th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #fafafa;
}

/* Table column widths */
.table th:nth-child(1), .table td:nth-child(1) { width: 42%; }
.table th:nth-child(2), .table td:nth-child(2) { width: 10%; }
.table th:nth-child(3), .table td:nth-child(3) { width: 12%; }
.table th:nth-child(4), .table td:nth-child(4) { width: 18%; }
.table th:nth-child(5), .table td:nth-child(5) { width: 18%; }
.table td, .table th { vertical-align: top; }

/* ── Marking table ───────────────────────────────────────────── */
.markingTable {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  /* Fixed layout means column widths are respected and cells cannot blow out */
  table-layout: fixed;
}
.markingTable th, .markingTable td {
  border: 1px solid var(--border);
  padding: 11px 13px;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
  /* Cells must not expand beyond their column width */
  overflow: hidden;
}
.markingTable th {
  background: #f9fafb;
  font-weight: 700;
  font-size: 12px;
  text-align: left;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.45px;
}
.markingTable .strandTitle {
  white-space: pre-line;
  line-height: 1.4;
  font-weight: 600;
}
.markingTable .col-strand .small.muted {
  white-space: pre-line;
  line-height: 1.35;
}
.markingTable select.markSelect,
.markingTable input.evidence-input,
.markingTable textarea.evidence-input {
  width: 100%;
  box-sizing: border-box;
}

/* Column widths for marking table */
.markingTable th:nth-child(1), .markingTable td:nth-child(1) { width: 32% !important; }
.markingTable th:nth-child(2), .markingTable td:nth-child(2) { width: 190px !important; min-width: 190px !important; }

/* ── Grid table (class view) ─────────────────────────────────── */
.grid-wrap { overflow: auto; }
.grid-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}
.grid-table th, .grid-table td {
  border-top: 1px solid var(--border);
  padding: 10px 10px;
  font-size: 13px;
  text-align: center;
  white-space: nowrap;
}
.grid-table th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
  font-weight: 700;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.grid-table td:first-child, .grid-table th:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 2;
}
.grid-table th.stickyCol { position: sticky; left: 0; background: var(--card); z-index: 2; }
.grid-table td.totalCol, .grid-table th.totalCol {
  position: sticky;
  right: 0;
  background: var(--card);
  z-index: 1;
}
.grid-table td.cell.rag-red   { background: rgba(239, 68, 68, 0.08); }
.grid-table td.cell.rag-amber { background: rgba(245, 158, 11, 0.10); }
.grid-table td.cell.rag-green { background: rgba(34, 197, 94, 0.10); }

/* ── Traffic light selects ───────────────────────────────────── */
select.traffic-green {
  background: #d1fae5 !important;
  border: 1.5px solid #34d399 !important;
  color: #065f46 !important;
  font-weight: 600;
}
select.traffic-amber {
  background: #fef3c7 !important;
  border: 1.5px solid #fbbf24 !important;
  color: #92400e !important;
  font-weight: 600;
}
select.traffic-red {
  background: #fee2e2 !important;
  border: 1.5px solid #f87171 !important;
  color: #991b1b !important;
  font-weight: 600;
}

/* Class grid traffic-light cells */
.tl-green { background: #d1fae5 !important; color: #065f46; font-weight: 600; }
.tl-amber { background: #fef3c7 !important; color: #92400e; font-weight: 600; }
.tl-red   { background: #fee2e2 !important; color: #991b1b; font-weight: 600; }

/* ── RAG badges ──────────────────────────────────────────────── */
.ragBadge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0 12px;
  border-radius: var(--r-pill);
  font-weight: 700;
  font-size: 12px;
  width: fit-content;
}
.rag-red   { background: #fee2e2; color: #991b1b; }
.rag-amber { background: #fef3c7; color: #92400e; }
.rag-green { background: #d1fae5; color: #065f46; }

/* ── Strand labels ───────────────────────────────────────────── */
.strand-title {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.1px;
}
.strand-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* ── Comment bank ────────────────────────────────────────────── */
.comment-bank {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.comment-bank button {
  border-radius: var(--r-pill);
  padding: 5px 11px;
  background: var(--primary-light);
  border: 1px solid #c7d8ed;
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
}
.comment-bank button:hover {
  background: #d4e5f7;
}

/* ── Score display ───────────────────────────────────────────── */
.total {
  font-size: 44px;
  font-weight: 900;
  margin-top: 6px;
  letter-spacing: -2px;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

/* ── Tip ─────────────────────────────────────────────────────── */
.tip {
  margin-left: auto;
  padding: 8px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--chip);
  font-size: 13px;
  color: var(--muted);
}

/* ── Tabs ────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  background: var(--chip);
  padding: 4px;
  border-radius: var(--r-md);
  width: fit-content;
}
.tab {
  border-radius: var(--r-sm);
  padding: 7px 14px;
  border: none;
  background: transparent;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.tab.active {
  background: #fff;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ── Evidence inputs ─────────────────────────────────────────── */
.evidence-input {
  width: 100%;
  max-width: 520px;
  min-width: 340px;
  padding: 9px 12px;
  border: 1.5px solid var(--border-mid);
  border-radius: var(--r-sm);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.evidence-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.10);
}
.evidenceInput {
  width: 100%;
  min-width: 0;
  max-width: 520px;
}

/* In marking tables */
.markingTable .evidence-input,
.markingTable input.evidence-input,
.markingTable textarea.evidence-input {
  min-width: 0 !important;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
}

/* ── Comment text ────────────────────────────────────────────── */
.comment-cell, .commentCell, .commentText {
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  overflow: hidden;
  /* Remove min-width so the cell respects its column boundary */
  min-width: 0;
}

/* The column itself must not overflow */
td.col-comment {
  overflow: hidden;
  max-width: 0;   /* combined with width below, forces the cell to honour table layout */
}

/* ── Marking layout (student view grid) ──────────────────────── */
.marking-table { width: 100%; }
.marking-header, .strand-row {
  display: grid;
  grid-template-columns: minmax(260px, 2.2fr) 120px 140px minmax(240px, 1.4fr) minmax(260px, 2fr);
  gap: 16px;
  align-items: start;
}
.marking-header {
  font-weight: 700;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 0 12px;
  border-bottom: 1px solid var(--border);
}
.strand-row {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
@media (max-width: 980px) {
  .marking-header { display: none; }
  .strand-row { grid-template-columns: 1fr; gap: 10px; }
}

/* Column rebalance */
.marking-table th:nth-child(1), .marking-table td:nth-child(1) { width: 38%; }
.marking-table th:nth-child(2), .marking-table td:nth-child(2) { width: 180px !important; min-width: 180px !important; white-space: nowrap; }
.marking-table td:nth-child(2) select { width: 70px !important; min-width: 70px !important; font-size: 14px !important; }

/* ── Student results table ───────────────────────────────────── */
#results .table { table-layout: fixed; }
#results .table th, #results .table td { overflow-wrap: anywhere; word-break: break-word; }
#results .table th:nth-child(1), #results .table td:nth-child(1) { width: 26%; }
#results .table th:nth-child(2), #results .table td:nth-child(2) { width: 90px; }
#results .table th:nth-child(3), #results .table td:nth-child(3) { width: 120px; }
#results .table th:nth-child(4), #results .table td:nth-child(4) { width: 220px; }
#results .table th:nth-child(5), #results .table td:nth-child(5) { width: 140px; }
#results .table th:nth-child(6), #results .table td:nth-child(6) { width: 22%; }
#results .table input[type="text"], #results .table textarea { width: 100%; max-width: 100%; }

/* ── Table scroll wrapper ────────────────────────────────────── */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
}

/* ── Column widths for wide tables ──────────────────────────── */
th.col-evidence, td.col-evidence { width: 200px; min-width: 160px; }
th.col-comment, td.col-comment { min-width: 260px; }
td.col-comment { width: 300px; }

/* ── Loading overlay ─────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(247,248,250,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(2px);
}
.loading-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: #fff;
  box-shadow: var(--shadow-lg);
}
.loading-text {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}

/* ── Spinner ─────────────────────────────────────────────────── */
.spinner {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ───────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  border-radius: var(--r-lg);
  padding: 14px 18px;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  width: min(520px, calc(100vw - 28px));
}
.toast-hidden { display: none; }
.toast-inner { display: flex; gap: 12px; align-items: center; }
.toast-title { font-weight: 700; font-size: 14px; line-height: 1.2; margin-bottom: 2px; }
.toast-msg { font-size: 13px; line-height: 1.2; opacity: 0.88; }

/* ── Centre number input ─────────────────────────────────────── */
#ursCentreNumber { min-width: 176px; width: 176px; max-width: 176px; }

/* ── Misc helpers ────────────────────────────────────────────── */
.linklist, .supportLinks { display: flex; flex-wrap: wrap; gap: 8px; }
.linklist a, .supportLinks a { color: var(--accent); text-decoration: underline; font-size: 13px; }
.linklist a:hover, .supportLinks a:hover { text-decoration: none; }
.supportLinks a { white-space: normal; }

.strandExtra { margin-top: 6px; }
.strandExtra div { margin: 0 0 2px; }

.mb-para { display: block; margin: 0 0 10px; }
.mb-para:last-child { margin-bottom: 0; }
.mb p, .criteria p, td p { margin: 0 0 8px; }

/* ── Admin section divider style ─────────────────────────────── */
.admin-section {
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
}
.admin-section:last-child { border-bottom: none; padding-bottom: 0; }
.admin-section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.admin-section-desc {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

/* Status message colours */
.success { color: var(--ok); font-weight: 600; }
.error   { color: var(--danger); font-weight: 600; }
.info    { color: var(--accent); font-weight: 500; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .evidence-input { min-width: 220px; max-width: 100%; }
  .comment-cell   { min-width: 280px; }
  .total          { font-size: 36px; }
  .container, .container-wide { padding: 16px; }
}
body { overflow-x: hidden; }

/* Prevent overflow in marking tables */
.markingTable { table-layout: fixed; }
.markingTable th, .markingTable td { overflow-wrap: anywhere; word-break: break-word; }

/* ================================================================
   Dual Flag System — Student & Teacher views
   ================================================================ */

/* ---- CRITICAL: override the generic .markingTable input rule ----
   That rule sets width:100% on ALL inputs, which distorts checkboxes.
   These selectors are more specific (2 classes + attr vs 1 class) and
   also carry !important so they can never be overridden by generic rules. */
.flag-cb,
.student-flag-ack-cb,
.student-remark-cb,
.teacher-improvement-cb,
.teacher-remark-clear-cb {
  width: 14px !important;
  min-width: 14px !important;
  height: 14px !important;
  min-height: 14px !important;
  flex-shrink: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  display: inline-block !important;
  cursor: pointer;
  accent-color: var(--primary);
  vertical-align: middle;
}

/* ---- Flag panel wrapper ---------------------------------------- */
.flag-panel {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.flag-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.flag-row-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  flex-shrink: 0;
  margin-top: 1px;
  line-height: 1.6;
}

.flag-row-label--improvement {
  background: #fff7ed;
  color: #9a3412;
  border: 1.5px solid #fed7aa;
}

.flag-row-label--remark {
  background: #eff6ff;
  color: #1e40af;
  border: 1.5px solid #bfdbfe;
}

.flag-items {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

/* ---- Individual flag item chip ---------------------------------- */
.flag-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px 4px 7px;
  border-radius: var(--r-pill);
  border: 1.5px solid var(--border-mid);
  background: #f9fafb;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  line-height: 1.3;
  transition: background 0.12s, border-color 0.12s;
}

/* Unchecked = neutral, hover shows interactivity */
.flag-item:not(.flag-item--lit):hover {
  background: #f0f0f0;
  border-color: #9ca3af;
}

/* Checked / active improvement flag — amber */
.flag-item--improvement-active {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #78350f;
  font-weight: 700;
}
.flag-item--improvement-active .flag-cb { accent-color: #d97706; }

/* Checked / active remark request — blue */
.flag-item--remark-active {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #1d4ed8;
  font-weight: 700;
}
.flag-item--remark-active .flag-cb { accent-color: #2563eb; }

/* Disabled-but-visible state (student can't SET teacher flags, teacher can't SET remark flags) */
.flag-item--readonly {
  cursor: default;
  opacity: 0.7;
}
.flag-item--readonly:hover { background: #f9fafb; border-color: var(--border-mid); }
.flag-item--readonly .flag-cb { cursor: default; pointer-events: none; }

/* ── CRITERION-ROW MATRIX ──────────────────────────────────────────────────
   Div-grid so it is safe to inject into a <td> via innerHTML.
   Each criterion row = row-number column + 3 band columns (MB1/MB2/MB3).
   ────────────────────────────────────────────────────────────────────────── */

.criterion-matrix {
  width: 100%;
  margin-top: 10px;
  font-size: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
  /* Force the div to lay out as a block so it fills the strand cell width */
  display: block;
  box-sizing: border-box;
}

/* ── Header + body rows share the same grid ── */
.crit-grid-header,
.crit-row {
  display: grid;
  /* 28px for row-number; three equal columns share the rest.
     min-width:0 on children prevents overflow from collapsing the cells. */
  grid-template-columns: 28px 1fr 1fr 1fr;
  width: 100%;
  box-sizing: border-box;
}

/* ── Header ── */
.crit-grid-header {
  border-bottom: 2px solid #d1d5db;
}

.crit-grid-header .crit-col {
  padding: 5px 6px;
  font-weight: 600;
  font-size: 11px;
  text-align: center;
  border-right: 1px solid #d1d5db;
  box-sizing: border-box;
  overflow: hidden;
  /* prevent the header text from overflowing */
  white-space: normal;
  word-break: break-word;
}
.crit-grid-header .crit-col:last-child { border-right: none; }

/* Band header colour coding */
.crit-header-mb1 { background: #fee2e2; color: #7f1d1d; }
.crit-header-mb2 { background: #fef9c3; color: #713f12; }
.crit-header-mb3 { background: #d1fae5; color: #064e3b; }

/* ── Criterion rows ── */
.crit-row {
  border-top: 1px solid #e5e7eb;
}
.crit-row:first-of-type { border-top: none; }

/* Row number */
.crit-col-num {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 8px;
  font-size: 10px;
  color: #9ca3af;
  border-right: 1px solid #e5e7eb;
  background: #fafafa;
  min-height: 36px;
  box-sizing: border-box;
  /* Prevent shrinking below declared width */
  min-width: 0;
}

/* Band criterion cell */
div.crit-cell {
  border-right: 1px solid #e5e7eb;
  transition: background 0.12s;
  cursor: pointer;
  /* Critical: allow grid cell to shrink without collapsing text */
  min-width: 0;
  box-sizing: border-box;
  overflow: hidden;
}
div.crit-cell:last-child { border-right: none; }
div.crit-cell:hover { background: #fefce8; }

/* Selected states per band */
div.crit-cell[data-band="mb1"].selected {
  background: #fee2e2 !important;
  outline: 2px solid #ef4444;
  outline-offset: -2px;
}
div.crit-cell[data-band="mb2"].selected {
  background: #fef08a !important;
  outline: 2px solid #ca8a04;
  outline-offset: -2px;
}
div.crit-cell[data-band="mb3"].selected {
  background: #d1fae5 !important;
  outline: 2px solid #059669;
  outline-offset: -2px;
}

/* The label makes the whole cell clickable */
.crit-cell-label {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  padding: 6px 6px 6px 6px;
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
  min-height: 36px;
  /* Overflow wrapping so text flows normally in the cell */
  overflow-wrap: anywhere;
  word-break: normal;
}

.crit-cell-label input[type="radio"] {
  margin-top: 2px;
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  accent-color: #ca8a04;
  cursor: pointer;
}

.crit-text {
  font-size: 11.5px;
  line-height: 1.4;
  color: #374151;
  /* Ensure text wraps and does not force column wide */
  overflow-wrap: anywhere;
  word-break: normal;
  min-width: 0;
}

/* Placeholder shown when a band has no statement at this row index */
.crit-placeholder {
  color: #9ca3af;
  font-style: italic;
  font-size: 11px;
}

/* Derived-mark hint shown below the mark dropdown */
.derived-mark-hint {
  margin-top: 4px;
  font-size: 10px;
  color: #9ca3af;
  text-align: center;
}

/* ── Evidence textarea ──────────────────────────────────────────────────── */
textarea.evidence-input {
  width: 100%;
  min-height: 80px;
  resize: vertical;
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
  line-height: 1.4;
  border: 1px solid var(--border-mid, #d1d5db);
  border-radius: 4px;
  box-sizing: border-box;
  background: var(--surface, #fff);
  color: var(--text, #111827);
}
textarea.evidence-input:focus {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: -1px;
  border-color: transparent;
}

@media print {
  .criterion-matrix { display: none !important; }
  .derived-mark-hint { display: none !important; }
}
