/* Onfarmanet SAS · FarmaGuard — Design System: BASE (reset, elementos, shell, íconos).
 * Dirección v4 «Estación clínica de sello». Depende de tokens.css. Cargar antes de components.css.
 * SHELL: la consola con sesión de rol usa RAIL lateral (232px, decisión del dueño 2026-08-13);
 * las páginas sin nav de rol (login, cuentas, errores, legales) usan la BANDA oscura. El hijo
 * elige el shell sobreescribiendo {% block shell_open %} con _partials/shell_rail.html
 * (y shell_close con sus DOS cierres); el default de base.html es la banda. */

/* ── 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): anillo 2px offset 2, universal ── */
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: var(--r-xs); }
:focus:not(:focus-visible) { outline: none; }
.topbar :focus-visible { outline-color: #fff; }

/* ── Tipografía: Inter en 4 pesos REALES (400/500/600/700). Nunca 550/650 sintetizados. ── */
h1, h2, h3, h4 { color: var(--ink); letter-spacing: var(--tracking-tight); font-weight: 700; }
h1 { font-size: var(--fs-xl); line-height: var(--lh-tight); }
h2 { font-size: var(--fs-lg); line-height: 1.4118; }
h3 { font-size: var(--fs-sm); line-height: 1.2308; font-weight: 600; letter-spacing: -0.01em; }
p { max-width: var(--measure); }
strong, b { font-weight: 600; color: var(--ink); }
/* 0.9em RELATIVO a propósito: corrección óptica del mono (se ve ~8% más grande a igual cuerpo)
   en cualquier contexto — no es un tamaño de la escala. */
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: 16px; height: 16px; 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: 14px; height: 14px; }
.icon--lg { width: 24px; height: 24px; 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-md); box-shadow: var(--shadow-lg);
  border: 1px solid var(--border); transition: top var(--ease);
}
.skip-link:focus { top: var(--s-3); }

/* ══ APP SHELL · RAIL (consola con nav de rol) ══
   Grid de 2 columnas. El gradiente del fondo pinta la columna del rail a TODA la altura de la
   página (el rail es sticky de 100vh: sin el gradiente la columna se corta en páginas largas). */
.app { min-height: 100vh; }
.app--rail {
  display: grid; grid-template-columns: var(--rail-w) 1fr;
  background: linear-gradient(90deg, var(--surface-raised) 0, var(--surface-raised) calc(var(--rail-w) - 1px),
    var(--border) calc(var(--rail-w) - 1px), var(--border) var(--rail-w), var(--surface) var(--rail-w));
}
.rail {
  background: var(--surface-raised); border-right: 1px solid var(--border);
  padding: var(--s-4) var(--s-3); display: flex; flex-direction: column; gap: var(--s-4);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; scrollbar-width: thin;
}
.rail__brand { display: flex; align-items: center; gap: var(--s-2); padding: 0 var(--s-2); }
.brand { display: inline-flex; align-items: center; gap: var(--s-2); color: var(--ink); flex-shrink: 0; min-width: 0; }
.brand:hover { color: var(--ink); }
.brand__logo { width: 24px; height: 24px; border-radius: var(--r-xs); display: block; flex: none; }
.brand__name { font-weight: 600; font-size: var(--fs-lg); line-height: 1.4118; letter-spacing: -0.01em; }
/* Tarjeta de contexto: farmacia + modo del piloto (o ámbito, para el superadmin sin tenant). */
.tenant {
  border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-2) var(--s-3);
  display: flex; flex-direction: column; gap: var(--s-1); background: var(--surface);
}
.tenant__label { font-size: var(--fs-2xs); line-height: 1.4545; font-weight: 500; letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--ink-subtle); }
.tenant__name { font-size: var(--fs-sm); line-height: 1.2308; font-weight: 500; color: var(--ink); overflow-wrap: anywhere; }
/* .mode = sombra (warning: el motor registra sin mostrar alertas — estado de seguridad, no neutro);
   .mode--visible = alertas visibles (success). */
