/* ════════════════════════════════════════════════════════════════════
   MÓDULO COMPOSICIONES — UI Enterprise / Clean Modern
   Industria: Facturación / Distribución
   Estilo: Data-Dense + Clean Modern
   Paleta: #1A3C8F (azul R&H), #1e293b (oscuro), #F8FAFC (fondo)
   Tipografía: Montserrat
   ════════════════════════════════════════════════════════════════════ */

/* ── PÁGINA WRAPPER ─────────────────────────────────────────────── */
#page-composiciones {
  background: #F1F5F9;
  min-height: 100vh;
  font-family: Montserrat, -apple-system, sans-serif;
  padding-bottom: 40px;
}

/* ── HEADER DEL MÓDULO ──────────────────────────────────────────── */
.comp-header {
  background: linear-gradient(135deg, #0F172A 0%, #1A3C8F 60%, #2563EB 100%);
  color: white;
  padding: 20px 24px 28px;
  position: relative;
  overflow: hidden;
}

.comp-header::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 180px; height: 180px;
  background: rgba(255,255,255,0.04);
  border-radius: 50%;
}

.comp-header::after {
  content: '';
  position: absolute;
  bottom: -60px; left: 20%;
  width: 260px; height: 260px;
  background: rgba(255,255,255,0.03);
  border-radius: 50%;
}

.comp-header h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.5px;
  position: relative;
  z-index: 1;
}

.comp-header p {
  margin: 0;
  font-size: 11px;
  opacity: 0.75;
  position: relative;
  z-index: 1;
}

/* ── BUSCADOR HERO ──────────────────────────────────────────────── */
.comp-search-wrap {
  position: relative;
  z-index: 1;
  margin-top: 16px;
}

.comp-search-wrap input {
  width: 100%;
  padding: 14px 16px 14px 44px;
  border: none;
  border-radius: 10px;
  font-family: Montserrat;
  font-size: 14px;
  font-weight: 600;
  background: rgba(255,255,255,0.96);
  color: #1e293b;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  box-sizing: border-box;
  outline: none;
}

.comp-search-wrap input::placeholder {
  color: #94A3B8;
  font-weight: 500;
}

.comp-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  pointer-events: none;
}

/* ── RESULTADOS DROPDOWN ────────────────────────────────────────── */
.comp-dropdown {
  background: white;
  border-radius: 10px;
  border: 1px solid #E2E8F0;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  max-height: 280px;
  overflow-y: auto;
  margin-top: 6px;
  display: none;
}

.comp-dropdown.visible { display: block; }

.comp-dropdown-item {
  padding: 11px 14px;
  border-bottom: 1px solid #F1F5F9;
  cursor: pointer;
  transition: background 0.12s;
}

