/* css/components/header.css */

.hamburger-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--clr-text);
  font-size: 1.6rem;
  cursor: pointer;
  padding: 0.5rem;
  line-height: 1;
  z-index: 1001;
}

.header-container {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  position: relative;
  padding: 0;
  height: auto;
  min-height: 60px;
}

.header-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding-right: 2rem;
}

header#main-header {
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.55);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2000;
  min-height: 60px;
}

body#readerpage header#main-header {
  transition: transform 0.3s ease-in-out;
}

header#main-header.is-hidden {
  transform: translateY(-100%);
}

.header-logo-center {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16rem;
  z-index: 2;
}

.site-title-link {
  text-decoration: none;
  color: var(--clr-bg-invert);
  font-weight: 700;
  font-size: 2.2rem;
  position: relative;
  line-height: 1;
  transition: color 0.3s ease, font-weight 0.3s ease, letter-spacing 0.3s ease;
  letter-spacing: -0.5px;
  display: block;
  text-align: left;
  margin: 0;
}

.site-title-link:hover {
  color: var(--clr-bg-invert);
  font-weight: 800;
  letter-spacing: 1px;
}

.site-title-link::after {
  content: none;
}

.header-left-group {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  gap: 2.5rem;
  min-width: 0;
  padding-left: 0;
}

.desktop-navigation-wrapper {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-grow: 1;
  justify-content: flex-start;
  padding-left: 0;
  margin-left: 0;
  min-width: 0;
}

.desktop-nav {
  display: flex;
  flex-direction: row;
  list-style: none;
  padding: 0;
  margin: 0;
}

.desktop-nav-main {
  gap: 1.8rem;
}

.desktop-nav-sub {
  gap: 1.2rem;
}

.nav-separator {
  color: var(--clr-text-sub);
  font-weight: 300;
  padding: 0 0.5rem;
}

.desktop-nav a {
  text-decoration: none;
  color: var(--clr-text-sub);
  font-weight: 600;
  position: relative;
  padding: 0.2em 0.1em;
  transition: color 0.3s ease;
  white-space: nowrap;
}

.desktop-nav a:hover {
  color: var(--clr-text);
}

.desktop-nav a::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -6px;
  width: 0;
  height: 2px;
  background: var(--clr-text);
  transition: width 0.3s ease;
}

.desktop-nav a:hover::after,
.desktop-nav a.active-nav-link::after {
  width: 100%;
}

.desktop-nav a.active-nav-link {
  color: var(--clr-text);
  font-weight: 700;
}

.desktop-nav a i {
  margin-right: 0.5rem;
}

/* --- Styles du menu déroulant --- */
.sub-nav-dropdown {
  position: relative;
  display: none;
}

.sub-nav-toggle-btn {
  background: none;
  border: none;
  color: var(--clr-text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.2em 0.1em; /* Pour aligner avec les autres liens */
}

.sub-nav-toggle-btn .dropdown-arrow {
  transition: transform 0.3s ease;
  font-size: 0.8em;
}

.sub-nav-toggle-btn[aria-expanded="true"] .dropdown-arrow {
  transform: rotate(180deg);
}

.sub-nav-menu {
  position: absolute;
  top: calc(100% + 26px); /* Espace par rapport au bouton */
  left: 70%;
  transform: translateX(-50%);
  background-color: rgba(
    var(--clr-bg-card-rgb),
    0.6
  ); /* Fond semi-transparent */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 8px;
  min-width: 220px;
  z-index: 10;
  opacity: 0;
  transform: translateX(-50%) translateY(-10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  padding: 0.5rem;
}

.sub-nav-menu.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.sub-nav-menu-item {
  list-style: none; /* On retire la puce par défaut */
}

.sub-nav-menu a {
  display: flex;
  align-items: center;
  padding: 0.6rem 0.8rem;
  text-decoration: none;
  color: var(--clr-text-sub);
  font-weight: 600;
  white-space: nowrap;
  border-radius: 4px;
}

/* Style de la puce personnalisée */
.sub-nav-menu a::before {
  content: "•";
  margin-right: 0.75rem;
  color: var(--clr-text-sub);
  transition: color 0.2s ease;
}

.sub-nav-menu a:hover {
  background-color: rgba(var(--clr-text-rgb), 0.08);
  color: var(--clr-text);
}

.sub-nav-menu a:hover::before {
  color: var(--clr-text);
}
/* Classe de contrôle pour l'état compressé */
.header-nav-compressed #desktop-nav-sub,
.header-nav-compressed #nav-separator:not(:last-of-type) {
  display: none;
}

.header-nav-compressed #sub-nav-dropdown-container {
  display: block;
}
.search-container {
  display: flex;
}