.mode { display: inline-flex; align-items: center; gap: var(--s-2); margin-top: var(--s-1); font-size: var(--fs-xs); line-height: 1.3333; font-weight: 500; color: var(--warning-text); }
.mode__dot { width: 8px; height: 8px; border-radius: var(--r-pill); background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); flex: none; }
.mode--visible { color: var(--success-text); }
.mode--visible .mode__dot { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
/* Navegación: el wrapper #menu es el destino del drawer móvil (:target, CSS-only bajo CSP 'self')
   y contiene nav principal + subnav de Métricas como HERMANOS (contrato de tests: aria-current
   único por <nav>). */
.navwrap { display: flex; flex-direction: column; gap: var(--s-1); flex: 1 1 auto; min-height: 0; }
.nav { display: flex; flex-direction: column; gap: var(--s-1); }
.navlink {
  display: flex; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-2); min-height: 32px;
  border-radius: var(--r-md); font-size: var(--fs-base); line-height: var(--lh-body); font-weight: 500;
  color: var(--ink-muted); white-space: nowrap;
  transition: color var(--ease), background var(--ease);
}
.navlink .icon { color: currentColor; }
.navlink:hover { color: var(--ink); background: var(--surface); }
.navlink:active { background: var(--surface-sunken); }
.navlink[aria-current="page"] { color: var(--brand-strong); background: var(--brand-tint); }
/* Sub-navegación de «Métricas» (DP-13): indentada bajo el destino, con rótulo de orientación. */
.subnav {
  display: flex; flex-direction: column; gap: var(--s-1);
  margin: 0 0 0 var(--s-3); padding-left: var(--s-2); border-left: 1px solid var(--border);
}
.subnav__label { font-size: var(--fs-2xs); line-height: 1.4545; font-weight: 500; letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--ink-subtle); padding: var(--s-1) var(--s-2) 0; }
.subnav .navlink { font-size: var(--fs-sm); min-height: 28px; }
.subnav .navlink .icon { width: 14px; height: 14px; }
/* Índice alfabético del contenido (kb_lista): FILA de chips. Antes reusaba .subnav, que en v4
   pasó a ser el sub-nav VERTICAL del rail — el índice quedó apilado en columna (re-caída cazada
   en la auditoría de pares v1↔v4 2026-08-17: clase compartida rediseñada sin censar consumidores). */
