/* OnFarmaNet · FarmaGuard — Design System: BASE (reset, elementos, shell, íconos).
 * Dirección "Clinical Precision". Depende de tokens.css. Cargar antes de components.css. */

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv05" 1, "cv09" 1, "ss03" 1;
  min-height: 100vh;
}
img, svg, video { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
a { color: var(--brand-strong); text-decoration: none; transition: color var(--ease); }
a:hover { color: var(--brand); }
::selection { background: var(--brand-soft); color: var(--brand-deep); }

/* ── Foco visible (accesibilidad) ── */
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: var(--r-xs); }
:focus:not(:focus-visible) { outline: none; }

/* ── Tipografía ── */
h1, h2, h3, h4 { line-height: var(--lh-tight); color: var(--ink); letter-spacing: var(--tracking-tight); font-weight: 650; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-md); font-weight: 600; letter-spacing: -0.01em; }
p { max-width: var(--measure); }
strong, b { font-weight: 600; color: var(--ink); }
code, kbd { font-family: var(--font-mono); font-size: 0.9em; }
hr { border: none; border-top: 1px solid var(--border); margin: var(--s-5) 0; }
:where(h1, h2, h3, .num, .tabular) { font-variant-numeric: tabular-nums; }

/* ── Íconos (sprite SVG inline, monolínea, hereda currentColor — CSP-safe) ── */
.sprite { display: none; }
.icon {
  width: 18px; height: 18px; flex: none; display: inline-block; vertical-align: middle;
  fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.icon--sm { width: 15px; height: 15px; }
.icon--lg { width: 22px; height: 22px; stroke-width: 1.5; }

/* ── Skip link ── */
.skip-link {
  position: absolute; left: var(--s-4); top: -56px; z-index: 100;
  background: var(--surface-raised); color: var(--brand-strong); font-weight: 600;
  padding: var(--s-2) var(--s-4); border-radius: var(--r-sm); box-shadow: var(--shadow-md);
  border: 1px solid var(--border); transition: top var(--ease);
}
.skip-link:focus { top: var(--s-3); }

/* ── App shell ── */
.app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__inner {
  /* El topbar respira más ancho que la columna de lectura (auditoría visual 2026-07-30): con
     nav de 5 destinos + chip de farmacia + logout, 1040px forzaba una segunda fila permanente. */
  max-width: min(calc(var(--container) + 160px), 100%); margin: 0 auto; min-height: var(--topbar-h);
  padding: var(--s-1) var(--s-5); display: flex; align-items: center; gap: var(--s-3);
  flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; gap: var(--s-3); color: var(--ink); flex-shrink: 0; }
.brand:hover { color: var(--ink); }
.brand__logo { width: 30px; height: 30px; border-radius: var(--r-sm); display: block; box-shadow: var(--shadow-xs); }
.brand__name { font-weight: 700; font-size: var(--fs-md); letter-spacing: -0.025em; }
.topbar__spacer { flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: nowrap; flex-shrink: 0; }

/* El nav envuelve a una segunda línea (flex-wrap en .topbar__inner) en vez de esconder ítems en
   una banda scrolleable sin indicador — el scroll oculto hacía indetectables 4 vistas (auditoría
   de producto 2026-07-14; antes, auditoría 2026-07-05 contra el scroll de página). DP-13
   (2026-07-16) fusionó los 9 destinos en 5 (Métricas agrupa las 5 vistas analíticas con .subnav),
   pero el wrap se conserva como defensa: la página nunca desborda horizontal. */
.topbar__nav { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-1); min-width: 0; }

/* Sub-navegación de "Métricas" (DP-13): banda de secciones bajo el page-head, reusa .navlink. */
.subnav {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-1);
  margin-bottom: var(--s-5); padding-bottom: var(--s-2); border-bottom: 1px solid var(--border);
}
.navlink {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: var(--fs-sm); font-weight: 550; color: var(--ink-muted);
  padding: var(--s-2) 10px; border-radius: var(--r-sm);
  transition: color var(--ease), background var(--ease);
}
.navlink:hover { color: var(--ink); background: var(--surface-sunken); }
.navlink[aria-current="page"] { color: var(--brand-strong); background: var(--brand-tint); }
.navlink .icon { color: var(--ink-subtle); }
.navlink:hover .icon, .navlink[aria-current="page"] .icon { color: currentColor; }

.rolechip {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-xs); font-weight: 600; color: var(--ink-muted);
  background: var(--surface); border: 1px solid var(--border);
  padding: 5px var(--s-3); border-radius: var(--r-pill); white-space: nowrap;
}
.rolechip .icon { color: var(--brand); }

/* ── Contenido ── */
.main { flex: 1; width: 100%; }
.container { max-width: var(--container); margin: 0 auto; padding: var(--s-7) var(--s-5); }
.container--narrow { max-width: var(--container-narrow); padding-top: var(--s-8); }

.page-head { margin-bottom: var(--s-6); }
.page-head h1 { margin-bottom: var(--s-2); }
.page-head .lede { color: var(--ink-muted); font-size: var(--fs-md); max-width: var(--measure); }

