/*
 * Print Preview Stylesheet
 * Handles both screen preview and @media print for actual printing.
 * Used by the print layout (app/views/layouts/print.html.erb).
 *
 * NOTE: This file is auto-loaded by Propshaft via stylesheet_link_tag :app.
 * All rules MUST be scoped to .print-container or print-specific classes
 * to avoid polluting the main application styles.
 */

/* ============================================
   Scoped Reset (print layout only)
   ============================================ */
.print-container *,
.print-container *::before,
.print-container *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.print-container {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  line-height: 1.3;
  color: #000;
}

/* ============================================
   Page Container
   ============================================ */
.print-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 20px;
}

.print-page {
  background: #fff;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
}

/* Page sizes */
.print-page--letter {
  width: 8.5in;
  min-height: 11in;
}

.print-page--a4 {
  width: 8.27in;
  min-height: 11.69in;
}

/* Wristband pages use inline width/height from settings */
.print-page--wristband {
  /* width and height set via inline style from wristband dimensions */
}

/* Wristband sheet: physical page containing tiled wristband cards */
.print-page--wristband-sheet {
  /* Override inherited flex/min-height so cards pack flush */
  display: block !important;
  min-height: 0 !important;
  height: auto !important;
  position: relative;
}

.wristband-sheet-grid {
  /* grid-template set via inline style; no gap between cards */
  display: grid !important;
  gap: 0 !important;
  align-content: start;
  justify-content: start;
}

.wristband-card {
  border: none;
  display: flex;
  flex-direction: column;
  position: relative;
}

.wristband-card .print-grid {
  flex: 1;
  border: none;
}

.wristband-card .print-watermark-logo {
  max-width: 120px;
  max-height: 120px;
}

.wristband-card .print-watermark-text {
  font-size: 32px;
  letter-spacing: 4px;
}

.wristband-card .print-footer {
  font-size: 5px;
}

.wristband-card .print-cell-header,
.print-cell-header--wristband {
  font-size: 7px;
  padding: 1px 3px;
  min-height: 12px;
}

.wristband-card .print-cell-header .play-number {
  width: 10px;
  height: 10px;
  font-size: 6px;
}

/* ============================================
   Watermark
   ============================================ */
.print-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-30deg);
  opacity: 0.04;
  pointer-events: none;
  z-index: 0;
  user-select: none;
}

.print-watermark-logo {
  max-width: 400px;
  max-height: 400px;
  width: auto;
  height: auto;
}

.print-watermark-text {
  font-size: 96px;
  font-weight: 900;
  letter-spacing: 12px;
  color: #000;
  white-space: nowrap;
}

/* ============================================
   Grid / Wristband Mode
   ============================================ */
.print-grid {
  flex: 1;
  display: grid;
  gap: 0;
  position: relative;
  z-index: 1;
  border: 2px solid #000;
}

.print-cell {
  border: 1px solid #000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.print-cell--empty {
  /* Empty cells just show border */
}

.print-cell-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: bold;
  border-bottom: 1px solid #000;
  min-height: 18px;
  flex-shrink: 0;
}

.print-cell-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.print-cell-diagram {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2px;
  min-height: 0;
}

.print-cell-diagram svg {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}

/* ============================================
   Play Number Badge
   ============================================ */
.play-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  flex-shrink: 0;
  line-height: 1;
}

.play-number--circle {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 11px;
}

.play-number--square {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  font-size: 11px;
}

.play-number--diamond {
  width: 22px;
  height: 22px;
  border-radius: 2px;
  transform: rotate(45deg);
  font-size: 10px;
}

.play-number--diamond > * {
  transform: rotate(-45deg);
}

/* Smaller variants for grid cells */
.print-cell-header .play-number {
  width: 16px;
  height: 16px;
  font-size: 9px;
}

.print-cell-header .play-number--diamond {
  width: 16px;
  height: 16px;
  font-size: 8px;
}

/* ============================================
   Text Play Content
   ============================================ */
.text-play-print {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.5;
  padding: 12px;
  text-align: left;
}

.text-play-print--small {
  font-size: 9px;
  line-height: 1.3;
  padding: 4px;
}

/* ============================================
   Calibration Rulers (print debug)
   ============================================ */
.print-ruler {
  position: absolute;
  z-index: 10;
}

.print-ruler--right {
  top: 0;
  width: 0.25in;
}

.print-ruler--right::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 1px;
  background: #000;
}

.print-ruler--bottom {
  position: absolute;
  height: 0.25in;
}

