/* ═══ view-pdf.css ═══
   Vista de la ficha PDF (Paso 2 de 3). Una A4 vertical con el aspecto
   Brikdata ("Mediterráneo cálido"): acento terracota, precio grande,
   tira de datos, descripción editable, huecos de foto vacíos como
   marcadores y pie "Generado con Brikdata".

   Depende de tokens.css (cargado antes; ver styles.css). Iconos:
   Phosphor duotone (cargado en app.html). Prefijo de clases: `pdf-`.

   Impresión: @page A4 + @media print dejan una sola página limpia
   (oculta header de la app, barra de herramientas y el resto de vistas).
   ═══════════════════════════════════════════════════════════════ */

/* ── Barra de herramientas (fuera de la hoja; oculta al imprimir) ── */
.pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 210mm;
  margin: 0 auto 16px;
  padding: 4px 2px;
}
.pdf-toolbar-title {
  flex: 1;
  text-align: center;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--c-text);
}
.pdf-toolbar .btn { display: inline-flex; align-items: center; gap: 7px; }

/* ── Lienzo / escenario ── */
.pdf-stage {
  display: flex;
  justify-content: center;
  padding: 8px 8px 40px;
  background: var(--c-bg2);
  overflow: auto;
}

/* ── La hoja A4 ──
   Tamaño físico fijo para que pantalla e impresión coincidan (WYSIWYG).
   overflow:hidden es el tope duro que impide que nada se derrame a una
   segunda página. */
.pdf-page {
  /* paleta local, mapeada a tokens */
  --pdf-brand: var(--c-primary);
  --pdf-deep: var(--c-primary-dark);
  --pdf-tint: var(--c-primary-light);
  --pdf-ink: var(--c-text);
  --pdf-muted: var(--c-text-muted);
  --pdf-line: var(--c-border);
  --pdf-paper: #FFFDF9;
  --pdf-ph: var(--c-bg3);
  --pdf-ph-icon: var(--c-text-light);
  --pdf-ph-label: var(--c-text-muted);
  --pdf-cream: #FFF3EC;
  --pdf-cream-soft: #F4D9CC;

  position: relative;
  width: 210mm;
  height: 297mm;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--pdf-paper);
  color: var(--pdf-ink);
  font-family: var(--font);
  border: 0.5px solid var(--pdf-line);
  border-radius: 4px;
  box-shadow: var(--shadow-lg);
}

/* franja de acento superior */
.pdf-accent {
  height: 8px;
  background: var(--pdf-brand);
  flex: 0 0 auto;
}

/* ── Cabecera: título + precio + foto de portada ── */
.pdf-head {
  display: flex;
  gap: 22px;
  padding: 30px 34px 22px;
  flex: 0 0 auto;
}
.pdf-head-main { flex: 1; min-width: 0; }
.pdf-price-pill {
  display: inline-block;
  background: var(--pdf-brand);
  color: var(--pdf-cream);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 3px 12px;
  border-radius: 12px;
}
.pdf-price {
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 600;
  color: var(--pdf-deep);
  line-height: 1;
  margin-top: 12px;
}
.pdf-title {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 600;
  line-height: 1.08;
  margin: 16px 0 0;
  color: var(--pdf-ink);
}
.pdf-loc {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--pdf-muted);
  margin-top: 8px;
}
.pdf-loc i { color: var(--pdf-brand); font-size: 16px; }

/* ── Huecos de foto (marcadores vacíos) ── */
.pdf-photo {
  background: var(--pdf-ph);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  overflow: hidden;            /* recorta la foto al rectángulo del hueco */
}
.pdf-photo i { font-size: 30px; color: var(--pdf-ph-icon); }
.pdf-photo-label { font-size: 12px; color: var(--pdf-ph-label); }
.pdf-photo-cover { flex: 1.05; min-height: 190px; }
.pdf-photos {
  display: flex;
  gap: 10px;
  padding: 18px 34px 6px;
  flex: 0 0 auto;
}
.pdf-photo-strip { flex: 1; height: var(--strip-h, 120px); }
.pdf-photo-strip i { font-size: 20px; }
.pdf-photo-strip .pdf-photo-label { font-size: 11px; }

/* hueco lleno: la foto cubre todo el rectángulo (recortada a cover) */
.pdf-photo-filled { background: var(--pdf-ph); }
.pdf-photo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ── Tira de datos (pins) ── */
.pdf-stats {
  display: flex;
  gap: 10px;
  margin: 6px 34px 0;
  padding: 16px 12px;
  background: var(--pdf-tint);
  border-radius: 8px;
  flex: 0 0 auto;
}
.pdf-stat { flex: 1; text-align: center; min-width: 0; }
.pdf-stat > i { font-size: 22px; color: var(--pdf-brand); }
.pdf-stat-val {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  color: var(--pdf-deep);
  margin-top: 4px;
  line-height: 1.1;
}
.pdf-stat-lbl { font-size: 12px; color: var(--pdf-muted); margin-top: 2px; }

