/* Safety & Compliance - interface styles.

   Design rules (keep to these when adding screens):
   - Official-form look: square corners, flat surfaces, 1-2px rules, no shadows,
     no gradients, no decorative icons or emoji.
   - One accent (navy/blue). Colour is reserved for status and risk, and every
     status is also spelled out in words, never colour alone.
   - Plain language, left-aligned text, real labels above fields.
   - Large touch targets (44px) and 16px form text so phones do not zoom.
   - Strong keyboard focus (yellow + black), visible on every control. */

:root {
  --ink: #0b0c0c;
  --ink-soft: #505a5f;
  --paper: #f3f2f1;
  --surface: #ffffff;
  --line: #d6d8da;
  --line-strong: #b1b4b6;
  --brand: #0b2a4a;
  --accent: #1d4f91;
  --accent-dark: #123761;
  --accent-soft: #e8eef6;
  --focus: #ffdd00;

  --risk-low: #00703c;
  --risk-medium: #594d00;
  --risk-high: #6e3619;
  --risk-extreme: #942514;
  --danger: #b1301a;

  --font: "Noto Sans", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 0;
  --header-h: 64px;
}

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

html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 12px); }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  font-size: 16px;
  line-height: 1.5;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 12px; font-weight: 700; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
h4 { font-size: 16px; }
p { margin: 0 0 14px; }

a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--accent-dark); text-decoration-thickness: 2px; }

/* Keyboard focus: high-contrast, never removed. */
a:focus-visible, button:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid transparent;
  background: var(--focus);
  color: var(--ink);
  box-shadow: 0 -2px var(--focus), 0 4px var(--ink);
  text-decoration: none;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 0;
  box-shadow: inset 0 0 0 2px var(--ink);
}

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--focus); color: var(--ink); padding: 10px 14px; font-weight: 700;
}
.skip-link:focus { top: 8px; }

/* ---------- Site header ---------- */

.site-header {
  background: var(--brand);
  color: #fff;
  border-bottom: 6px solid #3a78b5;
  position: sticky; top: 0; z-index: 40;
}
.site-header__inner {
  min-height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 8px 24px;
}
.site-header__brand { color: #fff; font-weight: 700; font-size: 18px; text-decoration: none; line-height: 1.2; }
.site-header__brand:hover { color: #fff; text-decoration: underline; }
.site-header__tools { display: flex; align-items: center; gap: 20px; }
.site-header__user { font-size: 15px; }
.site-header__signout {
  background: none; border: 0; padding: 8px 0; color: #fff; font: inherit; font-size: 15px;
  text-decoration: underline; cursor: pointer;
}
.site-header a:focus-visible, .site-header button:focus-visible { color: var(--ink); }

.menu-toggle {
  display: none;
  min-height: 44px; padding: 8px 16px;
  background: transparent; color: #fff; border: 2px solid #fff;
  font: inherit; font-weight: 700; cursor: pointer;
}
.menu-toggle:focus-visible { color: var(--ink); }

/* ---------- Page frame ---------- */

.shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: calc(100vh - var(--header-h)); }

.rail {
  background: var(--surface);
  border-right: 1px solid var(--line-strong);
  padding: 8px 0 24px;
}
.rail__nav { display: flex; flex-direction: column; }
.rail__group {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-soft); margin: 20px 20px 4px;
}
.rail__link {
  display: flex; align-items: center; min-height: 44px;
  padding: 8px 20px 8px 16px; border-left: 4px solid transparent;
  color: var(--ink); text-decoration: none; font-size: 16px;
}
.rail__link:hover { background: var(--paper); text-decoration: underline; }
.rail__link.is-active { border-left-color: var(--accent); font-weight: 700; background: var(--accent-soft); }

.main { min-width: 0; display: flex; flex-direction: column; }

.titlebar { background: var(--surface); border-bottom: 1px solid var(--line-strong); padding: 24px 32px 20px; }
.titlebar__title { margin: 0; font-size: 30px; font-weight: 700; }

.content { padding: 28px 32px 48px; width: 100%; max-width: 1200px; flex: 1; }

