/* BUSCAR.CSS - Diseño Moderno */

/* Reset básico de box-sizing para todos los elementos */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  color: #333;
  line-height: 1.6;
  background-color: #f5f7fa;
  margin: 0;
  padding: 0;
}

/* Contenedor principal */
.search-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
  position: relative;
  overflow: hidden; /* evita que cualquier cosa se salga */
}

/* ============ MODAL / OVERLAY ============ */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  pointer-events: none;
}

.modal-overlay.hidden {
  display: none;
}

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  z-index: -1;
  pointer-events: auto;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-content {
  background: white;
  border-radius: 20px;
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease;
  position: relative;
  pointer-events: auto;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Botón cerrar modal */
.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.8rem;
  font-weight: 300;
  color: #6c757d;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: all 0.2s ease;
  line-height: 1;
  z-index: 10;
}

.modal-close:hover {
  background: #f1f3f5;
  color: #212529;
  transform: rotate(90deg);
}

.modal-close:focus-visible {
  outline: 2px solid #284272;
  outline-offset: 2px;
}

.modal-header {
  text-align: center;
  margin-bottom: 1.5rem;
  padding-right: 1.5rem;
}

.modal-title {
  font-size: 1.8rem;
  font-weight: 700;
  color: #284272;
  margin-bottom: 0.25rem;
}

.modal-subtitle {
  color: #6c757d;
  font-size: 0.95rem;
}

/* Panel del formulario dentro del modal */
.search-sidebar {
  width: 100%;
}

/* Títulos de sección */
.section-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: #2c3e50;
  position: relative;
  padding-bottom: 0.5rem;
  margin-bottom: 0;
}

.section-title::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 50px;
  height: 3px;
  background: #284272;
}

/* Estilos del formulario */
.search-form .form-group {
  margin-bottom: 1.25rem;
}

.search-form label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: #2c3e50;
}

.search-form input,
.search-form select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  font-size: 0.95rem;
  transition: all 0.2s ease;
  background-color: #f8f9fa;
  box-sizing: border-box;
}

.search-form input:focus,
.search-form select:focus {
  border-color: #284272;
  outline: none;
  box-shadow: 0 0 0 3px rgba(40, 66, 114, 0.12);
  background-color: white;
}

.search-form input::placeholder {
  color: #aaa;
  font-style: italic;
}

.btn-search {
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, #284272, #1b2d4d);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-top: 0.5rem;
  letter-spacing: 0.5px;
}

.btn-search:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(40, 66, 114, 0.3);
}

.btn-search:active {
  transform: translateY(0);
}

/* ============ PANEL DE RESULTADOS ============ */
.search-results {
  display: block;
  background: white;
  border-radius: 16px;
  padding: 1.5rem 2rem 2rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  min-height: 400px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden; /* ← evita desborde horizontal */
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.btn-new-search {
  padding: 0.6rem 1.2rem;
  background: transparent;
  color: #284272;
  border: 2px solid #284272;
  border-radius: 30px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-new-search:hover {
  background: #284272;
  color: white;
  box-shadow: 0 4px 12px rgba(40, 66, 114, 0.2);
}

/* Mensajes de éxito / error */
#response-message,
#response-message-error {
  display: none;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
}

#response-message.visible,
#response-message-error.visible {
  display: block;
}

#response-message.visible {
  background-color: #e6f4ea;
  color: #1e7e34;
  border: 1px solid #c3e6cb;
}

#response-message-error.visible {
  background-color: #fdecea;
  color: #b02a37;
  border: 1px solid #f5c6cb;
}

/* ============ ESTADO VACÍO ============ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  text-align: center;
  min-height: 300px;
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

.empty-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: #2c3e50;
  margin: 0 0 0.5rem 0;
}

.empty-description {
  color: #6c757d;
  font-size: 1rem;
  margin: 0 0 1.5rem 0;
  max-width: 400px;
}

.empty-btn {
  padding: 0.7rem 2rem;
  background: linear-gradient(135deg, #284272, #1b2d4d);
  color: white;
  border: none;
  border-radius: 30px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.empty-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(40, 66, 114, 0.3);
}

/* ============ GRID DE LIBROS - VISTA HORIZONTAL ============ */
.libros-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden; /* ← evita desborde horizontal */
}

