:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --ink: #15232e;
  --muted: #5f7484;
  --muted-2: #8294a2;
  --line: #e4e9f0;
  --line-strong: #d2dbe4;
  --primary: #0e7c86;
  --primary-dark: #0a5f67;
  --primary-soft: #e6f3f4;
  --primary-softer: #f2f9fa;
  --accent: #1769aa;
  --warn: #a86a13;
  --warn-soft: #fbf0db;
  --ok: #1c7a49;
  --ok-soft: #e6f4ec;
  --danger: #b3261e;
  --danger-soft: #fbeae9;
  --radius: 12px;
  --radius-sm: 9px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 40, 60, .05), 0 1px 3px rgba(20, 40, 60, .05);
  --shadow-md: 0 4px 14px rgba(20, 40, 60, .07), 0 12px 32px rgba(20, 40, 60, .06);
  --shadow: 0 4px 14px rgba(20, 40, 60, .07), 0 12px 32px rgba(20, 40, 60, .06);
  --ring: 0 0 0 3px rgba(14, 124, 134, .16);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, #f4f7fa 0%, #e9eef3 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--primary-soft); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 22px;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 0 26px; height: 62px;
  position: sticky; top: 0; z-index: 10;
  box-shadow: 0 1px 0 rgba(20, 40, 60, .03), 0 6px 20px -12px rgba(20, 40, 60, .25);
}
.brand { display: flex; align-items: center; gap: 11px; font-size: 16.5px; letter-spacing: -.01em; }
.brand strong { color: var(--primary-dark); font-weight: 700; }
.brand-mark {
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(140deg, #15929e 0%, #0a5f67 100%);
  color: #fff; font-weight: 800; letter-spacing: -.02em;
  box-shadow: 0 2px 6px rgba(10, 95, 103, .35);
}
.brand-mark.big { width: 56px; height: 56px; border-radius: 16px; font-size: 28px; margin: 0 auto; }
/* Logo de marca por empresa (reemplaza al .brand-mark cuando window.BRAND_LOGO existe) */
.brand-logo { height: 30px; width: auto; display: block; }
.brand-logo-big { height: auto; max-width: 260px; width: 100%; margin: 0 auto 4px; display: block; }
.topnav { display: flex; gap: 2px; }
.nav-btn {
  border: none; background: none; padding: 8px 14px; border-radius: 8px;
  color: var(--muted); font-size: 14.5px; font-weight: 500; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: var(--surface-2); color: var(--ink); }
.nav-btn.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.user-info { display: flex; align-items: center; gap: 9px; }
#user-name { font-weight: 600; font-size: 14.5px; }
.role-badge {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  background: var(--primary-soft); color: var(--primary-dark);
  padding: 3px 9px; border-radius: 20px; font-weight: 700;
}

/* Layout */
.view { max-width: 1060px; margin: 0 auto; padding: 30px 26px 90px; }
.view-login { max-width: none; display: grid; place-items: center; min-height: 100vh; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.view-head h2 { margin: 0; font-size: 23px; font-weight: 700; letter-spacing: -.02em; }

/* Login */
.login-card {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  padding: 40px 38px; width: 372px; border: 1px solid var(--line);
}
.login-brand { text-align: center; margin-bottom: 26px; }
.link-btn { background: none; border: 0; color: var(--primary-dark); cursor: pointer; font-size: 13px; padding: 10px 0 0; text-decoration: underline; display: block; margin: 0 auto; }
.form-note { color: var(--muted); font-size: 13px; margin-top: 10px; text-align: center; line-height: 1.45; }
.login-brand h1 { font-size: 22px; margin: 16px 0 4px; font-weight: 700; letter-spacing: -.02em; }

/* Field labels (editor, login, user/surgeon forms) */
.card label, .login-card label, .modal .field label {
  display: block; margin-bottom: 14px;
  font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: .005em;
}

/* Inputs */
input, select, textarea {
  width: 100%; margin-top: 6px; padding: 9px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font: inherit; color: var(--ink); background: var(--surface);
  transition: border-color .15s, box-shadow .15s, background .15s;
  color-scheme: light;
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:hover, select:hover, textarea:hover { border-color: #bfccd8; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
textarea { resize: vertical; }
/* Campos del informe: crecen con el contenido (autoGrow en JS), sin scroll. */
textarea[data-field] { line-height: 1.6; overflow: hidden; resize: none; }
textarea.big { min-height: 128px; }

/* Buttons */
.btn {
  border: 1px solid transparent; border-radius: var(--radius-sm); padding: 9px 17px;
  font: inherit; font-weight: 600; cursor: pointer; background: var(--surface);
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(10, 95, 103, .25); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 2px 8px rgba(10, 95, 103, .3); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-block { width: 100%; margin-top: 8px; padding: 11px; }
.btn-danger-soft { color: var(--danger); }
.btn-danger-soft:hover { background: var(--danger-soft); }
/* Un <label> que actúa como botón (subida de fichero oculto). */
.btn-upload { display: inline-flex; align-items: center; gap: 6px; }

/* Fila de acciones (subir/descargar plantilla, etc.). */
.form-row-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 16px; }

/* Vista previa de la firma del médico en el modal de datos profesionales. */
.prof-firma-preview { margin: 8px 0; }
.prof-firma-preview img { max-width: 240px; max-height: 90px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; padding: 4px; }

/* Toolbar */
.toolbar { display: flex; gap: 14px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar #search { flex: 1; min-width: 240px; margin: 0; padding: 10px 14px; }
.filters { display: flex; gap: 6px; }
.chip {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted);
  padding: 8px 15px; border-radius: 20px; cursor: pointer; font-size: 13.5px; font-weight: 500;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover { border-color: #bfccd8; color: var(--ink); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }

/* Cards / fieldsets */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 20px 22px; margin: 0 0 18px;
}
.card legend {
  /* float saca a la legend de su posición por defecto SOBRE el borde superior;
     así el borde queda entero y la etiqueta cae dentro de la tarjeta. */
  float: left; width: 100%;
  font-weight: 700; color: var(--primary-dark); padding: 0; margin: 0 0 14px;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em;
  display: flex; align-items: center; gap: 8px;
}
.card > legend ~ * { clear: both; }   /* TODO el contenido va debajo de la legend (robusto aunque haya hijos ocultos) */
.card legend::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); flex: none;
}
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.editor-grid .card { margin-bottom: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
.grid-2 .span-2, .span-2 { grid-column: 1 / -1; }
#firmante-search-wrap { max-width: 560px; }

/* Reports table */
.reports-table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.reports-table th, .reports-table td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 14px; }
.reports-table th { background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.reports-table tbody tr { cursor: pointer; transition: background .12s; }
.reports-table tbody tr:last-child td { border-bottom: 0; }
.reports-table tbody tr:hover { background: var(--primary-softer); }
.reports-table .pt-name { font-weight: 600; color: var(--ink); }
.empty { text-align: center; color: var(--muted); padding: 54px 0; }

/* Status badges */
.status-badge, .badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 20px; font-size: 11.5px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; }
.status-badge::before, .badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-borrador, .status-badge.borrador { background: var(--warn-soft); color: var(--warn); }
.badge-firmado, .status-badge.firmado { background: var(--ok-soft); color: var(--ok); }
/* Estado del informe en el editor: prominente, visible a primera vista. */
#report-status { font-size: 12.5px; padding: 6px 16px; border: 1px solid transparent; }
#report-status.borrador { border-color: #e8cfa0; }
#report-status.firmado { border-color: #bfe3cf; }

/* Editor */
.editor-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.editor-head-info { display: flex; align-items: center; gap: 14px; }
.save-status { font-size: 13px; color: var(--muted); font-weight: 500; }
.save-status.saving { color: var(--accent); }
.save-status.saved { color: var(--ok); }
.save-status.error { color: var(--danger); }
.editor-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-top: 22px; padding: 16px 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.editor-actions .btn-primary { padding: 10px 22px; }

.signed-banner {
  background: linear-gradient(180deg, #ecf7f0, var(--ok-soft)); border: 1px solid #c4e4d1; color: #14532d;
  border-radius: var(--radius); padding: 16px 20px; margin-bottom: 18px;
}
.signed-banner .sig-hash { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; color: var(--muted); }
.sig-integrity { font-weight: 600; }
.sig-integrity.checking { color: var(--muted); font-weight: 400; }
.sig-integrity.ok { color: #15803d; }
.sig-integrity.bad { color: #b91c1c; }

.access-summary { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow-sm); margin-top: 16px; }
.access-summary h4 { margin: 0 0 8px; font-size: 14px; }
.access-summary ul { margin: 6px 0 0; padding-left: 18px; }

/* Patient / autocomplete search */
.patient-search { position: relative; margin-bottom: 10px; }
.autocomplete { position: relative; }
/* Indicador de desplegable (chevron) en los comboboxes con lista al enfocar. */
.autocomplete.combo input { padding-right: 30px; }
.autocomplete.combo::after {
  content: ''; position: absolute; right: 13px; top: 50%; width: 8px; height: 8px;
  transform: translateY(-70%) rotate(45deg);
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  pointer-events: none;
}
/* Mensaje cuando no hay opciones (lista vacía / sin resultados). */
.search-results .combo-hint { padding: 9px 12px; font-size: 13px; color: var(--muted); cursor: default; }
.search-results .combo-hint:hover { background: transparent; }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5;
  background: #fff; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  max-height: 244px; overflow-y: auto; padding: 4px;
}
.search-results div { padding: 9px 12px; cursor: pointer; font-size: 14px; border-radius: 7px; }
.search-results div:hover { background: var(--primary-soft); }

/* Catálogos (admin): alta + lista de valores */
.cat-add { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.cat-add input { flex: 1; }
.cat-list { display: flex; flex-direction: column; gap: 6px; }
.cat-row { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.cat-row.cat-off { opacity: .55; }
.cat-row .cat-label { font-size: 14px; }
.cat-row .cat-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Recorte de imagen (Cropper.js) */
.modal-crop { width: 720px; max-width: 95vw; }
.crop-stage { max-height: 62vh; margin: 10px 0; background: #0d1117; border-radius: var(--radius-sm); overflow: hidden; }
.crop-stage img { display: block; max-width: 100%; }

/* Eventos quirúrgicos: barra con botón de hora */
.eventos-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }

/* Revisión (Técnico Senior) */
.editor-actions-left { display: flex; flex-direction: column; gap: 4px; }
.editor-actions-right { display: flex; align-items: center; gap: 10px; }
.review-ok { color: #0a7a3f; font-weight: 600; }

/* 2FA / TOTP */
.mfa-qr { display: flex; justify-content: center; margin: 12px 0; }
.mfa-qr svg, .mfa-qr img { width: 184px; height: 184px; }
#mfa-secret { font-family: ui-monospace, monospace; word-break: break-all; font-size: 12px; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 30, 45, .5); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: var(--radius-lg); padding: 28px; width: 470px; max-width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-md); border: 1px solid var(--line); }
.modal h3 { margin: 0 0 10px; font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.share-block { margin: 16px 0; display: grid; gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; color: var(--ink); margin: 0; }
.check input { width: auto; margin: 0; }
.share-label { font-weight: 700; margin: 14px 0 6px; }
/* Bloque de adjunto dentro de la tarjeta Paciente (debajo de Sexo). */
.patient-images { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.patient-images .share-label { display: block; margin-top: 0; }
#indicacion-current { margin-top: 8px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.indicacion-link { font-weight: 600; color: var(--primary-dark); text-decoration: none; }
.indicacion-link:hover { text-decoration: underline; }
.share-user-list { max-height: 200px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px; }
.share-user-list label { display: flex; align-items: center; gap: 10px; padding: 8px; margin: 0; font-weight: 500; color: var(--ink); border-radius: 7px; }
.share-user-list label:hover { background: var(--surface-2); }
.share-user-list input { width: auto; margin: 0; }
.share-user-role { margin-left: auto; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* Form error / toast */
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 13px 22px; border-radius: 10px;
  box-shadow: var(--shadow-md); z-index: 100; font-size: 14px; max-width: 90%; font-weight: 500;
}
.toast.ok { background: var(--ok); }
.toast.error { background: var(--danger); }

/* Responsive (móvil / tablet) */
@media (max-width: 720px) {
  html, body { overflow-x: hidden; }       /* nada debe desbordar a la derecha */
  .editor-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .view { padding: 18px 14px 80px; }

  /* Barra superior: ALTURA AUTOMÁTICA (antes 62px fija → al envolver, las filas
     se salían y se solapaban con el contenido). Marca + botones en la fila 1;
     la navegación en su propia fila, deslizable. El nombre/rol se ocultan en
     móvil para que quepa sin desbordar. */
  .topbar { flex-wrap: wrap; height: auto; min-height: 54px; padding: 9px 12px; gap: 6px 8px; }
  .brand { font-size: 14.5px; gap: 8px; }
  .brand-mark { width: 28px; height: 28px; }
  .topbar-right { margin-left: auto; gap: 4px; }
  .topbar-right .btn { padding: 6px 10px; font-size: 13px; }
  .user-info { display: none; }
  .topnav { order: 3; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 4px; }

  /* Cabeceras y barras que envuelven en vez de desbordar. */
  .view-head { flex-wrap: wrap; gap: 10px; }
  .editor-head-info { flex-wrap: wrap; }
  .row-actions { flex-wrap: wrap; }

  /* Tablas anchas: scroll horizontal dentro de su contenedor. */
  #reports-container, #users-container, #surgeons-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .reports-table { min-width: 560px; }

  /* Modales y login a casi todo el ancho. */
  .modal { width: 92vw; max-width: 92vw; }
  .login-card { width: 92vw; max-width: 360px; }
}

/* Read-only editor */
.readonly input, .readonly select, .readonly textarea { background: var(--surface-2); color: var(--ink); cursor: default; border-color: var(--line); }
.readonly input:hover, .readonly select:hover, .readonly textarea:hover { border-color: var(--line); }

/* Historial de auditoría */
#audit-history { margin-top: 16px; }
.audit-list { list-style: none; margin: 6px 0 0; padding: 0; }
.audit-list li { display: grid; grid-template-columns: 150px 1fr auto; gap: 10px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--line); font-size: 0.92em; }
.audit-list li:first-child { border-top: 0; }
.audit-when { color: var(--muted); white-space: nowrap; }
.audit-who { color: var(--muted); }
@media (max-width: 720px) {
  .audit-list li { grid-template-columns: 1fr; gap: 2px; }
}

/* Botón admin "Devolver a borrador" sobre informe firmado */
.admin-revert-wrap { display: flex; justify-content: flex-end; margin-bottom: 18px; }

/* Acciones por fila en tablas de gestión (cirujanos, usuarios) */
.row-actions { display: flex; gap: 6px; white-space: nowrap; }

/* Campo con botón al lado (p. ej. fecha + "Hoy") */
.field-with-btn { display: flex; gap: 8px; align-items: center; }
.field-with-btn input { flex: 1; min-width: 0; }
.field-with-btn .btn { margin-top: 6px; border-color: var(--line-strong); color: var(--primary-dark); }
.field-with-btn .btn:hover { background: var(--primary-soft); border-color: var(--primary-soft); }
.btn-sm { padding: 8px 13px; font-size: 0.85em; white-space: nowrap; }
.btn-sm:disabled { opacity: 0.5; cursor: default; }

/* Imágenes del informe */
#images-upload-wrap { margin-bottom: 14px; }
#images-upload-wrap input[type="file"] { width: auto; border: none; padding: 0; margin-top: 0; font-size: 13.5px; }
#images-upload-wrap input[type="file"]::file-selector-button {
  font: inherit; font-weight: 600; cursor: pointer; margin-right: 12px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--primary-dark);
  transition: background .15s, border-color .15s;
}
#images-upload-wrap input[type="file"]::file-selector-button:hover { background: var(--primary-soft); border-color: var(--primary-soft); }
#images-hint { margin: 8px 0 0; }
.images-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.image-item { margin: 0; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; background: var(--surface); box-shadow: var(--shadow-sm); }
.image-item img { width: 100%; height: 140px; object-fit: cover; border-radius: 7px; background: var(--surface-2); display: block; }
.image-item .image-caption { margin-top: 6px; font-size: 13px; }
.image-item figcaption { margin-top: 6px; font-size: 13px; color: var(--muted); min-height: 1em; }
.image-item .image-actions { display: flex; gap: 6px; margin-top: 4px; }
.image-item .image-crop { padding: 4px 8px; }
.image-item .image-del { color: var(--danger); padding: 4px 8px; }

/* Visor de imágenes (lightbox + carrusel) */
.lightbox { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(8, 18, 28, .9); padding: 40px 16px; }
.lightbox img { max-width: 92vw; max-height: 82vh; object-fit: contain; border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5); background: #fff; }
.lightbox-close { position: absolute; top: 14px; right: 18px; width: 44px; height: 44px;
  border: none; background: rgba(255, 255, 255, .12); color: #fff; font-size: 30px; line-height: 1;
  border-radius: 50%; cursor: pointer; }
.lightbox-close:hover { background: rgba(255, 255, 255, .22); }
.lightbox-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 52px; height: 52px;
  border: none; background: rgba(255, 255, 255, .12); color: #fff; font-size: 34px; line-height: 1;
  border-radius: 50%; cursor: pointer; }
.lightbox-nav:hover { background: rgba(255, 255, 255, .22); }
.lightbox-prev { left: 14px; }
.lightbox-next { right: 14px; }
.lightbox-bar { position: absolute; bottom: 18px; left: 0; right: 0; text-align: center;
  color: #fff; display: flex; flex-direction: column; gap: 4px; padding: 0 16px; }
.lightbox-bar #lightbox-count { font-size: 13px; opacity: .8; }
.lightbox-bar #lightbox-caption { font-size: 15px; }
@media (max-width: 720px) {
  .lightbox-nav { width: 44px; height: 44px; font-size: 28px; }
  .lightbox-prev { left: 6px; } .lightbox-next { right: 6px; }
}

/* ===== Impresión / Descargar PDF del informe (docx-preview) =====
   El contenedor está oculto en pantalla; docx-preview lo rellena con el .docx
   real (membrete, fuentes, tablas) y solo se muestra al imprimir. La maqueta la
   aporta docx-preview; aquí solo paginamos y repetimos el membrete por hoja. */
#print-report { display: none; }

@media print {
  /* Aísla el informe: oculta el resto de la app, muestra solo el contenedor. */
  body > *:not(#print-report) { display: none !important; }
  #print-report { display: block !important; }

  /* Hoja Letter (tamaño de la plantilla); los márgenes de texto los aportan los
     paddings de abajo, igual que el .docx (1in = 25.4mm). */
  @page { size: letter; margin: 0; }

  /* Membrete repetido en cada hoja mediante <thead>/<tfoot>: el navegador los
     repite en todas las páginas impresas (técnica fiable y cross-browser). La
     paginación del cuerpo la hace el flujo normal dentro del <tbody>. */
  #print-report .docx-wrapper { display: block !important; background: #fff !important; padding: 0 !important; box-shadow: none !important; }
  #print-report table.print-frame { width: 100% !important; border-collapse: collapse !important; }
  #print-report table.print-frame td { padding: 0 !important; vertical-align: top !important; }
  /* Membrete (clones del header/footer reales) arriba y abajo de cada hoja. */
  #print-report .pf-head { padding: 12mm 25.4mm 0 25.4mm !important; height: auto !important; min-height: 0 !important; }
  /* docx-preview mete al header un margin-top negativo (~-13mm) para colocarlo en
     el margen de página; en el membrete repetido eso sube el logo y lo corta. */
  #print-report .pf-head header { margin-top: 0 !important; }
  #print-report .pf-foot { padding: 0 25.4mm 10mm 25.4mm !important; height: auto !important; min-height: 0 !important; }
  /* Cuerpo: lo soltamos (docx-preview lo pinta con alto fijo + overflow:hidden)
     para que fluya y se reparta en hojas; márgenes laterales = 1in como el .docx. */
  #print-report tbody section.docx { width: 100% !important; padding: 0 25.4mm !important; height: auto !important; min-height: 0 !important;
    overflow: visible !important; box-shadow: none !important; margin: 0 !important; }
  #print-report tbody section.docx > header, #print-report tbody section.docx > footer { display: none !important; }
}