.azindex { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1); }
.azindex .navlink { min-width: 32px; min-height: 32px; justify-content: center; padding: 0 var(--s-2); font-size: var(--fs-sm); }
.rail__foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: var(--s-3); display: flex; flex-direction: column; gap: var(--s-2); }
.rolechip { display: flex; align-items: center; gap: var(--s-2); padding: 0 var(--s-2); color: var(--ink); min-width: 0; }
.rolechip:hover { color: var(--ink); }
.rolechip__avatar {
  width: 28px; height: 28px; border-radius: var(--r-pill); background: var(--brand-soft); color: var(--brand-strong);
  font-size: var(--fs-2xs); line-height: 1.4545; font-weight: 600; display: grid; place-items: center; flex: none;
}
.rolechip__meta { display: flex; flex-direction: column; min-width: 0; }
.rolechip__name { font-size: var(--fs-xs); line-height: 1.3333; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Rol en 2 líneas máx. (clamp, mismo patrón que .list-link .name > span): con nowrap+ellipsis,
   «Gerencia del cliente (métricas)» quedaba siempre cortado a «…(métric…» en el rail de 232px. */
.rolechip__role { font-size: var(--fs-2xs); line-height: 1.4545; color: var(--ink-subtle); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
/* Columna (no fila con wrap): los 3 enlaces no caben en el rail y el wrap partía el grupo en
   dos líneas desiguales («Cerrar sesión» huérfano). Mismo eje vertical que la nav de arriba. */
.rail__links { display: flex; flex-direction: column; align-items: stretch; gap: var(--s-1); }
.rail__links a, .rail__links .btn--logout {
  display: inline-flex; align-items: center; justify-content: flex-start; min-height: 24px; padding: var(--s-1) var(--s-2); border-radius: var(--r-md);
  font-size: var(--fs-xs); line-height: 1.3333; font-weight: 400; color: var(--ink-muted); background: none; border: 0; box-shadow: none;
}
.rail__links a:hover, .rail__links .btn--logout:hover { color: var(--ink); background: var(--surface); border: 0; }
.rail__links form { display: contents; }
.menu-btn {
  display: none; align-items: center; min-height: 32px; padding: var(--s-1) var(--s-3); margin-left: auto;
  border: 1px solid var(--border-strong); border-radius: var(--r-md); font-size: var(--fs-sm); line-height: 1.2308; font-weight: 600; color: var(--ink);
}
.menu-cerrar { display: none; }
.main { min-width: 0; background: var(--surface); display: flex; flex-direction: column; }
/* flex:1 (paridad banda:198): sin él, en vistas cortas el pie flotaba a media pantalla.
   Alcanza a div.main (item de grid: flex ignorado, inocuo) y a main.main (crece). */
.app--rail .main { flex: 1 1 auto; }

/* Cabecera editorial de vista (sin topbar: el título vive UNA vez aquí, el tenant UNA vez en el
   rail). Apila eyebrow / H1 / lede; el filtro de fechas queda a la derecha vía las reglas
   .container > .page-head:has(+ .form-inline) de abajo (no hay clase de acciones). */
.page-head { display: grid; gap: var(--s-1); align-content: end; min-width: 0; }
.page-head > * { min-width: 0; overflow-wrap: anywhere; }
.page-head h1 { margin-top: 0; }
/* Cabecera + filtro de fechas en la MISMA fila (decisiones/KPIs/puntos): el container los pone
   lado a lado cuando el filtro sigue inmediatamente a la cabecera. */
.container > .page-head:has(+ .form-inline) { grid-column: 1 / span 6; }
.container > .page-head + .form-inline { grid-column: 7 / -1; justify-self: end; align-self: end; margin: 0; }
.page-head .lede { color: var(--ink-muted); font-size: var(--fs-base); line-height: var(--lh-body); max-width: 620px; }
.page-head > p:not(.eyebrow):not(.lede) { color: var(--ink-muted); font-size: var(--fs-sm); line-height: 1.5385; }
.eyebrow {
  display: flex; align-items: center; gap: var(--s-2); width: fit-content;
  color: var(--brand-strong); font-weight: 600; font-size: var(--fs-2xs); line-height: 1.4545;
  letter-spacing: var(--tracking-wider); text-transform: uppercase;
}
.lede { font-size: var(--fs-base); line-height: var(--lh-body); color: var(--ink-muted); }
.backlink {
  display: flex; width: fit-content; align-items: center; gap: var(--s-2); min-height: 24px; padding: var(--s-1) 0; margin-bottom: var(--s-1);
  font-size: var(--fs-sm); line-height: 1.2308; font-weight: 500; color: var(--ink-muted); border-radius: var(--r-md);
}
.backlink:hover { color: var(--ink); }
.backlink .icon { width: 14px; height: 14px; transition: transform var(--ease); }
.backlink:hover .icon { transform: translateX(-2px); }
/* El contenido de la vista: lienzo de 12 columnas (las vistas apilan cards; el grid deja que
   los módulos declaren span vía clases s12/s8/s7/s6/s5/s4). */
.container { max-width: var(--container); width: 100%; padding: var(--s-6) var(--s-5) var(--s-5); display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--s-4); align-items: start; align-content: start; flex: 1; }
.container > * { grid-column: 1 / -1; min-width: 0; }
.stack > * + * { margin-top: var(--s-4); }
.stack-lg > * + * { margin-top: var(--s-6); }

/* ══ APP SHELL · BANDA (páginas sin nav de rol: auth, cuentas, errores, legales) ══ */
/* min-height 100vh (paridad v1): sin él, en páginas cortas el pie flotaba a media pantalla. */
.app--banda { display: flex; flex-direction: column; min-height: 100vh; }
/* sticky (paridad v1): el glosario y el panel son largos; la banda mantiene la salida a mano. */
.topbar { background: var(--banda); position: sticky; top: 0; z-index: 40; }
.topbar__inner { max-width: 1280px; margin: 0 auto; width: 100%; padding: 0 var(--s-5); height: var(--topbar-h); display: flex; align-items: center; gap: 20px; }
.topbar .brand__logo { width: 28px; height: 28px; }
.topbar .brand__name { color: #fff; }
.topbar__spacer { flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: var(--s-2); }
.topbar__link { display: inline-flex; align-items: center; min-height: 32px; padding: var(--s-1) var(--s-3); border-radius: var(--r-pill); font-size: var(--fs-base); line-height: var(--lh-body); font-weight: 500; color: var(--banda-text); white-space: nowrap; }
.topbar__link:hover { color: #fff; background: rgba(255, 255, 255, 0.07); }
/* Como <button> (Cerrar sesión por POST) hereda la defensa button:not(.btn) de components.css:
   se neutraliza aquí con la misma especificidad+orden (base.css carga antes; por eso va con
   el selector de elemento explícito). */
button.topbar__link { border: 0; background: transparent; box-shadow: none; }
button.topbar__link:hover { border: 0; background: rgba(255, 255, 255, 0.07); color: #fff; }
.topbar__actions form { display: contents; }
.app--banda .main { flex: 1; }
.app--banda .container { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-4); max-width: var(--container-narrow); margin: 0 auto; padding: var(--s-6) var(--s-5); }
.app--banda .container > * { grid-column: auto; }
/* Las variantes estrechas centran POR SÍ SOLAS (también fuera del shell: 500.html es
   autosuficiente y no extiende base.html). Doble clase (0-2-0): ganan a .container por
   especificidad, no por orden de archivo (r15 — el empate 0-1-0 era frágil). */
.container.container--narrow, .container.container--prose { grid-template-columns: minmax(0, 1fr); margin: 0 auto; padding: var(--s-6) var(--s-5); }
.container.container--narrow > *, .container.container--prose > * { grid-column: auto; }
.container.container--narrow { max-width: var(--container-narrow); }
.container.container--prose { max-width: var(--container-prose); }
.container--narrow .page-head, .container--prose .page-head { padding: 0; }
.app--banda .page-head { padding: 0; margin: 0; display: block; }
.app--banda .page-head h1 { margin-top: var(--s-1); }
.app--banda .page-head .lede { margin-top: var(--s-1); }
/* Sin ancla de shell: 500.html (autosuficiente, sin .app--banda) usa el mismo centrado (r15). */
.page-head.text-center { text-align: center; }
.page-head.text-center .eyebrow { margin: 0 auto; }
.page-head.text-center .lede { margin-left: auto; margin-right: auto; }
.pagina-auth .container { min-height: calc(100vh - var(--topbar-h) - 100px); align-content: center; max-width: 384px; padding: var(--s-5); }

/* ── Footer (pie legal común a los dos shells) ── */
.footer { border-top: 1px solid var(--border); margin-top: var(--s-5); }
.footer__inner {
  max-width: var(--container); padding: var(--s-4) var(--s-5);
  display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); align-items: center;
  color: var(--ink-subtle); font-size: var(--fs-xs); line-height: 1.3333;
}
.app--banda .footer__inner { max-width: 1280px; margin: 0 auto; width: 100%; }
.footer__inner a { display: inline-flex; align-items: center; min-height: 24px; padding: var(--s-1) 0; color: var(--ink-subtle); }
.footer__inner a:hover, .footer__inner a:focus-visible { color: var(--ink); }
.footer__inner > span:last-child { margin-left: auto; }

/* ══ Responsivo (ÚLTIMA capa: gana por orden de fuente) ══ */
@media (max-width: 720px) {
  .app--rail { grid-template-columns: 1fr; background: var(--surface); }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: none; border-bottom: 1px solid var(--border); padding: var(--s-3) var(--s-4); gap: var(--s-3); }
  .rail__brand { padding: 0; flex: 1; }
  .menu-btn { display: inline-flex; }
  .tenant { flex-direction: row; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-3); flex-basis: 100%; }
  .tenant__label { display: none; }
  .mode { margin-top: 0; }
  .navwrap { display: none; }
  /* Panel EN FLUJO, no modal (Codex 2026-08-16): un overlay fixed sin JS no puede contener el foco
     ni volver inerte el fondo (CSP 'self', drawer CSS-only) → el menú abierto empuja el contenido
     y nada queda tapado: el orden de tabulación es exactamente lo que se ve. */
  .navwrap:target { display: flex; flex-basis: 100%; padding-top: var(--s-3); border-top: 1px solid var(--border); }
  .navwrap:target .navlink { font-size: var(--fs-lg); line-height: 1.4118; min-height: 44px; }
  .navwrap:target .subnav .navlink { font-size: var(--fs-base); }
  .navwrap:target .menu-cerrar { display: flex; align-items: center; justify-content: flex-end; min-height: 32px; padding: var(--s-1) var(--s-2); border-radius: var(--r-md); font-size: var(--fs-sm); line-height: 1.2308; font-weight: 600; color: var(--ink-muted); }
  .navwrap:target .rail__foot { padding-top: var(--s-4); }
  .navwrap:target .rail__links a, .navwrap:target .rail__links .btn--logout { min-height: 44px; padding: var(--s-2) var(--s-3); font-size: var(--fs-base); line-height: 1.7143; }
  .page-head { padding: var(--s-5) var(--s-4) 0; }
  /* En móvil el filtro de fechas cae DEBAJO del título a ancho completo: mantener las dos
     columnas partía el H1 («Decisiones de dispensaci-ón») — cazado en la ronda visual 375. */
  /* selector COMPLETO: la regla de escritorio es 0-3-0 y una versión corta (0-2-0) perdería. */
  .container > .page-head:has(+ .form-inline) { grid-column: 1 / -1; }
  .container > .page-head + .form-inline { grid-column: 1 / -1; justify-self: stretch; }
  .container { padding: var(--s-4); gap: var(--s-3); }
  .footer__inner { padding: var(--s-4); }
  .topbar__inner { height: auto; padding: var(--s-3) var(--s-4); gap: var(--s-3); flex-wrap: wrap; }
  .app--banda .container { padding: var(--s-5) var(--s-4); }
}

@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-4); }
.doc-head__meta { color: var(--ink-muted); font-size: var(--fs-sm); line-height: 1.5385; margin-top: var(--s-2); }
.doc-foot__nota { color: var(--ink-muted); font-size: var(--fs-sm); line-height: 1.5385; margin-top: var(--s-4); }
.doc-foot__aval { margin-top: var(--s-5); line-height: 2; page-break-inside: avoid; }

