/* ============================================================
   Laboratorio Clínico RM — Sistema "Plata" (DISENO.md)
   Tokens + clases ap-* · Temas claro / oscuro
   ============================================================ */

/* --- Tema Sol (default) --- */
:root {
  --ap-bg: #eaecee;
  --ap-bg-rgb: 234 236 238;
  --ap-sidebar: #fbfcfd;
  --ap-surface: #ffffff;
  --ap-surface-rgb: 255 255 255;
  --ap-surface-hover: #f4f5f7;
  --ap-primary: #1e2126;
  --ap-secondary: #4d5158;
  --ap-muted: #7b8087;
  --ap-accent: #6b7280;
  --ap-border: rgba(0, 0, 0, 0.08);
  --ap-border-light: rgba(0, 0, 0, 0.04);
  --ap-success: #059669;
  --ap-success-bg: #ecfdf5;
  --ap-brand: #059669;
  --ap-brand-bg: color-mix(in srgb, var(--ap-brand) 10%, transparent);
  --ap-amber: #d97706;
  --ap-amber-bg: #fef3e0;
  --ap-red: #ef4444;
  --ap-red-bg: #fdeaea;
  --ap-chart: #4f46e5;
  --ap-highlight: rgba(255, 255, 255, 0.9);
  --ap-shadow-sm: inset 0 1px 0 var(--ap-highlight), 0 1px 2px rgba(0, 0, 0, 0.06);
  --ap-shadow-md: inset 0 1px 0 var(--ap-highlight), 0 4px 14px rgba(0, 0, 0, 0.08);
  --ap-radius-sm: 6px;
  --ap-radius: 9px;
  --ap-radius-lg: 13px;
  --font-sans: "DM Sans", system-ui, sans-serif;
  --font-display: "Outfit", "DM Sans", sans-serif;
  --font-mono: "DM Mono", ui-monospace, monospace;
}

[data-font="clasica"] {
  --font-sans: Georgia, "Times New Roman", Times, serif;
  --font-display: Georgia, "Times New Roman", Times, serif;
}
[data-font="legible"] {
  --font-sans: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}
[data-font="tecnica"] {
  --font-sans: "DM Mono", ui-monospace, Consolas, monospace;
  --font-display: "DM Mono", ui-monospace, Consolas, monospace;
}

/* Tamaños de hoja — Carta por defecto */
:root,
[data-paper="carta"] {
  --paper-width: 216mm;
  --paper-height: 279mm;
}
[data-paper="a4"] {
  --paper-width: 210mm;
  --paper-height: 297mm;
}
[data-paper="oficio"] {
  --paper-width: 216mm;
  --paper-height: 356mm;
}

/* --- Tema Luna --- */
[data-theme="dark"] {
  --ap-bg: #0a0a09;
  --ap-bg-rgb: 10 10 9;
  --ap-sidebar: #111110;
  --ap-surface: #242422;
  --ap-surface-rgb: 36 36 34;
  --ap-surface-hover: #2f2f2c;
  --ap-primary: #f4f4f5;
  --ap-secondary: #b8b8be;
  --ap-muted: #828289;
  --ap-accent: #b8b8be;
  --ap-border: rgba(255, 255, 255, 0.1);
  --ap-border-light: rgba(255, 255, 255, 0.05);
  --ap-success: #10b981;
  --ap-success-bg: rgba(16, 185, 129, 0.1);
  --ap-brand: #10b981;
  --ap-brand-bg: color-mix(in srgb, var(--ap-brand) 15%, transparent);
  --ap-amber: #f59e0b;
  --ap-amber-bg: rgba(245, 158, 11, 0.1);
  --ap-red: #ef4444;
  --ap-red-bg: rgba(239, 68, 68, 0.1);
  --ap-highlight: transparent;
  --ap-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --ap-shadow-md: 0 4px 14px rgba(0, 0, 0, 0.5);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--ap-primary);
  background: var(--ap-bg);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Textura de puntos en main (§1 DISENO.md) */
.ap-page-shell {
  flex: 1;
  min-height: 0;
  max-width: none;
  margin: 0;
  padding: 12px 14px 14px;
  background-image: radial-gradient(circle, rgba(var(--ap-bg-rgb), 0) 0%, transparent 100%),
    radial-gradient(rgba(0, 0, 0, 0.04) 1px, transparent 1px);
  background-size: 100% 100%, 16px 16px;
  overflow: hidden;
}

[data-theme="dark"] .ap-page-shell {
  background-image: radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 16px 16px;
}

.ap-page-stack { display: flex; flex-direction: column; gap: 24px; }
.ap-page-stack-compact { gap: 16px; }

