:root {
  --fg: #111;
  --bg: #fff;
  --bg-soft: #f4f6f8;
  --accent: #0b5cad;
  --accent-fg: #fff;
  --muted: #555;
  --border: #ccd2d8;
  --focus: #ffbf00;
  --danger: #b00020;
  --ok: #1a7f37;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #f4f4f4;
    --bg: #121212;
    --bg-soft: #1c1f23;
    --accent: #66aaff;
    --accent-fg: #000;
    --muted: #bbb;
    --border: #3a3f45;
    --focus: #ffd23f;
    --danger: #ff6b78;
    --ok: #5fd17a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 1.05rem/1.5 system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}

body {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-height: 100vh;
}

header, nav, main, footer {
  padding: 1rem 1.25rem;
}

main {
  max-width: 70ch;
  width: 100%;
}

/* Let the grid regions shrink to the viewport so a wide data table never forces
   the whole page to scroll sideways. Instead each table scrolls within its own
   region (WCAG reflow allows a data table to scroll; the page must not). */
body > header, body > nav, body > main, body > footer { min-width: 0; }
#ticket-content, #stage-body, #skills-root, #users-root, #detail-root, .table-wrap {
  overflow-x: auto;
}

h1 { margin: 0 0 0.75rem; font-size: 1.75rem; }
h2 { margin: 1rem 0 0.5rem; font-size: 1.2rem; }

.brand {
  margin: 0;
  font-weight: 700;
  font-size: 1.4rem;
}
.brand a {
  color: var(--fg);
  text-decoration: none;
}
.tagline { margin: 0.25rem 0 0; color: var(--muted); }

nav {
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}
nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.user-strip {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
}
.user-strip strong { color: var(--fg); }
.user-strip button {
  margin-left: 0.5rem;
  padding: 0.3rem 0.6rem;
  font-size: 0.9rem;
  background: transparent;
  color: var(--accent);
}
.login-error {
  margin: 0.5rem 0;
  min-height: 1.4em;
  color: var(--danger);
  font-weight: 600;
}
nav a {
  display: inline-block;
  padding: 0.45rem 0.75rem;
  color: var(--accent);
  text-decoration: none;
  border: 2px solid transparent;
  border-radius: 4px;
}
nav a[aria-current="page"] {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}

a:focus, button:focus, input:focus, [tabindex]:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 0.5rem 0.75rem;
  z-index: 100;
}
.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}

.card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.1rem;
  margin: 0.85rem 0;
}

.note {
  color: var(--muted);
  font-style: italic;
}