@media print {
  .rail, .topbar, .footer, .skip-link, .backlink, .menu-btn, .no-print { display: none !important; }
  .print-only { display: block; }
  .app--rail { display: block; background: #fff; }
  /* .main pinta el papel (--surface) en pantalla: sin este reset, el PDF con fondos activados
     salía sobre papel verde en vez de documento blanco (Codex r11). */
  .main { padding: 0; background: #fff; display: block; }
  .container { max-width: none; padding: 0; display: block; }
  /* selectores 0-2-0 de pantalla (banda/auth) le ganaban al reset 0-1-0 (r15): mismo selector. */
  .app--banda .container, .pagina-auth .container { max-width: none; padding: 0; display: block; min-height: 0; align-content: start; }
  body { background: #fff; }
  /* Los resets de print de COMPONENTES (.table-wrap, filas, doc-print) viven al final de
     components.css: aquí perdían la cascada contra las reglas de pantalla de ese archivo
     (mismo selector, archivo posterior) — bug PREEXISTENTE en v1, medido y corregido
     2026-08-17 (Codex r9). */
}

/* Apaisado + tabla compacta SOLO en el imprimible EPS (13 columnas): named page + `.doc-print`. */
@page apaisado { size: landscape; margin: 12mm; }
@media print {
  .doc-print { page: apaisado; }
}
