/* =============================================
   VARIABLES Y ESTILOS BASE
   ============================================= */
:root {
  /* Paleta Principal */
  --color-bg-page: #f0f2f5;
  --color-bg-container: #ffffff;
  --color-text-primary: #1c1e21;
  --color-text-secondary: #606770;
  --color-accent: #0866ff;
  --color-accent-dark: #0058e6;

  /* Colores UI */
  --color-border: #ccd0d5;
  --color-border-light: #e4e6eb;
  --color-bg-hover: #f2f3f5;
  --color-bg-disabled: #e4e6eb;
  --color-text-disabled: #bcc0c4;
  --color-shadow: rgba(0, 0, 0, 0.1);

  /* Variables Modo Oscuro (futuro) */
  --dark-bg-page: #18191a;
  --dark-bg-container: #242526;
  --dark-text-primary: #e4e6eb;
  --dark-text-secondary: #b0b3b8;
  --dark-border: #3a3b3c;
  --dark-bg-hover: #3a3b3c;
}

html {
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  font-family: "Poppins", sans-serif;
  line-height: 1.6;
  margin: 0;
  background-color: var(--color-bg-page);
  color: var(--color-text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-wrapper {
  display: flex;
  justify-content: center;
  width: 100%;
  padding: 20px;
  flex-grow: 1;
}

.app-container {
  background: var(--color-bg-container);
  width: 100%;
  max-width: 900px;
  padding: 30px 40px;
  border-radius: 12px;
  box-shadow: 0 4px 12px var(--color-shadow);
  margin: 20px 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* =============================================
   CABECERA
   ============================================= */
.app-header {
  text-align: center;
  margin-bottom: 30px;
}

h1 {
  font-size: 2.5em;
  font-weight: 700;
  margin: 0;
}

.subtitle {
  font-size: 1.1em;
  color: var(--color-text-secondary);
  margin: 5px 0 0;
}

/* =============================================
   SECCIÓN DE BÚSQUEDA
   ============================================= */
.search-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 25px;
  margin-bottom: 40px;
}

.actor-inputs-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  width: 100%;
}

.actor-input-wrapper {
  position: relative;
}

.actor-input-container {
  height: 50px;
}

.actor-input {
  width: 100%;
  height: 100%;
  padding: 10px 15px;
  font-size: 1em;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.actor-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(8, 102, 255, 0.2);
}

#compareButton {
  padding: 12px 30px;
  font-size: 1.1em;
  font-weight: 600;
  background-color: var(--color-accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s;
}

#compareButton:hover:not(:disabled) {
  background-color: var(--color-accent-dark);
}

#compareButton:disabled {
  background-color: var(--color-bg-disabled);
  color: var(--color-text-disabled);
  cursor: not-allowed;
}

/* =============================================
   SUGERENCIAS DE BÚSQUEDA
   ============================================= */
.suggestions-list {
  list-style: none;
  padding: 5px 0;
  margin: 5px 0 0;
  position: absolute;
  width: 100%;
  background: var(--color-bg-container);
  border: 1px solid var(--color-border-light);
  border-radius: 6px;
  box-shadow: 0 4px 12px var(--color-shadow);
  z-index: 100;
  display: none;
  max-height: 300px;
  overflow-y: auto;
}

.suggestion-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.suggestion-item:hover {
  background-color: var(--color-bg-hover);
}

.suggestion-item img {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  background-color: var(--color-bg-hover);
}

.suggestion-item div {
  display: flex;
  flex-direction: column;
}

.suggestion-item span {
  font-weight: 500;
}

.suggestion-item small {
  color: var(--color-text-secondary);
  font-size: 0.85em;
}

/* =============================================
   TARJETA DE ACTOR SELECCIONADO
   ============================================= */
.actor-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--color-bg-hover);
  border: 1px solid var(--color-border-light);
  border-radius: 6px;
  padding: 5px;
  height: 50px;
}

.actor-card-img {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
}

