/* mrp References — the reference request form.
   Styled to match the assignment schedule PDF that ShinyShifts produces
   (R/assignment_schedule.R), and the PDF this app generates from it: a plain
   white A4-like page, the mrp logo top-left with the title right-aligned, a 3px
   brand-blue rule, section titles as centred bold bars on a pale-blue panel, and
   bordered label/value rows beneath. The colours are that document's constants.
   No background art, no gradients. */

:root {
  --ink: #0f172a;            /* TIMESHEETS_PDF_INK */
  --muted: #64748b;          /* TIMESHEETS_PDF_MUTED */
  --accent: #2c51f7;         /* TIMESHEETS_PDF_ACCENT */
  --accent-dark: #1e3ad1;
  --panel: #eef3ff;          /* TIMESHEETS_PDF_PANEL_FILL: section bars */
  --label-ink: #172554;      /* TIMESHEETS_PDF_LABEL_INK */
  --header-fill: #e8f1fb;    /* TIMESHEETS_PDF_HEADER_FILL: table headers */
  --border: #cbd5e1;         /* TIMESHEETS_PDF_HEADER_BORDER: every cell */
  --row-border: #dbe4f0;     /* TIMESHEETS_PDF_ROW_BORDER */
  --body-ink: #1f2937;       /* TIMESHEETS_PDF_BODY_INK */
  --danger: #b42318;
  --danger-tint: #fef3f2;
  --success: #1f9d63;
  --label-width: 230px;
  --focus: 0 0 0 2px rgba(44, 81, 247, 0.35);
}

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

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--body-ink);
  background: #f1f5f9;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent-dark); }

.req { color: var(--danger); }

/* ---------- page ---------- */

.progress {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 3px;
  background: var(--row-border);
}

.progress__bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 200ms ease;
}

.doc {
  max-width: 860px;
  margin: 24px auto;
  padding: 40px;
  background: #fff;
  border: 1px solid var(--row-border);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

@media (max-width: 720px) {
  .doc { margin: 0; padding: 20px 16px; border: 0; box-shadow: none; }
  body { background: #fff; }
}

.doc__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.doc__logo { display: block; height: 47px; width: auto; flex: none; }

.doc__logo-word { font-size: 28px; font-weight: 700; color: var(--ink); }

.doc__heading { text-align: right; min-width: 0; }

.doc__title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--ink);
}

.doc__org { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }

.doc__meta { margin: 2px 0 0; font-size: 11px; color: var(--muted); }

.doc__meta a { color: var(--muted); }

.doc__rule { height: 3px; margin: 14px 0 18px; background: var(--accent); }

@media (max-width: 560px) {
  .doc__header { flex-direction: column; }
  .doc__heading { text-align: left; }
  .doc__title { font-size: 22px; }
}

.doc__intro { margin: 0 0 4px; font-size: 13px; color: var(--body-ink); }

.doc__footer {
  margin-top: 28px;
  padding-top: 8px;
  border-top: 0.6px solid var(--row-border);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
  color: var(--accent);
}

.doc__footer a { color: var(--accent); }

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 0;
  color: var(--muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--row-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner, .btn__spinner { animation-duration: 3s; }
  .progress__bar { transition: none; }
}

/* ---------- sections: the PDF's centred title bar over a bordered table ---------- */

.doc-section { margin-top: 18px; }

.doc-section__title {
  margin: 0;
  padding: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  color: var(--ink);
}

.doc-section__intro {
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-top: 0;
  font-size: 12.5px;
  color: var(--muted);
}

/* Each row is a label cell and a value cell, borders shared with neighbours. */
.field {
  display: grid;
  grid-template-columns: var(--label-width) minmax(0, 1fr);
  border: 1px solid var(--border);
  border-top: 0;
}

.field > * { grid-column: 2; }

.field > .field__label {
  grid-column: 1;
  grid-row: 1 / span 4;
  padding: 9px 10px;
  border-right: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--label-ink);
}

.field > .control,
.field > .locked,
.field > .date-pair,
.field > .signature__pad {
  margin: 6px 8px 0;
}

.field > :last-child { margin-bottom: 6px; }

.field__hint,
.field__error {
  margin: 3px 10px 0;
  font-size: 12px;
}

.field__hint { color: var(--muted); }

.field__error { font-weight: 700; color: var(--danger); }

.field__error:empty { display: none; }

/* A label above, full width: the "further details" and comment boxes. */
.field--stacked { grid-template-columns: minmax(0, 1fr); }

.field--stacked > *,
.field--stacked > .field__label {
  grid-column: 1;
  grid-row: auto;
  border-right: 0;
}

.field--stacked > .field__label { padding-bottom: 0; }

@media (max-width: 640px) {
  .field { grid-template-columns: minmax(0, 1fr); }
  .field > *, .field > .field__label { grid-column: 1; grid-row: auto; border-right: 0; }
  .field > .field__label { padding-bottom: 0; font-weight: 700; }
}

.control {
  display: block;
  width: calc(100% - 16px);
  min-height: 38px;
  padding: 6px 8px;
  font: inherit;
  font-size: 16px; /* stops iOS zooming on focus */
  color: var(--body-ink);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 2px;
}

.locked .control,
.date-pair .control { width: 100%; }

.control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus);
}

textarea.control { min-height: 84px; resize: vertical; }

.field--invalid .control,
.field--invalid.control { border-color: var(--danger); background: var(--danger-tint); }

/* Supplied by the link: shown, not editable. */
.locked { position: relative; }

.locked .control {
  padding-right: 32px;
  background: var(--header-fill);
  color: var(--ink);
  cursor: default;
}

