/* Sistema de diseño XinerLAB (F0): superficies con borde de 1 px, radio único,
   un solo acento azul y colores semánticos con contraste AA. Sin degradados en este CSS
   (el único degradado vive en img/login-bg.svg) ni sombras decorativas: la elevación existe solo
   en superposiciones (diálogo y aviso). Capa de marca al final: superficies translúcidas y transiciones.
   Las fuentes se sirven localmente (public/fonts/): la app debe funcionar sin internet. */
@font-face { font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 400; font-display: block; src: url('/fonts/plex-sans-400.woff2') format('woff2'); }
@font-face { font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 500; font-display: block; src: url('/fonts/plex-sans-500.woff2') format('woff2'); }
@font-face { font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 600; font-display: block; src: url('/fonts/plex-sans-600.woff2') format('woff2'); }
@font-face { font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 700; font-display: block; src: url('/fonts/plex-sans-700.woff2') format('woff2'); }
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 500; font-display: block; src: url('/fonts/plex-mono-500.woff2') format('woff2'); }
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 600; font-display: block; src: url('/fonts/plex-mono-600.woff2') format('woff2'); }

:root {
  /* color: neutros planos + un acento */
  --bg: #f3f5f9;
  --surface: #ffffff;
  --border: #d5dce8;
  --control-border: #7d8aa3;     /* borde de campos: >= 3:1 sobre blanco (WCAG 1.4.11) */
  --border-soft: #e6EAF2;
  --ink: #10203a;
  --ink-muted: #4a5870;
  --ink-faint: #5d6a82;          /* antes #8b97ac (2,95:1); ahora >= 4,5:1 sobre blanco y sobre --bg */

  --accent: #15599e;
  --accent-dark: #0d3c70;
  --accent-light: #3f8de0;
  --accent-ink: #ffffff;
  --accent-soft: #e3edf9;

  /* semanticos clinicos: texto sobre su fondo suave >= 4,5:1 */
  --success: #146c43;
  --success-soft: #e4f6ec;
  --warning: #855400;
  --warning-soft: #fbf0dc;
  --danger: #b3301f;
  --danger-soft: #fbe9e6;
  --danger-ink: #ffffff;
  --neutral: #4a5870;
  --neutral-soft: #eaeef6;

  /* tipografia: 12 / 13 / 14 / 16 / 20 / 24 */
  --fs-xs: 12px; --fs-sm: 13px; --fs-md: 14px; --fs-lg: 16px; --fs-xl: 20px; --fs-2xl: 24px;
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;

  /* espaciado base 4 px */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  /* forma: un solo radio; elevacion solo en superposiciones */
  --radius: 6px;
  --elevation-overlay: 0 8px 24px rgba(16, 32, 58, .22);
  --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
  --control-h: 36px;
  color-scheme: light;

  /* nombres anteriores, conservados por compatibilidad con estilos en linea existentes */
  --blue: var(--accent);
  --blue-dark: var(--accent-dark);
  --green: var(--success);
  --red: var(--danger);
  --amber: var(--warning);
  --gray-bg: var(--bg);
  --gray-border: var(--border);
  --text: var(--ink);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  min-height: 100vh;
}

h1, h2, h3 { font-family: var(--font-body); text-wrap: balance; }
.num, input, select, td.mono, .mono { font-variant-numeric: tabular-nums; }

/* foco visible y uniforme para teclado */
:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- encabezado de la app ---------- */
header.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  padding: var(--sp-3) clamp(16px, 3vw, 32px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
}

header.app-header h1 { margin: 0; font-size: var(--fs-xl); font-weight: 600; line-height: 1.25; }
header.app-header .hdr-status { display: flex; align-items: center; gap: var(--sp-4); margin-left: auto; font-size: var(--fs-sm); color: var(--ink-muted); }
header.app-header .hdr-item { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
header.app-header .hdr-item b { color: var(--ink); font-weight: 600; }
header.app-header a.hdr-item:hover { color: var(--ink); text-decoration: underline; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: currentColor; }
.dot-ok { background: var(--success); }
.dot-danger { background: var(--danger); }

header.app-header .user-box { display: flex; align-items: center; gap: var(--sp-3); font-size: var(--fs-sm); color: var(--ink-muted); }
header.app-header .user-box span:not(.avatar) { line-height: 1.5; }
header.app-header .avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: var(--neutral-soft); color: var(--ink-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-xs); font-weight: 700; font-family: var(--font-body);
}
header.app-header button {
  background: var(--surface);
  color: var(--ink-muted);
  border: 1px solid var(--border);
  padding: 7px 13px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 500;
}
header.app-header button:hover { background: var(--neutral-soft); color: var(--ink); }

/* ---------- barra lateral agrupada por flujo ---------- */
.module-nav {
  position: fixed; top: 0; left: 0; bottom: 0; width: 232px; z-index: 60;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-3) var(--sp-5);
}
body:has(#moduleNav) { padding-left: 232px; }
.nav-brand { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-2) var(--sp-4); }
.nav-mark {
  flex: none; width: 32px; height: 32px; border-radius: var(--radius);
  background: url('/img/xinerlab-x.svg') center / contain no-repeat;
}
/* El logo es un enlace: la regla `.module-nav a` (mas especifica) le daba formato de item de menu; aqui se restaura y se centra. */
.module-nav a.nav-brand { display: flex; align-items: center; justify-content: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-2) var(--sp-4); border-left: 0; border-radius: 0; background: none; color: var(--ink); font-size: inherit; font-weight: inherit; }
.module-nav a.nav-brand:hover { background: none; }
.nav-brand-name { font-weight: 600; font-size: var(--fs-md); line-height: 1.25; overflow-wrap: anywhere; }
.nav-group { margin-bottom: var(--sp-4); }
.module-nav .nav-group-label {
  display: flex; align-items: center; justify-content: space-between; width: 100%; margin: 0; min-height: 0;
  background: none; border: 0; box-shadow: none; border-radius: var(--radius); cursor: pointer; text-align: left;
  font-family: inherit; font-size: var(--fs-xs); font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--ink-faint); padding: var(--sp-1) var(--sp-2);
}
.module-nav .nav-group-label:hover { background: var(--neutral-soft); color: var(--ink); }
.nav-chev {
  width: 7px; height: 7px; margin-right: 4px; flex: none;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
}
.nav-group.cerrado .nav-chev { transform: rotate(-45deg) translate(-2px, -2px); }
.nav-items { display: grid; grid-template-rows: 1fr; }
.nav-items > div { overflow: hidden; min-height: 0; }
.nav-group.cerrado .nav-items { grid-template-rows: 0fr; }
.nav-group.cerrado .nav-items > div { visibility: hidden; }
.module-nav a {
  display: block; color: var(--ink-muted); text-decoration: none;
  font-weight: 500; font-size: var(--fs-sm);
  padding: var(--sp-2) var(--sp-3); border-radius: var(--radius);
  border-left: 3px solid transparent;
  transition: background .12s ease, color .12s ease;
}
.module-nav a:hover { background: var(--neutral-soft); color: var(--ink); }
.module-nav a.active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; border-left-color: var(--accent); }

main { max-width: 1360px; margin: var(--sp-5) auto; padding: 0 clamp(16px, 3vw, 32px) 60px; }

/* ---------- tarjetas y grids ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5);
  margin-bottom: var(--sp-4);
}

.card h2 {
  margin: 0 0 var(--sp-4);
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--ink);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--sp-3);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px var(--sp-4); }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px var(--sp-4); }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- espacio de trabajo: formulario + resumen fijo ---------- */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--sp-5); align-items: start; }
@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .summary { position: static; }
}