.actor-card-name {
  flex-grow: 1;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.remove-actor-btn {
  background: none;
  border: none;
  font-size: 1.5em;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 0 10px;
  line-height: 1;
}

/* =============================================
   MODAL DE SELECCIÓN DE REPARTO
   ============================================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  background: var(--color-bg-container);
  border-radius: 8px;
  padding: 25px;
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.modal-close-btn {
  position: absolute;
  top: 10px;
  right: 15px;
  background: none;
  border: none;
  font-size: 2em;
  color: var(--color-text-secondary);
  cursor: pointer;
}

.modal-title {
  margin: 0 0 20px;
  text-align: center;
}

.modal-title span {
  font-style: italic;
  color: var(--color-accent);
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 20px;
  overflow-y: auto;
  padding-right: 10px; /* Para el scrollbar */
}

.modal-actor-item {
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s;
}

.modal-actor-item:hover {
  transform: scale(1.05);
}

.modal-actor-item img {
  width: 100%;
  height: auto;
  aspect-ratio: 2/3;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 8px;
  box-shadow: 0 2px 4px var(--color-shadow);
}

.modal-actor-item .actor-name {
  font-weight: 600;
  margin: 0;
}

.modal-actor-item .character-name {
  font-size: 0.85em;
  color: var(--color-text-secondary);
  margin: 0;
}

/* =============================================
   SECCIÓN DE RESULTADOS
   ============================================= */
.results-section {
  margin-top: 40px;
  padding-top: 30px;
  border-top: 1px solid var(--color-border-light);
}

#resultsTitle {
  text-align: center;
  margin-bottom: 30px;
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 25px;
}

.result-card {
  display: flex;
  gap: 20px;
  background: var(--color-bg-container);
  border: 1px solid var(--color-border-light);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px var(--color-shadow);
}

.result-card-poster {
  width: 120px;
  height: 180px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.result-card-info {
  display: flex;
  flex-direction: column;
}

.result-card-title {
  margin: 0;
  font-size: 1.5em;
}

.result-card-meta {
  margin: 5px 0 15px;
  color: var(--color-text-secondary);
  font-weight: 500;
}

.result-card-roles {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}


/* Estilos para el enlace del título en los resultados */
.result-card-title a {
  text-decoration: none;
  color: var(--color-text-primary);
  transition: color 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.result-card-title a:hover {
  color: var(--color-accent);
}

/* Icono pequeño de enlace externo */
.result-card-title a::after {
  content: "↗";
  font-size: 0.7em;
  color: var(--color-text-secondary);
  font-weight: normal;
}

.result-card-title a:hover::after {
  color: var(--color-accent);
}


/* =============================================
   MENSAJES (LOADING, ERROR)
   ============================================= */
#messageContainer {
  text-align: center;
  margin-top: 20px;
}

.message {
  padding: 10px;
  border-radius: 6px;
  font-weight: 500;
}

.message.loading {
  color: var(--color-text-secondary);
}

.message.error {
  background-color: #ffebe8;
  color: #c52a1a;
  border: 1px solid #c52a1a;
}

/* =============================================
   FOOTER
   ============================================= */
.site-footer {
  text-align: center;
  padding: 20px;
  color: var(--color-text-secondary);
  font-size: 0.9em;
  flex-shrink: 0;
}

.site-footer a {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 500;
}

.site-footer a:hover {
  text-decoration: underline;
}

/* =============================================
   RESPONSIVIDAD
   ============================================= */
@media (max-width: 768px) {
  .app-container {
    padding: 20px;
  }

  .actor-inputs-grid {
    grid-template-columns: 1fr;
  }

  .modal-content {
    padding: 20px;
  }

  .modal-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }

  .result-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .result-card-roles {
    align-items: center;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 2em;
  }

  .subtitle {
    font-size: 1em;
  }
}

/* =============================================
   PLACEHOLDER SVG
   ============================================= */
img[src$="placeholder.svg"] {
  background-color: var(--color-bg-hover);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23BCC0C4'%3E%3Cpath d='M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-8 12H9v-2h2v2zm4-4h-2v4h-2V9h-2V7h6v2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 50%;
}

/* =============================================
   AJUSTES PARA EL BUSCADOR DEL MODAL
   ============================================= */

.modal-search-wrapper {
  margin-bottom: 20px;
}

.modal-search-input {
  width: 100%;
  padding: 10px 15px;
  font-size: 1em;
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.modal-search-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(8, 102, 255, 0.2);
}