.locked .control:focus { box-shadow: none; border-color: var(--border); }

.locked__icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  line-height: 0;
}

.field--id .control { font-weight: 700; font-variant-numeric: tabular-nums; }

.date-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.date-part__label {
  display: block;
  margin-bottom: 2px;
  font-size: 12px;
  color: var(--muted);
}

.date-part .field__error { margin-left: 0; }

/* ---------- Yes/No questions: question | Yes  No, as on the paper form ---------- */

.question {
  border: 1px solid var(--border);
  border-top: 0;
}

.question__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px;
  align-items: stretch;
}

.question__text {
  float: left; /* lets the legend sit in a grid cell */
  width: 100%;
  margin: 0;
  padding: 9px 10px;
  font-size: 13.5px;
  color: var(--body-ink);
}

.question fieldset { margin: 0; padding: 0; border: 0; min-width: 0; display: contents; }

.choices {
  display: flex;
  align-items: center;
  justify-content: space-around;
  border-left: 1px solid var(--border);
  padding: 4px 8px;
}

.choice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 6px;
  font-size: 13.5px;
  cursor: pointer;
}

.choice input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.choice input:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 50%; }

.question > .field__error { margin: 0 10px 6px; }

.field--invalid .choices { background: var(--danger-tint); }

.question__details > .field { border-left: 0; border-right: 0; border-bottom: 0; border-top: 1px solid var(--border); }

@media (max-width: 640px) {
  .question__row { grid-template-columns: minmax(0, 1fr); }
  .choices { justify-content: flex-start; gap: 18px; border-left: 0; padding-top: 0; }
}

/* ---------- ratings: the PDF's grid, header fill across the scale ---------- */

.ratings { border: 1px solid var(--border); border-top: 0; }

.ratings__head,
.rating__row {
  display: grid;
  grid-template-columns: minmax(150px, 1.5fr) repeat(5, minmax(0, 1fr));
  align-items: stretch;
}

.ratings__head > span {
  padding: 6px 4px;
  background: var(--header-fill);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  color: var(--ink);
}

.ratings__head > span:first-child { border-left: 0; text-align: left; padding-left: 10px; color: var(--label-ink); }

.rating { margin: 0; padding: 0; border: 0; min-width: 0; }

.rating + .rating .rating__row { border-top: 1px solid var(--border); }

.rating__label {
  float: left;
  width: 100%;
  padding: 7px 10px;
  font-size: 13.5px;
  color: var(--label-ink);
}

.rating__cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid var(--border);
  cursor: pointer;
}

.rating__cell:has(input:checked) { background: var(--panel); }

.rating__cell input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.rating__cell input:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 50%; }

.rating__text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.rating .field__error { margin: 0 10px 6px; }

@media (max-width: 640px) {
  .ratings__head,
  .rating__row { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .ratings__head > span:first-child { display: none; }
  .ratings__head > span:nth-child(2) { border-left: 0; }
  .ratings__head > span { font-size: 10px; padding: 5px 2px; hyphens: manual; }
  .rating__label { grid-column: 1 / -1; padding-bottom: 2px; }
  .rating__cell { min-height: 36px; }
  .rating__row > .rating__cell:nth-child(2) { border-left: 0; }
}

/* ---------- signature: the PDF's shaded signature cell ---------- */

.signature__pad {
  position: relative;
  height: 160px;
  border: 1px solid var(--border);
  background: #f5f8ff;
  overflow: hidden;
}

.field--invalid .signature__pad { border-color: var(--danger); background: var(--danger-tint); }

.signature__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.signature__canvas:focus-visible { outline: none; box-shadow: inset var(--focus); }

.signature__line {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 36px;
  border-bottom: 1px solid var(--border);
  pointer-events: none;
}

.signature__placeholder {
  position: absolute;
  left: 18px;
  bottom: 42px;
  font-size: 13px;
  color: var(--muted);
  pointer-events: none;
}

.signature__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 4px 8px 0;
}

.signature__typed { margin: 4px 0 0; }

.signature__typed .field__hint { margin: 0 8px 2px; }

.signature__typed .control { margin: 0 8px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: 0.65; cursor: not-allowed; }

.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent-dark); }

.btn--small { min-height: 32px; padding: 4px 12px; font-size: 13px; font-weight: 400; }

.btn--link {
  min-height: 32px;
  padding: 4px 0;
  border: 0;
  background: none;
  font-size: 13px;
  font-weight: 400;
  color: var(--accent-dark);
  text-decoration: underline;
}

.btn__spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn--busy .btn__spinner { display: inline-block; }

/* ---------- submit ---------- */

.submit-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  margin-top: 18px;
}

.submit-row__note { flex: 1 1 320px; margin: 0; font-size: 12.5px; color: var(--muted); }

.error-summary {
  margin-top: 18px;
  padding: 10px 12px;
  border: 1px solid #f0b3ae;
  border-left: 3px solid var(--danger);
  background: var(--danger-tint);
  color: #7a271a;
}

.error-summary:focus { outline: none; }
.error-summary__title { margin: 0 0 4px; font-weight: 700; }
.error-summary__list { margin: 0; padding-left: 18px; font-size: 13.5px; }
.error-summary__list a { color: #7a271a; }

.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- messages (done, broken link) ---------- */

.notice-block {
  margin-top: 18px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
}

.notice-block--danger { border-top-color: var(--danger); }
.notice-block--success { border-top-color: var(--success); }

.notice-block__title { margin: 0 0 6px; font-size: 18px; color: var(--ink); }
.notice-block__text { margin: 0 0 12px; }
.notice-block__small { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); }

.field__required { color: var(--danger); margin-left: 2px; }