.site-footer { border-top: 1px solid var(--line-strong); background: var(--surface); padding: 16px 32px; font-size: 14px; color: var(--ink-soft); }

/* ---------- Messages ---------- */

.alert { padding: 14px 16px; margin-bottom: 24px; background: var(--surface); border: 1px solid var(--line-strong); border-left-width: 8px; }
.alert::before { display: block; font-weight: 700; margin-bottom: 6px; }
.alert--success { border-left-color: var(--risk-low); }
.alert--success::before { content: "Success"; }
.alert--error { border-left-color: var(--danger); }
.alert--error::before { content: "There is a problem"; color: var(--danger); }
.alert ul { margin: 0; padding-left: 20px; }
.alert .hint { margin: 6px 0 0; }

/* ---------- Status tags (words first; colour is secondary) ---------- */

.badge {
  display: inline-block; padding: 2px 8px; vertical-align: middle;
  font-size: 12px; font-weight: 700; line-height: 1.5; text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap; border-radius: 0;
  color: #383f43; background: #eeefef;
}
.badge::before { content: none; }
/* grey: not started / archived */
.badge--draft, .badge--identified, .badge--archived, .badge--employee, .badge--inactive { color: #383f43; background: #eeefef; }
/* orange: needs the Safety Department's attention */
.badge--submitted, .badge--received, .badge--returned, .badge--open, .badge--high, .badge--pending_verification { color: var(--risk-high); background: #fcd6c3; }
/* amber: being assessed or waiting on a step */
.badge--medium, .badge--under_review, .badge--acknowledged, .badge--classified, .badge--verification, .badge--action_required, .badge--pending_review, .badge--pending, .badge--expiring { color: var(--risk-medium); background: #fff7bf; }
/* blue: being worked */
.badge--in_progress, .badge--investigation, .badge--linked, .badge--direct_action, .badge--guest, .badge--active_work { color: #144e81; background: #bbd4ea; }
/* green: done / safe */
.badge--low, .badge--closed, .badge--verified, .badge--feedback_sent, .badge--compliant, .badge--active, .badge--passed, .badge--completed, .badge--accepted { color: var(--risk-low); background: #cce2d8; }
/* red: overdue / failed / extreme */
.badge--extreme, .badge--overdue, .badge--rejected, .badge--failed, .badge--non_compliant, .badge--expired { color: var(--risk-extreme); background: #f4cdc6; }

/* ---------- Surfaces ---------- */

.card { background: var(--surface); border: 1px solid var(--line-strong); padding: 20px; }
.card > h3:first-child, .card > h2:first-child { margin-top: 0; }
.card h3 { font-size: 18px; margin: 0 0 12px; }

.grid { display: grid; gap: 20px; }
.grid--stats {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0; border-top: 1px solid var(--line-strong); border-left: 1px solid var(--line-strong); margin-bottom: 32px;
}
.stat { background: var(--surface); padding: 16px 20px; border: 0; border-right: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); }
.stat__label { font-size: 15px; font-weight: 700; color: var(--ink); margin: 0 0 4px; }
.stat__value { font-size: 32px; font-weight: 700; margin: 0; font-variant-numeric: tabular-nums; color: var(--brand); line-height: 1.2; }

/* ---------- Tables ---------- */

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { text-align: left; font-weight: 700; color: var(--ink); font-size: 14px; padding: 10px 12px; border-bottom: 2px solid var(--ink); vertical-align: bottom; }
td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover td { background: #f8f8f8; }
/* key / value tables (no heading row): label column reads as a label */
table:not(:has(thead)) td:first-child { color: var(--ink-soft); font-weight: 700; width: 38%; }
tr[onclick] { cursor: pointer; }
/* identifiers and dates stay on one line */
td.mono, td[data-label="ID"], td[data-label="Date"], td[data-label="Number"], td[data-label="Due"], td .mono { white-space: nowrap; }

/* ---------- Controls ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px;
  border: 2px solid var(--accent); background: var(--surface); color: var(--accent);
  font: inherit; font-size: 16px; font-weight: 700; line-height: 1.2; text-decoration: none; cursor: pointer;
  border-radius: 0;
}
.btn:hover { background: var(--accent-soft); color: var(--accent-dark); text-decoration: none; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 3px 0 var(--accent-dark); }
.btn--primary:hover { background: var(--accent-dark); color: #fff; }
.btn--danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger); color: #fff; }
.btn:focus-visible { background: var(--focus); color: var(--ink); border-color: var(--ink); }

label { display: block; font-size: 16px; font-weight: 700; margin-bottom: 6px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 8px 10px;
  border: 2px solid var(--ink); border-radius: 0;
  font: inherit; font-size: 16px; background: var(--surface); color: var(--ink);
}
textarea { min-height: 96px; resize: vertical; }
input[type="checkbox"], input[type="radio"] {
  width: 24px; height: 24px; min-height: 0; padding: 0; flex-shrink: 0; accent-color: var(--accent); vertical-align: middle;
}
input[type="file"] { padding: 8px; border-style: dashed; }
input[type="date"], input[type="time"], input[type="datetime-local"] { min-width: 0; }
label:has(> input[type="checkbox"]), label:has(> input[type="radio"]) { font-weight: 400; }

.field { margin-bottom: 20px; }
.hint, .field .hint { font-size: 14px; color: var(--ink-soft); margin: 4px 0 0; font-weight: 400; }
p.hint { margin-bottom: 14px; }

.mono { font-family: var(--font-mono); font-size: 14px; }
.empty { padding: 32px 20px; color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line-strong); }

details > summary { cursor: pointer; padding: 6px 0; }

/* ---------- Admin screens (Users / Roles) ---------- */

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-header__eyebrow { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-soft); margin: 0 0 6px; }
.page-header__eyebrow a { color: var(--ink-soft); }
.page-header__title { margin: 0; font-size: 26px; display: flex; align-items: center; gap: 12px; }
.page-header__subtitle { margin: 6px 0 0; font-size: 16px; color: var(--ink-soft); max-width: 60ch; }
.page-header__actions { display: flex; gap: 8px; flex-wrap: wrap; }

.avatar-chip {
  width: 44px; height: 44px; background: var(--brand); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}

.panel { background: var(--surface); border: 1px solid var(--line-strong); margin-bottom: 24px; }
.panel__header { padding: 16px 20px; border-bottom: 1px solid var(--line-strong); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.panel__title { margin: 0; font-size: 18px; }
.panel__hint { margin: 2px 0 0; font-size: 14px; color: var(--ink-soft); }
.panel__body { padding: 20px; }
.panel__body + .panel__body { border-top: 1px solid var(--line-strong); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.field-row + .field-row { margin-top: 16px; }

.switch { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; min-height: 44px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track { width: 48px; height: 28px; border: 2px solid var(--ink); background: var(--surface); position: relative; flex-shrink: 0; }
.switch__track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: var(--ink); }
.switch input:checked + .switch__track { background: var(--risk-low); border-color: var(--risk-low); }
.switch input:checked + .switch__track::after { background: #fff; transform: translateX(20px); }
.switch input:focus-visible + .switch__track { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch__label { font-size: 16px; font-weight: 700; }

.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.role-pill { display: flex; align-items: center; gap: 10px; border: 2px solid var(--line-strong); padding: 10px 12px; font-size: 16px; font-weight: 400; cursor: pointer; margin: 0; min-height: 48px; }
.role-pill:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.role-pill input { margin: 0; }

.perm-group { border: 1px solid var(--line-strong); margin-bottom: 16px; }
.perm-group:last-child { margin-bottom: 0; }
.perm-group__header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: var(--paper); border-bottom: 1px solid var(--line-strong); flex-wrap: wrap; }
.perm-group__title { margin: 0; font-size: 16px; text-transform: capitalize; display: flex; align-items: center; gap: 8px; }
.perm-group__count { font-size: 14px; font-weight: 700; color: var(--ink-soft); }
.perm-group__toggle-all { font: inherit; font-size: 15px; font-weight: 700; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 8px 0; text-decoration: underline; }
.perm-group__body { padding: 12px 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 2px; }
.perm-check { display: flex; align-items: center; gap: 10px; padding: 8px; font-size: 15px; font-weight: 400; cursor: pointer; margin: 0; min-height: 44px; }
.perm-check:hover { background: var(--paper); }
.perm-check input { margin: 0; }
.perm-check code { font-family: var(--font-mono); font-size: 13px; color: var(--ink-soft); }

.form-actions {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom)); margin-top: 8px;
  background: var(--surface); border: 1px solid var(--line-strong); border-top: 3px solid var(--ink);
}
.form-actions__hint { font-size: 14px; color: var(--ink-soft); }

.stat-chip { display: inline-block; padding: 2px 8px; background: var(--accent-soft); color: var(--accent-dark); font-size: 13px; font-weight: 700; }

/* ---------- Safety reporting screens ---------- */

.panel-step { border-top: 1px solid var(--line-strong); padding-top: 16px; margin-top: 16px; }
.panel-step:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.sla--overdue { color: var(--risk-extreme); font-weight: 700; }
.hp { position: absolute; left: -9999px; height: 0; overflow: hidden; }
.guest-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.card--next-step { border-left: 8px solid var(--accent); }
.form-section { font-size: 20px; margin: 28px 0 14px; padding-top: 16px; border-top: 2px solid var(--ink); }
.form-section:first-of-type { margin-top: 0; padding-top: 0; border-top: 0; }

/* Guest / sign-in pages */
.guest-wrap { max-width: 760px; margin: 0 auto; padding: 28px 16px 56px; }
.guest-wrap--narrow { max-width: 480px; }

[style*="grid-template-columns"] > *, .field-row > *, .guest-grid > * { min-width: 0; }

/* ---------- Tablet and phone ---------- */

@media (max-width: 899px) {
  :root { --header-h: 60px; }

  .site-header__inner { padding: 8px 16px; }
  .site-header__user { display: none; }
  .menu-toggle { display: inline-flex; }

  .shell { display: block; min-height: 0; }

  /* Navigation becomes a full-width drawer under the header. Without JS it stays visible. */
  .js .rail { display: none; border-right: 0; border-bottom: 6px solid var(--brand); max-height: calc(100vh - var(--header-h)); overflow-y: auto; }
  .js .rail.is-open { display: block; position: sticky; top: var(--header-h); z-index: 30; }
  .rail__link { min-height: 48px; }
  .rail__user-mobile { display: block; padding: 12px 20px; border-top: 1px solid var(--line); font-size: 15px; color: var(--ink-soft); }

  /* Two-column layouts stack as soon as the sidebar becomes a drawer; wide tables scroll inside their card. */
  [style*="grid-template-columns"], .field-row, .guest-grid { grid-template-columns: 1fr !important; }
  .card, .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  .titlebar { padding: 18px 16px 14px; }
  .titlebar__title { font-size: 24px; }
  .content { padding: 20px 16px 40px; }
  .site-footer { padding: 16px; }
}

@media (min-width: 900px) { .rail__user-mobile { display: none; } }

@media (max-width: 719px) {
  body { font-size: 16px; }

  /* Every inline two/three-column layout collapses to one column. */
  [style*="grid-template-columns"], .field-row, .guest-grid { grid-template-columns: 1fr !important; }
  .grid--stats { grid-template-columns: 1fr 1fr !important; }
  [style*="justify-content:space-between"] { flex-wrap: wrap; gap: 12px; }
  [style*="max-width:640px"] { max-width: none !important; }

  .card, .panel__body { padding: 16px; }
  .panel__header { padding: 14px 16px; }
  .page-header__title { font-size: 22px; }
  .stat { padding: 14px 16px; }
  .stat__value { font-size: 28px; }

  /* Filter bars: one control per row. */
  form[style*="display:flex"] > .field { flex: 1 1 100%; min-width: 0; }
  form[style*="display:flex"] > .btn { flex: 1 1 100%; }
  form[style*="display:flex"] > div[style*="flex:1;"] { display: none; }

  .btn-row .btn, .page-header__actions .btn, .form-actions .btn { flex: 1 1 100%; }
  form:not([style*="display:inline"]):not([style*="display:flex"]) > .btn { width: 100%; }
  .form-actions { position: static; }

  /* Wide tables scroll inside their card instead of breaking the page. */
  .card, .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Tables marked .stack turn into one block per row, labelled from the column heading. */
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack thead { position: absolute; left: -9999px; }
  table.stack tr { border: 1px solid var(--line-strong); border-top-width: 3px; border-top-color: var(--ink); margin: 0 0 14px; background: var(--surface); }
  table.stack td { display: grid; grid-template-columns: 38% 1fr; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  table.stack td:last-child { border-bottom: 0; }
  table.stack td > .badge { justify-self: start; }
  table.stack td::before { content: attr(data-label); font-weight: 700; color: var(--ink-soft); font-size: 14px; }
  table.stack td[data-label=""] { display: block; }
  table.stack td[data-label=""]::before { content: none; }
  .card:has(> table.stack) { padding: 12px; background: transparent; border: 0; overflow: visible; }
  tbody tr:hover td { background: transparent; }
}

/* ---------- Print: forms and reports print cleanly ---------- */

@media print {
  .site-header, .rail, .site-footer, .menu-toggle, .btn, .form-actions, .skip-link, form[method="POST"] button { display: none !important; }
  .shell { display: block; }
  body { background: #fff; font-size: 12pt; }
  .card, .panel, .stat { border-color: #000; break-inside: avoid; }
  .content { padding: 0; max-width: none; }
  a { color: #000; text-decoration: none; }
}

/* ---- Report form: system-filled reporter box, audience note, attachments ---- */
.readonly-box { background: var(--paper); border: 1px solid var(--line-strong); padding: 14px 16px; margin-bottom: 20px; }
.readonly-box__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; margin: 0; }
.readonly-box dt { font-size: 14px; color: var(--ink-soft); }
.readonly-box dd { margin: 0; font-weight: 700; word-break: break-word; }
.readonly-box .hint { margin-top: 12px; }
.note-box { border-left: 8px solid var(--accent); background: var(--accent-soft); padding: 12px 16px; margin-bottom: 20px; }
.note-box p { margin: 0; }

.attachment-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; list-style: none; margin: 0 0 16px; padding: 0; }
.attachment { border: 1px solid var(--line-strong); background: var(--surface); display: flex; flex-direction: column; min-width: 0; }
.attachment__preview { background: var(--paper); display: flex; align-items: center; justify-content: center; min-height: 140px; max-height: 220px; overflow: hidden; }
.attachment__preview img, .attachment__preview video { width: 100%; max-height: 220px; object-fit: contain; display: block; }
.attachment__preview audio { width: 100%; padding: 12px; }
.attachment__kind { font-family: var(--font-mono); font-size: 14px; color: var(--ink-soft); padding: 24px 12px; text-transform: uppercase; }
.attachment__body { padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.attachment__name { font-weight: 700; word-break: break-word; }
.attachment__meta { font-size: 14px; color: var(--ink-soft); }
.attachment__actions { display: flex; gap: 12px; flex-wrap: wrap; font-size: 14px; }
.attachment__remove { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-top: 6px; }
.file-picked { list-style: none; margin: 8px 0 0; padding: 0; font-size: 14px; }
.file-picked li { padding: 4px 0; border-bottom: 1px solid var(--line); word-break: break-word; }
@media (max-width: 600px) { .readonly-box__grid { grid-template-columns: 1fr; } }

/* ---- Company switcher (top of the menu) ---- */
.company-switch { margin: 0 0 12px; padding: 0 0 12px; border-bottom: 1px solid var(--line-strong); }
.company-switch__label { display: block; font-size: 14px; color: var(--ink-soft); margin-bottom: 4px; }
.company-switch select { width: 100%; font-weight: 700; }
.company-switch--single { font-weight: 700; }
.company-switch--single .company-switch__label { display: inline; margin-right: 6px; font-weight: 400; }

/* ---- Required marker and declarations ---- */
.req { color: var(--danger, #b3261e); font-weight: 700; margin-left: 2px; }
.declarations { border: 1px solid var(--line-strong); background: var(--paper); padding: 14px 16px; margin: 20px 0; display: grid; gap: 12px; }
.declarations .perm-check { align-items: flex-start; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
