.pages-container { position: relative; width: 100%; padding: 20px 0; transform-origin: top center; }
.script-page { position: absolute; left: 50%; transform: translateX(-50%); width: 816px; height: 1056px; background: rgba(255,255,255,0.95); box-shadow: 0 10px 28px rgba(0,0,0,0.10); border-radius: 10px; outline: 1px solid rgba(0,0,0,0.06); backdrop-filter: saturate(108%) contrast(101%); -webkit-backdrop-filter: saturate(108%) contrast(101%); }
/* Transición suave para zoom individual */
.script-page { transition: transform 0.1s ease; transform-origin: center top; }
.page-content { height: 880px; overflow: hidden; font-family:'Courier New', Courier, monospace; font-size:16px; line-height:16px; white-space: pre-wrap; }
.script-line { user-select: text; outline: none; }
.script-line.character, .script-line.scene_heading { text-transform: uppercase; }
.ai-diff-insert { background: #e7ffe7; }
.ai-diff-delete { background: #ffe7e7; text-decoration: line-through; }
.ai-inline-actions { position: absolute; right: 18px; margin-top: -6px; background: rgba(255,255,255,0.9); border:1px solid #ddd; border-radius:6px; padding:2px 4px; display:flex; gap:6px; }
.ai-suggestion-card { border:1px solid #ddd; border-radius:8px; padding:8px; background:#fff; margin:8px 0; }
.ai-suggestion-card .header { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.micro-btn { font-size:12px; padding:2px 6px; }
.contd-line, .more-note { font-family:'Courier New', Courier, monospace; font-size:16px; line-height:16px; }

/* ===== SISTEMA PROFESIONAL DE EDITOR DE GUIONES CRIFLOO ===== */
/* Basado en estándares Hollywood: US Letter, Courier 12pt, ~55 líneas por página */

#script-editor .pages-container {
  position: relative;
  width: 100%;
  padding: 20px 0;
  transform-origin: top center;
  transition: transform 0.15s ease-out;
}

#script-editor {
  overflow: auto;
  width: 100%;
  height: 100%;
  /* Fondo vidrio translúcido: no afecta el DOM del guion */
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  font-family: 'Courier New', Courier, monospace;
  font-size: 16px; /* CORREGIDO: Consistente con JavaScript */
  line-height: 16px; /* CORREGIDO: Exactamente 16px para cumplir estándar de 55 líneas por página */
  color: #000000;
  outline: none;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.editor-wrapper {
  position: relative;
  width: 8.5in; /* US Letter */
  margin: 0 auto;
  transform-origin: center top;
}

.editor-flow {
  /* Contenedor del flujo editable igual al tamaño de la página,
     aplicando solo paddings horizontales de página (1.5" / 1")
     para que el ancho efectivo de contenido sea 6" (576px). */
  width: 816px; /* 8.5in @ 96dpi */
  padding-left: 144px; /* 1.5in */
  padding-right: 96px; /* 1.0in */
  margin: 0 auto; /* centrar en wrapper */
  outline: none;
  box-sizing: border-box;
}

.pages-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ===== SISTEMA DE PÁGINAS PROFESIONAL ===== */
/* Páginas US Letter REALES según estándar Final Draft */
#script-editor .script-page,
.script-editor .script-page {
  width: 816px;                    /* US Letter: 8.5" × 96dpi */
  height: 1056px;                  /* US Letter: 11" × 96dpi */
  background: rgba(255,255,255,0.95);
  margin: 0 0 30px 0;
  padding: 96px 96px 80px 144px;   /* 1" top/right, 1.5" left, 80px bottom para 55 líneas */
  box-shadow: 0 10px 28px rgba(0,0,0,0.10);
  border-radius: 10px;
  outline: 1px solid rgba(0,0,0,0.06);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
  transform-origin: center top;
  flex-shrink: 0;
}

#script-editor .page-content,
.script-editor .page-content {
  flex: 1;
  min-height: 0;
  max-height: 880px;               /* 55 líneas × 16px */
  height: 880px;                   /* 55 líneas × 16px */
  overflow: hidden;
  position: relative;
  box-sizing: border-box;
  word-wrap: break-word;
}

/* Quitar cualquier borde/outline al editar líneas (Windows/UA focus) */
#script-editor .script-line,
#script-editor .script-line:focus,
#script-editor .script-line:focus-visible,
#script-editor .script-line:focus-within,
.script-editor .script-line,
.script-editor .script-line:focus,
.script-editor .script-line:focus-visible,
.script-editor .script-line:focus-within {
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
}

/* Asegurar que las líneas reciban el foco aunque estén vacías */
.script-line:empty::before { content: '\200B'; }

/* Marca de agua en la primera línea (controlada por JS con clase watermark) */
.script-line.watermark:empty::before{
  content: 'INT. ESTÓMAGO EN UN HORNITORRINCO - DÍA';
  display: inline-block;
  white-space: pre;
  color: rgba(0,0,0,0.30);
  font-style: italic;
  pointer-events: none;
}
/* Evitar que vuelva a aparecer si hay texto en cualquier bloque siguiente */
.script-page .script-line.watermark:not(:empty)::before{ content: none; }

/* SISTEMA DE NUMERACIÓN DE PÁGINA CORRECTO (OVERLAY) */
/* Se usa un pseudo-elemento para no interferir con el contenido real */
/* Quitar numeración overlay para que no se duplique en impresión */
.script-page::before { content: none; }
/* Marcador sutil de página (normativo: arriba a la derecha, con margen interno) */
#script-editor .script-page::after,
.script-editor .script-page::after {
  content: attr(data-page);
  position: absolute;
  top: 96px;          /* margen top de página */
  right: 96px;        /* margen right de página */
  transform: translateY(-70px); /* elevar para que quede en la esquina con respiro */
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  color: rgba(0,0,0,0.45);
  pointer-events: none;
}

/* ===== ELEMENTOS DEL GUION PROFESIONALES ===== */
.script-line {
  min-height: 16px; /* CORREGIDO: Consistente con line-height */
  margin-bottom: 0; /* CORREGIDO: Sin margen para que cada línea sea exactamente 16px */
  position: relative;
  z-index: 2;
  background: transparent;
  padding: 0; /* CORREGIDO: Sin padding vertical para que cada línea sea exactamente 16px */
  font-family: 'Courier New', Courier, monospace;
  font-size: 16px; /* CORREGIDO: Consistente con JavaScript */
  line-height: 16px; /* CORREGIDO: Exactamente 16px para cumplir estándar de 55 líneas por página */
  white-space: pre-wrap;
  word-break: normal;
  box-sizing: border-box;
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
}

/* ENCABEZADOS DE ESCENA - SIEMPRE EN MAYÚSCULAS */
.script-line.scene_heading {
  margin-left: 0;
  margin-right: 0;
  text-transform: uppercase;
  font-weight: bold;
  padding-top: 0;
  padding-bottom: 0;
  margin-top: 0;
  margin-bottom: 0;
}

/* PERSONAJES - SIEMPRE EN MAYÚSCULAS */
.script-line.character {
  padding-left: 0; /* Indent horizontal lo aplica JS según métricas */
  padding-right: 0;
  text-transform: uppercase;
  font-weight: bold;
  padding-top: 0;
  padding-bottom: 0;
  margin-top: 0;
  margin-bottom: 0;
  text-align: left;
}

/* DIÁLOGOS */
.script-line.dialogue {
  padding-left: 0;  /* Indent horizontal lo aplica JS */
  padding-right: 0;
  width: auto;
  padding-top: 0;
  padding-bottom: 0;
  margin-top: 0;
  margin-bottom: 0;
}

/* PARÉNTESIS */
.script-line.parenthetical {
  padding-left: 0; /* Indent horizontal lo aplica JS */
  padding-right: 0; /* Indent horizontal lo aplica JS */
  padding-top: 0;
  padding-bottom: 0;
  margin-top: 0;
  margin-bottom: 0;
}

/* TRANSICIONES - SIEMPRE EN MAYÚSCULAS */
.script-line.transition {
  margin-left: 0;
  margin-right: 0;
  text-align: right;
  padding-top: 0;
  padding-bottom: 0;
  margin-top: 0;
  margin-bottom: 0;
  text-transform: uppercase;
  font-weight: normal;
}

/* ACCIONES */
.script-line.action {
  margin-left: 0;
  margin-right: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-top: 0;
  margin-bottom: 0;
  font-weight: normal;
  text-transform: none;
}

/* -- Aislamiento de estilos del editor respecto a styles.css --
   Algunos estilos globales (.script-line, .character, .dialogue, etc.) en styles.css
   estaban sobrescribiendo el layout del editor. Estas reglas de mayor
   especificidad neutralizan esos efectos SOLO dentro de .editor-flow. */
.editor-flow .script-line {
  font-family: 'Courier New', Courier, monospace;
  font-size: 16px;
  line-height: 16px;
  min-height: 16px;
  margin: 0;
  padding: 0;
  white-space: pre-wrap;
  word-break: normal;
  box-sizing: border-box;
}
.editor-flow .script-line.character,
.editor-flow .script-line.dialogue,
.editor-flow .script-line.parenthetical,
.editor-flow .script-line.scene_heading,
.editor-flow .script-line.transition,
.editor-flow .script-line.action {
  margin-left: 0;
  margin-right: 0;
}

/* ===== SISTEMA DE IMÁGENES PROFESIONAL ===== */
/* Marco de imagen inline estilo Canva (no cuadro de texto ajeno) */
.editable-image-wrapper {
  display: inline-block;
  vertical-align: middle;
  max-width: 100%;
  margin: 6px 6px;
  border: 1px dashed rgba(0,0,0,0.25);
  border-radius: 4px;
  background: rgba(255,255,255,0.6);
  position: relative;
  will-change: transform, width, height;
}

.editable-image-wrapper:hover { border-color: #007bff; box-shadow: 0 2px 8px rgba(0,123,255,0.2); }

.editable-image-wrapper.selected-image { outline: 2px solid #007bff; border-color: #007bff; box-shadow: 0 0 0 2px rgba(0,123,255,0.2); }

.editable-image-wrapper img { display:block; width:100%; height:auto; pointer-events:none; }

/* ===== SISTEMA DE ZOOM PROFESIONAL ===== */
/* Zoom individual por página (arquitectura original) */
.script-page {
  transition: transform 0.1s ease;
  transform-origin: center top;
}

.pages-layer {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px; /* separador entre páginas equivalente al margin */
  width: 100%;
  transform-origin: center top;
}

/* ===== CONTROLES DE EDITOR ===== */
.editor-header {
  background: #f8f9fa;
  padding: 15px 25px;
  border-bottom: 1px solid #e9ecef;
  display: grid;
  grid-template-columns: 1fr auto 1fr; /* izquierda | centro | derecha */
  align-items: center;
}

.editor-info {
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: center;
  grid-column: 2; /* coloca el bloque central en la columna del medio */
}

.page-info {
  color: #6c757d;
  font-size: 14px;
  font-weight: 500;
}

.element-info {
  background: #007bff;
  color: white;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

/* Controles de Zoom */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.05);
  padding: 6px 12px;
  border-radius: 25px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.zoom-controls button {
  background: none;
  border: none;
  color: #495057;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
  font-size: 14px;
}

.zoom-controls button:hover {
  background: rgba(0, 123, 255, 0.1);
  color: #007bff;
  transform: scale(1.05);
}

.zoom-controls button:active {
  transform: scale(0.95);
}

#zoom-level {
  font-size: 12px;
  font-weight: 600;
  color: #495057;
  min-width: 45px;
  text-align: center;
  user-select: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#element-cycle {
  background: none;
  border: none;
  color: #495057;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 4px;
  transition: all 0.2s ease;
  font-size: 14px;
  margin-right: 10px;
}

#element-cycle:hover {
  background: rgba(0, 123, 255, 0.1);
  color: #007bff;
}

/* ===== SISTEMA DE AUTOCORRECCIÓN ===== */
.autocomplete-popup {
  position: absolute;
  background: #1f2937;
  color: #f9fafb;
  border: 1px solid rgba(255,255,255,0.15);
  max-height: 220px;
  overflow: auto;
  z-index: 10000;
  box-shadow: 0 10px 20px rgba(0,0,0,0.25);
  border-radius: 8px;
  backdrop-filter: blur(6px);
  pointer-events: auto;
}

.autocomplete-popup ul {
  list-style: none;
  margin: 0;
  padding: 4px 0;
}

.autocomplete-popup li {
  padding: 8px 12px;
  cursor: pointer;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12pt;
}

.autocomplete-popup li.selected,
.autocomplete-popup li:hover {
  background: rgba(59,130,246,0.2);
}

/* ===== SISTEMA DE IMPRESIÓN PROFESIONAL ===== */
.print-page {
  page-break-after: always;
  box-sizing: border-box;
  width: 8.5in;
  height: 11in;
  padding: 1in 1in 1in 1.5in;
}

.pages-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.pages-background .page {
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  border-radius: 4px;
  width: 816px;   /* 8.5in @96dpi para alinear con metrics */
  height: 1056px; /* 11in  @96dpi para alinear con metrics */
}

/* ===== UTILIDADES ===== */
.page-number {
  font-family: 'Courier New', Courier, monospace;
  font-size: 12pt;
  color: gray;
}

/* ===== RESPONSIVE Y ACCESIBILIDAD ===== */
@media (max-width: 768px) {
  .script-page {
    width: 100%;
    max-width: 612px;
    height: auto;
    min-height: 792px;
  }
  
  .script-line.character {
    margin-left: 120px;
  }
  
  .script-line.dialogue {
    margin-left: 48px;
    margin-right: 96px;
  }
  
  .script-line.parenthetical {
    margin-left: 80px;
    margin-right: 120px;
  }
}

/* ===== ANIMACIONES Y TRANSICIONES ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Evitar parpadeo en rerender frecuente; solo animar primer montaje */
.script-page { animation: none; }
.script-page.animate-once { animation: fadeIn 0.2s ease-out; }

/* ===== ESTADOS ESPECIALES ===== */
.script-line.placeholder {
  color: #999;
  font-style: italic;
}

.script-line.error {
  background: rgba(220, 53, 69, 0.1);
  border-left: 3px solid #dc3545;
}

.script-line.warning {
  background: rgba(255, 193, 7, 0.1);
  border-left: 3px solid #ffc107;
}