:root {
  --ink: #111;
  --paper: #fff;
  --line: #171717;
  --ui-bg: #eef1f5;
  --primary: #1f5faa;
  --danger: #a52828;
}

* { box-sizing: border-box; }

html { background: var(--ui-bg); }

body {
  margin: 0;
  color: var(--ink);
  font-family: "Times New Roman", Times, serif;
  background: var(--ui-bg);
}

button, .button {
  border: 1px solid #174b86;
  border-radius: 5px;
  background: var(--primary);
  color: #fff;
  padding: 9px 14px;
  font: 600 14px/1.2 Arial, sans-serif;
  cursor: pointer;
  text-decoration: none;
}

button.secondary, .button.secondary {
  background: #fff;
  color: #243447;
  border-color: #9da9b7;
}

button:disabled { opacity: .55; cursor: wait; }

.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(16px, calc((100vw - 210mm) / 2));
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid #ccd3dc;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
  backdrop-filter: blur(6px);
}

.toolbar__group { display: flex; gap: 8px; flex-wrap: wrap; }
.page-shell { padding: 18px 8px 36px; overflow-x: auto; }

.paper {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  padding: 11.5mm 12.5mm 9mm;
  background: var(--paper);
  box-shadow: 0 8px 30px rgba(0,0,0,.18);
  font-size: 10.6pt;
  line-height: 1.06;
}

.document-header { border: .35mm solid var(--line); }
.document-header__top { display: grid; grid-template-columns: 38mm 1fr 56mm; height: 16mm; }
.logo-cell, .form-cell, .control-cell { min-width: 0; }
.logo-cell { display: flex; align-items: center; justify-content: center; border-right: .35mm solid var(--line); padding: 2mm; }
.logo-cell img { width: 32mm; max-height: 11mm; object-fit: contain; }
.form-cell { display: flex; align-items: center; justify-content: center; border-right: .35mm solid var(--line); font-weight: 700; font-size: 12pt; }
.control-cell { font-size: 8.2pt; font-style: italic; }
.control-cell > div { display: grid; grid-template-columns: 25mm 4mm 1fr; align-items: center; height: 4mm; padding: 0 .8mm; border-bottom: .25mm solid var(--line); }
.control-cell > div:last-child { border-bottom: 0; }
.control-cell strong { font-weight: 400; white-space: nowrap; }

