/* ============================================================
   Book Finder — Feuille de styles
   Dark mode premium, mobile-first, animations fluides
   ============================================================ */

/* ---- Variables CSS ---------------------------------------- */
:root {
  /* Palette dark premium */
  --bg-primary:     #0d0f14;
  --bg-secondary:   #151820;
  --bg-card:        #1a1d26;
  --bg-card-hover:  #1f2332;
  --bg-input:       #1e2130;
  --border-color:   #2a2e3e;
  --border-focus:   #6c63ff;

  /* Textes */
  --text-primary:   #e8eaf0;
  --text-secondary: #9097b0;
  --text-muted:     #5c6280;

  /* Accentuation */
  --accent-purple:  #6c63ff;
  --accent-purple-hover: #7c74ff;
  --accent-green:   #22c55e;
  --accent-green-hover:  #16a34a;
  --accent-amber:   #f59e0b;

  /* Sources */
  --source-gutenberg:   #f97316;
  --source-openlibrary: #3b82f6;
  --source-feedbooks:   #a855f7;
  --source-standard:    #eab308;
  --source-bnr:         #dc2626;
  --source-gallica:     #1d4ed8;
  --source-archive:     #b45309;

  /* Espacements */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Ombres */
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-elevated: 0 8px 40px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px rgba(108, 99, 255, 0.25);
}

/* ---- Reset & Base ----------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---- Utilitaires ------------------------------------------ */
.hidden { display: none !important; }

/* ============================================================
   PAGES — Système de navigation SPA
   ============================================================ */
.page {
  display: none;
  min-height: 100vh;
  flex-direction: column;
  animation: pageIn var(--transition-slow) both;
}

.page.active {
  display: flex;
}

@keyframes pageIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================================
   PAGE DE RECHERCHE
   ============================================================ */

/* En-tête logo */
.search-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3rem 1rem 0;
  flex: 1;
  justify-content: flex-end;
  padding-bottom: 2rem;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-icon {
  font-size: 2rem;
  filter: drop-shadow(0 0 12px rgba(108, 99, 255, 0.6));
}

.logo-text {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.logo-accent {
  color: var(--accent-purple);
}

.logo-tagline {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Zone de recherche principale */
.search-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem;
  flex: 1;
}

/* Boîte de recherche */
.search-box {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 640px;
  background: var(--bg-input);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 0.5rem 0.5rem 0.5rem 1.25rem;
  gap: 0.75rem;
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.search-box:focus-within {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-glow);
}

.search-icon {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-icon svg {
  width: 20px;
  height: 20px;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 1.05rem;
  font-weight: 400;
  padding: 0.5rem 0;
}

.search-input::placeholder {
  color: var(--text-muted);
}

/* Séparateur vertical dans la search-box */
.search-separator {
  width: 1px;
  height: 20px;
  background: var(--border-color);
  flex-shrink: 0;
}

/* Sélecteur de langue — s'intègre dans la search-box */
.lang-select {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.3rem 0.25rem;
  flex-shrink: 0;
  appearance: none;
  -webkit-appearance: none;
  min-width: 52px;
  letter-spacing: 0.01em;
}

.lang-select:focus {
  color: var(--text-primary);
  outline: none;
}

.lang-select option {
  background: var(--bg-input);
  color: var(--text-primary);
}

/* Version ultra-compacte pour la nav des résultats */
.lang-select-sm {
  font-size: 0.78rem;
  min-width: 44px;
  padding: 0.2rem 0.15rem;
}

.search-btn {
  background: var(--accent-purple);
  color: #fff;
  border: none;
  border-radius: var(--radius-lg);
  padding: 0.65rem 1.4rem;
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), transform var(--transition-fast);
  flex-shrink: 0;
}

.search-btn:hover {
  background: var(--accent-purple-hover);
}

.search-btn:active {
  transform: scale(0.97);
}

/* Texte d'aide sous la recherche */
.search-hint {
  margin-top: 1.25rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}

.hint-source {
  color: var(--text-secondary);
  font-weight: 500;
}

/* Footer page de recherche */
.search-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 1.5rem 1rem 2rem;
  border-top: 1px solid var(--border-color);
}

/* ============================================================
   PAGE DE RÉSULTATS — NAVIGATION
   ============================================================ */