/* --- Menubar estilo macOS --- */
.menubar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 38px;
  padding: 0 12px;
  flex-shrink: 0;
  background: var(--ap-sidebar);
  border-bottom: 1px solid var(--ap-border);
  box-shadow: var(--ap-shadow-sm);
  z-index: 200;
  user-select: none;
  position: relative;
  overflow: visible;
}
.menubar__app {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  margin-right: 2px;
  border-right: 1px solid var(--ap-border-light);
  font-family: inherit;
  color: inherit;
  background: transparent;
  border-top: none;
  border-left: none;
  border-bottom: none;
  border-radius: 6px;
  cursor: pointer;
}
.menubar__app:hover { background: var(--ap-surface-hover); }
.menubar__logo {
  width: 22px;
  height: 22px;
  object-fit: contain;
  border-radius: 4px;
}
.menubar__app-name {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--ap-primary);
}
.menubar__menus {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 1;
  min-width: 0;
  overflow: visible;
}
.menubar__right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.menubar__user {
  font-size: 11.5px;
  color: var(--ap-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.menubar__perfil {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ap-brand);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 8px;
  background: var(--ap-brand-bg);
  border-radius: 999px;
}
.menubar__perfil:empty { display: none; }
.menubar__identidad {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.menubar__identidad-texto {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.menubar__rol-hint {
  font-size: 10px;
  color: var(--ap-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.menubar__status {
  font-size: 11.5px;
  color: var(--ap-muted);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menubar-menu { position: relative; }
.menubar-menu__trigger {
  padding: 4px 10px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--ap-primary);
  background: transparent;
  border: none;
  border-radius: 5px;
  cursor: default;
}
.menubar-menu__trigger:hover,
.menubar-menu--open .menubar-menu__trigger {
  background: var(--ap-surface-hover);
}
.menubar-menu__dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 200px;
  padding: 5px;
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  border-radius: 10px;
  box-shadow: var(--ap-shadow-md), 0 8px 32px rgba(0, 0, 0, 0.12);
  z-index: 300;
}
.menubar-menu__dropdown--wide { min-width: 260px; max-height: 70vh; overflow-y: auto; }
.menubar-menu--open .menubar-menu__dropdown { display: block; }
.menubar-menu__dropdown--flotante {
  display: block !important;
  position: fixed;
  z-index: 9999;
  max-height: min(70vh, 480px);
  overflow-y: auto;
}
.menubar-menu__item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 10px 6px 28px;
  font-family: var(--font-sans);
  font-size: 13px;
  text-align: left;
  color: var(--ap-primary);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: default;
  position: relative;
}
.menubar-menu__item:hover {
  background: #007aff;
  color: #fff;
}
[data-theme="dark"] .menubar-menu__item:hover {
  background: #0a84ff;
  color: #fff;
}
.menubar-menu__sep {
  height: 1px;
  margin: 4px 8px;
  background: var(--ap-border-light);
}
.menubar-menu__label {
  padding: 6px 12px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--ap-muted);
  pointer-events: none;
}
.menubar-menu__hint {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--ap-muted);
  font-style: italic;
}
.menubar-menu__item--checked { font-weight: 600; }
.menubar-check {
  position: absolute;
  left: 8px;
  width: 14px;
  font-size: 12px;
  text-align: center;
}
.menubar-menu__item--btn {
  padding: 4px 12px;
  width: auto;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius-sm);
  background: var(--ap-surface);
}

/* --- Bienvenida / Hub inicio --- */
.vista-inicio {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
}
.inicio-hub {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 8px 20px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.inicio-hub__hero {
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
}
.inicio-hub__logo {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: var(--ap-radius);
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  padding: 4px;
}
.inicio-hub__titulo {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--ap-primary);
  line-height: 1.2;
}
.inicio-hub__sub {
  font-size: 12.5px;
  color: var(--ap-muted);
  margin-top: 4px;
  line-height: 1.4;
}
.inicio-hub__acciones {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.hub-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 18px 16px;
  text-align: left;
  font-family: inherit;
  color: var(--ap-primary);
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius-lg);
  box-shadow: var(--ap-shadow-sm);
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
}
.hub-card:hover {
  border-color: var(--ap-accent);
  box-shadow: var(--ap-shadow-md);
  transform: translateY(-1px);
}
.hub-card--muted { opacity: 0.92; }
.hub-card__ic {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ap-secondary);
  background: var(--ap-surface-hover);
  border-radius: var(--ap-radius-sm);
  border: 1px solid var(--ap-border-light);
}
.hub-card__titulo {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
}
.hub-card__desc {
  font-size: 11.5px;
  color: var(--ap-muted);
  line-height: 1.35;
}
.inicio-hub__seccion {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--ap-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 10px;
}
.hub-reciente {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hub-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  font-family: inherit;
  color: var(--ap-primary);
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius);
  cursor: pointer;
  transition: background 0.12s;
}
.hub-chip:hover { background: var(--ap-surface-hover); }
.hub-chip__estudio { font-size: 13.5px; font-weight: 600; }
.hub-chip__meta { font-size: 11.5px; color: var(--ap-muted); }