.field { display: flex; flex-direction: column; }
.field input, .field select { margin-bottom: 0; }
.search-row { display: flex; gap: var(--sp-3); align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.search-row .field { flex: 1; min-width: 180px; margin-bottom: 0; }
.search-row button { flex: none; }

.summary {
  position: sticky; top: 76px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--sp-5);
}
.summary h2 { margin: 0 0 var(--sp-4); font-size: var(--fs-lg); font-weight: 600; border-bottom: 1px solid var(--border); padding-bottom: var(--sp-3); }
.summary .bcv-row { display: flex; gap: var(--sp-3); align-items: flex-end; margin-bottom: 14px; }
.summary .bcv-row .field { flex: 1; margin-bottom: 0; }
.summary .bcv-row button { flex: none; }
.summary .bcv-display { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: var(--sp-1); }
.summary .bcv-display-label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-muted); }
.summary .bcv-display-value { font-family: var(--font-mono); font-weight: 600; color: var(--accent-dark); font-size: var(--fs-md); }
.summary .hint { font-size: var(--fs-xs); color: var(--ink-muted); margin: 0 0 14px; line-height: 1.4; }

.summary-items { margin: var(--sp-1) 0 14px; }
.summary-line { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 7px 0; border-bottom: 1px dashed var(--border-soft); font-size: var(--fs-sm); }
.summary-line:last-child { border-bottom: none; }
.summary-line .label { color: var(--ink-muted); }
.summary-line .value { font-family: var(--font-mono); font-weight: 600; white-space: nowrap; }
.summary-empty { font-size: var(--fs-sm); color: var(--ink-faint); padding: 6px 0 14px; }

.summary-item-derivable { border-bottom: 1px dashed var(--border-soft); padding: var(--sp-1) 0; }
.summary-item-derivable:last-child { border-bottom: none; }
.summary-item-derivable .summary-line { border-bottom: none; padding: 7px 0 2px; }
.derivado-toggle { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--warning); font-weight: 600; cursor: pointer; padding: 2px 0; }
.derivado-toggle input { width: 14px; height: 14px; }
.derivado-lab-input { width: 100%; margin: var(--sp-1) 0 var(--sp-2); font-size: var(--fs-sm); padding: 6px 9px; }

.summary-total-row { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--sp-3); padding: var(--sp-3) 0; border-top: 1px solid var(--border); margin-bottom: 14px; }
.summary-figure { font-family: var(--font-mono); font-size: var(--fs-xl); font-weight: 600; color: var(--accent-dark); }
.summary-figure-sm { font-family: var(--font-mono); font-size: var(--fs-sm); font-weight: 600; color: var(--ink-muted); text-align: right; }

.btn-share {
  display: flex; align-items: center; gap: var(--sp-2);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 13px; font-size: var(--fs-sm); font-weight: 600;
  color: var(--ink); text-decoration: none; background: var(--surface);
  transition: border-color .12s ease, background .12s ease;
}
.btn-share:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.btn-share svg { display: block; flex: none; }
.btn-share.chip-whatsapp { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.btn-share.chip-whatsapp:hover { background: var(--success-soft); border-color: var(--success); color: var(--success); }

.delivery-pill {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--accent-soft); color: var(--accent-dark); border-radius: var(--radius);
  padding: 9px var(--sp-3); font-size: var(--fs-sm); font-weight: 600; margin-bottom: var(--sp-4);
}

/* ---------- formularios ---------- */
label { display: block; font-size: var(--fs-sm); font-weight: 600; margin-bottom: 6px; color: var(--ink-muted); }
input, select, textarea {
  width: 100%;
  font-family: var(--font-body);
  padding: 9px 11px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  font-size: var(--fs-lg);
  margin-bottom: 14px;
  background: var(--surface);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
textarea { resize: vertical; min-height: 64px; }
.field-error { color: var(--danger); font-size: var(--fs-xs); margin: -8px 0 var(--sp-3); }

/* ---------- botones: primario / secundario / peligro / texto ---------- */
button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--accent);
  min-height: var(--control-h);
  padding: 9px var(--sp-5);
  border-radius: var(--radius);
  font-size: var(--fs-md);
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background .12s ease;
}
button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
button.secondary, a.secondary {
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--accent);
  min-height: var(--control-h);
  padding: 8px var(--sp-4);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background .12s ease;
}
button.secondary:hover, a.secondary:hover { background: var(--accent-soft); }
button.danger {
  background: var(--surface);
  border: 1px solid var(--danger);
  color: var(--danger);
  min-height: var(--control-h);
  padding: 8px var(--sp-4);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
}
button.danger:hover { background: var(--danger-soft); }
button.danger.solid { background: var(--danger); color: #fff; }
button.danger.solid:hover { background: #8f2618; }
button.text { background: none; border: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: var(--sp-1) var(--sp-2); }
button.text:hover { text-decoration: underline; }
button[aria-busy="true"] { opacity: .7; cursor: progress; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- catálogo de exámenes (chips) ---------- */
.test-catalog {
  max-height: 380px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  background: var(--bg);
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.test-catalog::-webkit-scrollbar { width: 8px; }
.test-catalog::-webkit-scrollbar-track { background: transparent; }
.test-catalog::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
.test-catalog::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }
.test-category {
  font-weight: 700; color: var(--accent-dark); margin: 14px 0 var(--sp-2); font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: .05em;
}
.test-category:first-child { margin-top: 0; }
.test-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 11px; margin-bottom: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  font-size: var(--fs-sm); cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.test-item:hover { border-color: var(--accent); }
.test-item input { width: auto; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.test-item:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- tablas ---------- */
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table th, table td { text-align: left; padding: 11px 13px; border-bottom: 1px solid var(--border-soft); }
table th {
  background: var(--bg); color: var(--ink-muted);
  font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table tbody tr:hover { background: var(--bg); }
table tbody tr:last-child td { border-bottom: none; }

/* ---------- insignias de estado (punto + texto) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 99px; font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge.pendiente { background: var(--warning-soft); color: var(--warning); }
.badge.en_proceso { background: var(--accent-soft); color: var(--accent); }
.badge.completado { background: var(--success-soft); color: var(--success); }
.badge.entregado { background: var(--neutral-soft); color: var(--neutral); }
.badge.emergencia { background: var(--danger-soft); color: var(--danger); }
.badge.urgente { background: var(--warning-soft); color: var(--warning); }
.badge.normal { background: var(--neutral-soft); color: var(--neutral); }
.badge.pagado { background: var(--success-soft); color: var(--success); }
.badge.parcial { background: var(--warning-soft); color: var(--warning); }

/* ---------- alertas en línea ---------- */
.alert { padding: 11px 15px; border-radius: var(--radius); margin-bottom: 14px; font-size: var(--fs-sm); border: 1px solid transparent; }
.alert.error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.alert.success { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.alert.warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning); }

/* Respuestas de IA: texto largo con buen contraste (no es un aviso corto de una línea). */
.ai-response {
  background: var(--accent-soft);
  color: var(--ink);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 13px var(--sp-4);
  font-size: var(--fs-md);
  line-height: 1.55;
}
.ai-response .ai-response-title { color: var(--accent-dark); font-weight: 700; display: block; margin-bottom: 6px; }
.ai-response ul { margin: 0 0 var(--sp-2) 18px; padding: 0; }
.ai-response li { margin-bottom: var(--sp-1); }
.ai-response p { margin: 0 0 6px; }
.ai-response .ai-response-meta { font-size: var(--fs-xs); color: var(--ink-muted); margin-top: var(--sp-2); }

.actions-row { display: flex; gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-3); align-items: center; }

.actions-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; min-width: 150px; }
.actions-cell button.secondary, .actions-cell button.danger { padding: 6px 11px; min-height: 0; font-size: var(--fs-xs); white-space: nowrap; }
.actions-cell.fila { flex-direction: row; flex-wrap: wrap; align-items: center; min-width: 280px; }
.filtros-fila { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.filtros-fila .field { margin: 0; }

.action-group { display: flex; align-items: center; gap: 7px; }
.action-group .grp-label {
  width: 56px; flex: none; font-size: var(--fs-xs); font-weight: 600; color: var(--ink-faint);
  text-transform: uppercase; letter-spacing: .03em;
}
.action-chips { display: flex; gap: 5px; }
.action-chip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: var(--radius); flex: none;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--ink-muted);
  text-decoration: none; line-height: 1;
  transition: border-color .12s ease, background .12s ease, color .12s ease;
}
.action-chip svg { display: block; }
button.action-chip { font: inherit; cursor: pointer; appearance: none; padding: 0; }
.action-chip:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.action-chip.chip-whatsapp { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.action-chip-disabled { opacity: .45; pointer-events: none; }
.action-buttons-row { display: flex; gap: 7px; flex-wrap: wrap; margin-top: var(--sp-1); }
.action-buttons-row:empty { display: none; }

/* ---------- bloques de examen (bioanalista) ---------- */
.exam-block {
  border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-4) var(--sp-5); margin-bottom: var(--sp-4);
  background: var(--surface);
}
.exam-block h3 { margin: 0 0 var(--sp-1); font-size: var(--fs-lg); font-weight: 600; color: var(--ink); display: flex; align-items: center; gap: 10px; }
.exam-block .exam-meta { font-size: var(--fs-sm); color: var(--ink-muted); margin-bottom: var(--sp-3); }
.exam-block table { margin: 0 0 var(--sp-3); }
.exam-block table input[type="text"] { margin-bottom: 0; }
.row-abnormal { background: var(--danger-soft); }

/* ---------- tarjetas de estadística ---------- */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-4);
}
.stat-card .stat-label { font-size: var(--fs-xs); color: var(--ink-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .stat-value { font-family: var(--font-mono); font-size: var(--fs-xl); font-weight: 600; color: var(--accent-dark); margin-top: var(--sp-1); }

/* ---------- informes ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: var(--sp-5); }
.report-controls { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.period-tabs {
  display: flex; gap: var(--sp-1); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-1); flex: none;
}
.period-tab {
  background: none; border: none; cursor: pointer; padding: var(--sp-2) var(--sp-4); border-radius: var(--radius);
  font-family: var(--font-body); font-size: var(--fs-sm); font-weight: 600; color: var(--ink-muted);
  transition: background .12s ease, color .12s ease;
}
.period-tab:hover { background: var(--neutral-soft); color: var(--ink); }
.period-tab.active { background: var(--accent); color: var(--accent-ink); }
.report-controls .field { margin-bottom: 0; min-width: 150px; }
.report-controls .field input { margin-bottom: 0; }

.breakdown-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: var(--fs-sm); }
.breakdown-label { width: 110px; flex: none; color: var(--ink-muted); }
.breakdown-bar { flex: 1; height: 10px; border-radius: 99px; background: var(--border-soft); overflow: hidden; }
.breakdown-fill { height: 100%; border-radius: 99px; }
.breakdown-value { width: 34px; flex: none; text-align: right; font-family: var(--font-mono); font-weight: 600; }

a.link-btn { color: var(--accent); text-decoration: none; font-weight: 600; }
a.link-btn:hover { text-decoration: underline; }

/* ---------- avisos emergentes (aria-live) ---------- */
.toast-host {
  position: fixed; top: 76px; right: var(--sp-4); z-index: 1100;
  display: flex; flex-direction: column; gap: var(--sp-2); max-width: 340px;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: var(--sp-3) 14px; font-size: var(--fs-sm); color: var(--ink);
  box-shadow: var(--elevation-overlay);
  opacity: 0; transition: opacity .12s ease;
}
.toast-visible { opacity: 1; }
.toast-danger { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--success); }
@media (max-width: 600px) { .toast-host { left: var(--sp-4); right: var(--sp-4); max-width: none; top: 70px; } }

/* ---------- ingreso ----------
   Primera impresión del sistema; el fondo (arte SVG img/login-bg.svg) es el del body en toda la app. */
.login-wrap {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-5); padding: var(--sp-5);
}
/* Arte animado del ingreso (isotipo grande sobre órbitas, como el hero de xinerlab.com). Solo transform y
   opacity, muy lento; con prefers-reduced-motion queda estático. Todo local, sin recursos externos. */
