/* Screenplay page opts out of document-style layout */
main[data-section="screenplay"] .panel {
  width: 100%;
  max-width: clamp(900px, 85vw, 1200px);
  margin: 16px auto;
  
}


.screenplay-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  border-radius: 4px;
  border: 1px solid var(--border);
  box-shadow:
  0 18px 50px rgba(0,0,0,0.45),
  inset 0 1px 0 rgba(230,230,230,0.05);
}

.screenplay-header {
  height: 48px;
  flex-shrink: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;

  padding: 0 24px;

  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.screenplay-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

/* Shared scene select dropdown — consistent across Lined Script, Shot List, Storyboard, Breakdown */
.section-scene-select {
  min-width: 180px;
  max-width: 220px;
  font-size: 12px;
  text-overflow: ellipsis;
}

.screenplay-header-right {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
}

/* ===============================
   SCREENPLAY VIEWER PAGE
   Uses shared .screenplay-page / .screenplay-header / .screenplay-canvas
   =============================== */

.screenplay-viewer-page {
  /* Inherits flex column + height:100% from .screenplay-page */
  border-width: 0px !important;
}

.screenplay-viewer-header {
  border-bottom: 0px !important;
}

/* Section header icon & title */
.screenplay-viewer-header .screenplay-header-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-muted) 100%);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.screenplay-viewer-header .screenplay-header-title-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-primary);
}

/* Canvas area */
.screenplay-viewer-canvas {
  background: transparent !important;
  border-width: 0px;
}

/* Header control groups */
.screenplay-page .header-control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.screenplay-page .header-control-group .control-label {
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.9;
}

#spZoomLabel {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 32px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* Draft selector dropdown */
.draft-selector {
  min-width: 260px;
}

/* Tool button (icon buttons in header) */
.screenplay-page .tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
}

.screenplay-page .tool-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.draft-label {
  white-space: nowrap;
}

.screenplay-canvas {
  flex: 1;
  min-height: 0;
  min-width: 0;          /* CRITICAL for flex scrolling */
  overflow-y: auto;

  background: #181818;

  padding: 24px 24px;
}

.screenplay-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

.screenplay-paper {
  width: 8.5in;
  min-height: 11in;
  background: #fff;
  color: #000;
  position: relative;
  box-shadow:
    0 0 0 1px #333,
    0 10px 30px rgba(0,0,0,.4);
}


.screenplay-paper-content {
  position: absolute;

  top: 1in;
  bottom: 1in;
  left: 1.5in;
  right: 1in;

  height: calc(11in - 2in); /* 9in usable space */

  font-family: "Courier Prime", "Courier New", Courier, monospace;
  font-size: 12pt;
  line-height: 12pt;

  overflow: hidden;
}


.sp-block {
  padding-bottom: 11.2pt;
}


.sp-scene {
  font-weight: 700;
  text-transform: uppercase;
  position: relative;
}

.sp-action {
  /* inherits block spacing */
}

.sp-character {
  margin-left: 2.2in;
  font-weight: 700;
  text-transform: uppercase;
}

.sp-dialogue {
  margin-left: 1in;
  width: 3.6in;
}

.sp-parenthetical {
  margin-left: .6in;
  width: 2.1in;
  text-align: left;
}

.sp-transition {
  margin-left: 4.5in;
  text-align: right;
  font-weight: 700;
  text-transform: uppercase;
}

/* ===============================
   NEW FOUNTAIN ELEMENT TYPES
   =============================== */

/* Centered text (>TEXT<) */
.sp-centered {
  text-align: center;
  font-weight: 700;
  text-transform: uppercase;
}

/* Lyrics (~line) */
.sp-lyric {
  font-style: italic;
  margin-left: 1in;
}

/* Sections (# Section) - metadata, shown faded */
.sp-section {
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  margin-top: 1em;
}

.sp-section-level-1 { font-size: 14pt; }
.sp-section-level-2 { font-size: 13pt; margin-left: 0.5in; }
.sp-section-level-3 { font-size: 12pt; margin-left: 1in; }

/* Synopsis (= text) - metadata, shown faded */
.sp-synopsis {
  font-style: italic;
  color: #666;
  margin-left: 0.5in;
}

/* Metadata blocks (sections, synopses) are typically hidden in production */
.sp-metadata {
  opacity: 0.5;
  border-left: 2px solid #888;
  padding-left: 0.5in;
  margin-left: -0.5in;
}

/* Page break (===) */
.sp-page-break {
  border-top: 1px dashed #aaa;
  margin: 1em 0;
  height: 0;
}

/* Dual dialogue marker */
.sp-dual-dialogue {
  display: inline-block;
  /* In a full implementation, dual dialogue would be side-by-side */
  /* For now, we just mark it visually */
}