.libros-grid:empty + .empty-state {
  display: flex;
}

.libro-link {
  text-decoration: none;
  color: inherit;
  display: block;
  transition: transform 0.2s ease;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden; /* ← evita desborde dentro del enlace */
}

.libro-link:hover {
  transform: translateY(-4px);
}

.libro {
  background: #f8f9fa;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  transition: box-shadow 0.2s ease;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  height: auto;
  min-height: 160px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.libro:hover {
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

/* Portada - ocupa el 35% del ancho, con máximo */
.libro img {
  width: 35%;
  max-width: 180px;
  height: auto;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: #e9ecef;
  flex-shrink: 0;
  box-sizing: border-box;
}

/* Info - ocupa el resto del ancho */
.libro-info {
  padding: 0.75rem 1rem 0.75rem 0.75rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  overflow: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-sizing: border-box;
}

.libro-titulo {
  font-size: 0.95rem;
  font-weight: 600;
  color: #1a1a2e;
  margin: 0 0 0.25rem 0;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.libro-autor {
  font-size: 0.8rem;
  color: #6c757d;
  margin: 0 0 0.35rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.libro-descripcion {
  font-size: 0.75rem;
  color: #495057;
  line-height: 1.4;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

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

/* 3 columnas */
@media (max-width: 1024px) {
  .libros-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
  }

  .libro img {
    width: 38%;
    max-width: 160px;
  }

  .libro-info {
    padding: 0.65rem 0.85rem 0.65rem 0.65rem;
  }

  .libro-titulo {
    font-size: 0.85rem;
  }

  .libro-autor {
    font-size: 0.75rem;
  }

  .libro-descripcion {
    font-size: 0.7rem;
    -webkit-line-clamp: 3;
  }
}

/* 2 columnas */
@media (max-width: 768px) {
  .modal-content {
    padding: 1.5rem;
    margin: 0.5rem;
    border-radius: 16px;
  }

  .modal-title {
    font-size: 1.4rem;
  }

  .modal-close {
    font-size: 1.5rem;
    top: 8px;
    right: 12px;
  }

  .search-container {
    padding: 1rem;
  }

  .search-results {
    padding: 1rem;
    min-height: 300px;
  }

  .results-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .btn-new-search {
    text-align: center;
  }

  .libros-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .libro img {
    width: 40%;
    max-width: 150px;
  }

  .libro-info {
    padding: 0.6rem 0.75rem 0.6rem 0.6rem;
  }

  .libro-titulo {
    font-size: 0.8rem;
  }

  .libro-autor {
    font-size: 0.7rem;
  }

  .libro-descripcion {
    font-size: 0.65rem;
    -webkit-line-clamp: 3;
  }

  .empty-state {
    padding: 2rem 1rem;
    min-height: 250px;
  }

  .empty-icon {
    font-size: 3rem;
  }

  .empty-title {
    font-size: 1.2rem;
  }
}

/* 1 columna - móviles */
@media (max-width: 480px) {
  .libros-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .libro {
    flex-direction: row;
    min-height: 140px;
  }

  .libro img {
    width: 35%;
    max-width: 130px;
  }

  .libro-info {
    padding: 0.5rem 0.75rem 0.5rem 0.5rem;
  }

  .libro-titulo {
    font-size: 0.9rem;
    -webkit-line-clamp: 2;
  }

  .libro-autor {
    font-size: 0.8rem;
  }

  .libro-descripcion {
    font-size: 0.75rem;
    -webkit-line-clamp: 3;
  }

  .search-results {
    padding: 0.75rem;
  }

  .modal-content {
    padding: 1rem;
    border-radius: 12px;
  }

  .section-title {
    font-size: 1.2rem;
  }
}

/* Móviles muy pequeños */
@media (max-width: 360px) {
  .libro img {
    width: 32%;
    max-width: 100px;
  }

  .libro-titulo {
    font-size: 0.75rem;
  }

  .libro-autor {
    font-size: 0.65rem;
  }

  .libro-descripcion {
    font-size: 0.6rem;
    -webkit-line-clamp: 2;
  }

  .libro-info {
    padding: 0.4rem 0.5rem 0.4rem 0.4rem;
  }
}