.title-cell { height: 13mm; border-top: .35mm solid var(--line); padding: 1.2mm 1.8mm; }
.title-cell > span { display: block; font-size: 10pt; }
.title-cell h1 { margin: 1.7mm 0 0; text-align: center; font-size: 14.5pt; line-height: 1; text-shadow: .15mm .15mm 0 #aaa; }

.intro-fields { height: 19mm; padding: 4mm 2mm 1.5mm; display: grid; align-content: start; gap: 2.3mm; }
.intro-fields label { display: grid; grid-template-columns: max-content 1fr; align-items: end; gap: 3mm; }
.intro-fields input { border: 0; border-bottom: .35mm solid var(--line); height: 5mm; padding: 0 1mm; font: inherit; background: transparent; min-width: 0; }

.report-table { width: 100%; border-collapse: collapse; table-layout: fixed; border: .35mm solid var(--line); }
.report-table col { width: auto; }
.report-table td, .report-table th { border: .28mm solid var(--line); padding: 1.4mm 1.7mm; vertical-align: top; font-weight: 400; }
.report-table tr > *:nth-child(1) { width: 33%; }
.report-table tr > *:nth-child(2) { width: 24%; }
.report-table tr > *:nth-child(3) { width: 23%; }
.report-table tr > *:nth-child(4) { width: 20%; }
.report-table label { display: flex; flex-direction: column; height: 100%; }
.report-table input:not([type="checkbox"]), .report-table textarea {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  padding: .8mm 0 0;
  resize: none;
}
.report-table textarea { flex: 1; line-height: 1.15; overflow: hidden; }
.report-table input:focus, .report-table textarea:focus, .intro-fields input:focus { background: #fffde4; box-shadow: inset 0 0 0 .3mm #e8ca52; }

.people-row { height: 8mm; }
.people-row-sub { height: 7mm; }
.people-row-location { height: 10mm; }
.people-cell textarea, .id-cell textarea { height: 18mm; }
.side-label { vertical-align: middle !important; }
.side-input { vertical-align: middle !important; }
.side-input textarea { height: 8mm; }

.section-heading { height: 6mm; }
.section-heading th { text-align: center; vertical-align: middle; padding: .8mm; font-size: 11pt; }
.types-row { height: 19mm; }
.check-grid { display: grid; grid-template-columns: 1fr 1.05fr 1.15fr; grid-auto-rows: 5.2mm; align-items: center; column-gap: 5mm; }
.check-grid label, .classification-grid label { display: flex; flex-direction: row; align-items: center; gap: 1.2mm; white-space: nowrap; }
input[type="checkbox"] { appearance: none; width: 3.3mm; height: 3.3mm; margin: 0; border: .35mm solid var(--line); background: #fff; flex: 0 0 auto; }
input[type="checkbox"]:checked::after { content: "✓"; display: block; margin: -.7mm 0 0 .1mm; font: 700 12pt/1 Arial, sans-serif; }
.other-check { min-width: 0; }
.inline-line { display: inline-block !important; flex: 1; border-bottom: .35mm solid var(--line) !important; height: 4mm; padding: 0 !important; }

.classification-row { height: 7mm; }
.classification-grid { display: grid; grid-template-columns: 1.35fr 1fr 1fr .8fr .9fr; align-items: center; gap: 3mm; }
.classification-grid input[type="checkbox"] { border-radius: 50%; }

.single-row { height: 7mm; }
.single-row label { display: grid; grid-template-columns: max-content 1fr; align-items: center; gap: 2mm; }
.damage-row input { border-bottom: .25mm solid transparent !important; }
.activity-row { height: 14mm; }
.equipment-row { height: 8mm; }
.equipment-label { width: 31% !important; }
.description-row { height: 18mm; }
.consequences-row { height: 16mm; }
.actions-row { height: 16mm; }
.recommendations-row { height: 16mm; }
.narrative-row textarea { padding-top: 1mm; }
.witness-row { height: 11mm; }
.employee-row { height: 16mm; }
.supervisor-row { height: 16mm; }
.project-row { height: 12mm; }
.witness-row input, .employee-row input, .supervisor-row input, .project-row input { flex: 1; }

.document-note { margin: 2.3mm 0 0; font-size: 9.5pt; font-style: italic; }
.document-note strong { font-weight: 400; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: min(390px, calc(100vw - 36px));
  padding: 12px 15px;
  border-radius: 6px;
  color: #fff;
  background: #263544;
  font: 14px/1.35 Arial, sans-serif;
  box-shadow: 0 6px 24px rgba(0,0,0,.24);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

.admin-body { font-family: Arial, sans-serif; background: #f2f4f7; color: #17202a; }
.admin-wrap { max-width: 1180px; margin: 0 auto; padding: 24px 16px 50px; }
.admin-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.admin-header h1 { margin: 0 0 5px; font: 700 26px/1.2 Arial, sans-serif; }
.admin-header p { margin: 0; color: #566474; }
.admin-controls { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; margin-bottom: 14px; }
.admin-controls input { min-width: 0; border: 1px solid #aeb8c4; border-radius: 5px; padding: 10px; font: 14px Arial, sans-serif; }
.card { background: #fff; border: 1px solid #d6dce3; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.05); overflow: hidden; }
.table-scroll { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; min-width: 900px; }
.admin-table th, .admin-table td { padding: 11px 12px; border-bottom: 1px solid #e2e6eb; text-align: left; vertical-align: top; font: 13px/1.35 Arial, sans-serif; }
.admin-table th { background: #f7f8fa; font-weight: 700; }
.admin-table tbody tr:hover { background: #fbfcfd; }
.empty { padding: 36px; text-align: center; color: #687685; }
.badge { display: inline-block; border-radius: 999px; padding: 3px 8px; background: #e9f1fb; color: #174f89; font-size: 12px; }
.mini-button { padding: 6px 9px; font-size: 12px; }
.modal { position: fixed; inset: 0; z-index: 50; display: none; align-items: flex-start; justify-content: center; padding: 24px; overflow: auto; background: rgba(0,0,0,.55); }
.modal.open { display: flex; }
.modal-card { width: min(900px, 100%); background: #fff; border-radius: 8px; padding: 20px; }
.modal-top { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 12px; }
.modal-top h2 { margin: 0; font-size: 20px; }
.detail-grid { display: grid; grid-template-columns: 190px 1fr; gap: 0; border: 1px solid #c8ced6; }
.detail-grid dt, .detail-grid dd { margin: 0; padding: 9px 10px; border-bottom: 1px solid #dce1e6; }
.detail-grid dt { font-weight: 700; background: #f7f8fa; }
.detail-grid dd { white-space: pre-wrap; overflow-wrap: anywhere; }

@media (max-width: 760px) {
  .toolbar { position: static; padding: 10px; flex-direction: column; }
  .toolbar__group { width: 100%; }
  .toolbar button, .toolbar .button { flex: 1 1 auto; text-align: center; }
  .page-shell { padding-top: 10px; }
  .admin-controls { grid-template-columns: 1fr; }
  .admin-header { flex-direction: column; }
  .detail-grid { grid-template-columns: 1fr; }
}

@page { size: A4 portrait; margin: 0; }

@media print {
  html, body { width: 210mm; height: 297mm; background: #fff; }
  .toolbar, .toast { display: none !important; }
  .page-shell { padding: 0; overflow: visible; }
  .paper { width: 210mm; height: 297mm; min-height: 0; margin: 0; box-shadow: none; overflow: hidden; }
  input::placeholder { color: transparent; }
  .report-table input:focus, .report-table textarea:focus, .intro-fields input:focus { background: transparent; box-shadow: none; }
}