.sp-dual-dialogue::before {
  content: "⬅ DUAL";
  font-size: 8pt;
  color: #888;
  margin-right: 0.5em;
  vertical-align: super;
}

.sp-scene-number {
  position: absolute;
  left: -1.25in;
  width: 1in;
  text-align: right;
  font-weight: 700;
}


.screenplay-page *,
.screenplay-page *::before,
.screenplay-page *::after {
  box-sizing: border-box;
}

@page {
  size: Letter;
  margin: 0;
}

/* ===============================
   EMPTY STATE
   =============================== */

.sp-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  gap: 32px;
  min-height: 400px;
}

/* Faux screenplay page thumbnail */
.sp-empty-paper {
  width: 180px;
  height: 233px;
  background: #fff;
  border-radius: 3px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.08),
    0 8px 30px rgba(0,0,0,0.35);
  position: relative;
  opacity: 0.5;
  transition: opacity 0.3s ease;
}

.sp-empty-state:hover .sp-empty-paper {
  opacity: 0.65;
}

.sp-empty-paper-content {
  position: absolute;
  top: 24px;
  left: 28px;
  right: 18px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Faux screenplay elements */
.sp-empty-faux-slug {
  height: 6px;
  width: 75%;
  background: #bbb;
  border-radius: 3px;
}

.sp-empty-faux-action {
  height: 5px;
  width: 100%;
  background: #d5d5d5;
  border-radius: 3px;
}

.sp-empty-faux-action.sp-empty-faux-short {
  width: 60%;
}

.sp-empty-faux-character {
  height: 5px;
  width: 40%;
  background: #c5c5c5;
  border-radius: 3px;
  margin-left: 36px;
  margin-top: 6px;
}

.sp-empty-faux-dialogue {
  height: 5px;
  width: 65%;
  background: #d8d8d8;
  border-radius: 3px;
  margin-left: 18px;
}

.sp-empty-faux-dialogue.sp-empty-faux-short {
  width: 45%;
  margin-left: 18px;
}

/* Text content */
.sp-empty-content {
  text-align: center;
  max-width: 380px;
}

.sp-empty-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-ui, system-ui, sans-serif);
}

.sp-empty-description {
  margin: 0 0 24px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.sp-empty-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.sp-empty-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 13px;
}

.sp-empty-btn svg {
  flex-shrink: 0;
}

.sp-empty-hint {
  margin: 14px 0 0;
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.6;
}

/* ===============================
   PRINT STYLES
   =============================== */

/* =============================================
   TITLE PAGE MODAL & PREVIEW
   ============================================= */

.tp-modal {
  max-width: 620px;
  width: 92vw;
}

.tp-preview-toggle {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
}

.tp-tab {
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 500;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 0;
}
.tp-tab:hover { color: var(--text-primary); }
.tp-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tp-form-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tp-field label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.tp-field input,
.tp-field textarea {
  width: 100%;
  font-size: 13px;
  padding: 7px 10px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
}

.tp-field input:focus,
.tp-field textarea:focus {
  border-color: var(--accent);
  outline: none;
}

.tp-field textarea {
  resize: vertical;
  font-family: inherit;
}

.tp-field-row {
  display: flex;
  gap: 12px;
}
.tp-field-row .tp-field { flex: 1; }

/* Preview page — simulates a physical page */
.tp-preview-page {
  width: 100%;
  aspect-ratio: 8.5 / 11;
  max-height: 540px;
  background: #fff;
  color: #000;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  line-height: 1.0;
  position: relative;
  overflow: hidden;
  padding: 1in;
  display: flex;
  flex-direction: column;
}

.tp-empty-preview {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
}

/* Title page render elements */
.tp-render-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding-bottom: 20%;
}

.tp-render-title {
  font-size: 12px;
  font-weight: normal;
  font-family: 'Courier New', Courier, monospace;
  margin-bottom: 2em;
  text-transform: uppercase;
  white-space: pre-wrap;
}

.tp-render-credit {
  font-size: 12px;
  margin-bottom: 1em;
}

.tp-render-author {
  font-size: 12px;
  margin-bottom: 1em;
}

.tp-render-source {
  font-size: 12px;
  margin-top: 2em;
}

.tp-render-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  font-size: 12px;
}

.tp-render-bottom-left {
  text-align: left;
  max-width: 50%;
}

.tp-render-bottom-right {
  text-align: right;
  max-width: 50%;
}

.tp-render-contact {
  margin-bottom: 0.5em;
  line-height: 1.2;
  white-space: pre-wrap;
}

.tp-render-copyright {
  font-size: 12px;
}

.tp-render-draft {
  margin-bottom: 0.5em;
}

.tp-render-draft-date {
  font-size: 12px;
}

/* =============================================
   TITLE PAGE — PRINT
   ============================================= */