.inicio-bienvenida {
  flex-shrink: 0;
  border-radius: var(--ap-radius-lg);
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  box-shadow: var(--ap-shadow-md);
}
.inicio-bienvenida__body {
  padding: 24px 22px;
  text-align: center;
}
.inicio-bienvenida__titulo {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--ap-primary);
  margin-bottom: 8px;
}
.inicio-bienvenida__texto {
  font-size: 13.5px;
  color: var(--ap-muted);
  max-width: 420px;
  margin: 0 auto 18px;
  line-height: 1.5;
}
.inicio-bienvenida__acciones {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

/* --- Vistas de lista --- */
.vista-lista {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  gap: 10px;
}
.lista-top {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.lista-top__titulo {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}
.lista-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 10px;
}
.lista-smartbar {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius-lg);
  box-shadow: var(--ap-shadow-sm);
}
.lista-smartbar__buscar {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}
.lista-smartbar__icon {
  position: absolute;
  left: 12px;
  font-size: 15px;
  color: var(--ap-muted);
  pointer-events: none;
  z-index: 1;
}
.lista-smartbar__input {
  width: 100%;
  padding-left: 36px;
  min-height: 40px;
  font-size: 14px;
}
.lista-smartbar__hint {
  font-size: 11.5px;
  color: var(--ap-muted);
  line-height: 1.4;
}
.lista-smartbar__hint kbd {
  display: inline-block;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ap-secondary);
  background: var(--ap-surface-hover);
  border: 1px solid var(--ap-border);
  border-radius: 4px;
}
.lista-filtros-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px 14px;
  padding-top: 4px;
  border-top: 1px solid var(--ap-border-light);
}
.lista-filtro {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.lista-filtro__label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.35px;
  color: var(--ap-muted);
}
.lista-filtro__select {
  min-height: 36px;
  font-size: 13px;
  padding: 6px 10px;
}
.lista-filtros-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-height: 0;
}
.lista-filtros-activos {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
.lista-filtros-activos:empty { display: none; }
.filtro-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ap-secondary);
  background: var(--ap-bg);
  border: 1px solid var(--ap-border);
  border-radius: 999px;
}
.filtro-tag__x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 14px;
  line-height: 1;
  color: var(--ap-muted);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
.filtro-tag__x:hover {
  color: var(--ap-primary);
  background: var(--ap-surface-hover);
}
.lista-filtros-limpiar {
  flex-shrink: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--ap-brand);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.lista-filtros-limpiar:hover { opacity: 0.85; }
.lista-stats {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--ap-muted);
  padding: 0 4px;
}
.lista-stats strong {
  color: var(--ap-primary);
  font-weight: 600;
}
.lista-cards {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 8px;
}
.lista-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  text-align: left;
  font-family: inherit;
  color: var(--ap-primary);
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius);
  box-shadow: var(--ap-shadow-sm);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
}
.lista-card:hover {
  background: var(--ap-surface-hover);
  border-color: var(--ap-brand);
  transform: translateY(-1px);
}
.lista-card__avatar {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  color: var(--ap-brand);
  background: var(--ap-brand-bg);
  border-radius: 10px;
}
.lista-card__avatar--estudio {
  font-size: 11px;
  letter-spacing: -0.3px;
}
.lista-card__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.lista-card__head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.lista-card__nombre {
  font-size: 14px;
  font-weight: 600;
}
.lista-card__badge {
  font-size: 10px;
  padding: 2px 8px;
}
.lista-card__meta {
  font-size: 12.5px;
  color: var(--ap-secondary);
}
.lista-card__sub {
  font-size: 11.5px;
  color: var(--ap-muted);
}
.lista-card__aside {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.lista-card__fecha {
  font-size: 11px;
  font-weight: 500;
  color: var(--ap-muted);
  white-space: nowrap;
}
.lista-card__action {
  font-size: 14px;
  color: var(--ap-muted);
  opacity: 0.5;
  transition: opacity 0.12s, transform 0.12s;
}
.lista-card:hover .lista-card__action {
  opacity: 1;
  color: var(--ap-success);
  transform: translateX(2px);
}
.lista-vacia {
  padding: 32px 20px;
  text-align: center;
  color: var(--ap-muted);
  font-size: 14px;
}
.lista-vacia--panel {
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius-lg);
  padding: 40px 24px;
}
.lista-vacia__hint {
  font-size: 12.5px;
  margin: 8px 0 16px;
}

