/* ==========================================================================
   Print Studio Modal Dialog
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  padding: 1.5rem;
  overflow-y: auto;
}

body.modal-open {
  overflow: hidden;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
  width: 100%;
  max-width: 960px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalFadeIn 0.15s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-header);
}

.modal-title-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-primary);
}

.modal-title-group h2 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.modal-close-btn:hover {
  color: var(--text-primary);
  background: var(--bg-input-hover);
}

.modal-body.print-studio-body {
  padding: 1.25rem;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1.25rem;
  overflow-y: auto;
  background: var(--bg-app);
}

@media (max-width: 768px) {
  .modal-body.print-studio-body {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Left Pane: Preview */
.print-preview-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.print-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
}

.preview-pane-title {
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
}

.preview-sheet-meta {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.print-paper-stage {
  background: #cbd5e1;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  height: min(64vh, 640px);
  min-height: 380px;
  overflow: auto;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .print-paper-stage {
  background: #1e293b;
}

.print-paper-sheet {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: none;
  margin: auto;
}

/* Padding matches PRINT_PAGE_MARGIN_MM, which is the @page margin on paper */
.print-paper-sheet .print-sheet-page {
  box-sizing: content-box;
  padding: 8mm;
  background: #ffffff;
  color: #000000;
  border-radius: 2px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Right Pane: Settings */
.print-settings-pane {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.print-section {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.print-tip-box {
  background: var(--accent-subtle);
  border: 1px solid rgba(37, 99, 235, 0.2);
  border-radius: 8px;
  padding: 0.75rem;
  display: flex;
  gap: 0.6rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text-secondary);
}

.print-tip-icon {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  color: var(--accent-primary, #2563eb);
  flex-shrink: 0;
  margin-top: 1px;
}

.print-tip-text strong {
  color: var(--text-primary);
}

/* Footer */
.modal-footer.print-studio-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--bg-header);
}

.modal-footer .footer-left,
.modal-footer .footer-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ==========================================================================
   Print Output Sheet & @media print
   ========================================================================== */
#print-output-sheet {
  display: none;
}

@media print {
  @page {
    size: auto;
    margin: 8mm;
  }

  *, *::before, *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: auto !important;
  }

  header, footer, aside, .mobile-tab-nav, .app-layout, .stats-strip, #cursor-tip, .actions, .preview-stage, .modal-backdrop, .toast-container, .stage-zoom-controls, .stage-drop-hint {
    display: none !important;
  }

  #print-output-sheet {
    display: block !important;
    width: 100% !important;
    margin: 0 auto !important;
    background: #ffffff !important;
  }

  .print-matrix {
    display: block !important;
    width: 100% !important;
  }

  .print-sheet-page {
    width: auto !important;
    height: auto !important;
    break-after: page;
  }

  .print-sheet-page:last-child {
    break-after: auto;
  }

  .print-sheet-cell {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
}

