:root {
  --charcoal: #3C3C3C;
  --orange: #E87722;
  --orange-dark: #C4620F;
  --grey: #EDEDED;
  --grey-mid: #D9D9D9;
  --text: #262626;
  --danger: #C0392B;
  --success: #2E7D32;
  --warn: #B7791F;
  --radius: 6px;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text); background: #FAFAFA; font-size: 15px; line-height: 1.5;
}
a { color: var(--orange-dark); }
h1 { font-size: 26px; margin: 0 0 12px; }
h2 { font-size: 19px; margin: 32px 0 10px; color: var(--charcoal); }
.muted { color: #777; }

/* sidebar layout — polished 20 July */
.app-shell { display: flex; align-items: flex-start; min-height: 100vh; }
.sidebar {
  width: 248px; flex: 0 0 248px; background: #2A2A2A; color: #fff;
  min-height: 100vh; display: flex; flex-direction: column; position: sticky; top: 0;
  border-right: 1px solid rgba(255,255,255,.06);
}
.sidebar .brand {
  display: flex; align-items: baseline; gap: 6px; color: #fff; text-decoration: none; font-weight: 700; font-size: 17px;
  letter-spacing: .3px; padding: 22px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-hire { color: var(--orange); }
.brand-sub { font-size: 10px; font-weight: 600; color: #8a8a8a; letter-spacing: 1.5px; margin-left: 2px; }
.sidenav { flex: 1; overflow-y: auto; padding: 14px 10px; }
.nav-icon { flex: 0 0 16px; opacity: .75; }
.sidenav > a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; margin: 1px 0; border-radius: 7px;
  color: #cfcfcf; text-decoration: none; font-size: 13.5px; font-weight: 500;
  border-left: 2px solid transparent;
}
.sidenav > a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidenav > a.active {
  background: rgba(232,119,34,.14); color: #fff; border-left: 2px solid var(--orange);
}
.sidenav > a.active .nav-icon { opacity: 1; color: var(--orange); }
.sidenav details { margin: 1px 0; }
.sidenav summary {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 7px;
  color: #cfcfcf; font-size: 13.5px; font-weight: 500; cursor: pointer; list-style: none;
}
.sidenav summary::-webkit-details-marker { display: none; }
.sidenav summary::after { content: '›'; margin-left: auto; font-size: 15px; color: #777; transition: transform .15s ease; }
.sidenav details[open] > summary::after { transform: rotate(90deg); }
.sidenav summary:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidenav details a {
  display: flex; align-items: center; padding: 7px 12px 7px 39px; margin: 1px 0; border-radius: 7px;
  color: #a8a8a8; text-decoration: none; font-size: 13px; border-left: 2px solid transparent;
}
.sidenav details a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidenav details a.active { background: rgba(232,119,34,.14); color: #fff; border-left: 2px solid var(--orange); }
.sidebar-user {
  padding: 14px 20px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar-user-name { color: #e6e6e6; font-weight: 600; }
.sidebar-user-company { color: #888; font-size: 11.5px; }
.sidebar-user a { color: var(--orange); text-decoration: none; margin-top: 6px; font-weight: 600; }
.sidebar-user a:hover { text-decoration: underline; }

.main-wrap { flex: 1; min-width: 0; background: #FAFAF9; }
.page { max-width: 1200px; margin: 0 auto; padding: 32px 28px 60px; }
.sitefooter { text-align: center; color: #999; font-size: 12px; padding: 20px; }

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; min-height: auto; position: static; }
  .sidenav { display: flex; flex-wrap: wrap; padding: 8px; }
  .sidenav > a { padding: 8px 12px; }
  .sidenav details { flex: 1 1 auto; }
}

/* flash */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; }
.flash-success { background: #E8F5E9; color: var(--success); border: 1px solid #C8E6C9; }
.flash-error   { background: #FDECEA; color: var(--danger); border: 1px solid #F5C6CB; }

/* forms */
label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: #444; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px;
  border: 1px solid var(--grey-mid); border-radius: var(--radius); font-size: 14px; font-family: inherit;
}
label.inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; margin-right: 16px; }
fieldset { border: 1px solid var(--grey-mid); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
legend { font-size: 12px; font-weight: 600; color: #666; padding: 0 6px; }
.form-grid { max-width: 520px; }

.btn {
  display: inline-block; padding: 9px 18px; border-radius: var(--radius); border: 1px solid var(--grey-mid);
  background: #fff; color: var(--text); text-decoration: none; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--orange); border-color: var(--orange-dark); color: #fff; }
.btn-primary:hover { background: var(--orange-dark); }
.btn-small { padding: 5px 10px; font-size: 12px; }

/* auth card */
.auth-card { max-width: 380px; margin: 60px auto; background: #fff; padding: 32px; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* tables */
.data-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--grey); font-size: 14px; }
.data-table th { background: var(--grey); font-weight: 700; color: var(--charcoal); }
.row-inactive { opacity: .5; }

.badge { padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-trial { background: #FFF3E0; color: var(--warn); }
.badge-active { background: #E8F5E9; color: var(--success); }
.badge-suspended, .badge-cancelled { background: #FDECEA; color: var(--danger); }

/* dashboard stat cards — polished 20 July */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin: 22px 0; }
.stat-card {
  background: #fff; border: 1px solid #ECECEA; border-left: 3px solid #ECECEA; border-radius: 10px; padding: 18px 20px;
  text-decoration: none; color: var(--text); display: flex; flex-direction: column; gap: 5px;
  box-shadow: 0 1px 2px rgba(0,0,0,.03); transition: box-shadow .15s ease, transform .15s ease;
}
.stat-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.08); transform: translateY(-1px); }
.stat-num { font-size: 30px; font-weight: 700; color: var(--charcoal); letter-spacing: -0.5px; }
.stat-label { font-size: 12.5px; color: #777; font-weight: 500; }
.stat-warn { border-left-color: var(--warn); }
.stat-warn .stat-num { color: var(--warn); }
.stat-danger { border-left-color: var(--danger); }
.stat-danger .stat-num { color: var(--danger); }

.page-header { margin-bottom: 6px; }
.page-header h1 { margin-bottom: 4px; }
.page-header .page-sub { color: #777; font-size: 14px; margin: 0; }

.quicklinks { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }

/* document register */
.filter-bar { display: flex; gap: 10px; align-items: center; margin: 16px 0; flex-wrap: wrap; }
.filter-bar select { width: auto; margin-top: 0; }
.text-danger { color: var(--danger); font-weight: 600; }

/* inductions */
.editor-toolbar { display: flex; gap: 6px; margin-bottom: 6px; }
.editor-toolbar button {
  padding: 6px 12px; border: 1px solid var(--grey-mid); background: #fff; border-radius: 4px; cursor: pointer; font-size: 13px;
}
.rich-editor {
  min-height: 220px; border: 1px solid var(--grey-mid); border-radius: var(--radius);
  padding: 14px; background: #fff; margin-bottom: 20px;
}
.rich-editor:focus { outline: 2px solid var(--orange); }
.induction-content {
  background: #fff; border: 1px solid var(--grey-mid); border-radius: var(--radius);
  padding: 20px; margin: 16px 0; line-height: 1.6;
}
.quiz-q {
  background: #fff; border: 1px solid var(--grey-mid); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.quiz-q label.inline { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.quiz-q input[type=text] { display: inline-block; width: auto; flex: 1; margin-top: 0; }

/* slide-deck authoring */
.content-type-toggle { display: flex; gap: 20px; margin-bottom: 14px; }
.slide-card {
  display: flex; gap: 14px; background: #fff; border: 1px solid var(--grey-mid);
  border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
}
.slide-card-img { flex: 0 0 160px; }
.slide-card-img img { width: 160px; height: 110px; object-fit: cover; border-radius: 4px; background: var(--grey); }
.slide-card-fields { flex: 1; }
.slide-card-fields textarea { min-height: 50px; }

/* slide-deck viewing */
.slide-viewer { background: #fff; border: 1px solid var(--grey-mid); border-radius: var(--radius); padding: 20px; margin: 16px 0; text-align: center; }
.slide-pane img { max-width: 100%; max-height: 480px; border-radius: 6px; }
.slide-caption { font-size: 16px; font-weight: 600; margin-top: 14px; color: var(--charcoal); }
.slide-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; }

/* template gallery */
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; margin-top: 18px; }
.template-card { background: #fff; border: 1px solid var(--grey-mid); border-radius: 10px; padding: 16px; }
.template-card img { width: 100%; height: 140px; object-fit: cover; border-radius: 6px; margin-bottom: 10px; }
.template-card h3 { margin: 0 0 6px; font-size: 16px; }

/* SWMS wizard */
.step-adder { background: #fff; border: 1px solid var(--grey-mid); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.task-builder-card { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--grey-mid); }
.hazard-card { background: var(--grey); border-radius: 6px; padding: 12px; margin: 10px 0; }
.hazard-fields { display: flex; gap: 16px; align-items: center; margin: 8px 0; font-size: 13px; flex-wrap: wrap; }
.hazard-fields select, .hazard-fields input[type=text] { width: auto; margin-top: 0; display: inline-block; }
.controls-list { font-size: 13px; margin-left: 6px; }
.controls-list label { font-weight: 400; margin-bottom: 4px; }
.hrcw-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 8px; background: #fff; border: 1px solid var(--grey-mid); border-radius: var(--radius); padding: 14px; }
.hrcw-grid label.inline { font-weight: 400; align-items: flex-start; }
.step-summary { background: #fff; border: 1px solid var(--grey-mid); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.step-summary ul { margin: 6px 0 0; padding-left: 20px; font-size: 13px; color: #555; }
.sop-picker { background: #FFF3E0; border-left: 4px solid var(--orange); padding: 10px 14px; margin: 10px 0; border-radius: 4px; }
.sop-picker select { margin-bottom: 8px; }
.sop-ref-tag { background: #FFF3E0; border-left: 3px solid var(--orange); font-size: 12px; padding: 4px 8px; margin: 6px 0; border-radius: 3px; }
.inline-add-form { display: flex; gap: 8px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.inline-add-form input[type=text] { width: auto; flex: 1; min-width: 200px; margin-top: 0; }
.inline-add-form select { width: auto; margin-top: 0; }
.sds-chip { display: inline-block; background: var(--grey); border-radius: 14px; padding: 4px 12px; margin: 3px 4px 3px 0; font-size: 13px; }
.sds-chip a { color: var(--danger); text-decoration: none; margin-left: 6px; font-weight: 700; }
.scope-suggestions { background: #FFF3E0; border-left: 4px solid var(--orange); border-radius: 4px; padding: 12px 14px; margin: 10px 0 20px; font-size: 13px; }
.scope-suggestions .btn-small { margin: 4px 6px 4px 0; }

/* training matrix */
.matrix-scroll { overflow-x: auto; }
.matrix-table { white-space: nowrap; }
.matrix-table th, .matrix-table td { text-align: center; }
.matrix-table td:first-child, .matrix-table th:first-child { text-align: left; white-space: normal; min-width: 140px; }
.matrix-cell { font-size: 18px; font-weight: 700; }
.matrix-cell a, .matrix-cell span { text-decoration: none; }
.matrix-current { background: #E8F5E9; color: #2E7D32; }
.matrix-expiring { background: #FFF3E0; color: #B7791F; }
.matrix-expired, .matrix-missing { background: #FDECEA; color: #C0392B; }
.matrix-pending { background: #E3F2FD; color: #1565C0; }
.matrix-na { color: #ccc; }

/* signature pad */
.sig-pad-wrap { margin: 8px 0 20px; }
.sig-pad-container { position: relative; max-width: 500px; }
.sig-pad {
  display: block; width: 100%; max-width: 500px; height: 150px;
  border: 2px solid #999; border-radius: 8px; background: #fcfcfc;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  touch-action: none; cursor: crosshair;
}
.sig-line {
  position: absolute; left: 24px; right: 24px; bottom: 34px;
  border-bottom: 1.5px dashed #bbb; pointer-events: none;
}
.sig-x {
  position: absolute; left: 24px; bottom: 30px; color: #bbb; font-size: 18px; font-weight: 700; pointer-events: none;
}

/* leading/lagging indicators */
.indicator-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 12px 0; }
.indicator-group { background: #fff; border: 1px solid var(--grey-mid); border-radius: 8px; padding: 14px 18px; }
.indicator-group h3 { margin: 0 0 10px; font-size: 14px; color: var(--charcoal); }
.indicator-row { display: flex; align-items: baseline; gap: 10px; padding: 6px 0; border-bottom: 1px solid #f2f2f2; font-size: 14px; }
.indicator-row span { font-weight: 700; font-size: 20px; min-width: 50px; color: var(--orange); }
@media (max-width: 700px) { .indicator-grid { grid-template-columns: 1fr; } }

/* investigation phase stepper */
.phase-stepper { display: flex; gap: 8px; margin: 16px 0 28px; flex-wrap: wrap; }
.phase-step {
  display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 20px;
  background: #fff; border: 1px solid var(--grey-mid); text-decoration: none; color: var(--charcoal); font-size: 13px;
}
.phase-step:hover { border-color: var(--orange); }
.phase-step.phase-active { background: var(--charcoal); color: #fff; border-color: var(--charcoal); }
.phase-step.phase-done { border-color: #2e7d32; }
.phase-step.phase-locked { color: #bbb; background: #f7f7f7; cursor: not-allowed; }
.phase-num {
  display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px;
  border-radius: 50%; background: rgba(0,0,0,.08); font-size: 12px; font-weight: 700;
}
.phase-active .phase-num { background: rgba(255,255,255,.25); }

.notifiable-helper { margin-top: 8px; font-size: 13px; background: #fafafa; border: 1px solid var(--grey-mid); border-radius: 6px; padding: 10px 14px; }
.notifiable-helper summary { cursor: pointer; color: var(--orange); font-weight: 600; }
.notifiable-helper p { margin: 8px 0; }
.ppe-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; background: #fff; border: 1px solid var(--grey-mid); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.ppe-grid label.inline { font-weight: 400; }