:root {
  --azul: #0d3b66;
  --azul2: #14568a;
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #d8dee6;
  --muted: #566372; /* subido de #6b7280 para cumplir contraste WCAG AA */
  --danger: #b30000;
  --ok: #0a7c2f;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg); color: #111; font-size: 14.5px;
}
a { color: var(--azul); text-decoration: none; }
a:hover { text-decoration: underline; }
small.muted, .muted { color: var(--muted); }
.small { font-size: 12px; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--azul); color: #fff;
  padding: 10px 18px;
}
.topbar a { color: #fff; opacity: 0.9; padding: 6px 8px; border-radius: 4px; }
.topbar a:hover { background: rgba(255,255,255,0.12); text-decoration: none; }
.topbar .brand { font-weight: 800; font-size: 18px; opacity: 1; }
.topbar .spacer { flex: 1; }
.topbar .user small { opacity: 0.7; }
.topbar .logout { background: rgba(255,255,255,0.18); }
/* "Salir" es un <button> dentro de un <form> (POST) pero se ve como el resto. */
.topbar .logout-form { display: inline; }
.topbar .logout-btn {
  color: #fff; border: 0; font: inherit; cursor: pointer;
  padding: 6px 10px; border-radius: 4px;
}
.topbar .logout-btn:hover { background: rgba(255,255,255,0.30); }

/* Nav agrupado con menús desplegables */
.topbar .nav-group { position: relative; display: inline-block; }
.topbar .nav-trigger {
  background: transparent; color: #fff; border: 0; padding: 6px 8px;
  border-radius: 4px; font: inherit; cursor: pointer; opacity: 0.9;
}
.topbar .nav-trigger:hover { background: rgba(255,255,255,0.12); }
.topbar .nav-menu {
  display: none; position: absolute; top: 100%; left: 0; z-index: 100;
  background: #1f3b56; border-radius: 0 0 6px 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,.25); min-width: 170px; padding: 4px 0;
}
.topbar .nav-menu a { display: block; padding: 8px 14px; border-radius: 0; }
.topbar .nav-menu a:hover { background: rgba(255,255,255,0.18); }
.topbar .nav-group:hover .nav-menu,
.topbar .nav-group:focus-within .nav-menu,
.topbar .nav-group.open .nav-menu { display: block; }

/* Menú hamburguesa: en escritorio no existe (contents = sin caja propia). */
.nav-toggle-cb, .nav-toggle { display: none; }
.nav-collapse { display: contents; }

.page { max-width: 1200px; margin: 18px auto; padding: 0 18px; }
.foot { text-align: center; color: var(--muted); padding: 24px 0; font-size: 12px; }

h1 { color: var(--azul); margin: 4px 0 14px; }
h2 { color: var(--azul2); margin-top: 18px; }
h3 { color: var(--azul2); margin-top: 14px; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 16px; margin: 12px 0;
}
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
@media (max-width: 800px) { .grid-4, .grid-2 { grid-template-columns: 1fr; } }
.card.stat { text-align: center; padding: 18px; }
.card.stat .num { font-size: 32px; font-weight: 800; color: var(--azul); }

/* Secciones colapsables tipo tarjeta (detalle de lote) */
details.card-sec > summary { cursor: pointer; list-style: none; }
details.card-sec > summary::-webkit-details-marker { display: none; }
details.card-sec > summary h2 {
  margin: 0; display: flex; align-items: baseline; gap: 8px;
}
details.card-sec > summary h2::before {
  content: "▸"; color: var(--azul2); font-size: .7em; flex: none;
}
details.card-sec[open] > summary h2::before { content: "▾"; }
details.card-sec[open] > summary { margin-bottom: .7rem; }

.pomos-masivo {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-bottom: .6rem; padding: .5rem .6rem;
  background: var(--panel, #f6f7f9); border: 1px solid var(--border, #dfe3e8);
  border-radius: 6px;
}

/* Fichas de datos (producto final, conteo UFC): reemplazan tablas kv apretadas. */
.spec-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin: .5rem 0 1rem;
}
.ufc-grid { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.spec {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--panel, #f6f7f9);
}
.spec-warn   { border-color: #f0d77a; background: #fffbeb; }
.spec-danger { border-color: #f5b5b5; background: #fef2f2; }
.spec-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 700;
}
.spec-value { font-size: 15px; font-weight: 600; color: #1a2430; }
.spec-value small { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.spec-value-muted { font-weight: 500; font-size: 13px; }
.spec-note { display: block; margin-top: 3px; font-size: 11px; color: var(--muted); }
.spec-note.warn { color: #b45309; }
.spec-note.danger { color: #991b1b; font-weight: 600; }

/* Sub-panel: agrupa un bloque (re-test, PDF+aprobación) con un marco suave. */
.subpanel {
  margin: 1rem 0; padding: .9rem 1.1rem;
  border: 1px solid var(--border); border-radius: 8px; background: #fbfcfe;
}
.subpanel > *:last-child { margin-bottom: 0; }
.subpanel-title {
  margin: 0 0 .6rem; font-size: .95rem; color: var(--azul2);
  border-bottom: 1px solid var(--border); padding-bottom: .4rem;
}

/* Formulario "añadir estudio" plegado: no intimida con una rejilla de inputs. */
.add-toggle { margin-top: 1rem; }
.add-toggle > summary { display: inline-block; cursor: pointer; list-style: none; }
.add-toggle > summary::-webkit-details-marker { display: none; }

/* Acciones por fila en la tabla de estudios: alinea edición + eliminar. */
.estudio-acciones { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.estudio-edit { display: inline-flex; gap: 5px; align-items: center; flex-wrap: wrap; margin: 0; }
.estudios-tabla td { vertical-align: middle; }

.inv-grupo { margin: 0 0 1rem; }
.inv-grupo-tit { margin: .2rem 0 .4rem; font-size: 1rem; }
details.inv-grupo > summary {
  cursor: pointer; padding: .45rem .6rem; font-weight: 600;
  background: var(--panel, #f6f7f9); border: 1px solid var(--border, #dfe3e8);
  border-radius: 6px;
}
details.inv-grupo[open] > summary { margin-bottom: .4rem; border-radius: 6px 6px 0 0; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: top; }
th { background: #eef2f7; color: var(--azul); }
tbody tr:hover { background: #f7faff; }

button, .btn {
  background: var(--azul); color: #fff; border: 0;
  padding: 7px 14px; border-radius: 5px; cursor: pointer; font-size: 14px;
  display: inline-block;
}
button.small, .btn.small { padding: 4px 8px; font-size: 12px; }
button.primary { background: var(--ok); }
button:hover, .btn:hover { background: var(--azul2); text-decoration: none; }
button:disabled { background: #888; cursor: not-allowed; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }

.form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.form-grid label { display: flex; flex-direction: column; font-size: 13px; color: #333; }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
  padding: 7px; border: 1px solid var(--border); border-radius: 4px; font: inherit;
}
.form-grid label.inline { flex-direction: row; align-items: center; gap: 6px; }

/* El formulario de edición del producto vive plegado: la vista por defecto son
   los datos ya registrados, no una rejilla de inputs. */
.editar-producto { margin-top: 12px; }
.editar-producto > summary { display: inline-block; cursor: pointer; list-style: none; }
.editar-producto > summary::-webkit-details-marker { display: none; }

/* Campo UFC/ml compuesto: mantisa x 10^exponente (ver _ufc_macro.html). */
.ufc-input { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ufc-input input[data-ufc-mant] { width: 5.5rem; }
.ufc-input select[data-ufc-exp] { width: 4.5rem; }
.ufc-input [data-ufc-out] { flex-basis: 100%; }
.form-grid fieldset.radios { border: 1px dashed var(--border); padding: 6px 10px; border-radius: 4px; }
.form-grid fieldset.radios label.inline { display: inline-flex; margin-right: 14px; }

fieldset { border: 1px solid var(--border); border-radius: 6px; margin: 12px 0; padding: 10px 14px; }
legend { color: var(--azul); font-weight: 600; padding: 0 6px; }

.alert { background: #fde8e8; color: var(--danger); padding: 8px 12px; border-radius: 4px; margin: 8px 0; }
.login-card { max-width: 360px; margin: 80px auto; background: #fff; padding: 24px; border-radius: 10px; box-shadow: 0 4px 18px rgba(0,0,0,0.08); }
.login-card label { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.login-card input { padding: 8px; border: 1px solid var(--border); border-radius: 4px; }
.login-card button { width: 100%; padding: 10px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 700; color: #fff; background: #888; }
.badge.b-D01 { background: #1f6feb; }
.badge.b-D02 { background: #6c4ad1; }
.badge.b-D03 { background: #b07c00; }
.badge.b-D04 { background: #0a7c2f; }
.badge.b-D05 { background: #0a7c84; }
.badge.b-CERRADO { background: #555; }
.badge.b-RECALL { background: #b30000; }
.badge.b-RECHAZADO { background: #b30000; }
.badge.rx-PENDIENTE { background: #ffb000; color: #000; }
.badge.rx-ACEPTADA  { background: #0a7c2f; }
.badge.rx-RECHAZADA { background: #b30000; }

/* Estados de prospecto (color por etapa) */
.badge.pe-NUEVO                { background: #64748b; }
.badge.pe-CONTACTADO           { background: #1f6feb; }
.badge.pe-PROTOCOLO_CONFIRMADO { background: #6c4ad1; }
.badge.pe-FECHA_CONFIRMADA     { background: #0a7c84; }
.badge.pe-PAGADO               { background: #b07c00; }
.badge.pe-CONVERTIDO           { background: #0a7c2f; }
.badge.pe-DESCARTADO           { background: #9ca3af; }

/* Pomos / inventario */
.badge.b-pomo-EN_PROCESO    { background: #888; }
.badge.b-pomo-EN_CUARENTENA { background: #ffb000; color: #000; }
.badge.b-pomo-DISPONIBLE    { background: #0a7c2f; }
.badge.b-pomo-RESERVADO     { background: #1f6feb; }
.badge.b-pomo-DISPENSADO    { background: #0a7c84; }
.badge.b-pomo-DESCARTADO    { background: #b30000; }
.badge.b-pomo-VENCIDO       { background: #555; }
.badge.sub-PENDIENTE      { background: #888; }
.badge.sub-NEGATIVO       { background: #0a7c2f; }
.badge.sub-POSITIVO       { background: #b30000; }
.badge.sub-NO_CONCLUYENTE { background: #ffb000; color: #000; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kpi { display: block; padding: 12px; border-radius: 6px; border: 1px solid var(--border);
       background: #fff; color: inherit; text-decoration: none; text-align: center; }
.kpi:hover { box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.kpi.b-pomo-EN_CUARENTENA { background: #fff8e1; border-color: #ffb000; }
.kpi.b-pomo-DISPONIBLE    { background: #e6f4ea; border-color: #0a7c2f; }
.kpi.b-pomo-RESERVADO     { background: #e8f0ff; border-color: #1f6feb; }
.kpi.b-pomo-DISPENSADO    { background: #e1f5f8; border-color: #0a7c84; }
.kpi.b-pomo-DESCARTADO    { background: #fde8e8; border-color: #b30000; }
.kpi.b-pomo-VENCIDO       { background: #f0f0f0; border-color: #555; }
.kpi-n { font-size: 28px; font-weight: 700; line-height: 1; }
.kpi-label { font-size: 12px; margin-top: 4px; color: var(--muted); }
.kpi-sub { font-size: 11px; margin-top: 2px; color: var(--muted); }

.states { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.states li { padding: 4px 10px; border: 1px solid var(--border); border-radius: 4px; background: #fff; font-size: 12px; }
.states li.active { background: var(--azul); color: #fff; border-color: var(--azul); }

.timeline { padding-left: 16px; }
.activity { list-style: none; padding: 0; font-size: 12px; }
.activity li { padding: 4px 0; border-bottom: 1px dotted var(--border); }
.activity .ts { color: var(--muted); margin-right: 6px; }

.doc-tree { columns: 2; column-gap: 24px; }
.doc-tree li { font-size: 13px; padding: 2px 0; break-inside: avoid; }
.doc-md { background: #fff; padding: 16px 24px; border: 1px solid var(--border); border-radius: 6px; }
.doc-md table { font-size: 13px; }
.doc-md pre { background: #f6f8fa; padding: 8px; border-radius: 4px; overflow: auto; }
.doc-md .mermaid { background: #fff; text-align: center; }
.frontmatter { background: #eef2f7; padding: 8px; border-radius: 4px; font-size: 12px; }

.sign-block { border: 1px dashed var(--border); padding: 10px; border-radius: 6px; }
.sign-label { font-size: 13px; margin-bottom: 4px; }
.sign-pad { background: #fff; border: 1px solid #999; border-radius: 4px; cursor: crosshair; touch-action: none; display: block; max-width: 100%; }

small.pii { background: #fde8e8; color: var(--danger); padding: 1px 5px; border-radius: 3px; font-size: 10px; margin-left: 4px; }

/* ----- v0.2 additions: roles, pendientes, firmas, kv list ----- */

.topbar .rol-switch { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #fff; opacity: 0.95; }
.topbar .rol-switch select { padding: 4px 6px; border: 0; border-radius: 4px; font-size: 12px; }
.topbar .rol-switch select:disabled { opacity: 0.7; }

.topbar .pendientes .badge-n {
  background: #ffb000; color: #000; padding: 0 6px; border-radius: 10px; font-size: 11px; font-weight: 700;
}

.btn.disabled { background: #aaa; color: #fff; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--azul); border: 1px solid var(--azul); }
.btn.ghost:hover { background: #eef2f7; }

.badge.sub-BORRADOR { background: #888; }
.badge.sub-EN_FIRMA { background: #ffb000; color: #000; }
.badge.sub-FIRMADO { background: var(--ok); }
.badge.sub-SIN_INICIAR { background: #aaa; }

/* Compuerta de avance del lote */
.gate { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin-top: .6rem; }
.gate.gate-ok { border-color: #b7dfc1; background: #f1f9f3; }
.gate.gate-block { border-color: #f0d77a; background: #fffaf0; }
.gate-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: .4rem; }
.gate-advance { margin-top: .7rem; }
.checklist { list-style: none; padding: 0; margin: .3rem 0; }
.checklist li { padding: 4px 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.checklist li .mark { font-weight: 700; width: 1.1em; text-align: center; }
.checklist li.done .mark { color: var(--ok); }
.checklist li.pending .mark { color: #b07c00; }
.checklist li .ci-act { margin-left: auto; }

/* Estados del lote como píldoras (reutiliza .states); marca etapas superadas. */
.states li.done { background: #eef7f0; border-color: #b7dfc1; color: var(--ok); }
.states li.done strong::after { content: " ✓"; }
.estado-critico { margin: .2rem 0 .8rem; }

/* Panorama de formularios por etapa (colapsable, sin caja extra) */
details.forms-overview { margin-top: 1rem; }
details.forms-overview > summary { cursor: pointer; padding: 4px 0; }
.acciones-criticas { margin-top: 1rem; }
.form-stage { margin: .8rem 0; padding-top: .4rem; }
.form-stage.stage-current { border-left: 3px solid var(--azul); padding-left: 10px; }
.form-stage.stage-done { border-left: 3px solid #b7dfc1; padding-left: 10px; }
.form-stage h3 { margin: .2rem 0 .4rem; }
.tag-req { font-size: 10px; font-weight: 700; color: #b07c00; border: 1px solid #f0d77a; border-radius: 8px; padding: 1px 6px; }
.tag-opt { font-size: 10px; font-weight: 700; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 1px 6px; }
tr.row-pending > td { background: #fffaf0; }
tr.row-done > td { background: #f7fbf8; }

.firma-ok { background: #e6f4ea; padding: 8px 10px; border-radius: 4px; border: 1px solid #b7dfc1; font-size: 13px; }
.firma-pendiente { background: #fff4d6; padding: 8px 10px; border-radius: 4px; border: 1px solid #f0d77a; font-size: 13px; }

/* Banner para formularios externos (paciente/donante/receptor) */
.externo-banner { border-left: 6px solid #1f3b56; }
.externo-pendiente { background: #fff7ed; border: 1px solid #f59e0b; border-left-color: #c2410c; }
.externo-ok { background: #ecfdf5; border: 1px solid #10b981; border-left-color: #047857; }
.externo-status { font-size: 13px; padding: 4px 8px; border-radius: 4px; display: inline-block; background: rgba(0,0,0,.04); }
.externo-pendiente .externo-status { background: #fef3c7; color: #92400e; }
.externo-ok .externo-status { background: #d1fae5; color: #065f46; }

/* Bloque de firma externa dentro del formulario */
.firma-externa { padding: 8px 10px; border-radius: 4px; font-size: 13px; }
.firma-externa-pendiente { background: #fff7ed; border: 1px solid #f59e0b; }
.firma-externa-ok { background: #ecfdf5; border: 1px solid #10b981; }
.firma-thumb { display: block; max-height: 70px; margin-top: 6px; background: #fff; border: 1px solid #ddd; padding: 4px; }
.sign-tabs { margin: 6px 0; font-size: 12px; }

.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 4px 14px; margin: 4px 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.roles-edit { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12px; }
.roles-edit label.inline { display: inline-flex; align-items: center; gap: 3px; padding: 2px 6px; background: #eef2f7; border-radius: 3px; }

/* Manuales SGC */
.docs-search{ margin:1rem 0 1.5rem; gap:.5rem; }
.docs-search input{ flex:1; min-width:18rem; }
.docs-group{ margin: 1.5rem 0 2rem; }
.docs-group h2{ font-size:1.05rem; border-bottom:1px solid #e2e6eb; padding-bottom:.35rem; margin:1rem 0 .75rem; color:#1f3b56; }
.docs-dossier{ margin: .75rem 0 1.25rem; }
.docs-dossier h3{ font-size:.92rem; margin:.75rem 0 .35rem; color:#3a5470; font-weight:600; }
.docs-tbl{ width:100%; }
.docs-tbl td{ vertical-align:top; padding:.35rem .55rem; }
.docs-tbl th{ text-align:left; font-size:.78rem; text-transform:uppercase; color:#6a7785; padding:.35rem .55rem; }
.docs-tbl code{ font-size:.82rem; color:#244; background:#f1f4f8; padding:.05rem .35rem; border-radius:3px; }
.kind{ display:inline-block; min-width:3.6rem; text-align:center; font-size:.7rem; font-weight:700; padding:.15rem .45rem; border-radius:3px; letter-spacing:.04em; }
.kind-Manual{ background:#3a5470; color:#fff; }
.kind-PR{ background:#5a4ea0; color:#fff; }
.kind-POE{ background:#1f7a4d; color:#fff; }
.kind-IT{ background:#2470b8; color:#fff; }
.kind-FR{ background:#b87a1f; color:#fff; }
.kind-Lista, .kind-Mapa, .kind-Matriz, .kind-Registro{ background:#6a7785; color:#fff; }
.kind-README{ background:#cfd6df; color:#2a3744; }
.kind-Otro{ background:#cfd6df; color:#2a3744; }

/* Visor de adjuntos */
.adjunto-viewer{ margin:1rem 0; }
.adjunto-viewer iframe{ width:100%; height:78vh; border:1px solid #cfd6df; border-radius:6px; background:#fff; }
.adjunto-viewer img{ max-width:100%; max-height:78vh; display:block; margin:auto; border:1px solid #cfd6df; border-radius:6px; background:#fff; }

/* Visor de manuales (markdown publicado) */
.breadcrumbs{ font-size:.82rem; color:#6a7785; margin-bottom:.75rem; }
.breadcrumbs a{ color:#2470b8; text-decoration:none; }
.breadcrumbs span{ margin:0 .25rem; }
.doc-header{ border-bottom:1px solid #e2e6eb; padding-bottom:.75rem; margin-bottom:1rem; }
.doc-header h1{ margin:.25rem 0 .5rem; color:#1f3b56; font-size:1.7rem; line-height:1.25; }
.doc-meta{ display:grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap:.35rem .75rem; margin:0; padding:.5rem .75rem; background:#f1f4f8; border-radius:6px; font-size:.82rem; }
.doc-meta div{ display:flex; gap:.4rem; }
.doc-meta dt{ font-weight:700; color:#3a5470; min-width:6rem; }
.doc-meta dd{ margin:0; color:#2a3744; }

.doc-layout{ display:grid; grid-template-columns: minmax(0, 1fr); gap:1.5rem; align-items:start; }
@media (min-width: 1100px){ .doc-layout{ grid-template-columns: 220px minmax(0, 1fr); } }
.doc-toc{ position:sticky; top:.5rem; background:#fbfcfd; border:1px solid #e2e6eb; border-radius:6px; padding:.6rem .8rem; font-size:.82rem; max-height:80vh; overflow:auto; }
.doc-toc strong{ display:block; margin-bottom:.35rem; color:#1f3b56; font-size:.85rem; }
.doc-toc ul{ list-style:none; padding-left:.75rem; margin:.2rem 0; }
.doc-toc > .toc > ul{ padding-left:0; }
.doc-toc a{ color:#2470b8; text-decoration:none; }
.doc-toc a:hover{ text-decoration:underline; }

.doc-md{
  background:#fff; padding: 1.5rem 2rem; border:1px solid #e2e6eb; border-radius:8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.65; color:#243240; max-width: 78ch;
}
.doc-md h1, .doc-md h2, .doc-md h3, .doc-md h4{ color:#1f3b56; line-height:1.3; }
.doc-md h1{ font-size:1.55rem; margin:1.25rem 0 .75rem; border-bottom:2px solid #1f3b56; padding-bottom:.25rem; }
.doc-md h2{ font-size:1.25rem; margin:1.5rem 0 .5rem; border-bottom:1px solid #cfd6df; padding-bottom:.2rem; }
.doc-md h3{ font-size:1.08rem; margin:1.1rem 0 .4rem; }
.doc-md h4{ font-size:.98rem; margin:1rem 0 .35rem; color:#3a5470; }
.doc-md p{ margin:.55rem 0; }
.doc-md ul, .doc-md ol{ margin:.4rem 0 .65rem 1.4rem; padding:0; }
.doc-md li{ margin:.18rem 0; }
.doc-md blockquote{ border-left:4px solid #b87a1f; padding:.25rem .9rem; margin:.6rem 0; background:#fdf6ec; color:#3a3a3a; }
.doc-md code{ background:#f1f4f8; padding:.05rem .35rem; border-radius:3px; font-size:.88em; }
.doc-md pre{ background:#0f172a; color:#e2e8f0; padding:.75rem 1rem; border-radius:6px; overflow:auto; }
.doc-md pre code{ background:transparent; color:inherit; padding:0; font-size:.85rem; }
.doc-md table{ border-collapse:collapse; width:100%; margin:.6rem 0; font-size:.88rem; }
.doc-md th, .doc-md td{ border:1px solid #cfd6df; padding:.35rem .55rem; vertical-align:top; }
.doc-md th{ background:#eef3f8; text-align:left; }
.doc-md tbody tr:nth-child(even){ background:#fafbfc; }
.doc-md hr{ border:none; border-top:1px solid #cfd6df; margin:1rem 0; }
.doc-md a{ color:#2470b8; }
.doc-md img{ max-width:100%; }
.doc-md dl{ margin:.5rem 0; }
.doc-md dt{ font-weight:700; color:#1f3b56; margin-top:.4rem; }
.doc-md dd{ margin:.1rem 0 .4rem 1.2rem; }
.doc-md .footnote{ font-size:.85rem; border-top:1px solid #cfd6df; margin-top:1rem; padding-top:.5rem; }

.doc-footer{ margin-top:1.5rem; padding-top:.75rem; border-top:1px solid #e2e6eb; display:flex; gap:.5rem; align-items:center; }

/* Firma digital + bloqueo */
.warning-banner{ background:#fff7ed; border:1px solid #f59e0b; border-left:6px solid #d97706; padding:.9rem 1rem; margin-bottom:1rem; }
.warning-banner strong{ color:#9a3412; font-size:1rem; }
fieldset.locked{ background:#f8fafc; border-color:#cfd6df; }
fieldset.locked input, fieldset.locked textarea, fieldset.locked select{ background:#eef2f7; color:#3a4a5b; }
.sign-checkbox{ background:#eef7ee; border:1px dashed #4ca34c; padding:.55rem .75rem; border-radius:6px; cursor:pointer; }
.sign-checkbox input[type=checkbox]{ transform: scale(1.15); margin-right:.4rem; }
.firma-digital{ padding:.4rem .6rem; }
.firma-stamp{ display:inline-block; border:1.5px solid #1f3b56; border-radius:6px; padding:.5rem 1rem; background:#f8fbff; min-width:240px; }
.firma-name{ font-family: "Brush Script MT", "Lucida Handwriting", cursive; font-size:1.5rem; color:#1f3b56; line-height:1.1; }
.firma-img{ display:block; max-width:260px; max-height:90px; }

/* Lienzo de firma manuscrita */
.sigpad { margin:.4rem 0; }
.sigpad-canvas {
  width:100%; max-width:440px; height:auto; display:block;
  border:1px dashed #94a3b8; border-radius:8px; background:#fff;
  touch-action:none; cursor:crosshair;
}
.sigpad-actions { display:flex; align-items:center; gap:.7rem; flex-wrap:wrap; margin-top:.35rem; }
.firma-meta{ font-size:.72rem; color:#6a7785; margin-top:.15rem; letter-spacing:.02em; }
button.danger{ background:#b91c1c; color:#fff; border:none; padding:.5rem .9rem; border-radius:5px; cursor:pointer; font-weight:600; }
button.danger:hover{ background:#991b1b; }

/* ---------- Imágenes / fotos ---------- */
img { max-width: 100%; height: auto; }
.foto-thumb { max-height: 56px; border-radius: 4px; border: 1px solid var(--border); vertical-align: middle; }

/* ---------- Responsive / móvil ---------- */
@media (max-width: 760px) {
  body { font-size: 14px; }
  .page { padding: 0 10px; margin: 12px auto; }

  /* Barra superior: marca a la izquierda + hamburguesa a la derecha. */
  .topbar { flex-wrap: wrap; gap: 4px 8px; padding: 8px 12px; }
  .topbar .brand { font-size: 16px; margin-right: auto; }

  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,.15); color: #fff; border-radius: 6px;
    padding: 6px 12px; font-size: 20px; line-height: 1; cursor: pointer; user-select: none;
  }
  .nav-toggle .nav-close { display: none; }
  .nav-toggle-cb:checked ~ .nav-toggle .nav-burger { display: none; }
  .nav-toggle-cb:checked ~ .nav-toggle .nav-close { display: inline; }

  /* El contenedor se vuelve un menú vertical, oculto hasta abrir. */
  .nav-collapse {
    display: none; flex-direction: column; align-items: stretch;
    width: 100%; gap: 2px; margin-top: 8px;
  }
  .nav-toggle-cb:checked ~ .nav-collapse { display: flex; }

  .topbar .spacer { display: none; }
  .topbar a, .topbar .nav-trigger { padding: 11px 10px; border-radius: 6px; }

  /* Grupos y submenús se muestran en línea (sin hover). */
  .topbar .nav-group { width: 100%; display: block; }
  .topbar .nav-trigger { width: 100%; text-align: left; opacity: .75; font-size: 13px; }
  .topbar .nav-menu {
    display: block; position: static; box-shadow: none; min-width: 0;
    background: rgba(255,255,255,.06); border-radius: 6px; padding: 2px 0;
  }
  .topbar .nav-menu a { padding-left: 26px; }
  .topbar .rol-switch { width: 100%; justify-content: flex-start; padding: 8px 10px; flex-wrap: wrap; }
  .topbar .rol-switch select { flex: 1; min-width: 140px; }
  .topbar .user { padding: 8px 10px; opacity: .85; }
  .topbar .logout { text-align: center; }

  /* Formularios a una sola columna */
  .form-grid { grid-template-columns: 1fr; }
  input, select, textarea { max-width: 100%; }

  /* Tablas deslizables horizontalmente: el bloque se desborda (nowrap) y
     se desplaza dentro de su propio contenedor, sin empujar la página. */
  table {
    display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
    white-space: nowrap; font-size: 13px;
  }
  /* Pista visual de que la tabla se puede deslizar. */
  table { scrollbar-width: thin; }

  /* Tarjetas estadísticas: 2 por fila en vez de 1 (mejor uso del ancho). */
  .grid-4 { grid-template-columns: 1fr 1fr; }

  /* Columnas dobles (p. ej. detalle de prospecto) a una sola en móvil. */
  .cols-2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }

  /* Evita que textos largos rompan el layout */
  .card, .page { overflow-wrap: anywhere; }
  h1 { font-size: 22px; }
  h2 { font-size: 18px; }
}

/* ---------- Modo kiosco (iPad para el paciente) ---------- */
.kiosk-body { background: #f4f7fb; }
.kiosk-bar {
  display: flex; align-items: baseline; gap: .6rem;
  padding: .7rem 1.1rem; background: #10243b; color: #fff;
}
.kiosk-bar .brand { font-weight: 700; letter-spacing: .04em; }
.kiosk-bar .kiosk-org { font-size: .8rem; opacity: .7; }
.kiosk-page { max-width: 820px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.kiosk-welcome { text-align: center; margin: 1.4rem 0 1.8rem; }
.kiosk-welcome h1 { font-size: 2rem; margin: .2rem 0; }
.kiosk-list { display: flex; flex-direction: column; gap: 1rem; }
.kiosk-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.4rem 1.6rem; background: #fff; border: 2px solid #cbd5e1;
  border-radius: 14px; text-decoration: none; color: #10243b;
  font-size: 1.15rem; box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.kiosk-item:hover, .kiosk-item:active { border-color: #2563eb; }
.kiosk-item .kiosk-item-title { font-weight: 600; }
.kiosk-item .kiosk-item-status { color: #64748b; font-size: .95rem; white-space: nowrap; }
.kiosk-item.done { border-color: #16a34a; background: #f0fdf4; }
.kiosk-item.done .kiosk-item-status { color: #16a34a; font-weight: 600; }
.kiosk-exit { text-align: center; margin-top: 2.5rem; }
.kiosk-exit a { color: #94a3b8; font-size: .85rem; text-decoration: none; }

/* En kiosco, agranda controles de formulario y firma para dedo/tableta. */
.kiosk-page input:not([type=checkbox]):not([type=radio]),
.kiosk-page select, .kiosk-page textarea { font-size: 1.05rem; padding: .7rem .8rem; }
.kiosk-page .sigpad-canvas { width: 100%; height: 220px; touch-action: none; }
.kiosk-page button.primary { font-size: 1.15rem; padding: .9rem 1.6rem; }
.kiosk-opt { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: #92710a; background: #fef3c7; border: 1px solid #f6d67a; border-radius: 999px;
  padding: 1px 8px; margin-left: 8px; vertical-align: middle; }

/* Bloque de texto de documento (consentimiento, información) dentro de un formulario */
.doc-block{ grid-column:1 / -1; background:#f8fafc; border:1px solid #e5e7eb;
  border-radius:8px; padding:.7rem 1rem; margin:.3rem 0 .6rem; line-height:1.5; }
.doc-block h4.doc-h{ margin:.75rem 0 .3rem; color:#0f2a4a; font-size:1rem; }
.doc-block h4.doc-h:first-child{ margin-top:.2rem; }
.doc-block p{ margin:.4rem 0; }
.doc-block ul{ margin:.3rem 0 .3rem 1.1rem; }
.doc-block li{ margin:.15rem 0; }

/* ---------- Accesibilidad y pulido (mejoras de la revisión) ---------- */

/* Foco de teclado visible y consistente (antes se usaba el del navegador). */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid #2f6f9f; outline-offset: 2px; border-radius: 3px;
}
.topbar a:focus-visible, .topbar button:focus-visible {
  outline: 3px solid #cfe4f5; outline-offset: 2px;
}

/* Tablas anchas: envolver en .table-scroll para no desbordar en móvil. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Etiqueta de scope "global" en el índice de formularios. */
.scope-tag.scope-global { background: #e7edf6; color: #26436b; }

/* Barra de progreso + estado de autoguardado en formularios largos. */
.form-progress { display: flex; align-items: center; gap: .6rem; margin: .8rem 0 .2rem; flex-wrap: wrap; }
.form-progress-bar { flex: 1 1 180px; height: 8px; background: #e5e9f0; border-radius: 999px; overflow: hidden; }
.form-progress-bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg,#12395e,#2f6f9f); transition: width .2s ease; }
.autosave-status { color: #0a7c2f; }

/* Salida del kiosco (re-autenticación del personal). */
.kiosk-exit details { max-width: 420px; margin: 0 auto; }
.kiosk-exit summary { cursor: pointer; color: #64748b; }
.kiosk-exit-form { display: flex; flex-direction: column; gap: .5rem; margin-top: .6rem; align-items: center; }
.kiosk-exit-form input[type=password] { max-width: 260px; }

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .form-progress-bar > i { transition: none; }
}

/* En móvil, las tablas anchas se vuelven desplazables horizontalmente en vez de
   desbordar la página (antes quedaban apretadas/cortadas). */
@media (max-width: 640px) {
  .page table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}