/* --- Roles de usuario --- */
.rol-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-radius: 999px;
  white-space: nowrap;
}
.rol-badge--sm { font-size: 9px; padding: 2px 7px; }
.rol-badge--violet { color: #5b21b6; background: #ede9fe; }
.rol-badge--indigo { color: #3730a3; background: #e0e7ff; }
.rol-badge--emerald { color: #047857; background: #d1fae5; }
[data-theme="dark"] .rol-badge--violet { color: #c4b5fd; background: rgba(91, 33, 182, 0.25); }
[data-theme="dark"] .rol-badge--indigo { color: #a5b4fc; background: rgba(55, 48, 163, 0.25); }
[data-theme="dark"] .rol-badge--emerald { color: #6ee7b7; background: rgba(4, 120, 87, 0.25); }
.rol-panel {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rol-panel__desc {
  font-size: 12px;
  color: var(--ap-secondary);
  line-height: 1.4;
}
.rol-panel__alcance {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ap-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.cuenta-rol-panel { margin: 4px 0; }

/* --- Navegación móvil inferior --- */
.mobile-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 150;
  padding: 6px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: rgba(var(--ap-surface-rgb), 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--ap-border);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.mobile-nav__btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 500;
  color: var(--ap-muted);
  background: transparent;
  border: none;
  border-radius: var(--ap-radius-sm);
  cursor: pointer;
  min-height: 48px;
}
.mobile-nav__btn--active {
  color: var(--ap-primary);
  background: var(--ap-surface-hover);
}
.mobile-nav__ic {
  font-size: 18px;
  line-height: 1;
}

/* --- Layout inicio: ficha | estudios --- */
.inicio-layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 12px;
  height: 100%;
  min-height: 0;
}
.inicio-ficha,
.inicio-estudios {
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.inicio-estudios { gap: 12px; }
.ap-panel--fill {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.ap-panel--fill .ap-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}
.ap-panel-hint {
  font-size: 11.5px;
  color: var(--ap-muted);
}
.ap-ficha-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}
.ap-ficha-grid .ap-field--full { grid-column: 1 / -1; }
.ap-textarea--compact { min-height: 48px; resize: vertical; }

/* --- Vista captura / reporte --- */
.vista-captura,
.vista-reporte {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.captura-layout {
  display: grid;
  grid-template-columns: minmax(200px, 260px) 1fr;
  gap: 12px;
  flex: 1;
  min-height: 0;
}
.captura-ficha { min-height: 0; display: flex; flex-direction: column; }
.captura-ficha__body { display: flex; flex-direction: column; gap: 10px; }
.captura-ficha__item { display: flex; flex-direction: column; gap: 2px; }
.captura-ficha__label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--ap-muted);
}
.captura-ficha__valor {
  font-size: 13px;
  font-weight: 500;
  color: var(--ap-primary);
  line-height: 1.35;
}
.captura-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-content: start;
}
.captura-grid .ap-panel--span { grid-column: 1 / -1; }
.captura-tablas-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.captura-tabla-col { min-width: 0; }
.captura-top {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  padding: 4px 2px 10px;
}
.captura-top__acciones {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.captura-top__hint {
  font-size: 11.5px;
  color: var(--ap-muted);
  max-width: 220px;
  line-height: 1.35;
  text-align: right;
}
.captura-top--reporte {
  justify-content: space-between;
}
.captura-scroll,
.reporte-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 8px;
}
.reporte-scroll { align-items: center; }
.btn--sm {
  padding: 6px 12px;
  font-size: 12.5px;
  min-height: auto;
}
.ap-card-action {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  font-size: 14px;
  color: var(--ap-muted);
  border-radius: var(--ap-radius-sm);
  transition: background 0.12s, color 0.12s;
}
.ap-card-interactive:hover .ap-card-action {
  background: var(--ap-surface-hover);
  color: var(--ap-primary);
}

/* --- Tabs / theme switcher --- */
.ap-tabs-filter {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--ap-surface-hover);
  border: 1px solid var(--ap-border-light);
  border-radius: var(--ap-radius);
}
.ap-tab-trigger {
  padding: 4px 10px;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ap-muted);
  background: transparent;
  border: none;
  border-radius: var(--ap-radius-sm);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.ap-tab-trigger:hover { color: var(--ap-secondary); background: var(--ap-surface); }
.ap-tab-trigger--active {
  color: var(--ap-primary);
  background: var(--ap-surface);
  box-shadow: var(--ap-shadow-sm);
}
.ap-tab-trigger:focus-visible { outline: 2px solid var(--ap-accent); outline-offset: 1px; }

/* --- Panel --- */
.ap-panel {
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius-lg);
  box-shadow: var(--ap-shadow-md);
  overflow: hidden;
}
.ap-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--ap-border-light);
  box-shadow: inset 0 1px 0 var(--ap-highlight);
  background: var(--ap-surface);
}
.ap-panel-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--ap-primary);
}
.ap-panel-body { padding: 18px; }

.ap-section-divider {
  height: 1px;
  background: var(--ap-border-light);
}
.ap-section-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ap-section-toolbar--end { justify-content: flex-end; }
.ap-section-toolbar--wrap { flex-wrap: wrap; }

/* --- Sedes --- */
.ap-sedes-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.ap-sede-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 14px 16px;
  text-align: left;
  font-family: inherit;
  color: var(--ap-primary);
  background: var(--ap-surface);
  border: 2px solid var(--ap-border);
  border-radius: var(--ap-radius);
  box-shadow: var(--ap-shadow-sm);
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.ap-sede-card:hover { background: var(--ap-surface-hover); }
.ap-sede-card--active {
  border-color: var(--ap-primary);
  box-shadow: var(--ap-shadow-md);
}
.ap-sede-card:focus-visible { outline: 2px solid var(--ap-accent); outline-offset: 2px; }
.ap-sede-card__nombre {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ap-primary);
}
.ap-sede-card__dir,
.ap-sede-card__tel {
  font-size: 11.5px;
  color: var(--ap-muted);
  line-height: 1.35;
}

/* --- Formulario --- */
.ap-account-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px 16px;
}
.ap-field { display: flex; flex-direction: column; gap: 5px; }
.ap-field--wide { grid-column: span 2; }
.ap-field--full { grid-column: 1 / -1; }
.ap-field__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ap-muted);
}
.ap-input {
  width: 100%;
  padding: 8px 10px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  color: var(--ap-primary);
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius-sm);
  box-shadow: var(--ap-shadow-sm);
  transition: border-color 0.12s;
}
.ap-input::placeholder { color: var(--ap-muted); }
.ap-input:focus {
  outline: none;
  border-color: var(--ap-accent);
}
.ap-input:focus-visible { outline: 2px solid var(--ap-accent); outline-offset: 1px; }
.ap-select { appearance: none; cursor: pointer; }
.ap-textarea {
  resize: vertical;
  min-height: 68px;
  line-height: 1.45;
}