/* ── Cuerpo: descripción (editable) + características ── */
.pdf-body {
  display: flex;
  gap: 26px;
  padding: 20px 34px 8px;
  flex: 1 1 auto;
  min-height: 0;
}
.pdf-desc-col { position: relative; flex: 1.55; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pdf-feats-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.pdf-section-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--pdf-brand);
  margin-bottom: 10px;
}

/* descripción editable: ÚNICO elemento editable de la ficha.
   altura flexible (rellena el hueco) + overflow oculto = tope físico;
   el JS reduce el cuerpo de letra hasta que el texto entra. */
.pdf-desc-box {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  font-size: 12px;          /* el JS lo ajusta entre 12px y 9px */
  line-height: 1.62;
  color: var(--pdf-ink);
  white-space: pre-wrap;
  word-break: break-word;
  /* señal sutil de editabilidad en pantalla (se anula al imprimir) */
  background: rgba(194, 106, 74, 0.035);
  border-radius: 5px;
  padding: 8px 10px;
  margin: -8px -10px 0;
  outline: none;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.pdf-desc-box:hover { background: rgba(194, 106, 74, 0.06); }
.pdf-desc-box:focus {
  background: var(--pdf-paper);
  box-shadow: inset 0 0 0 1.5px var(--pdf-brand);
}
.pdf-desc-box:empty::before {
  content: 'Descripción de la vivienda…';
  color: var(--pdf-ph-label);
}
/* Descripción en párrafos: MISMA separación que el CSS inline del PDF
   (_FICHA_CSS en pdf.js). Sin esta regla, el reset global `* { margin: 0 }`
   de base.css deja los <p class="pdf-desc-p"> pegados y la preview se ve como
   un bloque único mientras el PDF sí sale aireado en párrafos. */
.pdf-desc-box .pdf-desc-p { margin: 0 0 0.5em; }
.pdf-desc-box .pdf-desc-p:last-child { margin-bottom: 0; }

/* indicador de carga propio de la caja: tapa SOLO la columna de
   descripción mientras la IA genera el texto (lo monta/desmonta pdf.js
   alrededor de la llamada a la IA). Autocontenido e independiente del
   overlay de carga a pantalla completa de la app. Reutiliza el keyframes
   local pdf-spin. */
.pdf-desc-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-radius: 5px;
  background: var(--pdf-paper);
  color: var(--c-text-muted);
  font-size: 12.5px;
}
.pdf-desc-spin {
  width: 16px;
  height: 16px;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: pdf-spin 0.7s linear infinite;
}
.pdf-desc-loading-txt { font-weight: 500; }

/* lista de características con marcas */
.pdf-feats { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.pdf-feat {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--pdf-ink);
  padding: 3px 0;
}
.pdf-feat i { color: var(--pdf-brand); font-size: 15px; flex: 0 0 auto; }

/* ── Línea meta (estado · antigüedad · orientación + cert) ── */
.pdf-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 34px 16px;
  font-size: 12.5px;
  color: var(--pdf-muted);
  flex: 0 0 auto;
}
.pdf-meta-spacer { flex: 1; }
.pdf-meta-cert-lbl { color: var(--pdf-ink); }
.pdf-cert-pill {
  display: inline-block;
  background: var(--c-accent-light);
  color: var(--c-accent);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
}

/* ── Pie de marca ── */
.pdf-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 34px;
  background: var(--pdf-brand);
  flex: 0 0 auto;
  margin-top: auto;
}
.pdf-foot-agency { display: flex; align-items: center; gap: 10px; }
.pdf-foot-logo {
  width: 34px;
  height: 34px;
  border: 0.5px solid var(--pdf-cream-soft);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pdf-cream-soft);
  font-size: 18px;
}
.pdf-foot-agency-txt { font-size: 11.5px; color: var(--pdf-cream-soft); line-height: 1.35; }
.pdf-foot-brand { display: flex; align-items: center; gap: 7px; color: var(--pdf-cream); }
.pdf-foot-by { font-size: 11.5px; color: var(--pdf-cream-soft); }
.pdf-foot-brand i { font-size: 18px; }
.pdf-foot-name { font-family: var(--font-display); font-size: 16px; font-weight: 600; }

/* ── Panel editor de fotos (fuera de la hoja; oculto al imprimir) ──
   Gestiona las ocho ranuras: portada (grande), fachada (recomendada) y
   resto. Gestión por BORRAR + RESUBIR, sin arrastrar. */
.pdf-slots-panel {
  max-width: 210mm;
  margin: 0 auto 16px;
  padding: 16px 18px;
  background: var(--c-bg, #fff);
  border: 0.5px solid var(--c-border);
  border-radius: 10px;
}
.pdf-slots-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.pdf-slots-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--c-text);
}
.pdf-slots-title i { color: var(--c-primary); font-size: 19px; }
.pdf-slots-hint { font-size: 12.5px; color: var(--c-text-muted); }

/* rejilla compacta: el control de subida y la primera foto ocupan toda la
   fila; las demás miniaturas se acomodan en auto-fill más apretado */
.pdf-slots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 8px;
  align-items: start;
}