@media print {
  /* Hide everything by default */
  body.printing-screenplay * {
    visibility: hidden;
  }
  
  /* Show only the screenplay pages and their contents */
  body.printing-screenplay .screenplay-pages,
  body.printing-screenplay .screenplay-pages *,
  body.printing-screenplay .screenplay-paper,
  body.printing-screenplay .screenplay-paper * {
    visibility: visible;
  }
  
  /* Hide all UI chrome with display:none */
  body.printing-screenplay .lina-header,
  body.printing-screenplay .app-header,
  body.printing-screenplay .top-bar,
  body.printing-screenplay header,
  body.printing-screenplay nav,
  body.printing-screenplay aside,
  body.printing-screenplay .sidebar,
  body.printing-screenplay .screenplay-header,
  body.printing-screenplay .cloud-status,
  body.printing-screenplay .modal-backdrop,
  body.printing-screenplay #loadingModal {
    display: none !important;
  }
  
  /* Reset body for printing */
  body.printing-screenplay {
    background: white !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  /* Position the pages container */
  body.printing-screenplay .screenplay-pages {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
    gap: 0 !important;
    display: block !important;
    background: white !important;
  }
  
  /* Each screenplay page = one printed page */
  body.printing-screenplay .screenplay-paper {
    width: 8.5in !important;
    height: 11in !important;
    min-height: 11in !important;
    max-height: 11in !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    background: white !important;
    page-break-after: always !important;
    break-after: page !important;
    overflow: hidden !important;
    position: relative !important;
    display: block !important;
  }
  
  /* Last page doesn't need a page break after */
  body.printing-screenplay .screenplay-paper:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
  
  /* CRITICAL: Preserve the screenplay content positioning */
  body.printing-screenplay .screenplay-paper-content {
    position: absolute !important;
    top: 1in !important;
    bottom: 1in !important;
    left: 1.5in !important;
    right: 1in !important;
    height: calc(11in - 2in) !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: white !important;
  }
  
  /* Ensure text prints black */
  body.printing-screenplay .screenplay-paper-content * {
    color: black !important;
  }

  /* Title page print — same page dimensions, different content layout */
  body.printing-screenplay .screenplay-title-page .tp-print-content {
    position: absolute !important;
    top: 1in !important;
    bottom: 1in !important;
    left: 1.5in !important;
    right: 1in !important;
    height: calc(11in - 2in) !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: white !important;
    display: flex !important;
    flex-direction: column !important;
    font-family: 'Courier New', Courier, monospace !important;
    font-size: 12pt !important;
    line-height: 1.0 !important;
    color: black !important;
  }

  body.printing-screenplay .screenplay-title-page .tp-render-center {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    padding-bottom: 20% !important;
  }

  body.printing-screenplay .screenplay-title-page .tp-render-title {
    font-size: 12pt !important;
    font-weight: normal !important;
    font-family: 'Courier New', Courier, monospace !important;
    margin-bottom: 24pt !important;
    text-transform: uppercase !important;
    color: black !important;
  }

  body.printing-screenplay .screenplay-title-page .tp-render-credit,
  body.printing-screenplay .screenplay-title-page .tp-render-author,
  body.printing-screenplay .screenplay-title-page .tp-render-source {
    font-size: 12pt !important;
    font-family: 'Courier New', Courier, monospace !important;
    color: black !important;
  }

  body.printing-screenplay .screenplay-title-page .tp-render-credit {
    margin-bottom: 12pt !important;
  }

  body.printing-screenplay .screenplay-title-page .tp-render-author {
    margin-bottom: 12pt !important;
  }

  body.printing-screenplay .screenplay-title-page .tp-render-source {
    margin-top: 24pt !important;
  }

  body.printing-screenplay .screenplay-title-page .tp-render-bottom {
    display: flex !important;
    justify-content: space-between !important;
    align-items: flex-end !important;
    font-size: 12pt !important;
    font-family: 'Courier New', Courier, monospace !important;
    color: black !important;
  }

  body.printing-screenplay .screenplay-title-page .tp-render-bottom-left,
  body.printing-screenplay .screenplay-title-page .tp-render-bottom-right {
    max-width: 50% !important;
    color: black !important;
  }

  body.printing-screenplay .screenplay-title-page .tp-render-contact,
  body.printing-screenplay .screenplay-title-page .tp-render-copyright,
  body.printing-screenplay .screenplay-title-page .tp-render-draft,
  body.printing-screenplay .screenplay-title-page .tp-render-draft-date {
    font-size: 12pt !important;
    font-family: 'Courier New', Courier, monospace !important;
    color: black !important;
  }
  
  /* Page setup - no browser margins, we handle it ourselves */
  @page {
    size: 8.5in 11in;
    margin: 0;
  }
}
