/* ========================================
   MODELOS PREVIOS - VERSIÓN MEJORADA
   Basado en la versión que funcionaba correctamente
   ======================================== */

/* CONTENEDOR PRINCIPAL - SOLO PADDING VERTICAL */
#listadoModelosPreviosContainer {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  padding: 8px 0 !important;
  box-sizing: border-box !important;
  display: flex !important;
  flex-direction: column !important;
  overflow-x: hidden !important;
}

#listadoModelosPreviosContainer .modelos-previos-container {
  display: flex !important;
  flex-direction: column !important;
  padding: 0 !important;
  box-sizing: border-box !important;
  overflow-x: hidden !important;
  margin: 0 !important;
  width: 100% !important;
}

/* ==========================================
   FILTROS - 2 LÍNEAS HORIZONTALES MÁS COMPACTAS
   ========================================== */

/* OCULTAR el título h3 de filtros */
#listadoModelosPreviosContainer .filtros-section > h3 {
  display: none !important;
}

#listadoModelosPreviosContainer .filtros-section {
  background: #f8f9fa;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-bottom: 8px;
}

#listadoModelosPreviosContainer .filtros-container {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
}

#listadoModelosPreviosContainer .filtro-grupo {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

#listadoModelosPreviosContainer .filtro-grupo label {
  font-size: 10px;
  font-weight: 600;
  color: #555;
  margin: 0;
  white-space: nowrap;
  line-height: 1.2;
}

#listadoModelosPreviosContainer .filtro-select {
  padding: 4px 6px;
  font-size: 11px;
  border: 1px solid #ccc;
  border-radius: 3px;
  background: white;
  box-sizing: border-box;
  height: 26px;
  width: 85px; /* Reducido 40% desde ~140px */
}

#listadoModelosPreviosContainer .filtro-select:hover {
  border-color: #0073aa;
}

#listadoModelosPreviosContainer .filtro-select:focus {
  outline: none;
  border-color: #0073aa;
  box-shadow: 0 0 0 1px rgba(0, 115, 170, 0.2);
}

/* Botones alineados a la derecha */
#listadoModelosPreviosContainer .filtro-acciones {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

#listadoModelosPreviosContainer .btn-limpiar,
#listadoModelosPreviosContainer .btn-exportar {
  padding: 5px 12px;
  font-size: 11px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  color: white;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.2s ease;
  height: 26px;
  line-height: 1;
}

#listadoModelosPreviosContainer .btn-limpiar {
  background: #5b9bd5;
}

#listadoModelosPreviosContainer .btn-limpiar:hover {
  background: #4a8ac4;
  transform: translateY(-1px);
}

#listadoModelosPreviosContainer .btn-exportar {
  background: #28a745;
}

#listadoModelosPreviosContainer .btn-exportar:hover {
  background: #218838;
  transform: translateY(-1px);
}

/* ==========================================
   TABLA - RESTAURADA TAL CUAL FUNCIONABA
   ========================================== */

/* OCULTAR título de tabla */
#listadoModelosPreviosContainer .tabla-header > h3 {
  display: none !important;
}

#listadoModelosPreviosContainer .tabla-section {
  margin: 0;
}

#listadoModelosPreviosContainer .tabla-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: #f0f4f8;
  border-radius: 4px;
  border-left: 3px solid #0073aa;
}

#listadoModelosPreviosContainer .tabla-stats {
  display: flex;
  gap: 15px;
  font-size: 12px;
  color: #666;
}

#listadoModelosPreviosContainer .tabla-stats span {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

#listadoModelosPreviosContainer .tabla-stats strong {
  color: #0073aa;
  font-weight: 700;
  font-size: 14px;
}

#listadoModelosPreviosContainer .tabla-wrapper {
  overflow: hidden;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: white;
  margin-bottom: 10px;
}

#listadoModelosPreviosContainer .tabla-modelos {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  table-layout: fixed;
  box-sizing: border-box;
}

/* THEAD FIJO */
#listadoModelosPreviosContainer .tabla-modelos thead {
  display: table;
  width: 100%;
  table-layout: fixed;
  background: #0073aa;
}

#listadoModelosPreviosContainer .tabla-modelos thead th {
  padding: 6px 4px;
  text-align: left;
  color: white;
  font-weight: 600;
  font-size: 11px;
  border-right: 1px solid rgba(255,255,255,0.2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-sizing: border-box;
}

#listadoModelosPreviosContainer .tabla-modelos thead th:last-child {
  border-right: none;
}

