/* ============================================================
   BUSCADOR DE CÓDIGOS - COPROSA
   ============================================================ */

/* ----- Fuente Code 39 ----- */
@font-face {
  font-family: 'IDAutomationHC39M';
  src: url('fonts/IDAutomationHC39M.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* ----- Variables de diseño ----- */
:root {
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-primary: #1e3a8a;
  --color-primary-hover: #2563eb;
  --color-primary-light: #dbeafe;
  --color-accent: #06b6d4;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e1;
  --color-tag-bg: #eff6ff;
  --color-tag-text: #1e40af;
  --color-tag-cat-bg: #fef3c7;
  --color-tag-cat-text: #92400e;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.10);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --font-sans: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Inter', Tahoma, sans-serif;
  --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
}

/* ----- Reset ----- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   HEADER
   ============================================================ */
header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #06b6d4 100%);
  color: #fff;
  padding: 28px 40px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

header::after {
  content: '';
  position: absolute;
  top: -50%;
  right: -10%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(255,255,255,0.08) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

header h1 {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.subtitle {
  font-size: 0.92rem;
  opacity: 0.85;
  font-weight: 400;
}

/* ============================================================
   MAIN
   ============================================================ */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

/* ============================================================
   BUSCADOR
   ============================================================ */
.search-section {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  margin-bottom: 28px;
  position: sticky;
  top: 12px;
  z-index: 10;
  backdrop-filter: blur(8px);
}

.search-wrapper {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
  font-size: 1.1rem;
}

#searchInput {
  width: 100%;
  padding: 16px 20px 16px 52px;
  font-size: 1rem;
  font-family: var(--font-sans);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #f8fafc;
  color: var(--color-text);
  transition: all 0.2s ease;
  outline: none;
}

#searchInput::placeholder {
  color: #94a3b8;
}

#searchInput:focus {
  border-color: var(--color-primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

/* ----- Filtros ----- */
.filters {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.filters select {
  padding: 10px 36px 10px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  background: #fff url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 16px;
  color: var(--color-text);
  cursor: pointer;
  appearance: none;
  transition: border-color 0.15s;
  min-width: 180px;
}

.filters select:hover {
  border-color: var(--color-border-strong);
}

.filters select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.count {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--color-tag-text);
  font-weight: 600;
  padding: 8px 14px;
  background: var(--color-tag-bg);
  border-radius: 20px;
  white-space: nowrap;
}

/* ============================================================
   RESULTADOS
   ============================================================ */
.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(460px, 1fr));
  gap: 20px;
}

/* ----- Card ----- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s;
  display: flex;
  flex-direction: column;
  min-height: 340px;
  position: relative;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-left-color: var(--color-accent);
}

/* ----- Clave ----- */
.card .clave {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 8px;
  word-break: break-all;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

/* ----- Descripción ----- */
.card .desc {
  font-size: 0.87rem;
  color: var(--color-text-muted);
  margin-bottom: 14px;
  line-height: 1.5;
  flex-grow: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ----- Tags ----- */
.card .tags {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.68rem;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--color-tag-bg);
  color: var(--color-tag-text);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.tag.cat {
  background: var(--color-tag-cat-bg);
  color: var(--color-tag-cat-text);
}

/* ============================================================
   CÓDIGO DE BARRAS - CENTRADO Y NORMALIZADO
   ============================================================ */
/* ============================================================
   CÓDIGO DE BARRAS - ESTILO EXCEL
   ============================================================ */
.barcode-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 0 16px;
  border-top: 1px dashed var(--color-border);
  margin-top: auto;
  background: #fafbfc;
  border-radius: var(--radius-sm);
  width: 100%;
  overflow: hidden;
}

.barcode-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  height: 160px;
  overflow: hidden;
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  box-sizing: border-box;
}

.barcode {
  font-family: 'IDAutomationHC39M', monospace;
  font-size: 120px;
  line-height: 1;
  color: #000;
  background: #fff;
  white-space: nowrap;
  letter-spacing: 0;
  user-select: all;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: geometricPrecision;
  transform-origin: center center;
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
}

/* Ajustes según longitud del código */
.barcode.long   { font-size: 88px; }   /* 15-18 chars */
.barcode.xlong  { font-size: 66px; }   /* 19-24 chars */
.barcode.xxlong { font-size: 48px; }   /* > 24 chars */

/* Texto del código debajo del barcode (estilo Excel) */
.barcode-text {
  font-family: 'IDAutomationHC39M', var(--font-mono);
  font-size: 1.5rem;
  color: #000;
  margin-top: 14px;
  letter-spacing: 3px;
  font-weight: 400;
  text-align: center;
  word-break: break-all;
  padding: 0 8px;
  line-height: 1.3;
}

/* ✅ ELIMINAR este bloque si aún existe */
.barcode-label {
  display: none;
}

/* ============================================================
   ESTADOS VACÍOS
   ============================================================ */
.no-results {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 24px;
  color: var(--color-text-muted);
  font-size: 1.05rem;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--color-border-strong);
}

.no-results strong {
  display: block;
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.4;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 640px) {
  /* ... lo que ya tenías ... */
  
  .barcode-frame { height: 80px; }
  .barcode { font-size: 54px; }
  .barcode.long   { font-size: 40px; }
  .barcode.xlong  { font-size: 30px; }
  .barcode.xxlong { font-size: 22px; }

  .barcode-text {
    font-size: 0.68rem;
    letter-spacing: 2px;
  }
}

@media (max-width: 640px) {
  header { padding: 20px; }
  header h1 { font-size: 1.25rem; }
  .subtitle { font-size: 0.82rem; }
  main { padding: 16px 12px 40px; }
  .search-section { padding: 16px; position: static; }
  #searchInput { padding: 14px 16px 14px 46px; font-size: 0.95rem; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters select { width: 100%; }
  .count { margin-left: 0; text-align: center; }
  .results { grid-template-columns: 1fr; gap: 16px; }
  .card { padding: 18px; min-height: 300px; }
  .barcode { font-size: 30px; }
  .barcode.long { font-size: 22px; }
  .barcode.xlong { font-size: 16px; }
  .barcode.xxlong { font-size: 12px; }
}