.search-bar-container {
  position: relative;
  display: flex;
  align-items: center;
  background-color: rgba(var(--clr-text-rgb), 0.05);
  border-radius: 6px;
  padding: 0 0.75rem;
  border: 1.5px solid transparent;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}
.search-bar-container:focus-within {
  background-color: rgba(var(--clr-bg-card-rgb), 0.5);
  border-color: rgba(var(--clr-text-rgb), 0.2);
}

/* Bouton de recherche Mobile */
#mobile-search-toggle {
  display: none; /* Caché par défaut */
}

.search-icon {
  color: var(--clr-text-sub);
  font-size: 0.9rem;
}

#header-search-input {
  background: transparent;
  border: none;
  outline: none;
  width: 180px;
  height: 38px;
  padding-left: 0.75rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--clr-text);
}

#header-search-input::placeholder {
  color: var(--clr-text-sub);
  opacity: 0.8;
}

/* Personnalisation de la croix de suppression dans la barre de recherche */
#header-search-input::-webkit-search-cancel-button {
  -webkit-appearance: none; /* Retire le style par défaut */
  appearance: none;
  height: 18px;
  width: 18px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23FFF'><path d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/></svg>");
  background-size: 18px 18px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

#header-search-input::-webkit-search-cancel-button:hover {
  opacity: 1;
}

html:not(.dark) #header-search-input::-webkit-search-cancel-button {
  /* Version pour le thème clair (croix noire) */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23333'><path d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/></svg>");
}

/* --- Styles pour le panneau de résultats DESKTOP --- */
.search-results-container {
  position: absolute;
  top: calc(100% + 20px);
  left: 0;
  width: 400px;
  max-height: 70vh;
  overflow-y: auto;
  background-color: var(--clr-bg-card);
  border: 1px solid rgba(var(--clr-text-rgb), 0.1);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 2001;
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.search-results-container.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* --- Styles pour les ITEMS de résultat (communs au desktop et mobile) --- */
.search-result-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem;
  text-decoration: none;
  color: var(--clr-text);
  border-bottom: 1px solid rgba(var(--clr-text-rgb), 0.05);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background-color: rgba(var(--clr-text-rgb), 0.05);
}

.search-result-cover {
  width: 45px;
  height: 65px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.search-result-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.search-result-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-chapter {
  font-size: 0.85rem;
  color: var(--clr-text-sub);
}

.search-no-results,
.search-loading {
  padding: 2rem;
  text-align: center;
  color: var(--clr-text-sub);
}

/* --- Styles pour l'overlay de recherche MOBILE --- */
.mobile-search-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(var(--clr-bg-card-rgb), 0.5);
  z-index: 3000;
  padding: 1rem;
  display: none; /* Contrôlé par JS */
  flex-direction: column;
  gap: 1rem;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-search-overlay.visible {
  display: flex;
  opacity: 1;
  height: fit-content;
}

.mobile-search-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--clr-bg-card);
  border-radius: 8px;
  padding: 0 0.5rem 0 1rem;
  border: 1.5px solid rgba(var(--clr-text-rgb), 0.1);
}

#mobile-search-input {
  flex-grow: 1;
  height: 48px;
  border: none;
  background: none;
  outline: none;
  font-family: inherit;
  font-size: 1.1rem;
  color: var(--clr-text);
}

#mobile-search-close {
  background: none;
  border: none;
  color: var(--clr-text-sub);
  font-size: 2rem;
  line-height: 1;
  padding: 0.5rem 1rem;
  cursor: pointer;
}

#mobile-search-results {
  background-color: var(--clr-bg-card);
  border-radius: 8px;
  border: 1px solid rgba(var(--clr-text-rgb), 0.1);
  overflow-y: auto;
  flex-grow: 1; /* Permet au conteneur de prendre l'espace restant */
  min-height: 0; /* Correction de bug pour le scroll dans un conteneur flex */
}

.desktop-only {
  display: block;
}
.search-bar-container.desktop-only {
  display: flex;
}

@media (max-width: 1024px) {
  .desktop-only {
    display: none !important;
  }
  .mobile-search-overlay.mobile-only {
    display: none !important; /* L'overlay reste contrôlé par JS */
  }
  .mobile-search-overlay.mobile-only.visible {
    display: flex !important;
  }
}