#listadoModelosPreviosContainer .tabla-modelos thead th span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* TBODY CON SCROLL */
#listadoModelosPreviosContainer .tabla-modelos tbody {
  display: block;
  height: 216px;
  overflow-y: scroll !important;
  overflow-x: hidden;
  width: 100%;
  box-sizing: border-box;
}

#listadoModelosPreviosContainer .tabla-modelos tbody::-webkit-scrollbar {
  width: 12px;
}

#listadoModelosPreviosContainer .tabla-modelos tbody::-webkit-scrollbar-track {
  background: #f1f1f1;
}

#listadoModelosPreviosContainer .tabla-modelos tbody::-webkit-scrollbar-thumb {
  background: #888;
  border: 2px solid #f1f1f1;
}

#listadoModelosPreviosContainer .tabla-modelos tbody::-webkit-scrollbar-thumb:hover {
  background: #555;
}

#listadoModelosPreviosContainer .tabla-modelos tbody {
  scrollbar-width: auto;
  scrollbar-color: #888 #f1f1f1;
}

#listadoModelosPreviosContainer .tabla-modelos tbody tr {
  display: table;
  width: 100%;
  table-layout: fixed;
  border-bottom: 1px solid #e9ecef;
  cursor: pointer;
  transition: background 0.15s;
  box-sizing: border-box;
}

#listadoModelosPreviosContainer .tabla-modelos tbody tr:hover {
  background: #f0f8ff;
}

#listadoModelosPreviosContainer .tabla-modelos tbody tr.fila-seleccionada {
  background: #d1ecf1;
}

#listadoModelosPreviosContainer .tabla-modelos tbody tr.fila-cargando td {
  text-align: center;
  padding: 30px;
}

#listadoModelosPreviosContainer .loading-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #666;
}

#listadoModelosPreviosContainer .loading-spinner {
  animation: spin 1s linear infinite;
  font-size: 18px;
}

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

#listadoModelosPreviosContainer .tabla-modelos tbody td {
  padding: 6px 5px;
  font-size: 13px;
  font-weight: 600;
  color: #212529;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  height: 36px;
  vertical-align: middle;
  box-sizing: border-box;
}

/* ANCHOS DE COLUMNAS */
#listadoModelosPreviosContainer .col-procedencia { width: 10%; }
#listadoModelosPreviosContainer .col-marca { width: 10%; }
#listadoModelosPreviosContainer .col-anio { width: 6%; text-align: center; }
#listadoModelosPreviosContainer .col-combustible { width: 10%; }
#listadoModelosPreviosContainer .col-carroceria { width: 10%; }
#listadoModelosPreviosContainer .col-modelo { width: 14%; color: #0073aa; font-weight: 600; }
#listadoModelosPreviosContainer .col-cilindrada { width: 8%; }
#listadoModelosPreviosContainer .col-version { width: 14%; }
#listadoModelosPreviosContainer .col-imagen { width: 6%; text-align: center; }
#listadoModelosPreviosContainer .col-acciones { width: 12%; text-align: center; }

/* IMAGEN DEL MODELO */
#listadoModelosPreviosContainer .imagen-modelo-tabla,
#listadoModelosPreviosContainer .col-imagen img {
  max-width: 40px;
  max-height: 24px;
  object-fit: cover;
  border-radius: 2px;
  border: 1px solid #ddd;
  vertical-align: middle;
}

#listadoModelosPreviosContainer .sin-imagen {
  display: inline-block;
  width: 40px;
  height: 24px;
  background: #f8f9fa;
  border: 1px dashed #ccc;
  border-radius: 2px;
  line-height: 24px;
  text-align: center;
  font-size: 9px;
  color: #999;
}

/* BOTONES DE ACCIÓN EN TABLA */
#listadoModelosPreviosContainer .btn-accion-tabla,
#listadoModelosPreviosContainer .btn-editar,
#listadoModelosPreviosContainer .btn-duplicar,
#listadoModelosPreviosContainer .btn-detalles {
  padding: 2px 6px;
  font-size: 10px;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  color: white;
  margin: 0 2px;
  transition: transform 0.15s;
}

#listadoModelosPreviosContainer .btn-accion-tabla:hover {
  transform: scale(1.05);
}

#listadoModelosPreviosContainer .btn-editar { background: #0073aa; }
#listadoModelosPreviosContainer .btn-editar:hover { background: #005a87; }

#listadoModelosPreviosContainer .btn-duplicar { background: #28a745; }
#listadoModelosPreviosContainer .btn-duplicar:hover { background: #218838; }

#listadoModelosPreviosContainer .btn-detalles { background: #6c757d; }
#listadoModelosPreviosContainer .btn-detalles:hover { background: #5a6268; }