.results-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

/* Bouton retour */
.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.back-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.back-btn svg {
  width: 18px;
  height: 18px;
}

/* Logo réduit */
.logo-small .logo-icon { font-size: 1.2rem; }
.logo-small .logo-text { font-size: 1.2rem; }

/* Formulaire de recherche compact */
.results-search-form {
  flex: 1;
}

.search-box-small {
  max-width: 100%;
  padding: 0.3rem 0.3rem 0.3rem 1rem;
  border-radius: var(--radius-lg);
}

.search-box-small .search-icon svg {
  width: 16px;
  height: 16px;
}

.search-box-small .search-input {
  font-size: 0.92rem;
  padding: 0.35rem 0;
}

/* Bouton recherche icône seul (compact) */
.search-btn-small {
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
}

.search-btn-small svg {
  width: 16px;
  height: 16px;
}

/* ============================================================
   PAGE DE RÉSULTATS — CONTENU
   ============================================================ */

.results-main {
  flex: 1;
  padding: 1.5rem 1.5rem 3rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* En-tête résultats */
.results-header {
  margin-bottom: 1.5rem;
}

.results-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.results-title span {
  color: var(--accent-purple);
}

/* Info sources */
.sources-info {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid;
}

.source-badge.gutenberg {
  color: var(--source-gutenberg);
  border-color: var(--source-gutenberg);
  background: rgba(249, 115, 22, 0.1);
}

.source-badge.openlibrary {
  color: var(--source-openlibrary);
  border-color: var(--source-openlibrary);
  background: rgba(59, 130, 246, 0.1);
}

.source-badge.feedbooks {
  color: var(--source-feedbooks);
  border-color: var(--source-feedbooks);
  background: rgba(168, 85, 247, 0.1);
}

.source-badge.standard {
  color: var(--source-standard);
  border-color: var(--source-standard);
  background: rgba(234, 179, 8, 0.1);
}

.source-badge.bnr {
  color: var(--source-bnr);
  border-color: var(--source-bnr);
  background: rgba(220, 38, 38, 0.1);
}

.source-badge.gallica {
  color: var(--source-gallica);
  border-color: var(--source-gallica);
  background: rgba(29, 78, 216, 0.1);
}

.source-badge.archive {
  color: var(--source-archive);
  border-color: var(--source-archive);
  background: rgba(180, 83, 9, 0.1);
}

/* ---- Chargement ------------------------------------------- */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 3rem 0;
}

/* Spinner */
.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Skeleton cards */
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.25rem;
  width: 100%;
  margin-top: 1rem;
}

.skeleton-card {
  height: 320px;
  background: linear-gradient(
    90deg,
    var(--bg-card) 25%,
    var(--bg-card-hover) 50%,
    var(--bg-card) 75%
  );
  background-size: 200% 100%;
  border-radius: var(--radius-lg);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ---- États vides / erreur --------------------------------- */
.error-state,
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 4rem 1rem;
  text-align: center;
}

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

.error-title,
.empty-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.4rem;
  color: var(--text-primary);
}

.error-message,
.empty-message {
  color: var(--text-secondary);
  max-width: 420px;
}

.retry-btn {
  margin-top: 0.5rem;
  background: var(--accent-purple);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.65rem 1.5rem;
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.retry-btn:hover {
  background: var(--accent-purple-hover);
}

/* ============================================================
   GRILLE DE RÉSULTATS — CARTES
   ============================================================ */

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.25rem;
}

/* Carte livre */
.book-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal), border-color var(--transition-normal);
  cursor: default;
  animation: cardIn var(--transition-slow) both;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-elevated);
  border-color: var(--border-focus);
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Décalage d'animation en cascade */
.book-card:nth-child(1)  { animation-delay: 0ms; }
.book-card:nth-child(2)  { animation-delay: 40ms; }
.book-card:nth-child(3)  { animation-delay: 80ms; }
.book-card:nth-child(4)  { animation-delay: 120ms; }
.book-card:nth-child(5)  { animation-delay: 160ms; }
.book-card:nth-child(6)  { animation-delay: 200ms; }
.book-card:nth-child(7)  { animation-delay: 240ms; }
.book-card:nth-child(8)  { animation-delay: 280ms; }
.book-card:nth-child(9)  { animation-delay: 320ms; }
.book-card:nth-child(10) { animation-delay: 360ms; }
.book-card:nth-child(n+11) { animation-delay: 400ms; }