.field-hint {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* form-fill ticket: stacked label + control per field. */
.fill-form .form-field {
  margin: 0.6rem 0;
}
.fill-form .form-field label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.fill-form .form-field input[type="text"],
.fill-form .form-field select {
  width: 100%;
  max-width: 28rem;
  padding: 0.5rem 0.6rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.fill-form fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem 1rem;
  margin: 0.5rem 0;
}

/* timesheet ticket: a grid with an Hours input per day and a Total row. */
.timesheet .ts-input {
  width: 6rem;
  padding: 0.4rem 0.5rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.timesheet tfoot .ts-total-row th,
.timesheet tfoot .ts-total-row td {
  border-top: 2px solid var(--border);
  font-weight: 700;
}

/* image-ocr ticket: an intentionally inaccessible scanned-document image. */
.ocr-canvas, .ocr-image {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin: 0.5rem 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

/* file-upload ticket. */
.upload-form input[type="file"] {
  display: block;
  margin-top: 0.3rem;
}

/* roleplay ticket: full-sentence response choices, stacked and left-aligned. */
.roleplay-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.roleplay-actions .roleplay-btn {
  text-align: left;
  padding: 0.7rem 1rem;
  font-size: 1rem;
  min-height: 2.75rem;
}
.roleplay-scenario {
  font-style: italic;
  font-size: 1.05rem;
}
.coaching-note {
  border-left: 3px solid var(--accent);
  padding-left: 0.75rem;
  margin: 0.5rem 0;
}

/* Training certificate. */
.certificate {
  border: 4px double var(--accent);
  border-radius: 8px;
  padding: 2rem 2.5rem;
  text-align: center;
  max-width: 42rem;
  margin: 1rem auto;
}
.cert-kicker {
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}
.cert-title { font-size: 2rem; margin: 0.4rem 0 1rem; }
.cert-line { margin: 0.4rem 0; }
.cert-name { font-size: 1.7rem; font-weight: 700; margin: 0.75rem 0; }
.cert-stats { display: inline-block; text-align: left; margin: 1.25rem auto; }
.cert-date { margin-top: 1.5rem; color: var(--muted); }

@media print {
  header[role="banner"], nav, footer, .skip-link, .no-print, #user-strip {
    display: none !important;
  }
  body { background: #fff; }
  main { margin: 0; padding: 0; }
  .certificate { border-color: #333; }
}

/* Keyboard keys in the Resources reference. */
kbd {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.9em;
  line-height: 1.4;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: rgba(127, 127, 127, 0.12);
  white-space: nowrap;
}

/* clock-action ticket: a row of large, clear time-clock buttons. */
.clock-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0.75rem 0;
}
.clock-actions .clock-btn {
  flex: 1 1 8rem;
  min-height: 3rem;
  padding: 0.75rem 1rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.form-status {
  margin: 0.5rem 0;
  min-height: 1.4em;
  color: var(--accent);
  font-weight: 600;
  opacity: 1;
  transition: opacity 0.4s ease;
}
.form-status.flash-out { opacity: 0; }
@media (prefers-reduced-motion: reduce) {
  .form-status { transition: none; }
}

/* Admin user table: keep actions readable and flag deactivated rows. */
.admin-users td.row-actions {
  white-space: normal;
}
.admin-users .row-actions button {
  margin: 0.15rem 0.25rem 0.15rem 0;
}
tr.row-inactive th[scope="row"],
tr.row-inactive td {
  color: var(--muted);
  font-style: italic;
}

.meta {
  display: inline-block;
  margin-right: 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.button, button {
  display: inline-block;
  padding: 0.55rem 1rem;
  background: var(--accent);
  color: var(--accent-fg);
  border: 2px solid var(--accent);
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
}
.button-secondary,
button[type="button"] {
  background: transparent;
  color: var(--accent);
}
/* Destructive action (e.g. delete account): outlined in the danger colour,
   fills on hover/focus. Specificity beats the generic button[type="button"]. */
.button-danger,
button.button-danger[type="button"] {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
button.button-danger:not([disabled]):not([aria-disabled="true"]):hover,
button.button-danger:not([disabled]):not([aria-disabled="true"]):focus-visible {
  background: var(--danger);
  color: var(--accent-fg);
  border-color: var(--danger);
}
button[disabled],
button[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Hover affordances (enhancements only — focus styling and labels still carry
   the meaning). Disabled buttons do not change. */
nav a:hover { background: rgba(127, 127, 127, 0.15); }
.button:not([disabled]):hover,
button:not([disabled]):not([aria-disabled="true"]):hover {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
@media (prefers-reduced-motion: no-preference) {
  nav a, .button, button { transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease; }
}

dl.profile {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 1rem;
  margin: 0;
}
dl.profile dt { font-weight: 600; }
dl.profile dd { margin: 0; }

.campaign-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.campaign-list .card { margin: 1rem 0; }

fieldset {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.75rem 1rem 1rem;
  margin: 0;
}
legend { padding: 0 0.4rem; font-weight: 600; }

/* When a fieldset legend should act as the section's heading, wrap
   an h2.legend-as-heading inside <legend>; reset h2 visual styling
   so it inherits legend appearance, but keeps the heading semantics. */
.legend-as-heading {
  display: inline;
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

#settings-form fieldset label {
  display: block;
  margin: 0.25rem 0;
}

.hint {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.status {
  min-height: 1.4em;
  margin: 0.5rem 0 0;
  color: var(--ok);
  font-weight: 600;
}

/* ---------- Shift runner ---------- */

.meta-line {
  color: var(--muted);
  margin: 0 0 1rem;
}

.ticket-prompt {
  background: var(--bg-soft);
  border-left: 4px solid var(--accent);
  padding: 0.6rem 0.9rem;
  margin: 0.5rem 0 1rem;
}

.clock-line {
  margin: 0.25rem 0 1rem;
  font-variant-numeric: tabular-nums;
}

.clock-line button {
  margin-left: 0.5rem;
  font-size: 0.95rem;
  padding: 0.3rem 0.6rem;
}

.coaching {
  border-left: 4px solid var(--ok);
}

#answer-input {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  min-width: 16rem;
  background: var(--bg);
  color: var(--fg);
}

table.activity-log,
table.report-table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.5rem 0 1rem;
}
table.activity-log caption,
table.report-table caption {
  text-align: left;
  font-style: italic;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
table.activity-log th,
table.activity-log td,
table.report-table th,
table.report-table td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  text-align: left;
  vertical-align: top;
}
table.activity-log thead th,
table.report-table thead th {
  background: var(--bg-soft);
}

address {
  font-style: normal;
  margin: 0.25rem 0 1rem;
}

.report-actions h3 {
  margin: 1.25rem 0 0.25rem;
  font-size: 1.05rem;
}

/* ---------- Print ---------- */

@media print {
  /* Strip page chrome that doesn't belong on paper. */
  nav,
  footer,
  .skip-link,
  #announcer,
  .clock-line,
  .no-print {
    display: none !important;
  }

  body {
    background: #fff !important;
    color: #000 !important;
    display: block !important;
  }
  main { max-width: none !important; }

  /* Sharper printed tables. */
  table { border-collapse: collapse !important; }
  th, td {
    border: 1px solid #333 !important;
    padding: 0.25rem 0.5rem !important;
  }
  thead th {
    background: #eee !important;
    color: #000 !important;
  }

  /* Avoid ugly mid-row page breaks. */
  tr, h1, h2, h3 { break-inside: avoid; }
  h2, h3 { break-after: avoid; }

  a {
    color: #000 !important;
    text-decoration: underline;
  }
  .ticket-prompt {
    border-left: 2px solid #000 !important;
    background: transparent !important;
  }
}
