/* CSS para Impresión - V5 (Balanced Fix) */
/* Regresamos a la lógica V3 (que mostraba la hoja) pero arreglando el corte de página (Page 2) */

/* 1. CONFIGURACIÓN DE PÁGINA */
@page {
  size: letter;
  margin: 0.5cm;
}

/* 2. RESET DE COLORES (Blanco y Negro) */
* {
  /* background-color: transparent !important; -- Permitir fondos si definidos */
  /* background-image: none !important; -- Permitir imágenes */
  color: #000000 !important;
  box-shadow: none !important;
  text-shadow: none !important;
}

/* 3. ESTRUCTURA BASE (Overrides de alta especificidad vs Mobile Mode) */
html,
body,
html body.mobile-mode-edit,
html body.mobile-mode-view {
  background-color: #ffffff !important;
  width: 100% !important;
  /* CRÍTICO: Permitir altura infinita */
  height: auto !important;
  min-height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: visible !important; /* CRÍTICO: Permitir que el contenido fluya */
  display: block !important;
}

/* 4. CONTENEDOR PRINCIPAL (#app) */
/* Romper el Flexbox que limita la altura a 100vh */
html body #app,
html body.mobile-mode-edit #app {
  display: block !important; /* Adiós Flexbox */
  width: 100% !important;
  height: auto !important; /* Crecer con el contenido */
  overflow: visible !important; /* No cortar nada */
  position: static !important;
  background: white !important;
}

/* 5. VISIBILIDAD DE LA HOJA */
html body #app #sheet-preview,
html body.mobile-mode-edit #app #sheet-preview {
  display: block !important;
  width: 100% !important;
  height: auto !important; /* Altura automática */
  margin: 0 !important;
  padding: 0 !important;
  overflow: visible !important; /* CRÍTICO */
  opacity: 1 !important;
  visibility: visible !important;
}

/* 6. OCULTAR INTERFAZ (UI) */
html body #builder-controls,
html body.mobile-mode-edit #builder-controls,
html body #app #builder-controls,
.header-top,
#builder-nav,
.lang-selector,
#print-btn,
#view-toggle-btn,
button,
.btn-delete-item,
.btn-spell-add,
.btn-icon-add,
.mode-selector,
.shop-controls,
.shop-tabs,
.shield-toggle,
.toggle-switch,
.shop-search,
#kofi-button {
  display: none !important;
}

/* 7. ESTILOS DE PÁGINA (HOJA) */
.sheet-page {
  position: relative !important;
  display: block !important;
  width: 100% !important;
  max-width: 216mm !important;

  /* Altura segura para márgenes */
  min-height: 260mm !important;
  height: auto !important; /* Si el contenido es más largo, crece */

  margin: 0 auto !important;
  border: none !important;
  background-color: #ffffff !important;

  /* Saltos de página */
  page-break-after: always !important;
  break-after: page !important;
  page-break-inside: avoid !important;
  break-inside: avoid !important;

  /* Permitir ver contenido que sobresalga ligeramente antes de cortar */
  overflow: visible !important;
}

/* Marca de Agua (V13 - Revert to Functional V10 + Blank Page Fix) */
/* Regresamos a la configuración que el usuario aprobó (V10) pero con tamaño 70% original y arreglos de margen */

.sheet-page {
  position: relative !important;
  display: block !important;
  width: 216mm !important; /* Ancho físico fijo */
  height: 279mm !important; /* ALTO físico fijo para centrado idéntico */

  margin: 0 auto !important;
  padding: 0 !important;
  border: none !important;
  box-sizing: border-box !important;

  background: #ffffff !important;

  /* Paginación */
  page-break-after: always !important;
  break-after: page !important;
  page-break-inside: avoid !important;
  overflow: hidden !important; /* Cortar excedentes mínimos para evitar spillover */
}

.sheet-page.bestiary-page {
    display: block !important;
}

.monster-card.horizontal-layout {
    background-color: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    border: 1px solid #000 !important;
    border-left: 8px solid #000 !important;
}

.monster-img-large {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    background-color: #eee !important; /* Fallback visual */
    /* Asegurar que la imagen de fondo inline se imprima */
    background-image: inherit !important;
}
/* Truco: para que el inline style gane al reset universal (si existiera),
   pero como quitamos el reset, esto asegura renderizado exacto */

.stat-bubble {
    background-color: #ffffff !important;
    color: #000000 !important;
    border: 2px solid #000000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.sheet-page::before {
  content: "" !important;
  position: absolute !important;

  /* Centrado Matemático (V10 Logic - "The one that worked") */
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;

  /* Dimensiones: Restauradas a 70% (Donde era funcional) */
  width: 70% !important;
  height: 70% !important;

  background-image: url("../marca de agua2.png") !important;
  background-repeat: no-repeat !important;
  background-position: center center !important;
  background-size: contain !important;

  opacity: 0.1 !important;
  z-index: 0 !important;
  pointer-events: none !important;

  /* Estabilidad de Color/Imagen para Impresión */
  print-color-adjust: exact !important;
  -webkit-print-color-adjust: exact !important;
}

/* ANTI-HOJA BLANCA */
.sheet-page:last-child {
  page-break-after: auto !important;
  break-after: auto !important;
  margin-bottom: 0 !important;
}

/* Limpiar intentos fallidos */
body::after {
  display: none !important;
}

/* 8. RESTAURAR ESTILOS DE CONTENIDO */
/* Replicar la especificidad necesaria para que se vea bien */
.sheet-main-grid {
  display: grid !important;
  grid-template-columns: 200px 1fr !important;
  gap: 20px !important;
}

.page-2-grid-asym {
  display: grid !important;
  grid-template-columns: 3fr 7fr !important;
  gap: 20px !important;
}

/* Bordes y Colores de Texto */
.stat-compact-box,
.combat-box,
.stat-row,
.skill-item-sidebar,
table,
tr,
td,
th,
.spell-row,
.ac-value {
  border-color: #000000 !important;
}

.stat-compact-box,
.combat-box {
  border: 1px solid #000 !important;
}

table {
  border-collapse: collapse !important;
  width: 100% !important;
}

tr {
  border-bottom: 1px solid #ccc !important;
}

.stat-compact-mod {
  background-color: #f0f0f0 !important;
}

h1,
h2,
h3,
h4,
span,
div,
p,
label {
  color: #000000 !important;
}

.char-avatar-img {
  filter: none !important; /* Permitir color */
  border: 1px solid #000 !important;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

a {
  text-decoration: none !important;
  color: #000 !important;
}

/* Corrección Subclase Impresión - Visibilidad sobre fondo negro */
.subclass-badge {
    background-color: #000 !important;
    color: #fff !important;
    border: 1px solid #000 !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}