/* Couverture */
.book-cover-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 2/3;
  background: var(--bg-secondary);
  overflow: hidden;
}

.book-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform var(--transition-slow);
}

.book-card:hover .book-cover {
  transform: scale(1.04);
}

/* Placeholder couverture (initiale du titre) */
.book-cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 4rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.15);
  background: linear-gradient(135deg, var(--bg-card-hover) 0%, var(--bg-secondary) 100%);
  user-select: none;
}

/* Badge source sur la couverture */
.book-source-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  backdrop-filter: blur(8px);
}

.book-source-badge.gutenberg {
  background: rgba(249, 115, 22, 0.9);
  color: #fff;
}

.book-source-badge.openlibrary {
  background: rgba(59, 130, 246, 0.9);
  color: #fff;
}

.book-source-badge.feedbooks {
  background: rgba(168, 85, 247, 0.9);
  color: #fff;
}

.book-source-badge.standard {
  background: rgba(234, 179, 8, 0.92);
  color: #000;
}

.book-source-badge.bnr {
  background: rgba(220, 38, 38, 0.9);
  color: #fff;
}

.book-source-badge.gallica {
  background: rgba(29, 78, 216, 0.9);
  color: #fff;
}

.book-source-badge.archive {
  background: rgba(180, 83, 9, 0.9);
  color: #fff;
}

/* Label de langue dans le titre des résultats */
.results-lang-label {
  font-size: 0.78rem;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  color: var(--accent-purple);
  font-style: normal;
  margin-left: 0.25rem;
}

/* Corps de la carte */
.book-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 0.9rem;
  gap: 0.25rem;
}

.book-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.35;
  /* Tronquer à 2 lignes */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-author {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.2rem;
  flex-wrap: wrap;
}

.book-year {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.book-lang {
  font-size: 0.7rem;
  background: var(--bg-secondary);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Bouton téléchargement */
.btn-download {
  margin-top: auto;
  padding-top: 0.75rem;
}

.btn-download-link {
  display: block;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-md);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

/* Disponible */
.btn-download-link.available {
  background: var(--accent-green);
  color: #fff;
}

.btn-download-link.available:hover {
  background: var(--accent-green-hover);
  transform: scale(1.02);
}

/* Non disponible */
.btn-download-link.unavailable {
  background: var(--bg-secondary);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  cursor: not-allowed;
}

/* ============================================================
   PAGINATION
   ============================================================ */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 2.5rem;
}

.page-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.page-btn:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
}

.page-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.page-btn svg {
  width: 18px;
  height: 18px;
}

.page-info {
  font-size: 0.9rem;
  color: var(--text-secondary);
  min-width: 100px;
  text-align: center;
}

/* ============================================================
   FOOTER
   ============================================================ */

.footer-legal {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
  font-style: italic;
}

.footer-credit {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.results-footer {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1.25rem 1.5rem 1.75rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

/* ============================================================
   TOAST NOTIFICATION
   ============================================================ */

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
  font-size: 0.88rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-elevated);
  z-index: 9999;
  transition: transform var(--transition-slow), opacity var(--transition-slow);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.success { border-color: var(--accent-green); }
.toast.error   { border-color: #ef4444; }

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

/* Tablette */
@media (min-width: 600px) {
  .search-header {
    padding-top: 4rem;
  }

  .logo-text {
    font-size: 3rem;
  }

  .logo-icon {
    font-size: 2.5rem;
  }

  .results-grid {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .search-header {
    padding-top: 6rem;
  }

  .logo-text {
    font-size: 3.5rem;
  }

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

  .results-grid {
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  }

  .results-main {
    padding: 2rem 2.5rem 4rem;
  }
}

/* Mobile (très petit écran) */
@media (max-width: 400px) {
  .results-nav {
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }

  .logo-small {
    display: none;
  }

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

  .book-info {
    padding: 0.65rem;
  }

  .book-title {
    font-size: 0.82rem;
  }

  .book-author {
    font-size: 0.72rem;
  }
}
