:root {
  --blue: #1d3f77;
  --blue-dark: #17386c;
  --ink: #0b1320;
  --muted: #60708a;
  --line: #d4dae4;
  --paper: #ffffff;
  --bg: #f4f6fa;
  --success: #17a765;
  --warn: #a66b0b;
  --danger: #9d2d2d;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}
a { color: inherit; text-decoration: none; }

.topbar {
  height: 68px;
  background: var(--blue);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 7vw;
  box-shadow: 0 1px 0 rgba(0,0,0,.18);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand strong { display: block; font-size: 20px; }
.brand small { display: block; color: #c8d4e9; font-weight: 700; font-size: 12px; }
.shield {
  width: 28px; height: 28px; border: 2px solid white; border-radius: 8px;
  display: grid; place-items: center; font-size: 13px; color: transparent;
}
.nav { display: flex; gap: 14px; align-items: center; }
.nav-link { padding: 11px 15px; border-radius: 6px; font-weight: 700; font-size: 14px; color: white; }
.nav-link.active { background: white; color: #1c2c49; }
.nav-link.strong { background: transparent; }

.page { max-width: 1240px; margin: 0 auto; padding: 34px 24px 70px; }
.toolbar-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 34px; }
h1 { font-family: Georgia, 'Times New Roman', serif; font-size: 36px; margin: 0 0 6px; }
h2 { margin: 0; font-size: 20px; }
p { margin: 0; }
.toolbar-row p, .subtle { color: var(--muted); }

.button {
  appearance: none;
  border: 0;
  background: var(--blue-dark);
  color: white;
  border-radius: 6px;
  padding: 12px 18px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 2px 5px rgba(29,63,119,.22);
}
.button.ghost { background: white; color: var(--blue-dark); border: 1px solid var(--line); box-shadow: none; }
.button.small { padding: 8px 12px; font-size: 13px; }
.button.full { width: 100%; }
.button.accent { background: #0d6b54; }
.notice {
  background: #e8f7f0;
  border: 1px solid #a9dfc5;
  color: #0b6247;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 18px;
  font-weight: 800;
}

.filters { display: flex; gap: 12px; margin-bottom: 32px; align-items: center; flex-wrap: wrap; }
.search {
  width: min(450px, 100%);
  height: 36px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  color: var(--muted);
}
.search input { border: 0; outline: 0; flex: 1; font-size: 14px; }
select, input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  background: white;
  font: inherit;
}
textarea { resize: vertical; line-height: 1.45; }
label { display: grid; gap: 7px; font-weight: 700; font-size: 13px; color: #2d3a50; }

.case-list { display: grid; gap: 12px; }
.case-card {
  min-height: 114px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 20px 22px;
  box-shadow: 0 2px 5px rgba(19,30,52,.08);
}
.file-icon {
  width: 40px; height: 40px; border-radius: 8px; background: #e8ebf1;
  color: var(--blue-dark); display: grid; place-items: center; font-size: 20px;
}
.case-body { display: grid; gap: 8px; }
.case-body strong { font-size: 17px; }
.case-body small { color: var(--muted); font-size: 15px; }
.meta { display: flex; gap: 22px; flex-wrap: wrap; color: #52627d; font-size: 13px; }
.meta b { color: #44516a; }
.badge {
  display: inline-flex;
  width: fit-content;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
  margin-left: 10px;
  vertical-align: middle;
}
.badge-active { background: #e4f1ff; color: var(--blue-dark); border: 1px solid #b9d5ff; }
.badge-paused { background: #fff4dc; color: var(--warn); border: 1px solid #ffd995; }
.badge-closed { background: #d9f8e7; color: #087345; border: 1px solid #9ce6bd; }
.empty { background: white; border: 1px dashed var(--line); border-radius: 10px; padding: 28px; color: var(--muted); }

.auth-shell { min-height: calc(100vh - 140px); display: grid; place-items: center; }
.auth-card {
  width: min(420px, 100%);
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  box-shadow: 0 12px 35px rgba(20,31,54,.12);
  display: grid;
  gap: 16px;
}
.auth-logo { width: 130px; aspect-ratio: 1; object-fit: contain; justify-self: center; border-radius: 50%; background: #05070a; }
.auth-card h1 { text-align: center; margin: 0; }
.auth-card p, .muted-link { text-align: center; color: var(--muted); }
.alert { background: #fff0f0; color: #8e2323; border: 1px solid #f2b8b8; padding: 10px 12px; border-radius: 6px; }

.editor-grid, .document-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
.document-layout { grid-template-columns: minmax(0, 520px) minmax(430px, 1fr); }
.panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 22px;
  box-shadow: 0 2px 5px rgba(19,30,52,.07);
  display: grid;
  gap: 18px;
}
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid.one { grid-template-columns: 1fr; }
.compact-form {
  display: grid;
  gap: 12px;
}
.protocol-fields {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 14px;
}
.protocol-fields legend {
  padding: 0 8px;
  color: var(--blue-dark);
  font-weight: 800;
}
.side-stack { display: grid; gap: 20px; }
.doc-row { display: grid; gap: 3px; padding: 12px 0; border-bottom: 1px solid #edf0f5; }
.doc-row span { color: var(--muted); font-size: 12px; font-weight: 800; }
.item-list,
.timeline-list {
  display: grid;
  gap: 10px;
}
.info-row,
.timeline-row {
  border: 1px solid #edf0f5;
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 4px;
  background: #fbfcfe;
}
.info-row span,
.timeline-row time {
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 800;
}
.info-row small {
  color: var(--muted);
}
.info-row p,
.timeline-row p {
  color: var(--muted);
  font-size: 13px;
}
.thumb-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
figure { margin: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #f7f8fb; }
figure img { width: 100%; height: 110px; object-fit: cover; display: block; }
figcaption { padding: 7px; color: var(--muted); font-size: 12px; }
.image-open {
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
  position: relative;
  display: block;
}
.image-open span {
  position: absolute;
  right: 7px;
  bottom: 7px;
  background: rgba(11, 19, 32, .82);
  color: white;
  border-radius: 5px;
  padding: 4px 7px;
  font-size: 11px;
  font-weight: 800;
  opacity: 0;
  transition: opacity .16s ease;
}
.image-open:hover span,
.image-open:focus-visible span { opacity: 1; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }

.modal-open { overflow: hidden; }
.image-modal[hidden] { display: none; }
.image-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  grid-template-rows: auto 1fr;
  background: rgba(7, 12, 22, .92);
}
.image-modal__bar {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  color: white;
  background: rgba(13, 26, 48, .96);
}
.image-modal__bar strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.image-modal__actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.image-modal__actions button {
  border: 1px solid rgba(255,255,255,.22);
  background: rgba(255,255,255,.1);
  color: white;
  border-radius: 6px;
  padding: 9px 12px;
  font-weight: 800;
  cursor: pointer;
}
.image-modal__stage {
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 28px;
}
.image-modal__stage img {
  max-width: min(100%, 1400px);
  max-height: calc(100vh - 132px);
  transform-origin: center center;
  transition: transform .12s ease;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  background: white;
}

.paper-preview { overflow: auto; }
.paper, .print-paper .paper {
  width: 794px;
  min-height: 1123px;
  background: white;
  color: black;
  padding: 62px 80px;
  border: 1px solid #d9d9d9;
  box-shadow: 0 5px 18px rgba(0,0,0,.12);
  font-family: 'Times New Roman', Times, serif;
  position: relative;
}
.paper-page { position: absolute; top: 28px; right: 26px; font-size: 18px; }
.paper-head { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 28px; align-items: start; }
.paper-head h2, .protocol-head h2 { text-align: center; font: 28px Arial, Helvetica, sans-serif; margin-top: 10px; }
.paper small { display: block; font: 10px Arial, Helvetica, sans-serif; font-weight: 700; }
.paper p { font-size: 16px; margin-bottom: 4px; }
.crest { font-size: 58px; line-height: .8; }
.protocol-head { display: grid; grid-template-columns: 1.2fr 1.5fr .8fr; gap: 28px; align-items: start; }
.paper-meta {
  display: grid;
  grid-template-columns: 2fr .65fr .65fr 1fr 1fr;
  border-top: 2px solid #222;
  border-bottom: 2px solid #222;
  margin-top: 10px;
}
.paper-meta div { min-height: 34px; padding: 2px 5px; background: #eee; }
.paper-meta div:nth-child(n+4) { background: white; }
.paper-box { border-top: 2px solid #222; margin-top: 20px; padding-top: 8px; min-height: 650px; }
.paper-box h3 { font-size: 18px; margin: 2px 0 12px; font-weight: 400; }
.paper-content { white-space: normal; font-size: 18px; line-height: 1.05; padding-top: 14px; }
.protocol-table {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 2px solid #222;
  border-left: 1px solid #222;
  margin-top: 8px;
}
.protocol-table div {
  min-height: 36px;
  border-right: 1px solid #222;
  border-bottom: 1px solid #222;
  padding: 3px 6px;
}
.protocol-table .wide { grid-column: 1 / -1; }
.protocol-table .tall { min-height: 92px; }
.protocol-table .shade { background: #eee; grid-column: span 3; }
.protocol-index {
  margin-top: 18px;
  border-top: 2px solid #222;
  padding-top: 8px;
}
.protocol-index h3 {
  text-align: center;
  margin: 8px 0 0;
  font-size: 20px;
}
.protocol-index .paper-content {
  width: 76%;
  margin-left: auto;
  line-height: 1.55;
}
.print-body { background: #6f7580; padding: 30px; }
.print-button { position: fixed; top: 18px; right: 18px; z-index: 2; padding: 10px 14px; }
.print-toolbar {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 5;
  display: flex;
  gap: 10px;
}
.investigation-export {
  display: grid;
  justify-content: center;
  gap: 22px;
}
.export-page,
.export-cover,
.export-index,
.export-image-page {
  break-after: page;
  page-break-after: always;
}
.cover-brand {
  display: flex;
  align-items: center;
  gap: 24px;
  border-bottom: 3px solid #111;
  padding-bottom: 24px;
  margin-bottom: 28px;
}
.cover-brand img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border-radius: 50%;
  background: #05070a;
}
.cover-brand small {
  font: 700 14px Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}
.cover-brand h1 {
  font: 38px Arial, Helvetica, sans-serif;
  margin: 8px 0 0;
}
.cover-meta {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border-top: 1px solid #222;
  border-left: 1px solid #222;
  margin: 0 0 28px;
}
.cover-meta div {
  min-height: 58px;
  border-right: 1px solid #222;
  border-bottom: 1px solid #222;
  padding: 8px 10px;
}
.cover-meta dt {
  font: 700 11px Arial, Helvetica, sans-serif;
  margin-bottom: 5px;
}
.cover-meta dd {
  margin: 0;
  font-size: 18px;
}
.cover-summary {
  border-top: 2px solid #222;
  padding-top: 14px;
}
.cover-summary h2,
.export-index h1,
.export-image-page h1 {
  font: 24px Arial, Helvetica, sans-serif;
  margin: 0 0 12px;
}
.cover-summary p {
  font-size: 18px;
  line-height: 1.35;
}
.cover-counts {
  position: absolute;
  left: 80px;
  right: 80px;
  bottom: 62px;
  display: flex;
  gap: 16px;
  font: 700 14px Arial, Helvetica, sans-serif;
}
.cover-counts span {
  border: 1px solid #222;
  padding: 8px 12px;
}
.export-index ol {
  margin-top: 28px;
  font-size: 18px;
  line-height: 1.55;
}
.export-image-page {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
}
.export-image-page img {
  max-width: 100%;
  max-height: 830px;
  object-fit: contain;
  align-self: center;
  justify-self: center;
  border: 1px solid #222;
}
.export-image-page p {
  font: 13px Arial, Helvetica, sans-serif;
  color: #333;
}

@media (max-width: 900px) {
  .topbar { padding: 0 18px; }
  .nav { gap: 4px; }
  .nav-link { padding: 9px; }
  .toolbar-row, .panel-heading { align-items: flex-start; flex-direction: column; }
  .editor-grid, .document-layout { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .paper-preview { transform-origin: top left; max-width: 100%; }
  .paper { width: 100%; min-height: 900px; padding: 36px 28px; }
  .paper-head, .protocol-head, .paper-meta, .protocol-table { grid-template-columns: 1fr; }
  .protocol-table .shade { grid-column: auto; }
  .protocol-index .paper-content { width: 100%; }
  .image-modal__bar { align-items: stretch; flex-direction: column; }
  .image-modal__actions { flex-wrap: wrap; }
}

@media print {
  body { background: white; padding: 0; }
  .print-button, .print-toolbar { display: none; }
  .paper, .print-paper .paper { box-shadow: none; border: 0; width: 210mm; min-height: 297mm; margin: 0; }
  @page { size: A4; margin: 0; }
}
