:root {
  --navy: #2b2d5e;
  --navy-light: #3d4080;
  --gold: #f5b731;
  --gold-light: #fdd773;
  --gold-muted: #fef8e7;
  --text: #1a1c3d;
  --text-muted: #5a5d7a;
  --border: #e3e6f0;
  --card-border: #dfe2ec;
  --bg: #eceef6;
  --white: #ffffff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  /* aliases used across the app (previously undefined -> fell back to nothing) */
  --primary: #2b2d5e;
  --surface: #ffffff;
  --bg-alt: #f4f5fb;
  --bg-hover: #f0f1f9;
  --bg-light: #fafbfe;
  --border-light: #f0f1f7;
  --radius: 10px;
  --shadow-sm: 0 1px 3px rgba(43, 45, 94, 0.07), 0 0 0 1px rgba(43, 45, 94, 0.02);
  --shadow: 0 4px 12px rgba(43, 45, 94, 0.09);
  --shadow-lg: 0 8px 24px rgba(43, 45, 94, 0.12);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Login
   ============================================================ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--navy) 0%, #1a1b3d 100%);
}

.login-card {
  background: var(--white);
  padding: 48px 40px;
  border-radius: 16px;
  width: 360px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.login-card img {
  height: 48px;
  margin-bottom: 24px;
}

.login-card h1 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--navy);
}

.login-card p {
  color: var(--text-muted);
  margin-bottom: 28px;
  font-size: 14px;
}

.login-card select,
.login-card button {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  transition: var(--transition);
}

.login-card select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(245, 183, 49, 0.15);
}

.login-card button {
  background: var(--navy);
  color: var(--white);
  border: none;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.login-card button:hover {
  background: var(--navy-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

/* ============================================================
   Navigation
   ============================================================ */
nav {
  display: flex;
  align-items: center;
  background: var(--navy);
  color: var(--white);
  padding: 0 24px;
  height: 56px;
  box-shadow: 0 2px 8px rgba(43, 45, 94, 0.2);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-right: 36px;
}

.nav-brand img {
  height: 32px;
}

.nav-brand span {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.3px;
  opacity: 0.9;
}

.nav-links { display: flex; gap: 2px; flex: 1; }

.nav-links a {
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  position: relative;
}

.nav-links a:hover {
  color: var(--white);
  background: rgba(255,255,255,0.08);
}

.nav-links a.active {
  color: var(--white);
  background: rgba(245, 183, 49, 0.15);
}

.nav-links a.active::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 3px;
  background: var(--gold);
  border-radius: 3px;
}

.nav-badge {
  position: absolute;
  top: 2px;
  right: 4px;
  background: var(--gold);
  color: var(--navy);
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 8px;
  padding: 0 4px;
}

.nav-user {
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-user a {
  color: var(--gold-light);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
}

.nav-user a:hover { color: var(--gold); }

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  padding: 0;
  margin-left: 12px;
  background: transparent;
  border: none;
  cursor: pointer;
}

.nav-toggle span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--white);
  border-radius: 2px;
}

/* Grouped dropdown menus (Registers, Admin) - desktop click-to-open */
.nav-dropdown { position: relative; }

.nav-dropdown-toggle {
  color: rgba(255,255,255,0.65);
  background: transparent;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.nav-dropdown-toggle:hover,
.nav-dropdown-toggle.active {
  color: var(--white);
  background: rgba(255,255,255,0.08);
}

.nav-caret { font-size: 10px; }

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 180px;
  background: var(--navy);
  border-radius: 8px;
  box-shadow: 0 8px 16px rgba(43, 45, 94, 0.35);
  padding: 6px;
  z-index: 100;
  flex-direction: column;
}

.nav-dropdown.open .nav-dropdown-menu { display: flex; }

.nav-dropdown-menu a {
  padding: 10px 12px;
  border-radius: 6px;
  white-space: nowrap;
}

.nav-dropdown-menu a.active::after { display: none; }

/* ============================================================
   Main Layout
   ============================================================ */
main {
  max-width: 1800px;
  margin: 28px auto;
  padding: 0 28px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 2rem;
}

h2 {
  margin-bottom: 20px;
  font-size: 22px;
  font-weight: 700;
  color: var(--navy);
}

