:root {
  --blue: #253472;
  --ink: #090909;
  --line: #111;
  --muted: #626875;
  --bg: #f3f5f8;
}

* {
  box-sizing: border-box;
}

html,
body,
.pdf-page,
.pdf-page * {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
}

.is-hidden {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(380px, 520px) 1fr;
  gap: 24px;
  padding: 24px;
  align-items: start;
}

.page-topbar {
  grid-column: 1 / -1;
  margin-bottom: 0;
}

.panel {
  background: #fff;
  border: 1px solid #d7dce5;
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 10px 28px rgba(24, 35, 60, 0.08);
}

.brand-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 14px;
  align-items: center;
}

.brand-row img {
  width: 72px;
  height: 72px;
  object-fit: contain;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  font-size: 22px;
  margin-bottom: 4px;
}

.brand-row p,
.muted {
  color: var(--muted);
}

.text-link {
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

.text-link:hover {
  text-decoration: underline;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--blue);
  border-radius: 6px;
  padding: 9px 11px;
  color: #fff;
  background: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

.link-button {
  border: 0;
  padding: 0;
  color: var(--blue);
  background: transparent;
  font-weight: 700;
}

.login-shell,
.dashboard-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 420px);
  text-align: center;
}

.login-panel img {
  width: 92px;
  height: 92px;
  object-fit: contain;
}

.login-panel form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  text-align: left;
}

.dashboard-panel {
  width: min(100%, 760px);
}

.dashboard-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 18px 0;
}

.step,
button {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
  border-radius: 6px;
  padding: 9px 11px;
  cursor: pointer;
}

.step {
  font-size: 13px;
  min-height: 42px;
}

.step:not(.is-active),
.secondary {
  color: var(--blue);
  background: #fff;
}

.form-page {
  display: none;
}

.form-page.is-active {
  display: block;
}

.field-grid,
.signature-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 5px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid #b8c0ce;
  border-radius: 5px;
  padding: 8px 9px;
  background: #fff;
  font-weight: 400;
}

.multi-select {
  position: relative;
}

.multi-select-button {
  width: 100%;
  min-height: 39px;
  border: 1px solid #b8c0ce;
  background: #fff;
  color: var(--ink);
  text-align: left;
  font-weight: 400;
}

.multi-select-button::after {
  content: "▾";
  float: right;
}

.multi-select-menu {
  position: absolute;
  z-index: 10;
  display: none;
  width: 100%;
  margin-top: 4px;
  border: 1px solid #b8c0ce;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 12px 24px rgba(24, 35, 60, 0.16);
}

.multi-select.is-open .multi-select-menu {
  display: grid;
}

.multi-select-menu label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  font-weight: 400;
  cursor: pointer;
}

.multi-select-menu label + label {
  border-top: 1px solid #e4e8ef;
}

.multi-select-menu input {
  width: auto;
}

.check-grid {
  display: grid;
  gap: 8px;
}

.check-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
}

.check-grid input {
  width: auto;
}

.other-field {
  margin-top: 10px;
}

.table-wrap {
  overflow-x: auto;
}

.data-table,
.attendance-input {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td,
.attendance-input th,
.attendance-input td {
  border: 1px solid var(--line);
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
}

.data-table th,
.attendance-input th {
  color: #fff;
  background: var(--blue);
  font-weight: 400;
}

.attendance-input th:first-child,
.attendance-input td:first-child {
  width: 52px;
}

.attendance-input td:nth-child(2) {
  min-width: 150px;
  font-weight: 700;
}

.attendance-input td:nth-child(3) {
  min-width: 140px;
  text-align: center;
}

.attendance-input th:nth-child(3) {
  text-align: center;
}

.attendance-input td:nth-child(3) select {
  text-align: center;
  text-align-last: center;
}

.small-clear {
  margin-top: 6px;
  padding: 5px 8px;
  font-size: 12px;
}

.sig-pad {
  width: 100%;
  height: 120px;
  border: 1px solid #aeb6c4;
  border-radius: 5px;
  background: #fff;
  touch-action: none;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  padding-top: 12px;
  background: #fff;
}

.error {
  min-height: 20px;
  margin: 12px 0 0;
  color: #b00020;
  font-weight: 700;
}

.photo-preview {
  display: none;
  max-width: 100%;
  max-height: 360px;
  border: 1px solid #b8c0ce;
  object-fit: contain;
}

.admin-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px;
}