/* --- Barra de acciones captura --- */
.captura-barra {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 4px;
}

/* --- Grid de estudios (ap-card-interactive) --- */
.ap-estudios-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.ap-card-interactive {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  font-family: inherit;
  color: var(--ap-primary);
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius);
  box-shadow: var(--ap-shadow-sm);
  cursor: pointer;
  transition: background 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.ap-card-interactive:hover {
  background: var(--ap-surface-hover);
  box-shadow: var(--ap-shadow-md);
  border-color: var(--ap-border);
}
.ap-card-interactive:focus-visible {
  outline: 2px solid var(--ap-accent);
  outline-offset: 2px;
}
.ap-list-ic {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.3px;
  color: var(--ap-secondary);
  background: var(--ap-surface-hover);
  border: 1px solid var(--ap-border-light);
  border-radius: var(--ap-radius-sm);
}
.ap-list-body { flex: 1; min-width: 0; }
.ap-list-name {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ap-primary);
}
.ap-list-desc {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ap-muted);
  margin-top: 1px;
}

/* --- Tabla de captura --- */
.ap-table-wrap { overflow-x: auto; }
.ap-table {
  width: 100%;
  border-collapse: collapse;
}
.ap-table-header th {
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--ap-muted);
  text-align: left;
  border-bottom: 1px solid var(--ap-border);
  background: var(--ap-surface-hover);
}
.ap-table-row td {
  padding: 8px 14px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--ap-border-light);
  vertical-align: middle;
}
.ap-table-row:last-child td { border-bottom: none; }
.ap-table-row .col-analito { font-weight: 500; color: var(--ap-primary); }
.ap-table-row .col-unidad,
.ap-table-row .col-referencia {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ap-muted);
}
.ap-table-row .col-resultado input,
.ap-table-row .col-resultado select {
  width: 100%;
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ap-primary);
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius-sm);
}
.ap-table-row .col-resultado input:focus,
.ap-table-row .col-resultado select:focus {
  outline: none;
  border-color: var(--ap-accent);
}
.ap-table-row .col-resultado input:focus-visible,
.ap-table-row .col-resultado select:focus-visible {
  outline: 2px solid var(--ap-accent);
  outline-offset: 1px;
}
.ap-table--compact .ap-table-header th {
  padding: 5px 8px;
  font-size: 10px;
}
.ap-table--compact .ap-table-row td {
  padding: 4px 8px;
  font-size: 12.5px;
}
.ap-table--compact .ap-table-row .col-resultado input,
.ap-table--compact .ap-table-row .col-resultado select {
  padding: 4px 6px;
  font-size: 12px;
}
.ap-table--compact .ap-table-row .col-unidad,
.ap-table--compact .ap-table-row .col-referencia {
  font-size: 11px;
}

/* --- Botones --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--ap-radius-sm);
  cursor: pointer;
  transition: background 0.12s, box-shadow 0.12s;
}
.btn:focus-visible { outline: 2px solid var(--ap-accent); outline-offset: 2px; }
.btn--primary {
  color: #fff;
  background: var(--ap-brand);
  border-color: var(--ap-brand);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
[data-theme="dark"] .btn--primary {
  color: #fff;
  background: var(--ap-brand);
  border-color: var(--ap-brand);
}
.btn--primary:hover {
  filter: brightness(0.92);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.btn--xs {
  padding: 3px 10px;
  font-size: 11.5px;
  min-height: auto;
}
.btn--secondary {
  color: var(--ap-secondary);
  background: var(--ap-surface);
  border-color: var(--ap-border);
  box-shadow: var(--ap-shadow-sm);
}
.btn--secondary:hover { background: var(--ap-surface-hover); }
.btn--ghost {
  color: var(--ap-secondary);
  background: transparent;
  border-color: var(--ap-border);
}
.btn--ghost:hover { background: var(--ap-surface-hover); }
.btn--whatsapp {
  color: #fff;
  background: #25d366;
  border-color: #20bd5a;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.btn--whatsapp:hover {
  filter: brightness(0.94);
  box-shadow: 0 2px 6px rgba(37, 211, 102, 0.35);
}
[data-theme="dark"] .btn--whatsapp {
  color: #fff;
  background: #25d366;
  border-color: #20bd5a;
}

/* --- Modales --- */
.ap-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.ap-modal.oculto { display: none !important; }
.ap-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}
.ap-modal__panel {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: min(90vh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius-lg);
  box-shadow: var(--ap-shadow-md);
  overflow: hidden;
}
.ap-modal__panel--wide { max-width: 520px; }
.ap-modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--ap-border-light);
}
.ap-modal__titulo {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--ap-primary);
}
.ap-modal__sub {
  font-size: 12.5px;
  color: var(--ap-muted);
  margin-top: 4px;
}
.ap-modal__cerrar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  font-size: 22px;
  line-height: 1;
  color: var(--ap-muted);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.ap-modal__cerrar:hover {
  background: var(--ap-surface-hover);
  color: var(--ap-primary);
}
.ap-modal__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.ap-modal__foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 18px;
  border-top: 1px solid var(--ap-border-light);
}