h3 {
  margin: 24px 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ============================================================
   Dashboard Tiles
   ============================================================ */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.tile {
  background: var(--white);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--card-border);
  border-left: 4px solid var(--gold);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.tile:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.tile-warn { border-left-color: var(--warning); }
.tile-alert { border-left-color: var(--danger); }
.tile-info { border-left-color: var(--info); }
.tile-ci { border-left-color: #8b5cf6; }
.tile-approval { border-left-color: var(--success); }

.tile-number {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 4px;
  color: var(--navy);
}

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

/* Breakdown of what makes up a tile's tally, e.g. "3 Injury · 2 Incident" */
.tile-breakdown {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--card-border);
  font-size: 12px;
  color: var(--text);
  line-height: 1.7;
}
.tile-breakdown .bd-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: middle;
}
.tile-breakdown .bd-sep {
  color: var(--text-muted);
  margin: 0 7px;
}

/* Clickable tiles drill down to a popup of the records behind the tally */
.tile-clickable { cursor: pointer; position: relative; }
.tile-clickable::after {
  content: "View →";
  position: absolute;
  top: 16px; right: 18px;
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity .15s ease;
}
.tile-clickable:hover::after { opacity: 1; }

/* Tile drill-down popup rows */
.popup-close {
  position: absolute; top: 18px; right: 22px;
  background: none; border: none; cursor: pointer;
  font-size: 26px; line-height: 1; color: var(--text-muted);
}
.popup-close:hover { color: var(--navy); }
.tile-popup .modal { max-width: 560px; position: relative; }
.popup-list { display: flex; flex-direction: column; gap: 2px; }
.popup-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 8px;
  text-decoration: none; color: var(--text);
  border: 1px solid transparent;
  transition: var(--transition);
}
.popup-row:hover { background: var(--bg); border-color: var(--card-border); }
.popup-date { font-weight: 600; color: var(--navy); min-width: 96px; }
.popup-name { flex: 1; color: var(--text); }
.popup-go { font-size: 12px; font-weight: 600; color: var(--gold); white-space: nowrap; }
.popup-empty { color: var(--text-muted); padding: 8px 4px; }

/* ============================================================
   Tables
   ============================================================ */
/* Wrap any table that can outgrow a phone screen (5+ columns) in this so it
   scrolls sideways instead of forcing the whole page wider than the
   viewport - a wider-than-viewport page is what makes the fixed-width nav
   look short when the page is scrolled/zoomed. */
.report-table-wrap { overflow-x: auto; margin-bottom: 1rem; }
.report-table-wrap table { font-size: 12px; }
.report-table-wrap td { white-space: nowrap; padding: 8px 10px; }
.report-table-wrap th { white-space: normal; padding: 8px 10px; line-height: 1.25; vertical-align: bottom; }

table {
  width: 100%;
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

thead {
  background: var(--navy);
}

thead th {
  color: rgba(255,255,255,0.9);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  padding: 14px 16px;
  border-bottom: none;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}

tbody tr { transition: var(--transition); }
tbody tr:hover { background: var(--gold-muted); }
tbody tr:last-child td { border-bottom: none; }

/* Striped rows for IMS content tables */
.ims-section-content table {
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.ims-section-content table th,
.ims-section-content table td {
  padding: 10px 14px;
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}

.ims-section-content table thead {
  background: var(--navy);
}

.ims-section-content table thead th {
  color: var(--white);
}

.ims-section-content table tr:first-child td {
  background: var(--navy);
  color: var(--white);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.ims-section-content table tbody tr:nth-child(even) {
  background: #f8f9fd;
}

.ims-section-content table tbody tr:hover {
  background: var(--gold-muted);
}

/* ============================================================
   Toolbar
   ============================================================ */
.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.toolbar input,
.toolbar select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  transition: var(--transition);
  background: var(--white);
}

.toolbar input:focus,
.toolbar select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(245, 183, 49, 0.12);
}

.toolbar input { flex: 1; }

/* ============================================================
   Buttons
   ============================================================ */
.btn-primary {
  background: var(--navy);
  color: var(--white);
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
  transition: var(--transition);
  letter-spacing: 0.2px;
}

.btn-primary:hover {
  background: var(--navy-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--white);
  cursor: pointer;
  font-weight: 500;
  color: var(--text);
  transition: var(--transition);
}

.btn-sm:hover {
  background: var(--gold-muted);
  border-color: var(--gold);
  color: var(--navy);
}

/* ============================================================
   Status Badges
   ============================================================ */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: #f1f5f9;
  color: #475569;
}

