/* ============================================================
   PrintNUp — Estilos principales
   Estética: utilitarian/editorial con acentos de color fuertes
   ============================================================ */

/* ── Variables ── */
:root {
  --bg:          #f0ece4;
  --surface:     #faf8f4;
  --surface2:    #e8e3d8;
  --ink:         #1a1814;
  --ink-mid:     #4a4640;
  --ink-light:   #8a8478;
  --accent:      #d4420a;
  --accent-dark: #a33208;
  --accent-pale: #fde8df;
  --green:       #2a7a4b;
  --green-pale:  #d4f0e0;
  --border:      #ccc7bc;
  --shadow:      rgba(26, 24, 20, 0.12);
  --radius:      6px;
  --font-display: 'Georgia', 'Times New Roman', serif;
  --font-body:   'Courier New', 'Courier', monospace;
  --font-ui:     system-ui, -apple-system, sans-serif;

  /* A4 en pantalla */
  --a4-w-portrait:   210mm;
  --a4-h-portrait:   297mm;
  --a4-w-landscape:  297mm;
  --a4-h-landscape:  210mm;

  /* Escala de visualización */
  --sheet-scale: 0.72;
}

/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.app-header {
  background: var(--ink);
  color: #faf8f4;
  padding: 18px 32px;
  border-bottom: 3px solid var(--accent);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
}

.logo-icon {
  font-size: 28px;
  color: var(--accent);
  line-height: 1;
}

.logo-text {
  font-size: 24px;
  letter-spacing: -0.5px;
  color: #faf8f4;
}

.logo-text strong {
  color: var(--accent);
}

.tagline {
  font-size: 12px;
  color: #8a8478;
  font-family: var(--font-body);
  letter-spacing: 0.02em;
}

/* ── Main ── */
.app-main {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 24px 40px;
  width: 100%;
}

/* ── Controls bar ── */
.controls-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px var(--shadow);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-light);
  font-family: var(--font-body);
}

/* ── NUp selector ── */
.nup-selector {
  display: flex;
  gap: 6px;
}

.nup-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-mid);
  transition: all 0.15s ease;
  font-family: var(--font-ui);
  min-width: 52px;
}

.nup-btn:hover {
  background: var(--accent-pale);
  border-color: var(--accent);
  color: var(--accent);
}

.nup-btn.active {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #fff;
}

/* Mini iconos de grilla para cada opción NUp */
.nup-icon {
  display: grid;
  gap: 2px;
  width: 24px;
  height: 18px;
}

.nup-icon > * { background: currentColor; border-radius: 1px; }

.nup-2  { grid-template-columns: 1fr 1fr; }
.nup-2::before, .nup-2::after { content:''; background: currentColor; border-radius: 1px; }

.nup-3  { grid-template-columns: 1fr 1fr 1fr; }
.nup-4  { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.nup-6  { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
.nup-8  { grid-template-columns: 1fr 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }

/* Generamos los pseudo-hijos con box-shadow para los iconos */
.nup-btn .nup-icon { position: relative; overflow: hidden; }
.nup-btn .nup-icon::before {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0.2;
  border-radius: 1px;
}

/* ── Orientation selector ── */
.orientation-selector {
  display: flex;
  gap: 6px;
}

.orient-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-mid);
  transition: all 0.15s ease;
  font-family: var(--font-ui);
}

.orient-btn:hover {
  background: var(--accent-pale);
  border-color: var(--accent);
  color: var(--accent);
}

.orient-btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

/* ── Toggle ── */
.options-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-mid);
  user-select: none;
}

.toggle-label input[type="checkbox"] { display: none; }

.toggle-track {
  width: 36px;
  height: 20px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  position: relative;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.toggle-track::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  background: var(--ink-light);
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s, background 0.2s;
}

.toggle-label input:checked + .toggle-track {
  background: var(--accent);
  border-color: var(--accent-dark);
}

.toggle-label input:checked + .toggle-track::after {
  transform: translateX(16px);
  background: #fff;
}

/* ── Botones de acción ── */
.actions-group {
  flex-direction: row;
  gap: 10px;
  align-items: flex-end;
  margin-left: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: 1.5px solid;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font-ui);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.btn-upload {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #fff;
}
.btn-upload:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(212,66,10,0.3);
}

.btn-clear {
  background: transparent;
  border-color: var(--border);
  color: var(--ink-mid);
}
.btn-clear:hover {
  background: var(--surface2);
  border-color: var(--ink-mid);
}

.btn-print {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.btn-print:hover {
  background: #333;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--shadow);
}

/* ── Indicador de orientación ── */
.orientation-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 12px;
}