.login-wrap { position: relative; z-index: 1; }
@media (min-width: 1101px) { .login-wrap { align-items: flex-start; padding-left: clamp(32px, 20vw, 420px); } }
.login-art { --m: clamp(260px, 46vmin, 520px); position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.login-art > div { position: absolute; background-position: center; background-size: contain; background-repeat: no-repeat; }
.la-mark { width: var(--m); height: var(--m); left: calc(80% - var(--m) / 2); top: calc(50% - var(--m) / 2);
  background-image: url('/img/xinerlab-x.svg'); opacity: .5; }
.la-orbits { --o: .5; width: calc(var(--m) * 2.6); height: calc(var(--m) * 2.6); left: calc(80% - var(--m) * 1.3); top: calc(50% - var(--m) * 1.3);
  opacity: var(--o); }
.la-orbits.a { background-image: url('/img/login-orbits-a.svg'); }
.la-orbits.b { background-image: url('/img/login-orbits-b.svg'); }
.la-beam { width: 90vw; height: 22vh; left: 5vw; top: 64vh;
  background-image: url('/img/login-beam.svg'); background-size: 100% 100%; transform: rotate(-7deg); }
@media (max-width: 1100px) {
  .la-mark { left: calc(50% - var(--m) / 2); opacity: .16; }
  .la-orbits { --o: .25; left: calc(50% - var(--m) * 1.3); }
}
@keyframes la-spin { to { transform: rotate(360deg); } }
@keyframes la-breathe { from { opacity: calc(var(--o) * .65); } to { opacity: var(--o); } }
@keyframes la-drift { from { transform: translate3d(0, 0, 0) rotate(0deg); } to { transform: translate3d(8px, -10px, 0) rotate(2.5deg); } }
@keyframes la-beam { from { transform: translate3d(-4vw, 0, 0) rotate(-7deg); opacity: .5; } to { transform: translate3d(4vw, -2vh, 0) rotate(-7deg); opacity: 1; } }
@media (prefers-reduced-motion: no-preference) {
  .la-orbits { animation: la-spin 240s linear infinite, la-breathe 11s ease-in-out infinite alternate; }
  .la-orbits.b { animation-duration: 320s, 14s; animation-direction: reverse, alternate; }
  .la-mark { animation: la-drift 16s ease-in-out infinite alternate; }
  .la-beam { animation: la-beam 24s ease-in-out infinite alternate; }
}
.login-foot { margin: 0; width: 100%; text-align: center; color: #9fb0c3; font-size: var(--fs-sm); max-width: 400px; line-height: 1.5; }
.login-foot strong { color: #e8eef5; font-weight: 600; }
.login-card {
  background: var(--surface);
  padding: 44px 38px 34px; border-radius: var(--radius); width: 100%; max-width: 400px;
  border: 1px solid var(--border);
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand .login-mark {
  width: 64px; height: 64px; border-radius: var(--radius); margin: 0 auto var(--sp-4);
  background: url('/img/xinerlab-x.svg') center / contain no-repeat;
}
.login-card h1 { color: var(--ink); font-size: var(--fs-xl); font-weight: 600; margin: 0 0 var(--sp-1); }
.login-card h1 span { color: var(--accent); }
.login-card p.subtitle { color: var(--ink-muted); font-size: var(--fs-sm); margin: 0; }
.login-card label { font-size: var(--fs-xs); letter-spacing: .02em; }
.login-card input { font-size: 15px; }

.login-help { text-align: center; margin: var(--sp-5) 0 0; font-size: var(--fs-sm); }
.login-help a { color: var(--accent); font-weight: 600; }
button.block { width: 100%; }

footer.note { text-align: center; color: var(--ink-faint); font-size: var(--fs-xs); margin-top: 30px; }

/* ---------- impresión (recibo / resultados / presupuesto / cierre) ---------- */
.sheet { background: var(--surface); max-width: 780px; margin: 20px auto; padding: 32px 42px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.9rem; }
/* table-layout: fixed es necesario porque cada categoria de examenes imprime su propia <table>
   por separado; con layout automatico cada una calcula el ancho de columnas segun su propio
   contenido, asi que la columna "Tipo de muestra"/"Resultado" queda en una posicion distinta
   en cada categoria. Con colgroup (ver .js de cada vista) todas quedan alineadas entre si. */
.sheet table { margin: 6px 0 16px; table-layout: fixed; }
/* Sin nowrap/ellipsis a proposito: un numero de orden, fecha o nombre largo nunca debe
   recortarse con "..." en un documento clinico/fiscal. table-layout:fixed ya garantiza
   columnas alineadas; si el contenido no cabe en una linea, que la fila crezca en vez de
   perder datos. */
.sheet table th, .sheet table td { padding: 6px 9px; word-wrap: break-word; }

.report-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--accent-dark); padding-bottom: var(--sp-3); margin-bottom: var(--sp-4); }
.lab-name { font-size: 1.2rem; font-weight: 700; color: var(--accent-dark); font-family: var(--font-body); }
.lab-sub { color: var(--ink-muted); font-size: 0.8rem; }
.report-meta { text-align: right; font-size: 0.85rem; }
.report-meta .lbl { font-weight: 600; color: var(--ink-muted); }

.report-title { text-align: center; font-size: 1.05rem; color: var(--accent-dark); margin: var(--sp-1) 0 18px; text-transform: uppercase; letter-spacing: 0.03em; font-weight: 700; }

.patient-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-1) var(--sp-5); font-size: 0.88rem; margin-bottom: var(--sp-4); padding-bottom: var(--sp-3); border-bottom: 1px solid var(--border); }
.patient-grid .lbl { font-weight: 600; color: var(--ink-muted); }

