/**
 * ESTILOS DE IMPRESIÓN PARA INFORMES CLÍNICOS
 * Compatible con: Historiales, Notas SOAP, Evoluciones, Reportes Administrativos
 * Contexto: Modales multi-página con Tailwind CSS
 */

@media print {
  /* ========================================
     RESETS CRÍTICOS PARA MODALES
     ======================================== */
  
  html, body {
    height: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: white !important;
  }

  /* Forzar visibilidad de contenido en modales */
  .modal,
  .modal-content,
  .modal-body,
  [role="dialog"],
  [class*="modal"],
  [class*="Modal"] {
    position: static !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: none !important;
    z-index: 1 !important;
    overflow: visible !important;
    max-height: none !important;
    height: auto !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    border: none !important;
  }

  /* Ocultar overlays y backdrops */
  .modal-backdrop,
  .overlay,
  [class*="backdrop"],
  [class*="Backdrop"] {
    display: none !important;
  }

  /* ========================================
     OCULTAR ELEMENTOS NO IMPRIMIBLES
     ======================================== */
  
  /* Navegación y controles UI */
  nav,
  header,
  footer,
  .sidebar,
  .navbar,
  .menu,
  button:not(.print-signature),
  [role="navigation"],
  [class*="Navigation"],
  [class*="Sidebar"] {
    display: none !important;
  }

  /* Botones de acción (excepto firmas) */
  .btn:not(.print-signature),
  .button:not(.print-signature),
  [class*="Button"]:not(.print-signature) {
    display: none !important;
  }

  /* Controles de modal */
  .modal-close,
  .close-button,
  [aria-label*="close"],
  [aria-label*="cerrar"] {
    display: none !important;
  }

  /* Tabs y paginación */
  .tabs,
  .pagination,
  [role="tablist"],
  [class*="Tabs"],
  [class*="Pagination"] {
    display: none !important;
  }

  /* ========================================
     FORMATO CLÍNICO PROFESIONAL
     ======================================== */
  
  /* Márgenes estándar médicos */
  @page {
    size: letter;
    margin: 1cm 1.5cm;
  }

  /* Tipografía legible */
  body {
    font-family: 'Arial', 'Helvetica', sans-serif !important;
    font-size: 12pt !important;
    line-height: 1.5 !important;
    color: #000 !important;
  }

  /* Encabezados clínicos */
  h1 { font-size: 16pt !important; font-weight: bold !important; margin-bottom: 0.5cm !important; }
  h2 { font-size: 14pt !important; font-weight: bold !important; margin-bottom: 0.4cm !important; }
  h3 { font-size: 13pt !important; font-weight: bold !important; margin-bottom: 0.3cm !important; }
  h4 { font-size: 12pt !important; font-weight: bold !important; margin-bottom: 0.2cm !important; }

  /* Párrafos y listas */
  p {
    margin-bottom: 0.3cm !important;
    orphans: 3;
    widows: 3;
  }

  ul, ol {
    margin-left: 0.5cm !important;
  }

  /* ========================================
     TABLAS CLÍNICAS (MULTI-PÁGINA)
     ======================================== */
  
  table {
    width: 100% !important;
    border-collapse: collapse !important;
    page-break-inside: auto !important;
    font-size: 11pt !important;
  }

  thead {
    display: table-header-group !important;
    font-weight: bold !important;
  }

  tbody {
    display: table-row-group !important;
  }

  tr {
    page-break-inside: avoid !important;
    page-break-after: auto !important;
  }

  th, td {
    border: 1px solid #333 !important;
    padding: 0.2cm !important;
    text-align: left !important;
  }

  th {
    background-color: #f0f0f0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* ========================================
     SECCIONES CLÍNICAS ESPECÍFICAS
     ======================================== */
  
  /* Notas SOAP */
  .soap-section {
    page-break-inside: avoid !important;
    margin-bottom: 0.5cm !important;
    border-left: 3px solid #333 !important;
    padding-left: 0.3cm !important;
  }

  /* Códigos CIE-10 */
  .cie10-code,
  .diagnosis-code {
    font-family: 'Courier New', monospace !important;
    font-weight: bold !important;
    background-color: #f5f5f5 !important;
    padding: 0.1cm 0.2cm !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Timestamps y metadata */
  .timestamp,
  .metadata,
  .clinical-date {
    font-size: 10pt !important;
    color: #666 !important;
    font-style: italic !important;
  }

  /* Firmas digitales */
  .signature,
  .digital-signature,
  .print-signature {
    display: block !important;
    page-break-inside: avoid !important;
    margin-top: 1cm !important;
    padding-top: 0.5cm !important;
    border-top: 2px solid #333 !important;
  }

  .signature-name {
    font-weight: bold !important;
    font-size: 12pt !important;
  }

  .signature-credentials {
    font-size: 10pt !important;
    color: #666 !important;
  }

  /* ========================================
     EVOLUCIONES CLÍNICAS
     ======================================== */
  
  .evolution-entry {
    page-break-inside: avoid !important;
    margin-bottom: 0.5cm !important;
    padding: 0.3cm !important;
    border: 1px solid #ccc !important;
  }

  .evolution-date {
    font-weight: bold !important;
    margin-bottom: 0.2cm !important;
  }

  /* ========================================
     HISTORIAL DE PACIENTE
     ======================================== */
  
  .patient-header {
    page-break-after: avoid !important;
    margin-bottom: 0.5cm !important;
    padding-bottom: 0.3cm !important;
    border-bottom: 2px solid #333 !important;
  }

  .patient-info {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.3cm !important;
  }

  /* ========================================
     RICH TEXT EDITOR (TIPTAP)
     ======================================== */
  
  .ProseMirror,
  .tiptap {
    border: none !important;
    padding: 0 !important;
    min-height: auto !important;
  }

  /* Preservar formato de texto enriquecido */
  strong, b { font-weight: bold !important; }
  em, i { font-style: italic !important; }
  u { text-decoration: underline !important; }

  /* ========================================
     UTILIDADES DE PAGE-BREAK
     ======================================== */
  
  .page-break-before {
    page-break-before: always !important;
  }

  .page-break-after {
    page-break-after: always !important;
  }

  .page-break-avoid {
    page-break-inside: avoid !important;
  }

  .keep-together {
    page-break-inside: avoid !important;
  }

  /* ========================================
     REPORTES ADMINISTRATIVOS
     ======================================== */
  
  .report-summary {
    background-color: #f9f9f9 !important;
    padding: 0.3cm !important;
    margin-bottom: 0.5cm !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .report-totals {
    font-weight: bold !important;
    font-size: 13pt !important;
    margin-top: 0.5cm !important;
    padding-top: 0.3cm !important;
    border-top: 2px solid #333 !important;
  }

  /* ========================================
     IMÁGENES Y GRÁFICOS
     ======================================== */
  
  img {
    max-width: 100% !important;
    page-break-inside: avoid !important;
  }

  /* Ocultar gráficos interactivos, mostrar solo datos */
  canvas {
    display: none !important;
  }

  /* ========================================
     LINKS Y REFERENCIAS
     ======================================== */
  
  a {
    color: #000 !important;
    text-decoration: none !important;
  }

  a[href]:after {
    content: " (" attr(href) ")" !important;
    font-size: 9pt !important;
    color: #666 !important;
  }

  /* No mostrar URLs para links internos */
  a[href^="#"]:after,
  a[href^="/"]:after {
    content: "" !important;
  }

  /* ========================================
     CLASES AUXILIARES
     ======================================== */
  
  .print-only {
    display: block !important;
  }

  .no-print {
    display: none !important;
  }

  .print-visible {
    visibility: visible !important;
    opacity: 1 !important;
  }

  /* ========================================
     TAILWIND OVERRIDES
     ======================================== */
  
  /* Forzar visibilidad sobre clases Tailwind */
  .hidden,
  .invisible,
  .opacity-0 {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  /* Resetear transforms de Tailwind */
  .translate-x-full,
  .translate-y-full,
  .-translate-x-full,
  .-translate-y-full,
  .scale-0,
  .scale-95 {
    transform: none !important;
  }

  /* Resetear overflow de Tailwind */
  .overflow-hidden,
  .overflow-auto,
  .overflow-scroll {
    overflow: visible !important;
  }

  /* Resetear max-height de Tailwind */
  .max-h-0,
  .max-h-screen,
  [class*="max-h-"] {
    max-height: none !important;
  }
}

/* ========================================
   ESTILOS DE PANTALLA (NO AFECTAN PRINT)
   ======================================== */

/* Botón de impresión visible en pantalla */
@media screen {
  .print-button {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    background-color: #3b82f6;
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.2s;
  }

  .print-button:hover {
    background-color: #2563eb;
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
  }
}