.admin-topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.admin-topbar .brand-row {
  max-width: 640px;
}

.admin-layout {
  display: grid;
  gap: 18px;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.setup-card {
  display: grid;
  align-content: start;
  gap: 12px;
}

.setup-card.wide {
  grid-column: span 3;
}

.setup-list {
  display: grid;
  gap: 8px;
}

.setup-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
}

.setup-row.hazard-row {
  grid-template-columns: minmax(140px, 0.5fr) 1fr auto;
}

.setup-row.user-row {
  grid-template-columns: minmax(180px, 1fr) minmax(140px, 0.7fr) minmax(150px, 0.6fr) auto;
}

.setup-row textarea {
  min-height: 72px;
  resize: vertical;
}

textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #b8c0ce;
  border-radius: 5px;
  padding: 8px 9px;
  background: #fff;
  font: inherit;
}

.setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 18px;
}

.admin-actions {
  display: grid;
  grid-template-columns: minmax(180px, 260px) repeat(3, auto);
  gap: 12px;
  align-items: end;
}

.danger {
  border-color: #a82424;
  background: #a82424;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.summary-item {
  border: 1px solid #d7dce5;
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.summary-item strong {
  display: block;
  font-size: 24px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid #d7dce5;
  padding: 10px 8px;
  text-align: left;
  vertical-align: middle;
}

.admin-table th {
  color: #fff;
  background: var(--blue);
  font-weight: 400;
}

.admin-table a {
  color: var(--blue);
  font-weight: 700;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-button {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
}

.status-line {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--blue);
  font-weight: 700;
}

@media (max-width: 900px) {
  .admin-actions,
  .summary-grid,
  .setup-grid {
    grid-template-columns: 1fr;
  }

  .setup-card.wide {
    grid-column: auto;
  }

  .setup-row,
  .setup-row.hazard-row,
  .setup-row.user-row {
    grid-template-columns: 1fr;
  }
}

.print-preview {
  display: grid;
  gap: 20px;
  justify-items: center;
}

.pdf-page {
  position: relative;
  width: 210mm;
  min-height: 297mm;
  padding: 10mm 16mm 15mm;
  background: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.is-generating-pdf .pdf-page {
  width: 210mm;
  min-height: 0;
  height: 297mm;
  padding: 11mm 18mm 10mm;
  box-shadow: none;
  overflow: hidden;
}

.is-generating-pdf .pdf-header {
  grid-template-columns: 19mm 1fr;
  gap: 7mm;
}

.is-generating-pdf .pdf-header img {
  width: 19mm;
  height: 19mm;
}

.is-generating-pdf .pdf-header h2 {
  margin-bottom: 1mm;
  font-size: 15.6pt;
}

.is-generating-pdf .pdf-header h3 {
  font-size: 13pt;
}

.is-generating-pdf .blue-rule {
  height: 1.2mm;
  margin: 3.2mm 0 4.4mm;
}

.is-generating-pdf .project-table th,
.is-generating-pdf .project-table td {
  height: 6.4mm;
  font-size: 9pt;
  padding: 0.85mm 1.45mm;
}

.is-generating-pdf .pdf-section {
  margin-top: 3mm;
}

.is-generating-pdf .pdf-section h4 {
  margin-bottom: 1.7mm;
  font-size: 13pt;
}

.is-generating-pdf .activity-output {
  display: block;
  font-size: 9.55pt;
  line-height: 1.1;
}

.is-generating-pdf .activity-output div::before {
  width: 2.5mm;
  height: 2.5mm;
  margin-right: 1mm;
}

.is-generating-pdf .topic-list li {
  margin-bottom: 0.85mm;
  font-size: 8.45pt;
  line-height: 1.08;
}

.is-generating-pdf .topics-section {
  margin-top: 3mm;
}

.is-generating-pdf .hazards-section {
  margin-top: 2.6mm;
}

.is-generating-pdf .pdf-table th,
.is-generating-pdf .pdf-table td {
  padding: 0.68mm 1.2mm;
  font-size: 7.2pt;
  line-height: 1.04;
}

.is-generating-pdf .pdf-table th {
  font-size: 8.3pt;
}

.is-generating-pdf .hazards-table td {
  height: 5.6mm;
  max-height: 5.6mm;
}

.is-generating-pdf .hazards-table td:first-child,
.is-generating-pdf .hazards-table td:nth-child(2) {
  font-size: 6.75pt;
}

.is-generating-pdf .hazards-table .cell-fit {
  height: 4.45mm;
}

.is-generating-pdf .attendance-table td {
  height: 5.8mm;
  max-height: 5.8mm;
}

.is-generating-pdf .attendance-table td:last-child img {
  height: 4.7mm;
}

.is-generating-pdf .page-two .pdf-section {
  margin-top: 2.4mm;
}

.is-generating-pdf .page-two p,
.is-generating-pdf .sign-lines {
  font-size: 8.4pt;
  line-height: 1.08;
}

.is-generating-pdf .sign-lines {
  gap: 5mm;
}

.is-generating-pdf .sign-signature img {
  height: 7mm;
}

.is-generating-pdf .photo-section img {
  max-height: 48mm;
}

.pdf-header {
  display: grid;
  grid-template-columns: 24mm 1fr;
  gap: 8mm;
  align-items: center;
}

.pdf-header img {
  width: 24mm;
  height: 24mm;
  object-fit: contain;
}

.pdf-header h2 {
  margin: 0 0 2mm;
  font-size: 18pt;
  font-weight: 700;
}

.pdf-header h3 {
  margin: 0;
  font-size: 16pt;
  font-weight: 700;
}

.blue-rule {
  height: 1.8mm;
  margin: 5mm 0 8mm;
  background: var(--blue);
}

.project-table,
.pdf-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.project-label-col {
  width: 18%;
}

.project-value-col {
  width: 32%;
}

.project-table th,
.project-table td {
  height: 7.4mm;
  border: 1px solid var(--line);
  font-size: 10.4pt;
  text-align: left;
  font-weight: 400;
  padding: 1mm 2mm;
  vertical-align: middle;
}

.project-table th {
  font-weight: 700;
  white-space: nowrap;
}

.project-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-table td::after {
  content: "";
  display: block;
  border-bottom: 1px solid #777;
  min-height: 3.4mm;
}

.project-table td:not(:empty)::after {
  display: none;
}

.pdf-section {
  margin-top: 6mm;
}

.pdf-section h4 {
  margin-bottom: 3.5mm;
  font-size: 15.5pt;
  font-weight: 700;
}

.page-two .pdf-section h4:first-child {
  font-weight: 700;
}

.activity-output {
  font-size: 11pt;
  font-weight: 700;
  line-height: 1.16;
}

.activity-output div::before {
  content: "";
  display: inline-block;
  width: 3.2mm;
  height: 3.2mm;
  margin-right: 1.4mm;
  border: 1px solid var(--line);
  vertical-align: -0.4mm;
}

.activity-output div.is-checked::before {
  background: var(--ink);
}

.topic-list {
  padding-left: 0;
  margin: 0;
  list-style-position: inside;
}

.topic-list li {
  margin-bottom: 1.6mm;
  font-size: 9.7pt;
  line-height: 1.14;
  white-space: pre-line;
}

.topic-list ul {
  margin: 1mm 0 0 8mm;
  padding: 0;
}

.topic-list ul li {
  margin-bottom: 0.4mm;
  list-style: disc;
}

.pdf-table th,
.pdf-table td {
  border: 1px solid var(--line);
  padding: 1.05mm 1.8mm;
  text-align: left;
  vertical-align: middle;
  font-size: 8.2pt;
  line-height: 1.08;
  overflow: hidden;
}

.pdf-table th {
  color: #fff;
  background: var(--blue);
  font-size: 9.8pt;
  font-weight: 400;
}

.hazards-table th:first-child,
.hazards-table td:first-child {
  width: 27%;
}

.hazards-table td {
  height: 8.2mm;
  max-height: 8.2mm;
}

.hazards-table td:first-child {
  font-size: 8pt;
}

.hazards-table td:nth-child(2) {
  font-size: 7.8pt;
}

.hazards-table .cell-fit {
  display: -webkit-box;
  height: 6mm;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.attendance-table th:first-child,
.attendance-table td:first-child {
  width: 6%;
}

.attendance-table th:nth-child(2),
.attendance-table td:nth-child(2) {
  width: 36%;
}

.attendance-table th:nth-child(3),
.attendance-table td:nth-child(3) {
  width: 22%;
  text-align: center;
}

.attendance-table td {
  height: 7mm;
  max-height: 7mm;
}

.attendance-table td:last-child {
  padding: 0.5mm 1mm;
  text-align: center;
}

.attendance-table td:last-child img {
  display: block;
  width: 100%;
  height: 5.8mm;
  object-fit: contain;
}

.page-two .pdf-section {
  margin-top: 5.5mm;
}

.page-two p {
  font-size: 9.8pt;
  line-height: 1.16;
}

.sign-lines {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8mm;
  font-size: 9.8pt;
  align-items: end;
}

.sign-block {
  display: grid;
  gap: 2.2mm;
}

.sign-name {
  border-bottom: 1px solid #777;
  min-height: 6.5mm;
  font-weight: 700;
}

.sign-name span {
  font-weight: 400;
}

.sign-signature {
  display: grid;
  grid-template-columns: 19mm 1fr;
  gap: 2mm;
  align-items: end;
  min-height: 13mm;
  font-weight: 700;
}

.sign-signature img {
  display: block;
  width: 100%;
  height: 10mm;
  object-fit: contain;
  border-bottom: 1px solid #777;
}

.photo-section {
  break-inside: avoid;
}

.photo-section img {
  display: none;
  max-width: 100%;
  max-height: 68mm;
  object-fit: contain;
  border: 1px solid var(--line);
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body {
    background: #fff;
  }

  .page-topbar,
  .controls {
    display: none;
  }

  .app-shell {
    display: block;
    padding: 0;
  }

  .print-preview {
    display: block;
  }

  .pdf-page {
    width: auto;
    min-height: 0;
    height: 270mm;
    padding: 6mm 12mm;
    box-shadow: none;
    page-break-after: always;
    overflow: hidden;
  }

  .pdf-page:last-child {
    page-break-after: auto;
  }

  .pdf-header {
    grid-template-columns: 18mm 1fr;
    gap: 6mm;
  }

  .pdf-header img {
    width: 18mm;
    height: 18mm;
  }

  .pdf-header h2 {
    margin-bottom: 1mm;
    font-size: 15pt;
  }

  .pdf-header h3 {
    font-size: 12.5pt;
  }

  .blue-rule {
    height: 1.2mm;
    margin: 3mm 0 4mm;
  }

  .project-table th,
  .project-table td {
    height: 6.2mm;
    font-size: 8.8pt;
    padding: 0.8mm 1.4mm;
  }

  .pdf-section {
    margin-top: 2.7mm;
  }

  .pdf-section h4 {
    margin-bottom: 1.4mm;
    font-size: 12.5pt;
  }

  .activity-output {
    display: block;
    font-size: 9.2pt;
    line-height: 1.08;
  }

  .activity-output div::before {
    width: 2.5mm;
    height: 2.5mm;
    margin-right: 1mm;
  }

  .topic-list li {
    margin-bottom: 0.85mm;
    font-size: 8.35pt;
    line-height: 1.06;
  }

  .topics-section {
    margin-top: 3mm;
  }

  .pdf-table th,
  .pdf-table td {
    padding: 0.65mm 1.2mm;
    font-size: 7.05pt;
    line-height: 1.02;
  }

  .pdf-table th {
    font-size: 8.2pt;
  }

  .hazards-table td {
    height: 6mm;
    max-height: 6mm;
  }

  .hazards-table td:first-child,
  .hazards-table td:nth-child(2) {
    font-size: 6.8pt;
  }

  .hazards-table .cell-fit {
    height: 4.8mm;
  }

  .attendance-table td {
    height: 5.8mm;
    max-height: 5.8mm;
  }

  .attendance-table td:last-child img {
    height: 4.7mm;
  }

  .page-two .pdf-section {
    margin-top: 2.4mm;
  }

  .page-two p,
  .sign-lines {
    font-size: 8pt;
    line-height: 1.04;
  }

  .sign-lines {
    gap: 5mm;
  }

  .sign-signature img {
    height: 7mm;
  }

  .photo-section img {
    max-height: 48mm;
  }
}

@page {
  size: A4;
  margin: 8mm 0;
}