.exam-category { font-weight: 700; color: var(--accent-dark); background: var(--accent-soft); padding: 5px 10px; border-radius: var(--radius); margin-top: var(--sp-4); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; }
.exam-label-row td { font-weight: 700; color: var(--ink); background: var(--border-soft); padding-top: 9px; padding-bottom: 9px; white-space: normal; }
.obs-row td { font-size: 0.8rem; color: var(--ink-muted); font-style: italic; border-bottom: 1px solid var(--border-soft); white-space: normal; }
.pending { color: var(--warning); font-style: italic; }
.out-of-range-note { font-size: 0.8rem; color: var(--danger); font-weight: 600; }
.fine-print { margin-top: 18px; font-size: 0.8rem; color: var(--ink-faint); }
.exec-by { font-size: 0.85rem; font-weight: 600; color: var(--ink-muted); margin-top: var(--sp-1); }

.validity-box { border: 1.5px solid var(--warning); background: var(--warning-soft); border-radius: var(--radius); padding: var(--sp-3) var(--sp-4); margin: 18px 0; font-size: 0.9rem; color: var(--warning); }
.validity-box b { color: inherit; }

.totals-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-1) var(--sp-5); font-size: 0.9rem; margin-bottom: 18px; padding-bottom: var(--sp-3); border-bottom: 1px solid var(--border); }
.totals-grid .lbl { font-weight: 600; color: var(--ink-muted); }

.sign-row { display: flex; justify-content: space-between; margin-top: 54px; font-size: 0.85rem; }
.sign-line { border-top: 1px solid var(--ink); width: 220px; text-align: center; padding-top: 6px; color: var(--ink-muted); }