/* ==========================================
   BARRA INFERIOR - UNA LÍNEA HORIZONTAL
   Estadísticas + Estado + Acciones
   ========================================== */

/* OCULTAR títulos de las tarjetas */
#infoModelos .info-card h4 {
  display: none !important;
}

#infoModelos {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
}

#infoModelos .info-cards {
  display: flex !important;
  flex-direction: row !important;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 10px 12px;
  background: #f8f9fa;
  border: 1px solid #ddd;
  border-radius: 4px;
  flex-wrap: nowrap !important;
  box-sizing: border-box !important;
}

#infoModelos .info-card {
  display: flex !important;
  align-items: center;
  gap: 15px;
  padding: 0 !important;
  margin: 0 !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  flex-shrink: 0;
}

/* ESTADÍSTICAS en línea */
#infoModelos .info-card ul {
  display: flex !important;
  flex-direction: row !important;
  gap: 15px;
  list-style: none;
  padding: 0;
  margin: 0;
}

#infoModelos .info-card li {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 11px;
  color: #666;
  white-space: nowrap;
}

#infoModelos .info-card li span {
  font-size: 15px;
  font-weight: 700;
  color: #0073aa;
}

/* ESTADO DEL FILTRO */
#estadoFiltros {
  display: flex;
  align-items: center;
  gap: 5px;
}

#estadoFiltros .sin-filtros {
  font-size: 11px;
  color: #28a745;
  font-style: italic;
}

/* ACCIONES RÁPIDAS */
.acciones-rapidas {
  display: flex !important;
  flex-direction: row !important;
  gap: 8px;
  align-items: center;
}

.acciones-rapidas .btn-accion {
  padding: 5px 10px;
  font-size: 11px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  color: white;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
}

.acciones-rapidas .btn-accion:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.acciones-rapidas .btn-accion:nth-child(1) {
  background: #6c757d;
}

.acciones-rapidas .btn-accion:nth-child(1):hover {
  background: #5a6268;
}

.acciones-rapidas .btn-accion:nth-child(2) {
  background: #17a2b8;
}

.acciones-rapidas .btn-accion:nth-child(2):hover {
  background: #138496;
}

.acciones-rapidas .btn-accion:nth-child(3) {
  background: #ffc107;
  color: #333;
}

.acciones-rapidas .btn-accion:nth-child(3):hover {
  background: #e0a800;
}

/* ==========================================
   MENSAJES DE ESTADO
   ========================================== */

#mensajesEstado {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  max-width: 400px;
}

.mensaje {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.mensaje-exito {
  background: #d4edda;
  border-left: 4px solid #28a745;
  color: #155724;
}

.mensaje-error {
  background: #f8d7da;
  border-left: 4px solid #dc3545;
  color: #721c24;
}

.mensaje-info {
  background: #d1ecf1;
  border-left: 4px solid #17a2b8;
  color: #0c5460;
}

.mensaje-icono {
  font-size: 18px;
}

.mensaje-texto {
  font-size: 14px;
  font-weight: 500;
}

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 1400px) {
  #listadoModelosPreviosContainer .filtros-container {
    grid-template-columns: repeat(4, 1fr) auto;
  }
  
  #listadoModelosPreviosContainer .filtro-grupo:nth-child(5),
  #listadoModelosPreviosContainer .filtro-grupo:nth-child(6),
  #listadoModelosPreviosContainer .filtro-grupo:nth-child(7),
  #listadoModelosPreviosContainer .filtro-grupo:nth-child(8) {
    grid-row: 2;
  }
  
  #listadoModelosPreviosContainer .filtro-acciones {
    grid-column: 5;
    grid-row: 1 / 3;
  }
}

@media (max-width: 992px) {
  #infoModelos .info-cards {
    flex-wrap: wrap !important;
  }
  
  #infoModelos .info-card {
    width: 100%;
  }
}

@media (max-width: 768px) {
  #listadoModelosPreviosContainer .filtros-container {
    display: flex;
    flex-direction: column;
  }
  
  #listadoModelosPreviosContainer .filtro-grupo {
    width: 100%;
  }
  
  #listadoModelosPreviosContainer .filtro-acciones {
    width: 100%;
    flex-direction: row;
  }
  
  #listadoModelosPreviosContainer .filtro-acciones button {
    flex: 1;
  }
  
  #listadoModelosPreviosContainer .tabla-modelos tbody {
    height: calc(4 * 36px);
  }
  
  #infoModelos .info-card ul {
    flex-direction: column !important;
    gap: 8px;
  }
}