.orient-badge {
  font-weight: 700;
  font-family: var(--font-body);
  color: var(--accent);
  font-size: 12px;
}

.slot-count {
  color: var(--ink-light);
  font-family: var(--font-body);
}

/* ── Loading overlay ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,24,20,0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  color: #fff;
  font-size: 15px;
  gap: 16px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Sheet wrapper ── */
.sheet-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
  /* Permite scroll si la hoja es más grande que la ventana */
  overflow: auto;
  padding: 16px 0;
}

/* ── Hoja A4 (portrait) ── */
.sheet {
  background: #fff;
  position: relative;
  box-shadow: 0 4px 32px rgba(0,0,0,0.18), 0 1px 4px rgba(0,0,0,0.08);
  border-radius: 2px;

  /* Dimensiones A4 escaladas para pantalla */
  width:  calc(var(--a4-w-portrait) * var(--sheet-scale));
  height: calc(var(--a4-h-portrait) * var(--sheet-scale));
  padding: calc(8mm * var(--sheet-scale));

  transition: width 0.3s ease, height 0.3s ease;
}

/* Hoja A4 landscape */
.sheet.landscape {
  width:  calc(var(--a4-w-landscape) * var(--sheet-scale));
  height: calc(var(--a4-h-landscape) * var(--sheet-scale));
}

/* ── Grilla de la hoja ── */
.sheet-grid {
  display: grid;
  width: 100%;
  height: 100%;
  gap: 4px;
}

/* ── Slot (celda de la grilla) ── */
.slot {
  position: relative;
  overflow: hidden;
  background: #f9f9f9;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s;
}

.slot.has-border {
  outline: 0.5px solid #ccc;
}

/* Número de página */
.slot-number {
  position: absolute;
  bottom: 3px;
  right: 5px;
  font-size: 8px;
  color: #bbb;
  font-family: var(--font-body);
  z-index: 5;
  pointer-events: none;
}

/* Imagen dentro del slot */
.slot img {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* ── Botón "+" para slot vacío ── */
.slot-add-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: 100%;
  background: none;
  border: 2px dashed var(--border);
  border-radius: 2px;
  cursor: pointer;
  color: var(--ink-light);
  font-size: 11px;
  font-family: var(--font-ui);
  transition: all 0.15s ease;
}

.slot-add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-pale);
}

.slot-add-btn .plus-icon {
  font-size: 24px;
  font-weight: 300;
  line-height: 1;
}

/* ── Overlay de acciones sobre imagen ── */
.slot-actions {
  position: absolute;
  inset: 0;
  background: rgba(26,24,20,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.18s ease;
  z-index: 10;
  border-radius: 2px;
}

.slot:hover .slot-actions { opacity: 1; }

.slot-action-btn {
  padding: 6px 10px;
  background: rgba(255,255,255,0.92);
  border: none;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  color: var(--ink);
  transition: background 0.1s;
  font-family: var(--font-ui);
}

.slot-action-btn:hover { background: #fff; }
.slot-action-btn.delete-btn { color: var(--accent); }

/* ── Drag & drop highlight ── */
.slot.drag-over .slot-add-btn {
  border-color: var(--accent);
  background: var(--accent-pale);
  color: var(--accent);
}

/* ── Instrucciones ── */
.instructions {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

.instruction-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  flex: 1;
  min-width: 180px;
  max-width: 240px;
  font-size: 13px;
  color: var(--ink-mid);
}

.inst-icon {
  font-size: 18px;
  font-family: var(--font-display);
  color: var(--accent);
  flex-shrink: 0;
}

/* ── Footer ── */
.app-footer {
  text-align: center;
  padding: 16px;
  font-size: 11px;
  color: var(--ink-light);
  font-family: var(--font-body);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.app-footer a {
  color: var(--accent);
  text-decoration: none;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  :root { --sheet-scale: 0.48; }
  .controls-bar { gap: 16px; padding: 16px; }
  .actions-group { margin-left: 0; }
  .nup-selector { flex-wrap: wrap; }
  .header-inner { gap: 12px; }
  .tagline { display: none; }
}

@media (max-width: 480px) {
  :root { --sheet-scale: 0.38; }
}


/* ============================================================
   ESTILOS DE IMPRESIÓN
   La impresión se hace via iframe oculto generado por JS.
   Estos estilos son sólo un fallback de seguridad.
   ============================================================ */
@media print {
  /* Ocultar absolutamente todo — el iframe se encarga */
  * { display: none !important; }
}