/* ---------- responsivo: tableta y teléfono ---------- */
@media (max-width: 900px) {
  body:has(#moduleNav) { padding-left: 0; }
  .module-nav {
    position: static; width: auto; display: flex; gap: var(--sp-1);
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: var(--sp-1); margin: 0 0 var(--sp-4);
  }
  .module-nav::-webkit-scrollbar { display: none; }
  .nav-brand, .module-nav a.nav-brand, .module-nav .nav-group-label { display: none; }
  .nav-group { display: flex; gap: var(--sp-1); margin: 0; }
  .nav-items { display: contents; }
  .nav-items > div, .nav-group.cerrado .nav-items > div { display: flex; gap: var(--sp-1); overflow: visible; visibility: visible; }
  .module-nav a { white-space: nowrap; border-left: 0; flex: none; }
  .module-nav a.active { box-shadow: inset 0 -3px 0 var(--accent); border-radius: var(--radius) var(--radius) 0 0; }
  header.app-header .hdr-status { margin-left: 0; order: 3; width: 100%; }
}

@media (max-width: 760px) {
  body { font-size: 15.5px; }
  main { margin: 14px auto; padding: 0 14px 40px; }

  header.app-header { padding: 11px 14px; gap: 10px; }
  header.app-header h1 { font-size: var(--fs-lg); }
  header.app-header .user-box { font-size: var(--fs-xs); gap: var(--sp-2); }
  header.app-header button { padding: 6px 10px; font-size: var(--fs-xs); }

  .card, .exam-block, .summary, .stat-card { padding: var(--sp-4); }
  .card h2, .summary h2 { font-size: var(--fs-md); }

  /* tablas: en vez de achicar el texto hasta ser ilegible, se deslizan horizontalmente */
  table { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table thead, table tbody { display: table; width: 100%; min-width: max-content; }

  .search-row, .summary .bcv-row { flex-direction: column; align-items: stretch; }
  .search-row .field, .summary .bcv-row .field { min-width: 0; }
  .search-row button, .summary .bcv-row button { width: 100%; }

  .actions-row { flex-direction: column; align-items: stretch; }
  .actions-row > a, .actions-row > button { width: 100%; text-align: center; }

  .report-controls { flex-direction: column; align-items: stretch; }
  .period-tabs { justify-content: stretch; }
  .period-tab { flex: 1; }
  .report-controls .field { min-width: 0; width: 100%; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }

  button.primary, button.secondary, button.danger, a.secondary { min-height: 40px; }
  .action-chip { width: 32px; height: 32px; }
}

@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  header.app-header .user-box span:not(.avatar) { display: none; }
}

@media print {
  header.app-header, .no-print { display: none !important; }
  body { background: #fff; }
  .sheet { border: none; margin: 0; }
}

/* Tema de pantalla: oscuro siempre (azul noche + arte de img/login-bg.svg en todas las pantallas).
   Al imprimir (media print) se queda el tema claro de :root. */
@media screen {
  body { background: #0a111a url('/img/login-bg.svg') center / cover no-repeat fixed; }
  :root {
    --glass: rgba(18, 31, 50, .80); --glass-border: rgba(143, 188, 238, .20);
    --bg: #0b1420; --surface: #121f32; --border: #2c4264; --border-soft: #1b2b44; --control-border: #5a779f;
    --ink: #e9eef9; --ink-muted: #a9b6cf; --ink-faint: #93a1bc;
    --accent: #5a9ce3; --accent-dark: #8fbcee; --accent-light: #7bb3ec; --accent-ink: #071525; --accent-soft: #17293f;
    --success: #4bc98a; --success-soft: #153328; --warning: #e0a94a; --warning-soft: #332a14;
    --danger: #f08a7d; --danger-soft: #3a1f1c; --danger-ink: #1a0a07; --neutral: #a9b6cf; --neutral-soft: #16263d;
    --elevation-overlay: 0 8px 24px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
  button.danger.solid { color: #1a0a07; }
  button.danger.solid:hover { background: #f5a095; }
}

/* ---- Marca del laboratorio (perfil) ---- */
html.con-logo .nav-mark {
  font-size: 0;
  background: var(--logo-url) center / contain no-repeat #fff;
  box-shadow: 0 0 0 1px var(--border);
}
.login-mark.con-logo { background: #fff; padding: 6px; box-sizing: border-box; }
.login-mark.con-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.lab-brand { display: flex; align-items: center; gap: var(--sp-3); }
.lab-logo { max-height: 56px; max-width: 140px; object-fit: contain; }
.lab-datos { color: var(--ink-muted); font-size: var(--fs-xs); margin-top: 2px; }

/* ---- Diálogo estándar (reemplaza alert / prompt / confirm del navegador) ---- */
.modal-fondo { position: fixed; inset: 0; background: rgba(16, 32, 58, .55); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: var(--sp-4); }
.modal-caja { background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-5); width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; box-shadow: var(--elevation-overlay); }
.modal-caja h3 { margin: 0 0 var(--sp-2); font-size: var(--fs-lg); font-weight: 600; }
.modal-msg { margin: 0 0 var(--sp-4); color: var(--ink-muted); font-size: var(--fs-sm); white-space: pre-line; }
.modal-error { color: var(--danger); font-size: var(--fs-sm); min-height: 1.3em; margin-top: 6px; }
.modal-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-3); }
.modal-actions button { flex: 1; }

/* ---- Recepción en dos pasos ---- */
.steps { display: flex; gap: var(--sp-5); list-style: none; margin: 0 0 var(--sp-4); padding: 0; }
.steps li { display: flex; align-items: center; gap: var(--sp-2); color: var(--ink-muted); font-size: var(--fs-sm); font-weight: 500; }
.steps li.activo { color: var(--ink); font-weight: 600; }
.num-paso { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border); display: inline-flex; align-items: center; justify-content: center; font-size: var(--fs-xs); font-weight: 600; background: var(--surface); }
.steps li.activo .num-paso { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.grid-2 > .span-2 { grid-column: 1 / -1; }
.mas-opciones { margin-top: var(--sp-3); }
.mas-opciones > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: var(--fs-sm); padding: var(--sp-2) 0; }
.mas-opciones[open] > summary { margin-bottom: var(--sp-3); }
.summary-total-label { display: block; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-muted); }
.summary .hint, #saldoInfo.hint { font-size: var(--fs-xs); color: var(--ink-muted); }
button.text.block { margin-top: var(--sp-2); }
.orden-creada { text-align: center; font-size: var(--fs-xl); font-weight: 600; color: var(--accent-dark); margin: var(--sp-3) 0 var(--sp-4); }
.stack { display: flex; flex-direction: column; gap: var(--sp-2); margin: var(--sp-3) 0 var(--sp-4); }
[hidden] { display: none !important; }

/* ---- Bandeja de órdenes ---- */
.filters-row { display: flex; gap: var(--sp-3); align-items: flex-end; flex-wrap: wrap; margin-bottom: var(--sp-4); }
.filters-row .field { min-width: 200px; flex: 1; max-width: 320px; }
.filters-row .primary-link { margin-left: auto; }
a.primary-link {
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  min-height: var(--control-h); padding: 8px var(--sp-4); border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  font-size: var(--fs-sm); font-weight: 600; white-space: nowrap;
}
a.primary-link:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.table-wrap { overflow-x: auto; }
.orders-table td { vertical-align: top; }
.nota { font-size: var(--fs-xs); color: var(--ink-muted); margin-top: var(--sp-1); max-width: 34ch; }
.nota-sutil { font-size: var(--fs-xs); color: var(--ink-muted); margin-top: 2px; }
.accion-cell { min-width: 190px; }
.accion-cell button.primary, .accion-cell a.primary-link { padding: 6px var(--sp-3); min-height: 32px; font-size: var(--fs-sm); }
.menu-acciones { margin-top: var(--sp-2); }
.menu-acciones > summary { cursor: pointer; color: var(--accent); font-size: var(--fs-xs); font-weight: 600; }
.menu-lista { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; margin-top: var(--sp-1); }
.menu-lista a, .menu-lista button { background: none; border: none; padding: 4px 0; font: inherit; font-size: var(--fs-xs); color: var(--ink); text-align: left; cursor: pointer; text-decoration: none; }
.menu-lista a:hover, .menu-lista button:hover { color: var(--accent); text-decoration: underline; }
.field + .ayuda { margin-top: var(--sp-2); }
.menu-lista .peligro { color: var(--danger); }
.vacio { padding: var(--sp-5) 0; color: var(--ink-muted); text-align: center; }
.ayuda { font-size: var(--fs-sm); color: var(--ink-muted); margin: calc(-1 * var(--sp-2)) 0 var(--sp-4); }

/* ---- Hoja de laboratorio (transcripción) ---- */
.paciente-cabecera {
  position: sticky; top: 63px; z-index: 40;
  display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-5); align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-4); font-size: var(--fs-sm);
}
.paciente-cabecera .cab-lbl { display: block; font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-faint); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-4); border-bottom: 1px solid var(--border); padding-bottom: var(--sp-3); }
.card-head h2 { margin: 0; padding: 0; border: 0; }
.exam-block table input[data-item-resultado], .exam-block table select[data-item-resultado], .patient-sheet input[data-item-resultado], #patientsContainer input[data-item-resultado], #patientsContainer select[data-item-resultado] {
  max-width: 200px; font-family: var(--font-mono); font-size: var(--fs-md);
}
.res-valor { font-family: var(--font-mono); font-weight: 500; white-space: nowrap; }
.res-valor.res-fuera { font-weight: 700; }
.res-ref { color: var(--ink-muted); white-space: nowrap; }
.check-inline { display: flex; align-items: center; gap: var(--sp-1); font-weight: 400; margin: var(--sp-3) 0; }
.check-inline input { width: auto; margin: 0; }
td .check-inline { margin: 0; }
.hist-examen { margin-bottom: var(--sp-3); }
.hist-detalle { margin: 0; }
.hist-detalle h3 { margin-top: 0; }

/* Indicador: texto + icono; solo esta celda se destaca (nunca la fila ni solo el color) */
.ind { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--radius); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.ind-normal { color: var(--success); background: var(--success-soft); }
.ind-alto, .ind-bajo, .ind-anormal { color: var(--warning); background: var(--warning-soft); border-color: var(--warning); }
.ind-critico { color: var(--danger-ink); background: var(--danger); font-weight: 700; }
.ind-pend { color: var(--ink-faint); }

/* ---- Cifras principales (cierre de caja, informes) ---- */
.hero-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); margin: var(--sp-4) 0; }
.hero-cifra { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-4) var(--sp-5); background: var(--bg); display: flex; flex-direction: column; gap: 2px; }
.hero-lbl { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-muted); }
.hero-val { font-family: var(--font-mono); font-size: 32px; font-weight: 600; line-height: 1.2; color: var(--ink); font-variant-numeric: tabular-nums; }
.hero-sub { font-size: var(--fs-xs); color: var(--ink-muted); }
.desglose h3 { font-size: var(--fs-md); font-weight: 600; margin: 0 0 var(--sp-2); }
.card h2.subtitulo, h2.subtitulo { margin-top: var(--sp-6); }
.cierre-caja { margin-top: var(--sp-5); border-top: 1px solid var(--border); padding-top: var(--sp-4); max-width: 640px; }
.cierre-caja h3 { margin: 0 0 var(--sp-1); font-size: var(--fs-lg); }
.stat-delta { margin-top: var(--sp-1); font-size: var(--fs-xs); color: var(--ink-muted); }
.num-der { text-align: right; }
@media (max-width: 760px) { .hero-row { grid-template-columns: 1fr; } .hero-val { font-size: 26px; } }