.badge-annual_leave { background: #dbeafe; color: #1e40af; }
.badge-sick_leave { background: #fee2e2; color: #991b1b; }
.badge-bereavement_leave { background: #ede9fe; color: #5b21b6; }
.badge-unpaid_leave { background: #f3f4f6; color: #6b7280; }
.badge-parental_leave { background: #fef3c7; color: #92400e; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-draft { background: #fef3c7; color: #92400e; }
.badge-underreview { background: #dbeafe; color: #1e40af; }
.badge-superseded { background: #f3f4f6; color: #6b7280; }
.badge-open { background: #fef3c7; color: #92400e; }
.badge-inprogress { background: #dbeafe; color: #1e40af; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-scheduled { background: #dbeafe; color: #1e40af; }
.badge-awaitingapproval { background: #fef3c7; color: #92400e; }
.badge-approved { background: #d1fae5; color: #065f46; }
.badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-submitted { background: #dbeafe; color: #1e40af; }
.badge-closed { background: #f3f4f6; color: #6b7280; }
.badge-low { background: #d1fae5; color: #065f46; }
.badge-medium { background: #fef3c7; color: #92400e; }
.badge-high { background: #fee2e2; color: #991b1b; }
.badge-improvement { background: #ede9fe; color: #5b21b6; }

/* H&S incident types */
.badge-injury { background: #fee2e2; color: #991b1b; }
.badge-incident { background: #dbeafe; color: #1e40af; }
.badge-near_miss { background: #fef3c7; color: #92400e; }
.badge-no_injury { background: #d1fae5; color: #065f46; }

/* Hazardous substance state badges */
.badge-state { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.78rem; font-weight: 500; text-transform: capitalize; }
.badge-liquid { background: #dbeafe; color: #1e40af; }
.badge-solid { background: #fef3c7; color: #92400e; }
.badge-gas { background: #d1fae5; color: #065f46; }
.badge-aerosol { background: #ede9fe; color: #5b21b6; }

/* H&S tabs */
.hs-tabs { display: flex; gap: 0.5rem; margin: 1rem 0; flex-wrap: wrap; }
.hs-tab { padding: 0.5rem 1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); cursor: pointer; font-size: 0.9rem; color: var(--text-muted); }
/* H&S section picker - dropdown replaces the tab row on phone width, one tap
   instead of a grid of small buttons. */
.hs-tabs-mobile { display: none; }
.hs-tab.active { background: var(--navy); color: white; border-color: var(--navy); }
.hs-panel { margin-top: 0.5rem; }
.badge-nonconformance { background: #fee2e2; color: #991b1b; }
.badge-observation { background: #dbeafe; color: #1e40af; }
.badge-corrective { background: #fef3c7; color: #92400e; }

/* ============================================================
   IMS Layout
   ============================================================ */
.ims-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
  min-height: calc(100vh - 120px);
}

.ims-nav {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 120px);
  position: sticky;
  top: 72px;
  box-shadow: var(--shadow-sm);
}

.ims-nav-item {
  display: block;
  padding: 8px 12px;
  margin: 1px 0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  transition: var(--transition);
  border-left: 3px solid transparent;
}

.ims-nav-item:hover {
  background: var(--gold-muted);
  border-left-color: var(--gold);
}

.ims-nav-item.active {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  color: var(--white);
  border-left-color: var(--gold);
  font-weight: 500;
}

.ims-nav-item.level-0 {
  font-weight: 700;
  font-size: 13px;
  margin-top: 12px;
  padding: 10px 12px;
  color: var(--navy);
  cursor: pointer;
}

.ims-nav-item.level-0:first-child { margin-top: 0; }

.ims-nav-item.level-1 { padding-left: 24px; }
.ims-nav-item.level-2 { padding-left: 40px; font-size: 12px; color: var(--text-muted); }

.ims-nav-group { overflow: hidden; transition: max-height 0.3s ease; }
.ims-nav-group.collapsed { max-height: 0 !important; }

/* IMS Content Area */
.ims-content {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  padding: 40px 48px;
  min-height: 400px;
  box-shadow: var(--shadow-sm);
  animation: fadeIn 0.2s ease;
}

.ims-content h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--navy);
}

.ims-content h2 {
  font-size: 18px;
  margin: 24px 0 12px;
}

.ims-placeholder {
  color: var(--text-muted);
  text-align: center;
  padding: 80px 20px;
  font-size: 15px;
}

.ims-placeholder::before {
  content: '';
  display: block;
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  background: var(--gold-muted);
  border-radius: 50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23f5b731'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z'/%3E%3C/svg%3E");
  background-size: 32px;
  background-repeat: no-repeat;
  background-position: center;
}

.ims-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.ims-breadcrumb {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
}

.ims-breadcrumb span { color: var(--navy); font-weight: 600; }

/* IMS Section Content Typography */
.ims-section-content {
  line-height: 1.8;
  font-size: 14px;
  max-width: 720px;
  color: var(--text);
}

.ims-section-content p {
  margin-bottom: 14px;
}

.ims-section-content ul,
.ims-section-content ol {
  margin: 10px 0 14px 24px;
}

.ims-section-content li {
  margin-bottom: 6px;
  line-height: 1.6;
}

.ims-section-content strong {
  color: var(--navy);
}

.doc-logo {
  height: 40px;
  margin-bottom: 12px;
}

.doc-ref-link {
  color: var(--navy);
  text-decoration: none;
  font-weight: 600;
  background: var(--gold-muted);
  padding: 1px 6px;
  border-radius: 4px;
  border-bottom: 2px solid var(--gold);
  transition: var(--transition);
}

.doc-ref-link:hover {
  background: var(--gold);
  color: var(--white);
}

/* ============================================================
   Document Detail Panel
   ============================================================ */
.doc-title-link {
  color: var(--navy);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
}

.doc-title-link:hover {
  color: var(--gold);
}

.actions-cell {
  white-space: nowrap;
}

.actions-cell .btn-sm {
  margin-right: 4px;
  padding: 4px 10px;
  font-size: 11px;
}

.btn-fill {
  background: var(--gold) !important;
  color: var(--navy) !important;
  font-weight: 600 !important;
}

.btn-fill:hover {
  background: var(--gold-light) !important;
}

.btn-muted {
  opacity: 0.6;
}

.btn-muted:hover {
  opacity: 1;
}

.btn-secondary {
  background: var(--white);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  display: inline-block;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: var(--gold-muted);
  border-color: var(--gold);
  color: var(--navy);
}

.doc-detail-panel {
  background: var(--white);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  animation: fadeIn 0.2s ease;
}

.doc-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.doc-detail-header h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
}

.doc-detail-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  display: block;
}

.doc-tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.doc-tab {
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: var(--transition);
}

.doc-tab:hover {
  color: var(--navy);
}

.doc-tab.active {
  color: var(--navy);
  border-bottom-color: var(--gold);
}

.doc-detail-footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.doc-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  font-size: 14px;
}

.doc-info-grid div {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Review / Approval View
   ============================================================ */
.review-submitted-section {
  margin-bottom: 24px;
}

.review-submitted-section h4,
.review-office-section h4 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.review-field {
  display: flex;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}

.review-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  min-width: 180px;
  flex-shrink: 0;
}

.review-value {
  font-size: 14px;
  color: var(--text);
}

.review-office-section {
  background: var(--gold-muted);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

.review-office-section h4 {
  color: var(--navy);
  border-bottom-color: var(--gold);
}

.review-actions {
  padding-top: 16px;
}

/* ============================================================
   Scan Upload
   ============================================================ */
.scan-upload-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--text-muted);
}

.btn-scan {
  background: var(--navy) !important;
  color: var(--white) !important;
  cursor: pointer;
  padding: 6px 14px !important;
  font-size: 12px !important;
}

.btn-scan:hover {
  background: var(--navy-light) !important;
}

.scan-loading {
  color: var(--info);
  font-weight: 500;
}

.scan-loading::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--info);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}

.scan-success {
  color: var(--success);
  font-weight: 500;
}

.scan-error {
  color: var(--danger);
  font-weight: 500;
}

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

/* ============================================================
   Form Fields
   ============================================================ */
.form-field { margin-bottom: 16px; }

.form-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-field input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: var(--transition);
  background: var(--white);
}

.form-field input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(245, 183, 49, 0.12);
}

.form-field textarea { min-height: 100px; resize: vertical; }

.form-field input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):disabled,
.form-field select:disabled,
.form-field textarea:disabled {
  background: var(--bg);
  color: var(--text);
  opacity: 1;
  cursor: default;
  border-color: var(--border);
}

.checkbox-group {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px 16px;
}
.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  font-size: 14px;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: 0;
  cursor: pointer;
}
.checkbox-group input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--primary);
}

/* ============================================================
   Attachments
   ============================================================ */
.attachments-upload, .attachments-view { margin-top:24px; }
.attachments-label { font-size:12px; font-weight:600; text-transform:uppercase; letter-spacing:.3px; color:var(--text-muted); margin-bottom:8px; }
.attach-drop-zone { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:4px; border:2px dashed var(--border); border-radius:10px; padding:24px 16px; cursor:pointer; transition:border-color .15s, background .15s; text-decoration:none; }
.attach-drop-zone:hover, .attach-drop-zone.drag-over { border-color:var(--primary); background:rgba(43,45,94,.03); }
.attach-icon { font-size:28px; line-height:1; }
.attach-hint { font-size:14px; font-weight:600; color:var(--text); }
.attach-hint-sub { font-size:12px; color:var(--text-muted); }
.attach-list { list-style:none; padding:0; margin:10px 0 0; display:flex; flex-direction:column; gap:6px; }
.attach-list li { display:flex; align-items:center; gap:8px; font-size:13px; color:var(--text); background:var(--bg); border:1px solid var(--border); border-radius:6px; padding:8px 12px; }
.attach-list a { color:var(--primary); text-decoration:none; font-size:13px; }
.attach-list a:hover { text-decoration:underline; }
.attach-size { color:var(--text-muted); margin-left:auto; font-size:12px; }
.attach-remove { margin-left:8px; background:none; border:none; color:var(--text-muted); cursor:pointer; font-size:14px; padding:0 2px; line-height:1; }
.attach-remove:hover { color:var(--danger); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
  .ims-layout {
    grid-template-columns: 1fr;
  }
  .ims-nav {
    position: static;
    max-height: none;
  }
  .tiles {
    grid-template-columns: repeat(2, 1fr);
  }
  .ims-content { padding: 24px; }
  .dashboard-grid { grid-template-columns: 1fr; }

  /* Toolbar (search + filter rows) - wrap instead of forcing the page wider
     than the screen. A <select> sizes to its longest option, which was
     pushing pages like Documents past the viewport width. */
  .toolbar { flex-wrap: wrap; }
  .toolbar form { flex-wrap: wrap; }
  .toolbar input, .toolbar select { flex: 1 1 auto; min-width: 0; }

  /* H&S section picker - dropdown instead of the tab row */
  .hs-tabs { display: none; }
  .hs-tabs-mobile {
    display: block;
    width: 100%;
    padding: 10px 14px;
    margin: 1rem 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--navy);
    background: var(--white);
  }

  /* Hamburger nav */
  /* position:static, not sticky - iOS Safari has a known bug where pinch-zoom
     breaks sticky-positioned elements, making them float over content instead
     of sitting above it in normal flow. */
  nav { padding: 0 12px; position: static; top: auto; }
  .nav-brand { margin-right: auto; gap: 8px; }
  .nav-brand span { display: none; }
  .nav-user { gap: 8px; font-size: 12px; }
  .nav-toggle { display: flex; }

  .nav-links {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    flex-direction: column;
    gap: 0;
    flex: none;
    background: var(--navy);
    box-shadow: 0 8px 16px rgba(43, 45, 94, 0.25);
    max-height: calc(100vh - 56px);
    overflow-y: auto;
    z-index: 99;
  }

  .nav-links.open { display: flex; }

  .nav-links a {
    padding: 14px 24px;
    font-size: 14px;
    border-radius: 0;
    border-bottom: 1px solid rgba(255,255,255,0.08);
  }

  .nav-links a.active::after { display: none; }

  /* Dropdowns become flat, always-expanded sections inside the mobile menu */
  .nav-dropdown { width: 100%; }
  .nav-dropdown-toggle {
    width: 100%;
    justify-content: space-between;
    padding: 14px 24px;
    border-radius: 0;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    cursor: default;
  }
  .nav-caret { display: none; }
  .nav-dropdown-menu {
    display: flex;
    position: static;
    box-shadow: none;
    padding: 0;
    background: rgba(0,0,0,0.15);
  }
  .nav-dropdown-menu a { padding: 12px 24px 12px 40px; border-radius: 0; border-bottom: 1px solid rgba(255,255,255,0.08); }
}

/* Pilot 4: bigger tap targets on phones. Form checkboxes (the toolbox
   attendee list is 24 of them at 16px) and in-table action buttons were too
   small to hit reliably one-handed in a van. Scoped to <=600px so desktop and
   tablet layouts are untouched. */
@media (max-width: 600px) {
  .checkbox-group input[type="checkbox"] { width: 22px; height: 22px; }
  .report-table-wrap td .btn-sm,
  .report-table-wrap td a.btn-sm,
  table td .btn-sm {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
  }
}

/* History view */
.history-employee {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.history-employee-name {
  margin: 0;
  padding: 12px 16px;
  background: var(--bg-alt);
  cursor: pointer;
  font-size: 1em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.history-employee-name:hover { background: var(--bg-hover); }
.history-employee-body { padding: 0 16px 16px; }
.history-employee.collapsed .history-employee-body { display: none; }
.history-formtype { margin-top: 12px; }
.history-formtype-name {
  margin: 0;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 500;
}
.history-formtype-name:hover { background: var(--bg-hover); }
.history-formtype.collapsed .history-formtype-body { display: none; }
.history-formtype-body { margin-top: 4px; }
.history-table { width: 100%; border-collapse: collapse; }
.history-table tr:hover { background: var(--bg-hover); }
.history-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 0.85em; }
.history-count { font-weight: 400; color: var(--text-muted); font-size: 0.85em; }
.badge-legacy { background: #e8e0f0; color: #6b4d8a; }
.badge-app { background: #d4edda; color: #155724; }

/* Login page */
.login-page { display:flex; align-items:center; justify-content:center; min-height:100vh; background:#f1f5f9; }
.login-card { background:white; border-radius:12px; padding:2.5rem; width:100%; max-width:400px; box-shadow:0 4px 24px rgba(0,0,0,0.08); }
.login-logo { text-align:center; margin-bottom:2rem; }
.login-logo img { height:60px; margin-bottom:1rem; }
.login-logo h1 { font-size:1.1rem; color:var(--navy); font-weight:600; margin:0; }
.login-card label { display:flex; flex-direction:column; gap:4px; margin-bottom:1rem; font-size:0.9rem; font-weight:500; }
.login-card input { padding:0.6rem 0.75rem; border:1px solid var(--border); border-radius:6px; font-size:1rem; font-family:inherit; }
.login-card input:focus { outline:2px solid var(--navy); border-color:transparent; }
.btn-full { width:100%; padding:0.75rem; font-size:1rem; margin-top:0.5rem; }
.login-hint { text-align:center; color:var(--text-muted); font-size:0.85rem; margin-top:1.5rem; }
.btn-google { display:flex; align-items:center; justify-content:center; gap:0.6rem; text-decoration:none; }
.btn-google-icon { width:18px; height:18px; }
.btn-link { background:none; border:none; color:var(--navy); text-decoration:underline; cursor:pointer; font-size:0.85rem; padding:0; }
.btn-link:hover { color:var(--navy-light); }
.page-sub { color:var(--text-muted); margin-top:-0.5rem; margin-bottom:1.5rem; }
.alert { padding:0.75rem 1rem; border-radius:6px; margin-bottom:1rem; font-size:0.9rem; }
.alert-error { background:#fee2e2; color:#991b1b; border:1px solid #fca5a5; }

/* Page header */
.page-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:1.5rem; }
.page-header h2 { margin:0; }

/* Pagination */
.pagination { display:flex; gap:4px; margin-top:1rem; }
.pagination a, .pagination span { padding:4px 10px; border:1px solid var(--border); border-radius:4px; font-size:0.85rem; text-decoration:none; color:var(--text); }
.pagination a:hover { background:var(--surface); }
.pagination .current { background:var(--navy); color:white; border-color:var(--navy); }

/* Form modal improvements */
/* Modal overlay - backdrop + centred card (was used but never defined) */
.modal-overlay {
  position:fixed; inset:0; z-index:1000;
  background:rgba(26,28,61,.45);
  display:flex; align-items:flex-start; justify-content:center;
  padding:48px 16px; overflow-y:auto;
  animation:fadeIn .15s ease;
}
.modal {
  width:100%; max-width:640px;
  background:var(--white);
  border:1px solid var(--card-border);
  border-radius:var(--radius);
  box-shadow:var(--shadow-lg);
  padding:28px 32px;
}
.modal h3 { color:var(--navy); font-size:18px; font-weight:700; margin-bottom:18px; text-transform:none; letter-spacing:0; }
.form-grid { display:grid; grid-template-columns:1fr 1fr; gap:1rem; }
.form-grid .full { grid-column:1/-1; }
.form-group { display:flex; flex-direction:column; gap:5px; }
.form-group label { font-size:12px; font-weight:600; color:var(--text-muted); text-transform:uppercase; letter-spacing:.3px; }
.form-group input, .form-group select, .form-group textarea {
  padding:10px 14px; border:1px solid var(--border); border-radius:8px;
  font-size:14px; font-family:inherit; background:var(--white);
  transition:var(--transition);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline:none; border-color:var(--gold); box-shadow:0 0 0 3px rgba(245,183,49,.12);
}

/* Detail panel - card styling to match variant C */
.detail-panel { background:var(--white); border:1px solid var(--card-border); border-left:4px solid var(--gold); border-radius:var(--radius); padding:1.5rem; margin-top:1.5rem; box-shadow:var(--shadow-sm); }
.detail-panel h3 { margin:0 0 1rem; color:var(--navy); font-size:18px; font-weight:700; text-transform:none; letter-spacing:0; }
.detail-panel h4 { margin:1.25rem 0 .75rem; font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:.4px; color:var(--text-muted); padding-bottom:.4rem; border-bottom:1px solid var(--border); }
.detail-grid { display:grid; grid-template-columns:1fr 1fr; gap:0.75rem; }
.detail-item strong { display:block; font-size:0.8rem; color:var(--text-muted); text-transform:uppercase; letter-spacing:0.04em; margin-bottom:2px; }

/* ============================================================
   Badges
   ============================================================ */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Status */
.badge-open          { background:#fef3c7; color:#92400e; }
.badge-closed        { background:#d1fae5; color:#065f46; }
.badge-in_progress   { background:#dbeafe; color:#1e40af; }
.badge-scheduled     { background:#e0e7ff; color:#3730a3; }
.badge-cancelled     { background:#f1f5f9; color:#64748b; }
.badge-completed     { background:#d1fae5; color:#065f46; }

/* Incident types */
.badge-injury        { background:#fee2e2; color:#991b1b; }
.badge-incident      { background:#dbeafe; color:#1e40af; }
.badge-near_miss     { background:#fef3c7; color:#92400e; }
.badge-no_injury     { background:#d1fae5; color:#065f46; }

/* Priority */
.badge-critical      { background:#fee2e2; color:#991b1b; }
.badge-high          { background:#ffedd5; color:#c2410c; }
.badge-medium        { background:#fef3c7; color:#92400e; }
.badge-low           { background:#f0fdf4; color:#166534; }

/* Record types */
.badge-site_audit    { background:#dbeafe; color:#1e40af; }
.badge-tailgate      { background:#e0e7ff; color:#3730a3; }
.badge-toolbox       { background:#f0fdf4; color:#166534; }

/* Ingestion */
.badge-manual        { background:#f1f5f9; color:#64748b; }
.badge-ocr           { background:#dbeafe; color:#1e40af; }
.badge-legacy        { background:#e8e0f0; color:#6b4d8a; }
.badge-app           { background:#d4edda; color:#155724; }

/* Substance state */
.badge-state         { font-size:0.75rem; font-weight:600; padding:2px 10px; border-radius:999px; }
.badge-liquid        { background:#dbeafe; color:#1e40af; }
.badge-solid         { background:#f1f5f9; color:#475569; }
.badge-gas           { background:#fef9c3; color:#713f12; }
.badge-aerosol       { background:#fce7f3; color:#9d174d; }

/* Category */
.badge-improvement   { background:#d1fae5; color:#065f46; }
.badge-process       { background:#dbeafe; color:#1e40af; }
.badge-equipment     { background:#fef3c7; color:#92400e; }
.badge-training      { background:#e0e7ff; color:#3730a3; }
.badge-compliance    { background:#fee2e2; color:#991b1b; }

/* Certs */
.badge-current       { background:#d1fae5; color:#065f46; }
.badge-expired       { background:#fee2e2; color:#991b1b; }
.badge-expiring_soon { background:#fef3c7; color:#92400e; }

/* Audit types */
.badge-internal      { background:#f1f5f9; color:#475569; }
.badge-external      { background:#dbeafe; color:#1e40af; }
.badge-supplier      { background:#e0e7ff; color:#3730a3; }
.badge-regulatory    { background:#fee2e2; color:#991b1b; }

/* Modal actions footer */
.modal-actions { display:flex; justify-content:flex-end; gap:0.75rem; margin-top:1.5rem; padding-top:1rem; border-top:1px solid var(--border); }

/* Section header - navy bar, matches dashboard table headers (variant C) */
.section-header {
  background: var(--navy);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .2px;
  padding: 11px 16px;
  border-left: 4px solid var(--gold);
  border-radius: 8px 8px 0 0;
  margin: 24px 0 0;
}
/* the field wrapper right after a section header should butt up flush */
.form-field:has(.section-header) { margin-bottom: 0; }
.ratings-table { width:100%; margin-top:4px; }
.ratings-hdr { display:flex; align-items:flex-end; padding-bottom:4px; gap:16px; }
.ratings-row { display:flex; align-items:center; padding:10px 0; border-bottom:1px solid var(--border-light,#f0f1f5); gap:16px; }
.ratings-row:last-child { border-bottom:none; }
.ratings-label { font-size:13px; color:var(--text); flex:1; min-width:0; }
/* col labels: positioned container, each span absolutely placed at tick % */
.snap-col-labels { position:relative; width:260px; flex-shrink:0; height:16px; }
.snap-col-labels span { position:absolute; transform:translateX(-50%); font-size:10px; font-weight:700; color:var(--text-muted); }
/* rating cell */
.snap-rating { position:relative; width:260px; flex-shrink:0; }
/* editable slider */
.snap-slider { -webkit-appearance:none; appearance:none; width:100%; height:5px; border-radius:3px; outline:none; cursor:pointer; display:block; margin:0; }
.snap-slider[data-empty="1"] { opacity:.4; }
.snap-slider::-webkit-slider-thumb { -webkit-appearance:none; appearance:none; width:22px; height:22px; border-radius:50%; background:var(--primary); cursor:pointer; box-shadow:0 2px 6px rgba(0,0,0,.25); border:3px solid #fff; margin-top:-8px; }
.snap-slider::-moz-range-thumb { width:22px; height:22px; border-radius:50%; background:var(--primary); cursor:pointer; box-shadow:0 2px 6px rgba(0,0,0,.25); border:3px solid #fff; }
/* tip label — sits below the track, moves with thumb */
.snap-tip { position:absolute; top:calc(100% + 2px); transform:translateX(-50%); font-size:11px; font-style:italic; font-weight:600; white-space:nowrap; transition:left .1s; pointer-events:none; }
/* readonly track */
.snap-track { position:relative; height:5px; background:var(--border); border-radius:3px; }
.snap-fill { height:100%; border-radius:3px; }
.snap-thumb { position:absolute; top:50%; transform:translate(-50%,-50%); width:22px; height:22px; border-radius:50%; border:3px solid #fff; box-shadow:0 2px 6px rgba(0,0,0,.25); pointer-events:none; }

/* Audit section field type (variant C) */
.audit-section {
  margin: 0 0 24px;
  border: 1px solid var(--card-border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
}
.audit-table { width:100%; border-collapse:collapse; font-size:15px; }
.audit-table thead th { text-align:left; padding:9px 16px; font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.05em; color:var(--text-muted); background:#eef0f7; border-bottom:1px solid var(--border); }
/* tight option columns - pulls Yes/No/N/A in next to the question, no big gap */
.audit-table thead th:not(:first-child) { text-align:center; width:64px; }
.audit-table tbody td { padding:11px 16px; border-bottom:1px solid var(--border-light); vertical-align:middle; font-size:15px; line-height:1.4; }
.audit-table tbody tr:last-child td { border-bottom:none; }
.audit-table tbody tr:nth-child(even) { background:var(--bg-light); }
.audit-table tbody tr:hover { background:var(--gold-muted); }
.audit-radio { text-align:center; width:64px; }
.audit-radio input[type=radio] { width:18px; height:18px; accent-color:var(--navy); cursor:pointer; }
.audit-yes { display:inline-block; padding:2px 8px; border-radius:12px; font-size:12px; font-weight:600; background:#d1fae5; color:#065f46; }
.audit-no  { display:inline-block; padding:2px 8px; border-radius:12px; font-size:12px; font-weight:600; background:#fee2e2; color:#991b1b; }
.audit-na  { display:inline-block; padding:2px 8px; border-radius:12px; font-size:12px; font-weight:600; background:#f1f5f9; color:#64748b; }
.audit-comments { font-size:14px; color:var(--text); padding:12px 16px; background:var(--bg-alt); border-top:1px solid var(--border); }
.audit-section > textarea { width:100%; margin:0; font-size:14px; padding:12px 16px; border:none; border-top:1px solid var(--border); border-radius:0; resize:vertical; min-height:64px; background:var(--white); font-family:inherit; }
.audit-section > textarea:focus { outline:none; box-shadow:inset 0 0 0 2px var(--gold); }

/* action_rows — repeating table (e.g. QMSF08 Forward Actions) */
.action-rows-table { width:100%; border-collapse:collapse; font-size:14px; margin-top:4px; }
.action-rows-table thead th { text-align:left; padding:8px 10px; font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.05em; color:var(--text-muted); background:#eef0f7; border:1px solid var(--border); }
.action-rows-table tbody td { padding:6px 8px; border:1px solid var(--border-light); vertical-align:middle; }
.action-rows-table input[type=text], .action-rows-table input[type=date] { width:100%; border:1px solid var(--border); border-radius:5px; padding:7px 9px; font-size:14px; font-family:inherit; }
.action-rows-table input[type=checkbox] { width:18px; height:18px; accent-color:var(--navy); cursor:pointer; }