.comp-dropdown-item:hover { background: #F8FAFC; }
.comp-dropdown-item:last-child { border-bottom: none; }

.comp-dropdown-item .nombre {
  font-weight: 700;
  font-size: 13px;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.comp-dropdown-item .meta {
  font-size: 11px;
  color: #64748B;
  margin-top: 2px;
  display: flex;
  gap: 10px;
}

.comp-dropdown-item .meta span {
  background: #F1F5F9;
  padding: 1px 6px;
  border-radius: 4px;
}

.comp-dropdown-item .meta .stock-ok { background:#DCFCE7; color:#15803D; }
.comp-dropdown-item .meta .stock-bajo { background:#FEF3C7; color:#92400E; }
.comp-dropdown-item .meta .stock-cero { background:#FEE2E2; color:#DC2626; }

/* ── CONTENIDO PRINCIPAL ────────────────────────────────────────── */
.comp-body {
  padding: 16px;
  max-width: 1080px;
  margin: 0 auto;
}

/* ── PANEL CONFIGURADOR ─────────────────────────────────────────── */
.comp-configurador {
  display: none;
  background: white;
  border-radius: 12px;
  border: 1px solid #E2E8F0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  margin-bottom: 16px;
  overflow: hidden;
}

.comp-configurador.visible { display: block; }

.comp-config-header {
  background: #1e293b;
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.comp-config-header .articulo-info { flex: 1; }
.comp-config-header .articulo-nombre {
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.comp-config-header .articulo-meta {
  font-size: 10px;
  opacity: 0.7;
  margin-top: 2px;
}

.comp-config-header .articulo-badge {
  background: rgba(255,255,255,0.15);
  color: white;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  margin-left: 12px;
}

/* ── LAYOUT CONFIGURADOR: 2 COLUMNAS ───────────────────────────── */
.comp-config-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 300px;
}

@media (max-width: 680px) {
  .comp-config-grid { grid-template-columns: 1fr; }
}

/* ── COLUMNA IZQUIERDA: PRESENTACIONES ──────────────────────────── */
.comp-col-presentaciones {
  padding: 16px;
  border-right: 1px solid #E2E8F0;
  background: #FAFBFC;
}

.comp-col-presentaciones h4 {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #64748B;
  margin: 0 0 12px;
  text-transform: uppercase;
}

/* Tarjetas de presentación */
.comp-pres-card {
  border: 2px solid #E2E8F0;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.15s;
  background: white;
  position: relative;
}

.comp-pres-card:hover { border-color: #93C5FD; transform: translateX(2px); }
.comp-pres-card.pres-und.on { border-color: #1A3C8F; background: #EFF6FF; }
.comp-pres-card.pres-sobre.on { border-color: #9333EA; background: #F5F3FF; }
.comp-pres-card.pres-display.on { border-color: #0891B2; background: #ECFEFF; }

.comp-pres-card .pres-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.comp-pres-card .pres-icon { font-size: 22px; }

.comp-pres-card .pres-label {
  flex: 1;
  font-weight: 700;
  font-size: 13px;
  color: #1e293b;
}

.comp-pres-card .pres-label small {
  display: block;
  font-size: 10px;
  color: #64748B;
  font-weight: 600;
  margin-top: 1px;
}

.comp-pres-card .pres-toggle {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: #CBD5E1;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.comp-pres-card.on .pres-toggle { background: #1A3C8F; }
.comp-pres-card.pres-sobre.on .pres-toggle { background: #9333EA; }
.comp-pres-card.pres-display.on .pres-toggle { background: #0891B2; }

.comp-pres-card .pres-toggle::after {
  content: '';
  position: absolute;
  left: 2px; top: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: white;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.comp-pres-card.on .pres-toggle::after { left: 18px; }

/* Input de cantidad */
.comp-pres-qty {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #E2E8F0;
}

.comp-pres-card.on .comp-pres-qty { display: flex; align-items: center; gap: 8px; }

.comp-pres-qty label {
  font-size: 11px;
  color: #64748B;
  font-weight: 700;
  white-space: nowrap;
}

.comp-pres-qty input {
  width: 70px;
  padding: 6px 8px;
  border: 1.5px solid #CBD5E1;
  border-radius: 6px;
  font-family: Montserrat;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  color: #1e293b;
}

.comp-pres-qty input:focus {
  outline: none;
  border-color: #1A3C8F;
}

.comp-pres-qty span {
  font-size: 10px;
  color: #94A3B8;
}

/* ── BARRA DE COSTOS ────────────────────────────────────────────── */
.comp-costos-bar {
  background: #0F172A;
  color: white;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 14px;
  border-radius: 8px;
}

.comp-costos-bar .costo-item {
  text-align: center;
  padding: 4px;
  border-right: 1px solid rgba(255,255,255,0.1);
}

.comp-costos-bar .costo-item:last-child { border-right: none; }

.comp-costos-bar .costo-label {
  font-size: 9px;
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.comp-costos-bar .costo-val {
  font-size: 13px;
  font-weight: 800;
  color: #34D399;
  margin-top: 2px;
}

/* ── COLUMNA DERECHA: TABLA DE PRECIOS ──────────────────────────── */
.comp-col-precios {
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.comp-col-precios h4 {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #64748B;
  margin: 0 0 12px;
  text-transform: uppercase;
}

/* ── TABLA 4 LISTAS × 3 PRESENTACIONES ─────────────────────────── */
.comp-tabla {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  flex: 1;
}

.comp-tabla thead tr {
  background: #1e293b;
  color: white;
}

.comp-tabla thead th {
  padding: 10px 8px;
  text-align: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.comp-tabla thead th:first-child {
  text-align: left;
  padding-left: 12px;
  width: 65px;
}

.comp-tabla thead th.th-und { background: #1D4ED8; }
.comp-tabla thead th.th-sobre { background: #7E22CE; }
.comp-tabla thead th.th-display { background: #0E7490; }

.comp-tabla tbody tr {
  border-bottom: 1px solid #F1F5F9;
  transition: background 0.1s;
}

.comp-tabla tbody tr:hover { background: #FAFBFC; }

.comp-tabla td {
  padding: 6px 4px;
  vertical-align: middle;
}

.comp-tabla td:first-child {
  padding-left: 12px;
  font-weight: 800;
  font-size: 11px;
  color: #1e293b;
  white-space: nowrap;
}

.comp-tabla td.td-und { background: rgba(29,78,216,0.04); }
.comp-tabla td.td-sobre { background: rgba(126,34,206,0.04); }
.comp-tabla td.td-display { background: rgba(14,116,144,0.04); }
.comp-tabla td.td-disabled { background: #F8FAFC; text-align: center; color: #CBD5E1; }

/* Celda de precio + margen */
.comp-precio-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px;
}

.comp-precio-cell input {
  width: 100%;
  padding: 5px 6px;
  border: 1.5px solid #E2E8F0;
  border-radius: 5px;
  font-family: Montserrat;
  font-size: 12px;
  font-weight: 700;
  text-align: right;
  color: #1e293b;
  background: white;
  min-width: 0;
}

.comp-precio-cell input:focus {
  outline: none;
  border-color: #1A3C8F;
  box-shadow: 0 0 0 2px rgba(26,60,143,0.1);
}

.comp-precio-cell .margen-badge {
  font-size: 9px;
  font-weight: 700;
  color: #64748B;
  text-align: right;
  padding-right: 2px;
}

.comp-precio-cell .margen-badge.mg-ok { color: #16A34A; }
.comp-precio-cell .margen-badge.mg-warn { color: #D97706; }
.comp-precio-cell .margen-badge.mg-bad { color: #DC2626; }

/* ── ACCIONES DEL CONFIGURADOR ──────────────────────────────────── */
.comp-config-actions {
  padding: 12px 16px;
  border-top: 1px solid #E2E8F0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #FAFBFC;
}

.btn-comp {
  padding: 10px 20px;
  border: none;
  border-radius: 7px;
  font-family: Montserrat;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-comp-primary {
  background: #1A3C8F;
  color: white;
}
.btn-comp-primary:hover { background: #163072; transform: translateY(-1px); }

.btn-comp-secondary {
  background: #F1F5F9;
  color: #475569;
}
.btn-comp-secondary:hover { background: #E2E8F0; }

/* ── LISTA DE COMPOSICIONES GUARDADAS ───────────────────────────── */
.comp-lista-card {
  background: white;
  border-radius: 12px;
  border: 1px solid #E2E8F0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  overflow: hidden;
}

.comp-lista-header {
  background: #1A3C8F;
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.comp-lista-header h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.comp-lista-header .comp-badge {
  background: rgba(255,255,255,0.2);
  color: white;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}

.comp-lista-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.comp-lista-table thead {
  background: #F8FAFC;
  border-bottom: 2px solid #E2E8F0;
}

.comp-lista-table thead th {
  padding: 9px 12px;
  text-align: left;
  font-size: 10px;
  font-weight: 800;
  color: #64748B;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.comp-lista-table tbody tr {
  border-bottom: 1px solid #F1F5F9;
  cursor: pointer;
  transition: background 0.12s;
}

.comp-lista-table tbody tr:hover { background: #F8FAFC; }
.comp-lista-table tbody tr:last-child { border-bottom: none; }

.comp-lista-table td {
  padding: 10px 12px;
  vertical-align: middle;
}

.comp-lista-table td .comp-nombre {
  font-weight: 700;
  color: #1e293b;
  font-size: 12px;
}

.comp-lista-table td .comp-codigo {
  font-size: 10px;
  color: #94A3B8;
  margin-top: 1px;
}

.comp-pres-chips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.comp-chip {
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.chip-und { background: #DBEAFE; color: #1D4ED8; }
.chip-sobre { background: #EDE9FE; color: #7E22CE; }
.chip-display { background: #CFFAFE; color: #0E7490; }

.comp-lista-table td .costo-valor {
  font-weight: 800;
  color: #1e293b;
  font-size: 12px;
}

.btn-comp-delete {
  background: #FEE2E2;
  color: #DC2626;
  border: none;
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  font-family: Montserrat;
  transition: all 0.12s;
}

.btn-comp-delete:hover { background: #DC2626; color: white; }

/* Mensaje vacío */
.comp-empty {
  text-align: center;
  padding: 32px 20px;
  color: #94A3B8;
}

.comp-empty .icon { font-size: 36px; margin-bottom: 8px; }
.comp-empty p { font-size: 13px; font-weight: 600; margin: 0; }

/* ── LOADER ─────────────────────────────────────────────────────── */
.comp-loader {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  font-size: 12px;
  color: #94A3B8;
}

.comp-loader.visible { display: flex; }

.comp-loader-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #1A3C8F;
  animation: compBounce 1.2s infinite ease-in-out;
}

.comp-loader-dot:nth-child(2) { animation-delay: 0.2s; }
.comp-loader-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes compBounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── MEJORAS UI v2 ──────────────────────────────────────────────── */

/* Lista card: mismo ancho que el buscador hero */
.comp-body {
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

/* Porcentaje de margen: pill con color semáforo */
.comp-precio-cell .margen-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  padding: 2px 7px;
  border-radius: 20px;
  margin-top: 3px;
  background: #F1F5F9;
  color: #64748B;
  width: fit-content;
  min-width: 52px;
  float: right;
}

.comp-precio-cell .margen-badge.mg-ok  { background: #DCFCE7; color: #15803D; }
.comp-precio-cell .margen-badge.mg-warn { background: #FEF3C7; color: #92400E; }
.comp-precio-cell .margen-badge.mg-bad  { background: #FEE2E2; color: #DC2626; }

/* Input de precio más limpio */
.comp-precio-cell input {
  border: 1.5px solid #E2E8F0;
  border-radius: 6px;
  padding: 6px 8px;
  font-weight: 700;
  font-size: 13px;
  text-align: right;
  width: 100%;
  background: white;
  transition: border-color 0.15s;
}

.comp-precio-cell input:focus {
  border-color: #1A3C8F;
  box-shadow: 0 0 0 3px rgba(26,60,143,0.08);
  outline: none;
}

/* ── PILL AL LADO DEL PRECIO ────────────────────────────────────── */
.comp-precio-cell {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.comp-precio-cell input {
  flex: 1;
  min-width: 0;
}

.comp-precio-cell .margen-badge {
  float: none;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 52px;
  text-align: center;
}