/* control único "Subir fotos" (acepta varias a la vez). Ocupa toda la fila. */
.pdf-uploader {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 18px 16px;
  border: 1.5px dashed var(--c-border);
  border-radius: 10px;
  background: transparent;
  color: var(--c-text-muted);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.pdf-uploader:hover {
  border-color: var(--c-primary);
  color: var(--c-primary);
  background: var(--c-primary-light);
}
.pdf-uploader i { font-size: 26px; }
.pdf-uploader-main { font-size: 14px; font-weight: 600; }
.pdf-uploader-sub { font-size: 12px; }
/* tope alcanzado: mismo bloque sin afordancia de clic */
.pdf-uploader--full { cursor: default; border-style: solid; }
.pdf-uploader--full:hover {
  border-color: var(--c-border);
  color: var(--c-text-muted);
  background: transparent;
}

.pdf-slot { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.pdf-slot--cover { grid-column: 1 / -1; }
.pdf-slot-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-muted);
}
.pdf-slot-box {
  position: relative;
  height: 96px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--c-bg3);
}
.pdf-slot--cover .pdf-slot-box { height: 150px; }

/* afordancia "añadir foto" en ranura vacía */
.pdf-slot-empty {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1.5px dashed var(--c-border);
  border-radius: 8px;
  background: transparent;
  color: var(--c-text-muted);
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.pdf-slot-empty i { font-size: 22px; }
.pdf-slot-empty:hover {
  border-color: var(--c-primary);
  color: var(--c-primary);
  background: var(--c-primary-light);
}
.pdf-slot-empty--err {
  border-color: var(--c-danger, #c0392b);
  color: var(--c-danger, #c0392b);
}
.pdf-slot-empty--err span { padding: 0 8px; text-align: center; line-height: 1.3; }

/* ranura llena: miniatura + botón borrar */
.pdf-slot-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pdf-slot-del {
  position: absolute;
  bottom: 6px;
  right: 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: rgba(20, 16, 14, 0.72);
  border: none;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.pdf-slot-del:hover { background: var(--c-danger, #c0392b); }
.pdf-slot-del i { font-size: 14px; }

/* ranura subiendo */
.pdf-slot-busy {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--c-text-muted);
}
.pdf-slot-spin {
  width: 15px;
  height: 15px;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: pdf-spin 0.7s linear infinite;
}
@keyframes pdf-spin { to { transform: rotate(360deg); } }

/* mensaje de gating (qué falta para previsualizar/descargar) */
.pdf-gate-msg {
  margin-top: 12px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--c-text);
  background: var(--c-primary-light);
  border-radius: 8px;
}
.pdf-gate-msg.ok {
  background: var(--c-accent-light);
  color: var(--c-accent);
}

/* botones bloqueados por el gating */
.pdf-toolbar .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Responsive: en pantallas estrechas la A4 se escala para no desbordar ──
   (la impresión usa siempre el tamaño físico real; ver @media print). */
@media (max-width: 840px) {
  /* Barra: el título salta a su propia línea (ancho completo) y los tres
     botones ocupan la fila siguiente, creciendo para ser cómodos de pulsar
     (con wrap a una tercera línea si no caben). */
  .pdf-toolbar {
    max-width: none;
    padding: 4px 10px;
    flex-wrap: wrap;
    row-gap: 10px;
  }
  .pdf-toolbar-title {
    order: -1;            /* título primero, encima de los botones */
    flex: 1 1 100%;       /* fila completa propia → no se espachurra */
    text-align: center;
  }
  .pdf-toolbar .btn { flex: 1 1 auto; justify-content: center; }

  /* La hoja A4 se ENCOGE para caber entera (WYSIWYG: lo que se ve sigue
     siendo el PDF, solo más pequeño). pdf.js calcula la escala
     (= ancho disponible / ancho A4, nunca > 1) y la fija en --pdf-scale;
     transform-origin:top center la centra y el calc() de margin-bottom
     reabsorbe el alto sobrante para que no quede hueco bajo la hoja
     (scale=1 → margin 0 → sin cambios). overflow-x:hidden recorta cualquier
     sobrante de redondeo sin permitir scroll lateral. */
  .pdf-stage { padding: 6px 0 32px; overflow-x: hidden; }
  .pdf-page {
    transform: scale(var(--pdf-scale, 1));
    transform-origin: top center;
    margin-bottom: calc(297mm * (var(--pdf-scale, 1) - 1));
  }

  .pdf-slots-panel { max-width: none; margin: 0 10px 16px; }
}

/* ── Impresión: una sola A4 limpia ── */
@page { size: A4 portrait; margin: 0; }

@media print {
  body * { visibility: hidden !important; }
  #viewPdf, #viewPdf * { visibility: visible !important; }
  #viewPdf { position: absolute; inset: 0; margin: 0; padding: 0; }

  .pdf-toolbar { display: none !important; }
  .pdf-slots-panel { display: none !important; }
  .pdf-stage {
    padding: 0 !important;
    background: none !important;
    display: block !important;
    overflow: visible !important;
  }
  .pdf-page {
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    transform: none !important;
  }
  .pdf-desc-box {
    background: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  html, body { background: #fff !important; }

  /* forzar impresión de fondos de color (acento, tinte, pie) */
  .pdf-page, .pdf-page * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
