/* Estilos para Generador de Códigos de Barras Térmico */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #10b981;
  --success-hover: #059669;
  --warning: #f59e0b;
  --danger: #ef4444;
  --dark: #0f172a;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --radius: 10px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);

  /* Medidas dinámicas de la etiqueta (Por defecto: 2 al paso 50x25mm) */
  --columns-count: 2;
  --label-width: 50mm;
  --label-height: 25mm;
  --column-gap: 3mm;
  --offset-x: 0mm;
  --offset-y: 0mm;
  --row-total-width: 103mm;
  --label-padding: 1mm;
  --font-size-text: 18px;
  --font-family: 'Arial Black', 'Arial Bold', Gadget, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background-color: #f1f5f9;
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100vh;
}

/* Encabezado */
.navbar {
  background: #ffffff;
  border-bottom: 1px solid var(--gray-200);
  padding: 0.85rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  background: var(--primary-light);
  color: var(--primary);
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border: 1px solid #dbeafe;
}

.brand-info h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--dark);
  line-height: 1.2;
}

.brand-info span {
  font-size: 0.8rem;
  color: var(--gray-600);
}

.navbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Indicador de impresora */
.printer-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gray-700);
  cursor: pointer;
  transition: all 0.2s ease;
}
.printer-pill:hover {
  background: var(--gray-200);
}
.printer-pill.online {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}
.printer-pill.warning {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
  flex-shrink: 0;
}
.printer-pill.online .status-dot {
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}
.printer-pill.warning .status-dot {
  background: #f59e0b;
}

/* Badge de usuario en navbar */
.user-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gray-800);
}
.user-badge button {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-weight: 700;
  margin-left: 4px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 2px;
}
.user-badge button:hover {
  text-decoration: underline;
}

/* Pantalla de Inicio de Sesión */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 50% 30%, #1e293b 0%, #0f172a 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  padding: 20px;
  backdrop-filter: blur(6px);
}
.login-box {
  background: #ffffff;
  border-radius: 18px;
  max-width: 420px;
  width: 100%;
  padding: 36px 30px;
  box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.1);
  animation: loginFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes loginFadeIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.login-header {
  text-align: center;
  margin-bottom: 24px;
}
.login-logo {
  font-size: 46px;
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1));
}
.login-header h2 {
  font-size: 1.35rem;
  color: #0f172a;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.login-header p {
  font-size: 0.85rem;
  color: #64748b;
  margin-top: 4px;
}
.login-alert {
  display: none;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 16px;
  text-align: center;
}

/* Envoltorio del campo contraseña con botón de miquito */
.password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.password-wrapper input {
  padding-right: 46px !important;
}

.btn-toggle-password {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 1.3rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background-color 0.15s ease;
  user-select: none;
}

.btn-toggle-password:hover {
  background-color: #f1f5f9;
  transform: translateY(-50%) scale(1.15);
}

.btn-toggle-password:active {
  transform: translateY(-50%) scale(0.95);
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}
.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-success {
  background: var(--success);
  color: white;
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.2);
}
.btn-success:hover {
  background: var(--success-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}
.btn-secondary:hover {
  background: var(--gray-200);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover {
  background: var(--primary-light);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

/* Layout Principal */
.app-container {
  display: grid;
  grid-template-columns: 430px 1fr;
  gap: 24px;
  padding: 24px;
  max-width: 1700px;
  margin: 0 auto;
}

@media (max-width: 1050px) {
  .app-container {
    grid-template-columns: 1fr;
  }
}

/* Tarjetas */
.card {
  background: #ffffff;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 20px;
}

.card:last-child {
  margin-bottom: 0;
}

.card-header {
  padding: 14px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body {
  padding: 18px;
}

/* Pestañas */
.tabs {
  display: flex;
  background: var(--gray-100);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1;
  text-align: center;
  padding: 7px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-600);
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

/* Formularios */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 5px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  font-size: 0.9rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  color: var(--dark);
  background: #fff;
  transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea {
  font-family: monospace;
  font-size: 0.95rem;
  resize: vertical;
}

/* Subida de archivo arrastrar y soltar */
.dropzone {
  border: 2px dashed var(--gray-300);
  border-radius: 8px;
  padding: 24px 16px;
  text-align: center;
  background: var(--gray-50);
  cursor: pointer;
  transition: all 0.2s ease;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.dropzone-icon {
  font-size: 36px;
  color: var(--primary);
  margin-bottom: 8px;
}

.dropzone-text {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gray-700);
}

.dropzone-sub {
  font-size: 0.75rem;
  color: var(--gray-600);
  margin-top: 4px;
}

/* Checkbox estilizados */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--gray-700);
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Vista Previa */
.preview-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  background: #ffffff;
  padding: 12px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
}
.badge-info {
  background: #e0f2fe;
  color: #0369a1;
}

/* Visualizador de Rollo Continuo */
.roll-viewer {
  background: #334155;
  border-radius: var(--radius);
  padding: 24px;
  overflow-x: auto;
  min-height: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.3);
}

.roll-paper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
  position: relative;
}

/* Fila de etiquetas para 1 o 2 al paso */
.label-row {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  gap: var(--column-gap);
  padding-left: var(--offset-x);
  padding-top: var(--offset-y);
  box-sizing: border-box;
}

/* Línea indicadora de rollo continuo */
.roll-paper::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: repeating-linear-gradient(to bottom, #475569 0, #475569 6px, transparent 6px, transparent 12px);
  z-index: 0;
  transform: translateX(-50%);
}

/* La Etiqueta Física Visualizada */
.label-item {
  width: var(--label-width);
  height: var(--label-height);
  padding: var(--label-padding);
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  overflow: hidden;
  user-select: none;
  transition: transform 0.15s ease;
}