/* ---- Catálogo, primeros pasos y formularios de configuración ---- */
.cat-grupo { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: var(--sp-2); background: var(--surface); }
.cat-grupo > summary { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); cursor: pointer; padding: var(--sp-3) var(--sp-4); font-weight: 600; font-size: var(--fs-sm); }
.cat-grupo[open] > summary { border-bottom: 1px solid var(--border); }
.cat-grupo .table-wrap { padding: 0 var(--sp-2); }
.checklist > summary { cursor: pointer; font-weight: 600; font-size: var(--fs-lg); }
.checklist-lista { list-style: none; margin: var(--sp-4) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.checklist-lista li { display: flex; align-items: flex-start; gap: var(--sp-3); }
.checklist-lista li .badge { flex: none; margin-top: 2px; }
.checklist-lista li > div { flex: 1; }
.checklist-lista li > a { flex: none; }
.campo-corto { max-width: 420px; }
.field.boton-campo { justify-content: flex-end; }

/* ---- Informe de resultados (impreso) y portal del paciente ---- */
.res-grande { font-size: 1.05rem; }
.sheet td.res-valor.res-fuera { font-weight: 700; }
.resumen-resultados { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-2) var(--sp-3); margin: var(--sp-3) 0; font-size: 0.9rem; }
.resumen-resultados.resumen-fuera { border-color: var(--warning); background: var(--warning-soft); color: var(--warning); }
.portal-main { max-width: 480px; margin: var(--sp-6) auto; padding: 0 var(--sp-4); }
.portal-marca { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.portal-lab { font-weight: 600; font-size: var(--fs-lg); }
.portal-pie { text-align: center; font-size: var(--fs-xs); color: var(--ink-faint); margin-top: var(--sp-5); }
a.primary-link.block, .stack a.primary-link { width: 100%; }
.card h2 .ind { margin-right: var(--sp-2); vertical-align: middle; }
@media print {
  /* En blanco y negro el indicador se lee por su forma y su palabra, no por el color */
  .ind { background: none !important; color: #000 !important; border: 1px solid #000; }
  .ind-critico { border-width: 2px; font-weight: 700; }
  .resumen-resultados, .resumen-resultados.resumen-fuera { background: none; color: #000; border-color: #000; }
}

/* ---- Utilidades que reemplazan estilos en línea ---- */
.precio { color: var(--accent-dark); }
.lista-compacta { margin: 6px 0 0 18px; padding: 0; }
.fila-between { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); }
.centrado { text-align: center; }
.texto-aviso { color: var(--warning); }
.exam-meta.texto-aviso { font-weight: 600; }
.h-sub { font-size: var(--fs-md); margin: var(--sp-4) 0 var(--sp-2); border: 0; padding: 0; }
.bloque-ingreso { border-top: 1px solid var(--border); margin-top: var(--sp-4); padding-top: var(--sp-4); }
.exam-block button.secondary { margin: var(--sp-2) var(--sp-2) 0 0; }
.hist-box { margin-top: var(--sp-2); font-size: var(--fs-xs); }
.hist-fila { padding: 6px 0; border-top: 1px dashed var(--border-soft); }

.orders-table td.mono { white-space: nowrap; }

/* ---- Capa de marca: superficies translúcidas sobre el fondo y transiciones ----
   Solo en pantalla. El vidrio (blur) va solo en barras, resumen, login y diálogos: un backdrop-filter
   crea contexto de apilamiento y taparía los menús desplegables que salen de las tarjetas. */
@media screen {
  header.app-header, .module-nav, .summary, .login-card, .modal-caja {
    -webkit-backdrop-filter: blur(16px) saturate(1.25); backdrop-filter: blur(16px) saturate(1.25);
  }
  header.app-header, .module-nav, .card, .exam-block, .summary, .stat-card, .cat-grupo, .login-card {
    background: var(--glass); border-color: var(--glass-border);
  }
  .modal-fondo { background: rgba(5, 10, 18, .60); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
  .modal-caja { background: rgba(18, 31, 50, .94); border-color: var(--glass-border); }
}
@keyframes entrar { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes velo { from { opacity: 0; } to { opacity: 1; } }
/* Ojo: <nav class="module-nav"> (position: fixed) vive dentro de <main>. Una animación de transform con
   fill-mode forwards/both convierte a main en su bloque contenedor y descoloca la barra: main solo anima
   opacidad, y las animaciones con transform usan fill-mode backwards (sin efecto al terminar). */
@media screen and (prefers-reduced-motion: no-preference) {
  .nav-chev { transition: transform .22s ease; }
  .nav-items { transition: grid-template-rows .24s ease; }
  .nav-group.cerrado .nav-items > div { transition: visibility 0s .24s; }
  .login-card, .login-foot { animation: entrar .45s cubic-bezier(.2, .7, .2, 1) backwards; }
  .login-foot { animation-delay: .1s; }
  .modal-fondo { animation: velo .2s ease-out both; }
  .modal-caja, .toast-host > * { animation: entrar .25s cubic-bezier(.2, .7, .2, 1) backwards; }
  button, a, input, select, textarea, summary, tbody tr, .test-item, .action-chip, .module-nav a {
    transition: background-color .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease, opacity .18s ease, transform .18s ease;
  }
  button.primary:not(:disabled):hover { transform: translateY(-1px); }
  button.primary:not(:disabled):active { transform: none; }
}

/* Cambio de pantalla suave: Chrome/Edge/Safari hacen fundido entre páginas y la barra lateral y el
   encabezado se quedan fijos (no parpadean). Sin soporte, main entra con un fundido corto.
   Ojo: no poner view-transition-name en main ni en sus ancestros (el nav fijo vive dentro de main). */
@media screen and (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  .module-nav { view-transition-name: nav-lateral; }
  header.app-header { view-transition-name: cabecera; }
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .12s; }
  @supports not (view-transition-name: none) { main { animation: velo .3s ease-out both; } }
}

/* ---- Pulido de uso diario (misma tipografía; solo estados y legibilidad) ---- */
html { scroll-padding-top: 84px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
main:focus { outline: none; }
.saltar { position: absolute; left: var(--sp-3); top: -60px; z-index: 2000; background: var(--accent); color: var(--accent-ink); padding: var(--sp-2) var(--sp-4); border-radius: var(--radius); font-weight: 600; text-decoration: none; }
.saltar:focus { top: var(--sp-3); }
::selection { background: rgba(90, 156, 227, .35); }
input::placeholder, textarea::placeholder { opacity: .8; }
input:hover:not(:disabled):not(:focus), select:hover:not(:disabled):not(:focus), textarea:hover:not(:disabled):not(:focus) { border-color: var(--ink-faint); }
input:disabled, select:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; }
button, a.secondary, select, summary { touch-action: manipulation; }
button:disabled { transform: none; }
.card table td { font-size: var(--fs-md); }
@media screen {
  table tbody tr:hover { background: rgba(143, 188, 238, .07); }
}

/* ---- Ayuda IA: ejemplos de consulta ---- */
.ejemplos { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin: var(--sp-4) 0; }
.ejemplo {
  background: transparent; color: var(--ink-muted); border: 1px solid var(--border); border-radius: 99px;
  padding: 4px 12px; font: inherit; font-size: var(--fs-sm); cursor: pointer; touch-action: manipulation;
}
.ejemplo:hover { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }

/* ---- Encabezado de tabla fijo en listas largas ----
   Solo en pantallas anchas: .table-wrap con overflow-x:auto es un contenedor de scroll y rompería el sticky
   respecto a la ventana; en anchos menores se conserva el desplazamiento horizontal. */
@media screen and (min-width: 1100px) {
  .table-wrap { overflow: visible; }
  .table-wrap table { border-collapse: separate; border-spacing: 0; }
  .table-wrap thead th { position: sticky; top: 64px; z-index: 5; }
}

/* Modo sin conexion (etapa 1) */
.offline-insignia { position: fixed; left: var(--sp-4); bottom: var(--sp-4); z-index: 50; min-height: 0; padding: 8px 14px; font-size: var(--fs-sm); border: 1px solid var(--border); border-radius: var(--radius); background: var(--glass, #111a28); color: var(--ink); cursor: pointer; }
.offline-insignia.con-conflicto { border-color: #d9534f; }
.franja-conexion { position: fixed; top: 72px; left: 50%; transform: translateX(-50%); z-index: 70; max-width: min(720px, 92vw); padding: 8px 16px; border-radius: var(--radius); font-size: var(--fs-sm); background: #1d3a2f; color: #d8f5e6; border: 1px solid #2f7a5a; text-align: center; }
.franja-conexion.sin-conexion { background: #4a1f1f; color: #fde2e2; border-color: #d9534f; }

/* ---- Tipografia estilo Apple (DESIGN.md): SF Pro en equipos Apple; en el resto Inter, el sustituto que recomienda
   DESIGN.md, con espaciado ajustado. Colores, fondos y formas del tema original no cambian. ---- */
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 100 900; font-display: swap; src: url('/fonts/inter-latin-wght.woff2') format('woff2'); }
:root {
  --font-body: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', 'Segoe UI', Roboto, sans-serif;
  --font-mono: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', 'Segoe UI', Roboto, sans-serif;
}
body { letter-spacing: -0.02em; font-feature-settings: 'ss03'; font-variant-numeric: tabular-nums; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.03em; line-height: 1.15; }

/* ---- Tema claro/oscuro (boton junto al usuario; public/js/tema.js). El oscuro es el de siempre. El claro usa
   exactamente la paleta clara original: solo cambian colores, no bordes, margenes ni tamanos. ---- */
@media screen {
  html[data-tema="claro"] {
    --glass: rgba(255, 255, 255, .92); --glass-border: #d5dce8;
    --bg: #f3f5f9; --surface: #ffffff; --border: #d5dce8; --border-soft: #e6eaf2; --control-border: #7d8aa3;
    --ink: #10203a; --ink-muted: #4a5870; --ink-faint: #5d6a82;
    --accent: #15599e; --accent-dark: #0d3c70; --accent-light: #3f8de0; --accent-ink: #ffffff; --accent-soft: #e3edf9;
    --success: #146c43; --success-soft: #e4f6ec; --warning: #855400; --warning-soft: #fbf0dc;
    --danger: #b3301f; --danger-soft: #fbe9e6; --danger-ink: #ffffff; --neutral: #4a5870; --neutral-soft: #eaeef6;
    --elevation-overlay: 0 8px 24px rgba(16, 32, 58, .22);
    color-scheme: light;
  }
  html[data-tema="claro"] body { background: #e6e6ea url('/img/login-bg-claro.svg') center / cover no-repeat fixed; }
  html[data-tema="claro"] .modal-fondo { background: rgba(16, 32, 58, .45); }
  html[data-tema="claro"] .modal-caja { background: var(--surface); }
  html[data-tema="claro"] table tbody tr:hover { background: rgba(21, 89, 158, .06); }
  html[data-tema="claro"] .login-foot { color: var(--ink-muted); }
  html[data-tema="claro"] .login-foot strong { color: var(--ink); }
  html[data-tema="claro"] button.danger.solid { color: #fff; }
  html[data-tema="claro"] button.danger.solid:hover { background: #8f2618; }
}
.tema-btn { width: 36px; height: 36px; min-height: 0; padding: 0; flex: none; line-height: 1; font-size: 16px; cursor: pointer; }
header.app-header .tema-btn { padding: 0; }
.tema-btn { color: var(--ink); display: inline-flex; align-items: center; justify-content: center; }
.tema-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tema-btn.flotante { position: fixed; left: 16px; top: 16px; z-index: 100; background: var(--surface); border: 1px solid var(--ink-faint); border-radius: var(--radius); }
@media print { .tema-btn { display: none; } }

/* Logo del menu: mas grande para ocupar el espacio libre. El isotipo es un SVG (vectorial): al ampliarlo no se pixela. */
.module-nav a.nav-brand { padding: var(--sp-4) var(--sp-2) var(--sp-5); gap: 14px; }
.module-nav a.nav-brand .nav-mark { width: 48px; height: 48px; }
.module-nav a.nav-brand .nav-brand-name { font-size: var(--fs-xl); letter-spacing: -0.03em; }
/* Alineado a la izquierda con el texto de los grupos del menu (RECEPCION, LABORATORIO...): mismo relleno lateral. */
.module-nav a.nav-brand { justify-content: flex-start; padding-left: var(--sp-2); }
/* El bloque del logo mide lo mismo que la cabecera y su linea inferior continua la de la cabecera: logo y titulo
   quedan a la misma altura. Solo en escritorio (en pantallas angostas el logo se oculta). */
@media (min-width: 901px) {
  header.app-header { min-height: 76px; }
  .module-nav a.nav-brand {
    height: 76px; margin: calc(var(--sp-3) * -1) calc(var(--sp-3) * -1) var(--sp-4);
    padding: 0 calc(var(--sp-3) + var(--sp-2)); border-bottom: 1px solid var(--border);
  }
}
/* Sin lineas alrededor del bloque del logo: se quita la de abajo y la divisoria lateral solo en esa franja
   (la lateral se redibuja con el mismo color y grosor desde debajo del logo hacia abajo). */
@media (min-width: 901px) {
  .module-nav a.nav-brand { border-bottom: 0; }
  .module-nav { border-right: 0; }
  .module-nav::after { content: ''; position: absolute; top: 76px; bottom: 0; right: 0; width: 1px; background: var(--border); pointer-events: none; }
}

/* Quitar un examen desde el resumen de la orden */
.quitar-examen { flex: none; width: 24px; height: 24px; min-height: 0; padding: 0; margin-right: var(--sp-2); border: 1px solid var(--border); background: transparent; color: var(--ink-muted); border-radius: var(--radius); font-size: var(--fs-xs); line-height: 1; cursor: pointer; }
.quitar-examen:hover { color: var(--danger); border-color: var(--danger); }
.summary-line .label { flex: 1; }

/* Botones de accion de una fila de resultados (Usar este paciente / Registrar hijo/a) */
.acciones-fila { display: flex; gap: var(--sp-2); flex-wrap: wrap; justify-content: flex-end; }

/* Representante de un menor: fila completa bajo los datos del paciente en los impresos */
.patient-rep { grid-column: 1 / -1; }
.patient-rep .lbl { font-weight: 600; color: var(--ink-muted); }

/* Lista de presupuestos realizados: una fila resumida por presupuesto; el detalle se abre con "Ver" */
.ppto-fila { border: 1px solid var(--border); border-radius: var(--radius); margin-top: var(--sp-2); background: var(--surface); overflow: hidden; }
.ppto-fila[open] { border-color: var(--accent); margin-top: var(--sp-4); margin-bottom: var(--sp-4); }
.ppto-fila > summary {
  display: grid; grid-template-columns: 150px 1fr 130px 90px 110px 56px; gap: var(--sp-3); align-items: center;
  padding: var(--sp-3) var(--sp-4); cursor: pointer; list-style: none; font-size: var(--fs-md);
}
.ppto-fila[open] > summary { background: var(--accent-soft); }
.ppto-fila > summary::-webkit-details-marker { display: none; }
.ppto-fila > summary:hover { background: var(--accent-soft); }
.ppto-paciente { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ppto-fecha { color: var(--ink-muted); font-size: var(--fs-sm); }
.ppto-ver { color: var(--accent); font-size: var(--fs-sm); font-weight: 600; text-align: right; }
.ppto-ver::before { content: 'Ver'; }
.ppto-fila[open] .ppto-ver::before { content: 'Ocultar'; }
.ppto-detalle { padding: var(--sp-4); border-top: 1px solid var(--accent); }
@media (max-width: 700px) {
  .ppto-fila > summary { grid-template-columns: 1fr auto; row-gap: var(--sp-1); }
  .ppto-fecha { grid-column: 1; }
}
.ppto-cabecera {
  display: grid; grid-template-columns: 150px 1fr 130px 90px 110px 56px; gap: var(--sp-3);
  padding: var(--sp-2) calc(var(--sp-4) + 1px) 0; font-size: var(--fs-xs); font-weight: 600;
  color: var(--ink-muted); text-transform: uppercase; letter-spacing: .04em;
}
@media (max-width: 700px) { .ppto-cabecera { display: none; } }

/* La lista queda separada del formulario de arriba (antes las tarjetas se tocaban) */
.ppto-lista { margin-top: var(--sp-6); }

/* Submenu (p. ej. Presupuestos): encabezado sin enlace y opciones con sangria */
.module-nav .nav-subtitulo { display: block; padding: var(--sp-2) var(--sp-3) var(--sp-1); font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
.module-nav a.nav-sub { padding-left: var(--sp-5); }
@media (max-width: 900px) {
  .module-nav .nav-subtitulo { display: none; }
  .module-nav a.nav-sub { padding-left: var(--sp-3); }
}

/* Resumen con descuento: subtotal y descuento, antes del total */
.summary-desglose { font-size: var(--fs-sm); color: var(--ink-muted); margin-top: var(--sp-3); }
.summary-desglose > div { display: flex; justify-content: space-between; padding: 2px 0; }

/* Hoja de impresos (recibo, presupuesto, resultados, cierre): en pantalla se ve como el papel, claro aunque la app sea oscura */
@media screen {
  .sheet {
    --bg: #f3f5f9; --surface: #ffffff; --border: #d5dce8; --border-soft: #e6eaf2; --control-border: #7d8aa3;
    --ink: #10203a; --ink-muted: #4a5870; --ink-faint: #5d6a82;
    --accent: #15599e; --accent-dark: #0d3c70; --accent-light: #3f8de0; --accent-soft: #e3edf9;
    --success: #146c43; --success-soft: #e4f6ec; --warning: #855400; --warning-soft: #fbf0dc;
    --danger: #b3301f; --danger-soft: #fbe9e6; --neutral: #4a5870; --neutral-soft: #eaeef6;
    background: #ffffff; color: var(--ink); box-shadow: none;
  }
}

.texto-enlace { display: block; text-align: center; margin-top: var(--sp-3); font-size: var(--fs-sm); }

/* Tablas como tarjetas en el telefono (Ordenes, Facturas): cada fila es una tarjeta con sus datos y su accion a la vista (la tabla escondia la accion fuera de pantalla) */
@media (max-width: 700px) {
  .tabla-tarjetas thead { display: none; }
  .tabla-tarjetas, .tabla-tarjetas tbody, .tabla-tarjetas tr, .tabla-tarjetas td { display: block; width: 100%; }
  .tabla-tarjetas tr { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: var(--sp-3); padding: var(--sp-2) var(--sp-3); background: var(--surface); }
  .tabla-tarjetas td { display: flex; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) 0; border: 0; text-align: right; }
  .tabla-tarjetas td::before { content: attr(data-label); flex: none; font-size: var(--fs-xs); font-weight: 600; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .04em; text-align: left; }
  .tabla-tarjetas td.accion-cell { display: block; text-align: left; min-width: 0; border-top: 1px solid var(--border-soft); margin-top: var(--sp-1); }
  .tabla-tarjetas td.accion-cell::before { content: none; }
}
/* Acciones apiladas en una tabla (Facturas): mismo ancho */
.acciones-apiladas { display: flex; flex-direction: column; gap: var(--sp-1); align-items: stretch; }
@media (max-width: 700px) {
  .tabla-tarjetas { overflow-x: visible; }
  .tabla-tarjetas tbody { min-width: 0; }
}
@media (max-width: 700px) { .tabla-tarjetas .actions-cell, .tabla-tarjetas .actions-cell.fila { min-width: 0; } }

/* ---------- Impresion de hojas (resultados, recibo, presupuesto, cierre): compacta y sin filas partidas ---------- */
@media print {
  @page { size: A4; margin: 11mm 12mm; }
  .sheet { max-width: none; padding: 0; font-size: 9.5pt; line-height: 1.35; }
  /* En papel A4 el ancho cae bajo el punto de corte de telefono: sin esto las tablas se volvian bloques con desplazamiento y los resultados salian cortados */
  .sheet table { display: table; width: 100%; overflow: visible; margin: 3px 0 10px; }
  /* Mas ancho para el nombre del parametro (los de 5 columnas de resultados); el resto se ajusta */
  .sheet table.tabla-resultados col:nth-child(1) { width: 38% !important; }
  .sheet table.tabla-resultados col:nth-child(2) { width: 15% !important; }
  .sheet table.tabla-resultados col:nth-child(3) { width: 12% !important; }
  .sheet table.tabla-resultados col:nth-child(4) { width: 17% !important; }
  .sheet table.tabla-resultados col:nth-child(5) { width: 18% !important; }
  .sheet table thead { display: table-header-group; width: auto; min-width: 0; }
  .sheet table tbody { display: table-row-group; width: auto; min-width: 0; }
  .sheet table th, .sheet table td { padding: 2px 6px; font-size: 9pt; }
  .sheet table th { font-size: 8pt; }
  .res-grande { font-size: 10pt; }
  .ind { padding: 0 6px; font-size: 7.5pt; gap: 3px; }
  .report-title { font-size: 12pt; margin: 4px 0 10px; }
  .lab-name { font-size: 11.5pt; }
  .patient-grid, .totals-grid { font-size: 8.5pt; gap: 1px 18px; margin-bottom: 8px; padding-bottom: 6px; }
  .resumen-resultados { margin: 6px 0; padding: 4px 8px; font-size: 8.5pt; }
  .exam-category { margin-top: 8px; padding: 3px 8px; font-size: 8pt; }
  .exam-label-row td { padding-top: 4px; padding-bottom: 4px; }
  .fine-print { margin-top: 10px; font-size: 7.5pt; }
  /* Ninguna fila se parte entre dos paginas, el titulo de cada grupo se queda con su primera fila y la cabecera de columnas se repite */
  .sheet tr { break-inside: avoid; page-break-inside: avoid; }
  .exam-category, .exam-label-row, .sheet thead tr { break-after: avoid; page-break-after: avoid; }
  .report-head, .patient-grid, .resumen-resultados, .sign-row { break-inside: avoid; page-break-inside: avoid; }
}

/* Vista de impresion que muestra el PDF (mismo documento que la descarga) */
.sheet.sheet-pdf { padding: 0; max-width: 860px; overflow: hidden; }
.pdf-frame { display: block; width: 100%; height: calc(100vh - 150px); min-height: 720px; border: 0; background: #fff; }
.pdf-ayuda { margin: 0; padding: 8px 14px; font-size: var(--fs-xs); color: var(--ink-muted); text-align: center; }
@media print { .sheet.sheet-pdf { display: none; } }