.print-ruler--bottom::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: #000;
}

.print-ruler .ruler-tick {
  position: absolute;
}

/* Right ruler ticks (horizontal lines from left edge) */
.print-ruler--right .ruler-tick--major {
  left: 0;
  width: 8px;
  border-top: 1px solid #000;
}

.print-ruler--right .ruler-tick--major span {
  position: absolute;
  left: 10px;
  top: -5px;
  font-size: 6px;
  font-family: Arial, sans-serif;
  color: #000;
}

.print-ruler--right .ruler-tick--minor {
  left: 0;
  width: 4px;
  border-top: 1px solid #000;
}

/* Bottom ruler ticks (vertical lines from top edge) */
.print-ruler--bottom .ruler-tick--major {
  top: 0;
  height: 8px;
  border-left: 1px solid #000;
}

.print-ruler--bottom .ruler-tick--major span {
  position: absolute;
  top: 10px;
  left: -3px;
  font-size: 6px;
  font-family: Arial, sans-serif;
  color: #000;
}

.print-ruler--bottom .ruler-tick--minor {
  top: 0;
  height: 4px;
  border-left: 1px solid #000;
}

/* ============================================
   Footer / Identifier
   ============================================ */
.print-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 4px;
  margin-top: auto;
  font-size: 7px;
  color: #999;
  border-top: 0.5px solid #ddd;
  position: relative;
  z-index: 1;
}

.print-id {
  font-family: 'Courier New', monospace;
  font-weight: bold;
  letter-spacing: 1px;
}

.print-meta {
  text-align: right;
}

/* ============================================
   Print Config Form Styles
   (scoped to .print-config-form to avoid leaking)
   ============================================ */
.print-config-form .btn-group { display: flex; gap: 0.25em; }
.print-config-form .btn-group-vertical { flex-direction: column; }

.print-config-form .grid-btn {
  background: var(--bg-tertiary, #e7e5e4);
  color: var(--text-color, #292524);
  border: none;
  border-radius: 6px;
  padding: 0.4em 0.8em;
  font-size: 1em;
  cursor: pointer;
  margin-bottom: 0.2em;
  transition: box-shadow 0.2s, background 0.2s;
  min-width: 2.5em;
  min-height: 2.5em;
  display: flex;
  align-items: center;
  justify-content: center;
}

.print-config-form .grid-btn.active,
.print-config-form .grid-btn:focus {
  background: #b45309 !important;
  color: #fff !important;
  box-shadow: none;
  outline: none;
  border: none;
}

.print-config-form .grid-btn:hover {
  background: #fffbeb;
  box-shadow: 0 0 0 2px rgba(180, 83, 9, 0.6);
}

.print-config-form .preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 0.25em;
  margin-bottom: 0.2em;
}

.print-config-form .preset-grid-2x3 {
  grid-template-columns: repeat(3, 1fr);
}

/* For wristband presets that include 7 items (6 brands + Custom) */
.print-config-form .preset-grid-2x3 .preset-btn:nth-child(7) {
  grid-column: 2;
}

.print-config-form .preset-btn {
  font-size: 0.95em;
  padding: 0.3em 0.7em;
  margin: 0;
  min-width: 90px;
  min-height: 2.5em;
}

.print-config-form .print-style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75em;
}

.print-config-form .form-color-input {
  width: 50px;
  height: 32px;
  padding: 2px;
  cursor: pointer;
}

.print-config-form .btn-group-rows > button,
.print-config-form .btn-group-cols > button {
  flex: 1 1 0;
  min-width: 0;
}

/* ============================================
   @media print — Actual printing
   ============================================ */
@media print {
  .print-container {
    background: white;
    padding: 0;
    gap: 0;
  }

  .print-page {
    box-shadow: none;
    page-break-after: always;
    break-after: page;
  }

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

  /* Force exact colors */
  .print-container * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  /* Ensure watermark prints */
  .print-watermark {
    opacity: 0.04 !important;
  }

  /* Hide any browser chrome */
  @page {
    margin: 0;
  }
}

/* ============================================
   Dark Mode overrides for config form only
   (print preview always uses light/white)
   ============================================ */
html.dark-mode .print-config-form .grid-btn {
  background: #44403c;
  color: #d6d3d1;
}

html.dark-mode .print-config-form .grid-btn:hover {
  background: #57534e;
}

html.dark-mode .print-config-form .grid-btn.active {
  background: #b45309 !important;
  color: #fff !important;
}
