/* Match screenplay page layout exactly */
.lined-script-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}


.lined-tools .btn {
  min-width: 80px;
}

.lined-overlay line {
  pointer-events: stroke;
}

.lined-overlay line:hover {
  stroke-width: 4;
}

/* Lined Script Line States */

.lined-overlay line {
  pointer-events: stroke;
  stroke-linecap: round;
}

.line-drawing {
  stroke: #e74c3c;
  stroke-width: 4;
}

.line-normal {
  stroke: #3498db;
}

.line-selected {
  stroke: #2ecc71;
}

.line-armed {
  stroke: #e74c3c;
  stroke-dasharray: 4 2;
}

/* Ensure overlay is always above the screenplay text */
.lined-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: all;
}

/* Prevent text selection in the lined script tool */
.lined-script-page,
.lined-script-page * {
  -webkit-user-select: none;
  user-select: none;
}

/* But allow inputs to still be selectable/typable if you add any later */
.lined-script-page input,
.lined-script-page textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* Make sure the line strokes capture input reliably */
.lined-overlay line {
  pointer-events: stroke;
  stroke-linecap: round;
}

.lined-overlay {
  touch-action: none;
}


/* ===============================
   LINED SCRIPT — SQUIGGLES
   =============================== */

.lined-squiggle {
  fill: none;
  stroke: #000;
  stroke-width: 2.2px;
  stroke-linecap: round;
  pointer-events: stroke;
}

/* Tool cursor hints */
.lined-canvas[data-tool="squiggle"] {
  cursor: crosshair;
}

.lined-canvas[data-tool="eraser"] {
  cursor: cell;
}

/* ===============================
   LINED SCRIPT PAGE
   Uses shared .screenplay-page / .screenplay-header / .screenplay-canvas
   =============================== */

.lined-script-page {
  border-width: 0px !important;
}

.lined-script-header {
  border-bottom: 0px !important;
}

/* Section header icon & title */
.lined-script-header .lined-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;
}

.lined-script-header .lined-header-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-primary);
  width: 100px;
  flex-shrink: 0;
}

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

/* Tool button group — flat layout, no pill background */
.tool-group {
  display: flex;
  gap: 4px;
}

/* History tool group (undo/redo) - slightly separated */
.tool-group-history {
  margin-left: 12px;
}

/* Tool buttons */
/* ===============================
   LINED SCRIPT TOOLBAR
   =============================== */

.ls-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: var(--bg-elevated, rgba(0, 0, 0, 0.2));
  border-radius: 5px;
  border: 1px solid var(--border, #4b4b50);
}