.label-item.empty {
  visibility: hidden;
  border: 1px dashed #cbd5e1;
  background: transparent;
  box-shadow: none;
}

.label-item:hover {
  transform: scale(1.03);
}

.label-plate-text {
  font-weight: 900;
  font-family: var(--font-family, 'Arial Black', 'Arial Bold', Gadget, sans-serif);
  color: #000000;
  text-align: center;
  letter-spacing: 0.5px;
  line-height: 1.1;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  margin-top: 1px;
}

.label-barcode-container {
  width: 100%;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  padding: 0 1mm;
  box-sizing: border-box;
}

.label-barcode-container canvas,
.label-barcode-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  display: block;
}

/* Zoom para vista previa en pantalla */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--gray-600);
}

/* Modal de Guía de Impresión Zebra */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  z-index: 999;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(3px);
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: 12px;
  max-width: 650px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.1rem;
  color: var(--dark);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--gray-600);
}

.modal-body {
  padding: 20px;
}

.guide-step {
  display: flex;
  gap: 14px;
  margin-bottom: 16px;
}

.step-number {
  background: var(--primary-light);
  color: var(--primary);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.step-text h4 {
  font-size: 0.95rem;
  margin-bottom: 3px;
  color: var(--gray-800);
}

.step-text p {
  font-size: 0.85rem;
  color: var(--gray-600);
}

/* ======================================================
   RESPONSIVIDAD MÓVIL Y TABLET
   ====================================================== */
@media (max-width: 768px) {
  .navbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 0.85rem 1rem;
  }

  .brand {
    justify-content: flex-start;
  }

  .brand-icon {
    width: 36px;
    height: 36px;
    font-size: 19px;
  }

  .brand-info h1 {
    font-size: 1.1rem;
  }

  .brand-info span {
    font-size: 0.74rem;
  }

  .navbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    justify-content: flex-start;
  }

  .navbar-actions .btn,
  .navbar-actions .printer-pill {
    flex: 1 1 auto;
    justify-content: center;
    text-align: center;
    font-size: 0.82rem;
    padding: 7px 10px;
  }

  #btn-direct-print {
    width: 100%;
    order: -1; /* Darle máxima visibilidad al botón principal de imprimir */
  }

  .user-badge {
    width: 100%;
    justify-content: space-between;
    margin-top: 2px;
  }

  .app-container {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 16px;
  }

  .card-body {
    padding: 14px;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .form-row-3 {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .preview-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }

  .preview-toolbar > div {
    justify-content: space-between;
    width: 100%;
  }

  .roll-viewer {
    padding: 14px 8px;
    min-height: 360px;
  }

  .modal-content {
    width: 95%;
    max-height: 94vh;
  }

  .modal-header {
    padding: 12px 16px;
  }

  .modal-body {
    padding: 16px;
  }

  .login-box {
    padding: 24px 18px;
    border-radius: 14px;
  }

  .login-logo {
    font-size: 38px;
  }

  .login-header h2 {
    font-size: 1.2rem;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 14px;
  }

  .brand-info h1 {
    font-size: 1rem;
  }

  .brand-info span {
    display: none; /* Ahorrar espacio vertical en celulares pequeños */
  }

  .navbar {
    padding: 0.65rem 0.85rem;
  }

  .app-container {
    padding: 8px;
  }

  .card-header h2 {
    font-size: 0.92rem;
  }

  .tab-btn {
    padding: 6px 8px;
    font-size: 0.78rem;
  }

  .btn {
    font-size: 0.82rem;
  }
}

/* ======================================================
   REGLAS ESTRICTAS DE IMPRESIÓN TÉRMICA (ZEBRA / ROLLO)
   ====================================================== */
@media print {
  /* Configuración de tamaño de página milimétrico exacto para la fila (1 o 2 al paso) */
  @page {
    size: var(--row-total-width) var(--label-height);
    margin: 0 !important;
  }

  html, body {
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    width: var(--row-total-width) !important;
    height: auto !important;
  }

  /* Ocultar toda la interfaz de usuario en la impresión */
  .no-print,
  .navbar,
  .sidebar,
  .preview-toolbar,
  .modal-overlay,
  .zoom-controls {
    display: none !important;
  }

  .app-container {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
  }

  .preview-container {
    display: block !important;
  }

  .roll-viewer {
    background: transparent !important;
    padding: 0 !important;
    box-shadow: none !important;
    overflow: visible !important;
    min-height: auto !important;
  }

  .roll-paper {
    padding: 0 !important;
    gap: 0 !important;
    display: block !important;
  }

  .roll-paper::before {
    display: none !important;
  }

  /* Fila completa de etiquetas: salto de página después de cada fila */
  .label-row {
    width: var(--row-total-width) !important;
    height: var(--label-height) !important;
    display: flex !important;
    flex-direction: row !important;
    justify-content: flex-start !important;
    align-items: center !important;
    gap: var(--column-gap) !important;
    padding-left: var(--offset-x) !important;
    padding-top: var(--offset-y) !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    overflow: hidden !important;
  }

  /* Cada etiqueta física individual dentro de la fila */
  .label-item {
    width: var(--label-width) !important;
    height: var(--label-height) !important;
    padding: var(--label-padding) !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    box-sizing: border-box !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    align-items: center !important;
    overflow: hidden !important;
    transform: none !important;
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  .label-item.empty {
    visibility: hidden !important;
  }

  .label-plate-text {
    color: #000000 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .label-barcode-container canvas,
  .label-barcode-container img {
    image-rendering: pixelated !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