/* --- WhatsApp UI --- */
.wa-estado {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--ap-surface-hover);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius);
}
.wa-estado__punto {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.wa-estado__punto--off { background: var(--ap-muted); }
.wa-estado__punto--wait { background: var(--ap-amber); animation: wa-pulse 1.2s ease infinite; }
.wa-estado__punto--on { background: #25d366; }
@keyframes wa-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
.wa-estado__texto {
  font-size: 13px;
  font-weight: 600;
  color: var(--ap-primary);
}
.wa-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--ap-bg);
  border-radius: var(--ap-radius);
}
.wa-tab {
  flex: 1;
  padding: 8px 12px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ap-muted);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.wa-tab:hover { color: var(--ap-primary); }
.wa-tab--activo {
  color: var(--ap-primary);
  background: var(--ap-surface);
  box-shadow: var(--ap-shadow-sm);
}
.wa-panel__desc {
  font-size: 12.5px;
  color: var(--ap-secondary);
  line-height: 1.45;
  margin-bottom: 12px;
}
.wa-qr-wrap {
  display: flex;
  justify-content: center;
  padding: 8px 0;
}
.wa-qr-placeholder {
  width: 220px;
  height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  text-align: center;
  background: var(--ap-bg);
  border: 2px dashed var(--ap-border);
  border-radius: var(--ap-radius);
}
.wa-qr-placeholder__icon {
  font-size: 48px;
  color: var(--ap-muted);
  opacity: 0.5;
}
.wa-qr-placeholder__texto {
  font-size: 12.5px;
  color: var(--ap-secondary);
  line-height: 1.4;
}
.wa-qr-placeholder__hint {
  font-size: 11px;
  color: var(--ap-muted);
  line-height: 1.35;
}
.wa-qr-img {
  width: 220px;
  height: 220px;
  object-fit: contain;
  border-radius: var(--ap-radius);
  border: 1px solid var(--ap-border);
}
.wa-codigo-input {
  font-family: var(--font-mono);
  font-size: 18px;
  letter-spacing: 0.15em;
  text-align: center;
  text-transform: uppercase;
}
.wa-codigo-generado {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--ap-border-light);
}
.wa-codigo-display {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-align: center;
  padding: 14px;
  margin: 8px 0;
  color: var(--ap-primary);
  background: var(--ap-bg);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius);
}
.wa-sesion-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--ap-border-light);
}
.wa-enviar-estado {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--ap-secondary);
  background: var(--ap-amber-bg);
  border: 1px solid var(--ap-amber);
  border-radius: var(--ap-radius);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* --- Personalizar --- */
.pers-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--ap-bg);
  border-radius: var(--ap-radius);
}
.pers-tab {
  flex: 1;
  padding: 8px 12px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ap-muted);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.pers-tab--activo {
  color: var(--ap-primary);
  background: var(--ap-surface);
  box-shadow: var(--ap-shadow-sm);
}
.pers-panel__intro {
  font-size: 12.5px;
  color: var(--ap-secondary);
  line-height: 1.45;
  margin-bottom: 4px;
}
.pers-seccion { margin-bottom: 4px; }
.pers-seccion__titulo {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.35px;
  color: var(--ap-muted);
  margin-bottom: 8px;
}
.pers-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pers-chip {
  padding: 7px 14px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ap-secondary);
  background: var(--ap-surface-hover);
  border: 1px solid var(--ap-border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.pers-chip:hover { border-color: var(--ap-accent); }
.pers-chip--activo {
  color: #fff;
  background: var(--ap-brand);
  border-color: var(--ap-brand);
}
.pers-perfiles-layout {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 16px;
  min-height: 280px;
}
.pers-perfiles-lista-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.pers-perfiles-lista {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}
.pers-perfil-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  font-family: inherit;
  color: var(--ap-primary);
  background: var(--ap-surface-hover);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.pers-perfil-item:hover { border-color: var(--ap-accent); }
.pers-perfil-item--activo {
  border-color: var(--ap-brand);
  background: var(--ap-brand-bg);
}
.pers-perfil-item__avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ap-brand);
  background: var(--ap-surface);
  border-radius: 8px;
}
.pers-perfil-item__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pers-perfil-item__nombre {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pers-perfil-item__cargo {
  font-size: 11px;
  color: var(--ap-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pers-perfil-item__badge {
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--ap-brand);
  padding: 3px 7px;
  background: var(--ap-surface);
  border-radius: 4px;
}
.pers-perfil-form-wrap {
  padding: 12px 14px;
  background: var(--ap-bg);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius);
}
.pers-perfil-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.pers-perfil-form__acciones {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}
.pers-firma-preview {
  padding: 10px 12px;
  background: var(--ap-surface);
  border: 1px dashed var(--ap-border);
  border-radius: var(--ap-radius-sm);
}
.pers-firma-preview__linea {
  display: block;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--ap-primary);
  text-align: center;
  font-size: 12px;
  color: var(--ap-muted);
}

/* --- Badge --- */
.ap-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ap-secondary);
  background: var(--ap-surface-hover);
  border: 1px solid var(--ap-border-light);
  border-radius: var(--ap-radius-sm);
}