.eyebrow {
  display: inline-flex; align-items: center; gap: var(--s-2);
  color: var(--brand-strong); font-weight: 650; font-size: var(--fs-xs);
  letter-spacing: var(--tracking-wide); text-transform: uppercase; margin-bottom: var(--s-3);
}
.lede { font-size: var(--fs-lg); color: var(--ink-muted); line-height: 1.5; }

.backlink {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-sm); font-weight: 550; color: var(--ink-muted); margin-bottom: var(--s-4);
}
.backlink:hover { color: var(--brand-strong); }
.backlink .icon { transition: transform var(--ease); }
.backlink:hover .icon { transform: translateX(-2px); }

.stack > * + * { margin-top: var(--s-4); }
.stack-lg > * + * { margin-top: var(--s-6); }

/* ── Footer ── */
.footer { border-top: 1px solid var(--border); background: var(--surface-raised); margin-top: var(--s-9); }
.footer__inner {
  max-width: var(--container); margin: 0 auto; padding: var(--s-5) var(--s-5);
  display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-5);
  justify-content: space-between; align-items: center; color: var(--ink-muted); font-size: var(--fs-xs);
}
.footer__inner a { color: var(--ink-muted); text-decoration: underline; }
.footer__inner a:hover, .footer__inner a:focus-visible { color: var(--brand-strong); text-decoration: underline; }

/* §6b.2 (crítica de producto 2026-07-30): la nav JAMÁS queda solo-íconos — «Decisiones» no se
   decodifica de un ✓ y aria-label no arregla lo que el usuario vidente no puede leer. Bajo
   1100px el navlink se APILA (ícono arriba, etiqueta a 10px debajo): 5 destinos caben en 375px
   y el objetivo táctil crece solo. */
@media (max-width: 1100px) {
  .navlink { flex-direction: column; gap: 2px; padding: 6px var(--s-2); font-size: 0.625rem; /* 10px */ font-weight: 600; letter-spacing: 0.01em; }
  .navlink .icon { width: 16px; height: 16px; }
}

@media (max-width: 680px) {
  .topbar__inner { padding: var(--s-1) var(--s-3); gap: var(--s-1); }
  .container { padding: var(--s-6) var(--s-4); }
  /* Presupuesto de cromo (§6b.6): DOS filas deliberadas — [marca … identidad/salir] y debajo
     la nav a ancho completo repartida; sin esto la nav envolvía tras la marca y el header
     crecía a 3 filas (~22% del viewport). */
  .brand { order: 0; }
  .topbar__spacer { order: 1; }
  .topbar__actions { order: 2; }
  .topbar__nav { order: 3; width: 100%; justify-content: space-between; gap: 0; }
  /* Marca compacta en móvil. */
  .brand__logo { width: 26px; height: 26px; }
  .brand__name { font-size: var(--fs-base); }
  /* §6b c2: el chip CONSERVA el nombre (truncado) — la fila 1 nueva [marca … chip salir] tiene
     el ancho que antes no había (walkthrough m2 quedó superado por el header de 2 filas). Solo
     «Salir» colapsa a ícono (title lo conserva). */
  .rolechip span { max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .btn--logout span { display: none; }
  .section-head { margin: var(--s-6) 0 var(--s-3); }
  .section-head h2 { font-size: var(--fs-lg); }
}

/* Objetivo táctil mínimo 44px para la navegación icon-only en pantallas táctiles. */
@media (pointer: coarse) {
  .navlink { min-height: 44px; min-width: 44px; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ── Documento imprimible (reporte EPS → PDF nativo del navegador, Ctrl/⌘+P) ── */
.print-only { display: none; }
.doc-head { display: flex; align-items: flex-start; gap: var(--s-4); margin-bottom: var(--s-6); }
.doc-head__meta { color: var(--ink-muted); font-size: var(--fs-sm); line-height: 1.6; margin-top: var(--s-2); }
/* Pie del documento: nota DATO(regente)/AVAL(QF) + bloque de firma manual del QF (solo impreso). */
.doc-foot__nota { color: var(--ink-muted); font-size: var(--fs-sm); line-height: 1.6; margin-top: var(--s-5); }
.doc-foot__aval { margin-top: var(--s-6); line-height: 2; page-break-inside: avoid; }

@media print {
  .topbar, .footer, .skip-link, .backlink, .no-print { display: none !important; }
  .print-only { display: block; }
  .main { padding: 0; }
  .container { max-width: none; padding: 0; }
  body { background: #fff; }
  .table-wrap { border: none; box-shadow: none; border-radius: 0; overflow: visible; }
  .table tbody tr:hover td { background: transparent; }
  .table .row--total td { background: #f0f0f0; }
}

/* Apaisado + tabla compacta SOLO en el imprimible EPS (13 columnas): named page + `.doc-print`
   (lo pone `{% block body_class %}` de reporte_eps_imprimible.html). Antes `@page { size: landscape }`
   y el `.table … 11px` vivían sueltos en `@media print` → TODA página del sitio imprimía apaisada y
   cualquier tabla bajaba a 11px (auditoría 2026-07-05). */
@page apaisado { size: landscape; margin: 12mm; }
@media print {
  .doc-print { page: apaisado; }
  .doc-print .table th, .doc-print .table td { border: 1px solid #999; padding: 4px 6px; font-size: 11px; }
}