.desktop-social-icons {
  display: flex;
  gap: 1rem;
}

.desktop-social-icons a {
  color: var(--clr-bg-invert);
  font-size: 1.25rem;
  transition: color 0.3s ease, transform 0.2s ease;
}

.desktop-social-icons a:hover {
  color: var(--clr-bg-invert);
  transform: translateY(-2px) scale(1.05);
}

.theme-toggle {
  background: none;
  border: none;
  color: var(--clr-bg-invert);
  border-radius: 50%;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  transition: transform 0.4s ease;
}

.theme-toggle:hover {
  transform: rotate(360deg);
}

#mobile-search-toggle {
  display: none;
}

/* --- Media Queries --- */
@media (max-width: 1024px) {
  .hamburger-menu-btn {
    display: block;
  }
  .header-logo-center {
    width: auto;
    padding-left: 0.8rem;
  }
  .header-left-group {
    gap: 0.8rem;
  }
  .desktop-navigation-wrapper,
  .desktop-nav,
  .desktop-social-icons {
    display: none;
  }
  .theme-toggle {
    font-size: 1rem;
    width: 32px;
    height: 32px;
  }
  .nav-separator {
    display: none;
  }
  .header-actions {
    gap: 0.8rem;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-right: 3.8rem;
  }

  .search-bar-container {
    display: none;
  }
  #mobile-search-toggle {
    display: flex;
  }

  .mobile-nav-title-link {
    display: block !important;
    color: var(--clr-bg-invert);
    font-size: 1.6rem;
    font-weight: 700;
    text-decoration: none;
    line-height: 1;
    align-self: center;
  }
  .mobile-nav-title-link:hover {
    color: var(--clr-bg-invert);
    font-weight: 800;
    letter-spacing: 1px;
  }
}

@media (max-width: 768px) {
  .header-logo-center {
    width: auto;
    padding-left: 0.6rem;
  }
  .site-title-link {
    font-size: 1.6rem;
  }
}

@media (max-width: 768px) {
  .header-logo-center {
    width: auto;
    padding-left: 0.6rem;
  }

  .site-title-link {
    font-size: 1.6rem;
  }
}

.desktop-only {
  display: block;
}
.mobile-nav-title-link {
  display: none;
}

#history-toggle {
  position: relative;
}

.history-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 1.5rem;
  width: 380px;
  max-width: 90vw;
  z-index: 1000;
  background-color: var(--clr-bg-card);
  border-radius: 8px;
  border: 1px solid rgba(var(--clr-text-rgb), 0.1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.history-panel.visible {
  display: flex;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(var(--clr-text-rgb), 0.1);
  flex-shrink: 0;
}

.history-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.history-close-btn {
  background: none;
  border: none;
  color: var(--clr-text-sub);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem;
}

.history-content {
  padding: 0.4rem;
  overflow-y: auto;
  max-height: 70vh;
}

.history-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--clr-text-sub);
}

/* History Card */
.history-card {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem;
  border-radius: 6px;
  text-decoration: none;
  color: var(--clr-text);
  transition: background-color 0.2s ease;
}

.history-card:hover {
  background-color: rgba(var(--clr-text-rgb), 0.05);
}

.history-card-cover {
  width: 45px;
  height: 65px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.history-card-info {
  flex-grow: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.history-card-title-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.8rem;
}

.history-card-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-grow: 1; /* Permet au titre de prendre l'espace disponible */
  min-width: 0; /* Important pour que l'ellipsis fonctionne dans un flex container */
}

.history-card-rating {
  display: flex;
  align-items: center;
  gap: 0.3em;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--clr-text-sub);
  flex-shrink: 0; /* Empêche la note de se compresser */
}

.history-card-rating .fa-star {
  color: var(--clr-accent);
}

/* Progress Bar */
.history-progress {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.history-progress-bar {
  width: 100%;
  height: 6px;
  background-color: rgba(var(--clr-text-rgb), 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.history-progress-bar-inner {
  height: 100%;
  background-color: var(--clr-text);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.history-progress-text {
  font-size: 0.8rem;
  color: var(--clr-text-sub);
}

@media (max-width: 768px) {
  .history-panel {
    right: 0.5rem;
  }

  .history-card {
    padding: 0.4rem;
  }

  .history-card-cover {
    width: 50px;
    height: 75px;
  }

  .history-header {
    padding: 0.3rem 0.8rem;
  }
}