.ls-toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.ls-toolbar-sep {
  width: 1px;
  height: 16px;
  background: var(--border, #4b4b50);
  margin: 0 3px;
  flex-shrink: 0;
}

.ls-tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 28px;
  padding: 0;
  color: var(--text-secondary, #b5b5b5);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.12s ease;
}

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

.ls-tool-btn:hover {
  color: var(--text-primary, #e6e6e6);
  background: rgba(255, 255, 255, 0.06);
}

.ls-tool-btn.tool-active {
  color: #fff;
  background: var(--accent, #d18b3c);
  border-color: var(--accent, #d18b3c);
}

.ls-tool-btn.tool-active:hover {
  background: var(--accent, #d18b3c);
  filter: brightness(1.1);
}

.ls-tool-btn:disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

/* Keep .tool-btn styles for settings, print, and other standalone icon buttons */
.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  transition: all 0.15s ease;
}

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

/* Disabled state for undo/redo */
.tool-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.tool-btn:disabled:hover {
  background: transparent;
  border-color: var(--border);
}

/* ===============================
   ZOOM DISPLAY
   =============================== */

.zoom-display {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 0 8px;
  margin: 0 8px;
  border-radius: 6px;
  min-width: 36px;
  text-align: center;
  opacity: 0.7;
  cursor: default;
  user-select: none;
}

.zoom-reset-flash {
  animation: zoom-flash 0.4s ease;
}

@keyframes zoom-flash {
  0%   { color: #2ecc71; border-color: rgba(46, 204, 113, 0.5); opacity: 1; }
  100% { color: var(--text-secondary); border-color: var(--border); opacity: 0.7; }
}

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

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

.zoom-controls {
  gap: 4px;
}

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

/* Scene jump dropdown */
/* ===============================
   DRAW-MODE MARGIN OVERLAY
   Dims the 0.5in margins when the Line tool is active
   =============================== */

.lined-canvas[data-tool="line"] .screenplay-paper::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 9; /* just below .lined-overlay (z-index: 10) */
  background: rgba(0, 0, 0, 0.35);
  clip-path: polygon(
    /* outer rect (full page) */
    0% 0%, 100% 0%, 100% 100%, 0% 100%, 0% 0%,
    /* inner rect (drawable area) — cut out */
    48px 48px, 48px calc(100% - 48px), calc(100% - 48px) calc(100% - 48px), calc(100% - 48px) 48px, 48px 48px
  );
  pointer-events: none;
  transition: opacity 0.2s ease;
}

/* ===============================
   Tool Cursors (Lined Script)
   =============================== */

.lined-canvas[data-tool="select"] .screenplay-paper {
  cursor: default;
}

.lined-canvas[data-tool="line"] .screenplay-paper {
  cursor: copy;
}

.lined-canvas[data-tool="line"] .screenplay-paper.in-margin,
.lined-canvas[data-tool="line"] .screenplay-paper.in-margin .lined-overlay {
  cursor: not-allowed;
}

.lined-canvas[data-tool="squiggle"] .screenplay-paper {
  cursor: row-resize;
}

.lined-canvas[data-tool="eraser"] .screenplay-paper {
  cursor: vertical-text;
}

.lined-canvas[data-tool="squiggle"] .lined-overlay:hover,
.lined-canvas[data-tool="eraser"] .lined-overlay:hover {
  cursor: inherit;
}

/* Scene numbers in the script */
.lined-script-page .scene-number {
  font-weight: bold;
  font-size: 16px;
  line-height: 12pt;
  position: absolute;
  left: 1in;
  font-family: "Courier Prime", "Courier New", Courier, monospace;
  opacity: 0.75;
  user-select: none;
  pointer-events: none;
}

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

@media print {
  /* Hide everything by default */
  body.printing-lined-script * {
    visibility: hidden;
  }
  
  /* Show only the lined script pages and their contents */
  body.printing-lined-script .lined-script-pages,
  body.printing-lined-script .lined-script-pages *,
  body.printing-lined-script .screenplay-paper,
  body.printing-lined-script .screenplay-paper * {
    visibility: visible;
  }
  
  /* Hide all UI chrome with display:none */
  body.printing-lined-script .lina-header,
  body.printing-lined-script .app-header,
  body.printing-lined-script .top-bar,
  body.printing-lined-script header,
  body.printing-lined-script nav,
  body.printing-lined-script aside,
  body.printing-lined-script .sidebar,
  body.printing-lined-script .screenplay-header,
  body.printing-lined-script .cloud-status,
  body.printing-lined-script .modal-backdrop,
  body.printing-lined-script #loadingModal {
    display: none !important;
  }
  
  /* Reset body for printing */
  body.printing-lined-script {
    background: white !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  /* Position the pages container */
  body.printing-lined-script .lined-script-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-lined-script .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-lined-script .screenplay-paper:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
  
  /* CRITICAL: Preserve the screenplay content positioning - DO NOT change margins */
  body.printing-lined-script .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;
  }
  
  /* SVG overlay must be visible and positioned correctly */
  body.printing-lined-script .lined-overlay {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 10 !important;
    pointer-events: none !important;
    overflow: visible !important;
  }
  
  /* CRITICAL: Let lines keep their actual stroke color - don't override! */
  body.printing-lined-script .lined-overlay line {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  
  /* Arrow fills should also preserve color */
  body.printing-lined-script .lined-overlay path:not(.lined-squiggle) {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  
  /* Squiggles print in black */
  body.printing-lined-script .lined-squiggle {
    stroke: #000 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  
  /* Ensure text prints black */
  body.printing-lined-script .screenplay-paper-content * {
    color: black !important;
  }
  
  /* Scene numbers should print */
  body.printing-lined-script .scene-number {
    color: black !important;
    opacity: 1 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  /* Shot labels should print with color */
  body.printing-lined-script .lined-shot-label text {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  
  body.printing-lined-script .lined-shot-label rect {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  
  /* Bottom tick handles should print (they're part of the traditional lined script look) */
  body.printing-lined-script .lined-overlay .lined-bottom-handle {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  
  /* Page setup - no browser margins, we handle it ourselves */
  @page {
    size: 8.5in 11in;
    margin: 0;
  }
}

/* ===============================
   LINED SCRIPT SETTINGS MODAL
   =============================== */

.ls-settings-form {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ls-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.ls-setting-row:last-child {
  border-bottom: none;
}

.ls-setting-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.ls-setting-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.ls-setting-desc {
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.75;
}

.ls-setting-control {
  flex-shrink: 0;
}

/* Select dropdown */
.ls-select {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 28px 6px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23b5b5b5' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  min-width: 120px;
  transition: border-color 0.15s ease;
}

.ls-select:hover {
  border-color: var(--accent-muted);
}

.ls-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(209, 139, 60, 0.2);
}

/* Toggle switch */
.ls-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.ls-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.ls-toggle-track {
  width: 40px;
  height: 22px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 11px;
  position: relative;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.ls-toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: transform 0.2s ease, background 0.2s ease;
}

.ls-toggle input:checked + .ls-toggle-track {
  background: rgba(46, 204, 113, 0.2);
  border-color: rgba(46, 204, 113, 0.5);
}

.ls-toggle input:checked + .ls-toggle-track::after {
  transform: translateX(18px);
  background: #2ecc71;
}