/* --- Toast (reemplaza alert) --- */
.ap-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ap-primary);
  background: var(--ap-surface);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius);
  box-shadow: var(--ap-shadow-md);
  z-index: 1000;
  animation: toast-in 0.2s ease;
}
.ap-toast--warning {
  color: var(--ap-amber);
  background: var(--ap-amber-bg);
  border-color: var(--ap-amber);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* --- Hoja de reporte (vertical / impresión) --- */
.hoja-reporte {
  position: relative;
  overflow: hidden;
  background: #ffffff;
  color: #1e2126;
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius-lg);
  box-shadow: var(--ap-shadow-md);
  max-width: var(--paper-width);
  min-height: var(--paper-height);
  margin: 0 auto;
  --watermark-opacity: 0.14;
}
.hoja-reporte::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: var(--watermark-url, none) center center / 58% no-repeat;
  opacity: var(--watermark-opacity);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.hoja-reporte__watermark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 0;
}
.hoja-reporte__watermark img {
  width: 58%;
  max-width: 320px;
  opacity: var(--watermark-opacity);
  object-fit: contain;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.hoja-reporte__contenido {
  position: relative;
  z-index: 1;
  padding: 28px 32px 36px;
}
.reporte-encabezado {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 2px solid #1e2126;
}
.reporte-encabezado__lab {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.reporte-encabezado__logo-img {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  object-fit: contain;
}
.reporte-encabezado__nombre {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: #1e2126;
  line-height: 1.25;
}
.reporte-encabezado__sub { font-size: 11px; color: #7b8087; }
.reporte-encabezado__contacto {
  flex-shrink: 0;
  max-width: 42%;
  text-align: right;
  font-size: 10.5px;
  line-height: 1.45;
  color: #4d5158;
}
.reporte-paciente {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px 16px;
  padding: 12px 0;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 12.5px;
}
.reporte-paciente__item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.reporte-paciente__label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #7b8087;
}
.reporte-paciente__valor {
  font-weight: 500;
  color: #1e2126;
}
.reporte-titulo-estudio {
  text-align: center;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #1e2126;
  margin: 16px 0 12px;
}
.reporte-cuerpo {
  margin-bottom: 8px;
}
.reporte-seccion__titulo {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: #1e2126;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  padding-bottom: 4px;
  margin: 14px 0 6px;
}
.tabla-reporte { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.tabla-reporte th {
  padding: 5px 8px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #7b8087;
  text-align: left;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.tabla-reporte td {
  padding: 5px 8px;
  font-size: 13px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}
.tabla-reporte .celda-resultado {
  font-family: var(--font-mono);
  font-weight: 500;
  color: #1e2126;
}
.tabla-reporte .celda-ref {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #7b8087;
}
.reporte-firma {
  margin-top: 96px;
  padding-top: 16px;
  display: flex;
  justify-content: flex-end;
}
.reporte-firma__linea {
  width: 220px;
  padding-top: 6px;
  border-top: 1px solid #1e2126;
  text-align: center;
  font-size: 12px;
  color: #7b8087;
}
.reporte-pie {
  margin-top: 24px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  text-align: center;
  font-size: 10.5px;
  color: #7b8087;
}

/* --- Utilidades --- */
.oculto { display: none !important; }

/* --- Responsive --- */
@media (max-width: 900px) {
  body { overflow: auto; }
  .ap-page-shell { overflow: visible; min-height: calc(100vh - 38px); }
  .inicio-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - 62px);
  }
  .inicio-ficha { max-height: none; }
  .ap-panel--fill { min-height: auto; }
  .ap-panel--fill .ap-panel-body { overflow: visible; max-height: none; }
  .ap-account-grid { grid-template-columns: 1fr 1fr; }
  .ap-field--wide { grid-column: span 2; }
  .ap-estudios-grid { grid-template-columns: 1fr 1fr; }
  .vista-captura,
  .vista-reporte { height: auto; min-height: calc(100vh - 62px); }
  .captura-layout { grid-template-columns: 1fr; }
  .captura-grid { grid-template-columns: 1fr; }
  .captura-tablas-split { grid-template-columns: 1fr; }
  .captura-scroll,
  .reporte-scroll { overflow: visible; }
}

@media (max-width: 640px) {
  body { padding-bottom: 64px; }
  .mobile-nav { display: grid; }
  .menubar-menu--desktop { display: none; }

  .ap-page-shell {
    padding: 10px max(10px, env(safe-area-inset-right)) max(72px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .menubar {
    height: 44px;
    min-height: 44px;
    flex-wrap: nowrap;
    padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
    gap: 0;
  }
  .menubar__app {
    flex-shrink: 0;
    padding-right: 8px;
    border-right: none;
  }
  .menubar__app-name { display: none; }
  .menubar__menus {
    flex: 1;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .menubar-menu__trigger {
    padding: 8px 10px;
    font-size: 13px;
    white-space: nowrap;
  }
  .menubar__right { display: none; }

  .inicio-hub__acciones { grid-template-columns: 1fr; }
  .inicio-hub { padding: 16px 0 12px; }
  .inicio-hub__hero { flex-direction: column; text-align: center; }
  .inicio-hub__titulo { font-size: 18px; }

  .menubar__menus {
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .menubar__menus::-webkit-scrollbar { display: none; }

  .lista-top { flex-wrap: wrap; }
  .lista-top .btn--sm { min-height: 40px; }
  .lista-smartbar { padding: 12px; }
  .lista-filtros-grid { grid-template-columns: 1fr; }
  .lista-card { padding: 12px; gap: 10px; }
  .lista-card__avatar { width: 38px; height: 38px; font-size: 12px; }
  .menubar__identidad { display: none; }

  .ap-ficha-grid { grid-template-columns: 1fr; }
  .ap-ficha-grid .ap-field--full { grid-column: auto; }

  .ap-account-grid { grid-template-columns: 1fr; }
  .ap-field--wide,
  .ap-field--full { grid-column: auto; }

  .ap-estudios-grid { grid-template-columns: 1fr; }

  .ap-panel-body { padding: 14px; }

  /* Inputs táctiles — 16px evita zoom en iOS */
  .ap-input,
  .ap-select,
  .ap-textarea,
  .btn {
    min-height: 44px;
    font-size: 16px;
  }
  .ap-textarea { min-height: 80px; }

  /* Tablas → tarjetas en móvil */
  .ap-table-header { display: none; }
  .ap-table,
  .ap-table tbody,
  .ap-table-row { display: block; width: 100%; }
  .ap-table-row {
    padding: 12px 14px;
    margin-bottom: 8px;
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-radius);
    background: var(--ap-surface-hover);
  }
  .ap-table-row td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border: none;
  }
  .ap-table-row td::before {
    content: attr(data-th);
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--ap-muted);
  }
  .ap-table-row .col-analito {
    font-size: 14px;
    font-weight: 600;
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--ap-border-light);
  }
  .ap-table-row .col-analito::before { display: none; }
  .ap-table-row .col-resultado { flex-direction: column; align-items: stretch; }
  .ap-table-row .col-resultado::before { margin-bottom: 4px; }

  .captura-top {
    position: sticky;
    top: 0;
    z-index: 50;
    flex-wrap: wrap;
    padding: 8px 0;
    background: var(--ap-bg);
    border-bottom: 1px solid var(--ap-border-light);
  }
  .captura-top__acciones { width: 100%; }
  .captura-top__acciones .btn { flex: 1; }
  .captura-top__hint { display: none; }
  .wa-sesion-info { grid-template-columns: 1fr; }
  .pers-perfiles-layout { grid-template-columns: 1fr; }
  .menubar__perfil { display: none; }
  .ap-modal { padding: 12px; align-items: flex-end; }
  .ap-modal__panel { max-height: 92vh; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }

  .ap-toast {
    bottom: max(72px, calc(env(safe-area-inset-bottom) + 64px));
    width: calc(100% - 28px);
    max-width: 400px;
    text-align: center;
  }

  /* Reporte en pantalla móvil */
  .hoja-reporte {
    min-height: auto;
    border-radius: var(--ap-radius);
  }
  .hoja-reporte__contenido { padding: 20px 16px 24px; }
  .reporte-encabezado { flex-direction: column; }
  .reporte-encabezado__contacto {
    max-width: none;
    text-align: left;
  }
  .reporte-paciente { grid-template-columns: 1fr 1fr; }

  .tabla-reporte { font-size: 12px; }
  .tabla-reporte th,
  .tabla-reporte td { padding: 4px 6px; }
}

@media (max-width: 380px) {
  .reporte-paciente { grid-template-columns: 1fr; }
}

/* --- Impresión vertical --- */
@media print {
  body {
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .no-print { display: none !important; }
  #vista-inicio,
  #vista-captura,
  #vista-pacientes,
  #vista-referidos,
  #vista-historial,
  .mobile-nav { display: none !important; }
  #vista-reporte {
    display: block !important;
    height: auto;
    overflow: visible;
  }
  #vista-reporte.oculto { display: block !important; }
  .ap-page-shell {
    padding: 0;
    background: none;
    max-width: none;
    overflow: visible;
  }
  .reporte-scroll {
    overflow: visible;
    padding: 0;
  }
  .hoja-reporte {
    box-shadow: none;
    border: none;
    border-radius: 0;
    width: var(--paper-width);
    max-width: var(--paper-width);
    min-height: var(--paper-height);
    margin: 0 auto;
    overflow: visible;
    page-break-after: auto;
    position: relative;
    --watermark-opacity: 0.2;
  }
  .hoja-reporte::before {
    position: absolute;
    inset: 0;
    display: block !important;
    opacity: var(--watermark-opacity) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .hoja-reporte__watermark {
    position: absolute;
    inset: 0;
    display: flex !important;
    align-items: center;
    justify-content: center;
    z-index: 0;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .hoja-reporte__watermark img {
    opacity: var(--watermark-opacity) !important;
    width: 58%;
    max-width: 300px;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .hoja-reporte__contenido {
    padding: 0;
    position: relative;
    z-index: 1;
  }
  .reporte-firma {
    margin-top: 110px;
    padding-top: 20px;
    page-break-inside: avoid;
  }
  .reporte-seccion { page-break-inside: avoid; }
}
