/* --- FILE: /css/pages/series.css --- */

/* ========================================================== */
/* --- SECTION 1 : MISE EN PAGE GÉNÉRALE & TITRE          --- */
/* ========================================================== */

#seriespage .series-list-section {
  padding-top: 4rem;
}

.series-list-section .page-title {
  display: flex;
  align-items: baseline;
  margin-bottom: 1rem;
}

.page-title #results-count {
  font-size: 0.7em;
  font-weight: 500;
  color: var(--clr-text-sub);
  margin-left: 0.75rem;
}

@media (max-width: 768px) {
  .series-list-section .page-title {
    font-weight: 700;
    line-height: 1.1;
    font-size: 2.4rem;
    display: block; /* On retire le flex pour que les éléments se placent les uns sous les autres */
  }

  .page-title #results-count {
    display: block; /* Le span prend toute la largeur et passe à la ligne */
    font-size: 1rem; /* On ajuste la taille pour qu'elle soit lisible mais discrète */
    font-weight: 400;
    margin-left: 0; /* On retire la marge de gauche */
    margin-top: 0.25rem; /* On ajoute un petit espace en haut */
  }
}

/* ========================================================== */
/* --- SECTION 2 : PANNEAU DE FILTRES (CONTENEUR & BOUTON) --- */
/* ========================================================== */

.search-filters-container {
  position: relative; /* Indispensable pour que z-index fonctionne */
  z-index: 10;
  margin-bottom: 2.5rem;
  padding: 0;
  border: none;
  background-color: transparent;
}

.toggle-filters-btn {
  flex-shrink: 0;
  height: 44px;
  padding: 0 1.5rem;
  border-radius: 6px;
  border: none; /* Bordure retirée */
  background-color: rgba(var(--clr-bg-card-rgb), 0.5);
  color: var(--clr-text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background-color 0.2s;
}

.toggle-filters-btn:hover {
  background-color: var(--clr-bg-card);
}

.toggle-filters-btn i {
  transition: transform 0.3s ease;
}

.toggle-filters-btn.active i {
  transform: rotate(180deg);
}

.filters-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.filters-panel.visible {
  display: flex;
}

/* ========================================================== */
/* --- SECTION 3 : LIGNE DE RECHERCHE & FILTRES PRINCIPAUX --- */
/* ========================================================== */

.filter-subgroup {
  transition: max-height 0.4s ease-out, margin-top 0.4s ease-out,
    padding 0.4s ease-out;
  overflow: hidden;
}

.filter-subgroup:has(.custom-dropdown-menu.show) {
  overflow: visible;
}

.filter-subgroup:first-child {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
}

.filters-panel:not(.visible) .filter-subgroup:not(:first-child) {
  max-height: 0;
  margin-top: 0;
  padding-top: 0;
  padding-bottom: 0;
  pointer-events: none;
}
.filters-panel.visible .filter-subgroup:not(:first-child) {
  max-height: 500px; /* Valeur arbitrairement grande */
  margin-top: 1rem;
}

.text-search-group {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.input-wrapper {
  position: relative;
  background-color: rgba(var(--clr-bg-card-rgb), 0.5);
  border-radius: 6px;
  border: none;
  display: flex;
  align-items: center;
  transition: background-color 0.2s;
}

.input-wrapper:hover {
  background-color: var(--clr-bg-card);
}

.input-wrapper .fa-search {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--clr-text-sub);
  pointer-events: none;
}

#search-input {
  width: 100%;
  height: 44px;
  padding: 0.5rem 1rem 0.5rem 3rem;
  border: none;
  background: transparent;
  color: var(--clr-text);
  font-size: 1rem;
  outline: none;
}

.filter-group-row {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

.filters-panel:not(.visible) .filter-group-row {
  opacity: 0;
  transform: translateY(-1rem);
}

.filters-panel.visible .filter-group-row {
  opacity: 1;
  transform: translateY(0);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.filter-group > label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--clr-text);
  margin-bottom: 0.25rem;
}

/* ========================================================== */
/* --- SECTION 4 : MENUS DÉROULANTS (STATUT, TYPE, ETC.)  --- */
/* ========================================================== */

#tags-filter-container {
  position: static;
}

.custom-dropdown {
  position: relative;
}

.custom-dropdown-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 44px;
  padding: 0.5rem 1rem;
  background-color: rgba(var(--clr-bg-card-rgb), 0.5);
  border: none;
  color: var(--clr-text-sub);
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: 0.3s;
}

.custom-dropdown-toggle:hover,
.custom-dropdown-toggle[aria-expanded="true"] {
  color: var(--clr-text);
  background-color: var(--clr-bg-card);
}

.custom-dropdown-toggle span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-dropdown-toggle .dropdown-arrow {
  margin-left: 0.5rem;
  transition: transform 0.3s ease;
}

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

.custom-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 100%;
  min-width: 240px;
  background-color: var(--clr-bg-card);
  border-radius: 8px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
  z-index: 100;
  overflow-y: auto;
  opacity: 0;
  transform: translateY(-10px);
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

.custom-dropdown-menu.show {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
}

.custom-dropdown-option {
  display: flex;
  align-items: center;
  padding: 0.7rem 1rem;
  cursor: pointer;
  user-select: none;
}

.custom-dropdown-option:hover {
  background-color: rgba(var(--clr-text-rgb), 0.05);
}

.custom-dropdown-option label {
  display: flex;
  align-items: center;
  width: 100%;
  cursor: pointer;
  margin: 0;
  font-weight: 500;
  color: var(--clr-text-sub);
  position: relative;
  padding-left: 28px;
}

.custom-dropdown-option input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.custom-dropdown-option label::before {
  content: "\f0c8";
  font-family: "Font Awesome 6 Free";
  font-weight: 400; /* regular */
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  color: rgba(var(--clr-text-rgb), 0.4);
}

.custom-dropdown-option input[type="checkbox"]:checked + label {
  color: var(--clr-text);
}

.custom-dropdown-option input[type="checkbox"]:checked + label::before {
  content: "\f14a";
  font-weight: 900; /* solid */
  color: var(--clr-text);
}

/* ========================================================== */
/* --- SECTION 5 : FILTRE PAR TAGS (POP-UP)               --- */
/* ========================================================== */

.tags-popup {
  width: 100%;
  height: unset;
  left: 0;
  top: 100%;
  margin-top: 0.75rem;
  min-width: 0;
  padding: 1rem;
  gap: 1rem;
  display: flex;
  flex-direction: column;
}

.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  overflow-y: auto;
  padding: 0;
  background-color: transparent;
  border-radius: 0;
}

.tags-container .tag-btn {
  background-color: var(--clr-bg);
  color: var(--clr-text-sub);
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1.5px solid transparent;
}

.tags-container .tag-btn:hover {
  background-color: var(--clr-bg-card-invert);
  color: var(--clr-text-invert);
}

.tags-container .tag-btn.selected-include {
  background-color: transparent;
  color: var(--clr-text);
  border-color: var(--clr-text);
  border-style: dotted;
  font-weight: 600;
}

.tags-container .tag-btn.selected-exclude {
  background-color: transparent;
  color: var(--clr-error);
  border-color: var(--clr-error);
  border-style: dotted;
  font-weight: 600;
}

/* ========================================================== */
/* --- SECTION 6 : ACTIONS ET BARRE D'OUTILS                --- */
/* ========================================================== */

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

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.toolbar-action-btn {
  background-color: rgba(var(--clr-bg-card-rgb), 0.5);
  color: var(--clr-text-sub);
  border: none;
  padding: 0 1rem;
  height: 40px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
  justify-content: center;
}

.toolbar-action-btn:hover {
  color: var(--clr-text);
  background-color: var(--clr-bg-card);
}

.sort-dropdown .custom-dropdown-toggle {
  color: var(--clr-text);
  border: none;
  height: 40px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  min-width: 220px;
}
.sort-dropdown .custom-dropdown-toggle:hover {
  color: var(--clr-text);
}

.sort-dropdown .custom-dropdown-menu {
  background-color: var(--clr-bg-card);
  min-width: 100%;
}

.sort-dropdown .custom-dropdown-option {
  padding: 0.7rem 1rem;
  font-weight: 500;
  font-size: 0.9rem;
}
.sort-dropdown .custom-dropdown-option:hover {
  background-color: rgba(var(--clr-text-rgb), 0.05);
}

.view-toggle-buttons {
  display: flex;
  gap: 0.5rem;
}

.view-toggle-buttons button {
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  background-color: var(--clr-bg-card);
  color: var(--clr-text-sub);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.view-toggle-buttons button.active,
.view-toggle-buttons button:hover {
  background-color: var(--clr-bg-card-invert);
  color: var(--clr-text-invert);
}

/* ========================================================== */
/* --- SECTION 7 : VUES DES RÉSULTATS (GRILLE & LISTE)    --- */
/* ========================================================== */

.series-list-view {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.series-list-item {
  position: relative; /* Pour la pastille de statut */
  background-color: var(--clr-bg-card);
  padding: 1rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--clr-text);
  transition: background-color 0.2s;
}

.series-list-item:hover {
  background-color: rgba(var(--clr-bg-card-invert-rgb), 0.1);
}

.status-dot-badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.status-dot-badge.ongoing {
  background-color: var(--iclr-success-light);
}
.status-dot-badge.paused {
  background-color: var(--iclr-warning-light);
}
.status-dot-badge.cancelled {
  background-color: var(--iclr-disabled-light);
}
.status-dot-badge.finished {
  background-color: var(--iclr-error-light);
}

/* --- Styles communs aux éléments internes --- */
.series-list-item .series-cover {
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}
.series-list-item .series-info {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}
.series-list-item .series-title {
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
  padding-right: 1.5rem;
}
.series-tags-row {
  margin-bottom: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.series-tags-row .tag {
  background: var(--clr-bg);
  color: var(--clr-text-sub);
  font-weight: 600;
  font-size: 0.7rem;
  padding: 0.3em 0.7em;
}
.series-list-item .series-description {
  color: var(--clr-text-sub);
  line-height: 1.5;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Layout DESKTOP (Grid) --- */
@media (min-width: 769px) {
  .series-list-item {
    display: grid;
    grid-template-columns: 100px 1fr;
    grid-template-rows: auto 1fr;
    gap: 0 1.25rem;
    align-items: start;
  }
  .series-list-item .series-cover {
    grid-column: 1;
    grid-row: 1 / 3; /* L'image occupe les deux lignes en hauteur */
    width: 100px;
    height: 140px;
  }
  .series-list-item .series-info {
    grid-column: 2;
    grid-row: 1;
  }
  .series-list-item .series-description {
    grid-column: 2;
    grid-row: 2;
    font-size: 0.9rem;
  }
  .series-list-item .series-title {
    font-size: 1.3rem;
  }
  .series-tags-row .tag {
    font-size: 0.75rem;
  }
}

/* --- Layout MOBILE (Grid) --- */
@media (max-width: 768px) {
  .series-list-item {
    display: grid;
    grid-template-columns: 80px 1fr; /* Image: 80px, Reste: flexible */
    grid-template-rows: auto auto; /* Ligne 1: Titre/Tags, Ligne 2: Description */
    gap: 0.5rem 1rem;
  }
  .series-list-item .series-cover {
    grid-column: 1;
    grid-row: 1; /* L'image est en haut à gauche */
    width: 80px;
    height: 115px;
  }
  .series-list-item .series-info {
    grid-column: 2;
    grid-row: 1; /* Les infos sont en haut à droite */
    gap: 0.5rem;
  }
  .series-list-item .series-description {
    grid-column: 1 / 3; /* La description s'étend sur les 2 colonnes */
    grid-row: 2; /* sur la deuxième ligne */
    font-size: 0.85rem;
  }
  .series-list-item .series-title {
    font-size: 1.1rem;
  }
}

/* --- Utilities pour le JS --- */
.desktop-only {
  display: flex;
}
.mobile-only {
  display: none;
}
.mobile-filters-overlay,
.mobile-filters-panel {
  display: none;
}

/* ========================================================== */
/* --- SECTION 8 : RESPONSIVE (MOBILE)                      --- */
/* ========================================================== */

@media (max-width: 768px) {
  #seriespage .series-list-section {
    padding-top: unset;
    margin-top: unset;
  }

  #seriespage main > section {
    padding-top: 1rem;
  }

  /* --- Utilitaires --- */
  .desktop-only {
    display: none !important;
  }
  .mobile-only {
    display: flex !important;
  }

  /* --- Correction : Masquer les filtres desktop sur mobile --- */
  #filters-panel .filter-subgroup:not(:first-child) {
    display: none;
  }

  /* --- Barre de recherche --- */
  .filter-subgroup:first-child {
    gap: 0.5rem;
  }

  #search-input {
    height: 40px;
    font-size: 1rem;
  }
  .toggle-filters-btn {
    height: 40px;
    padding: 0 1.2rem;
  }

  /* --- Barre d'outils --- */
  .results-toolbar {
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 0.5rem;
  }

  .toolbar-left,
  .toolbar-right {
    gap: 0.5rem;
  }

  #random-series-btn {
    padding: 0;
    width: 40px;
  }

  .sort-dropdown .custom-dropdown-toggle {
    min-width: unset;
  }

  .search-filters-container {
    margin-bottom: 1rem;
  }

  /* --- Panneau de filtres mobile --- */
  .mobile-filters-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }
  .mobile-filters-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-filters-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--clr-bg);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    z-index: 1001;
    transform: translateY(100%);
    transition: transform 0.3s ease-out, height 0.3s ease-out;
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    height: 50vh;
  }

  .mobile-filters-panel.is-open {
    transform: translateY(0);
  }

  .panel-header {
    padding: 0.75rem;
    text-align: center;
    position: relative;
    flex-shrink: 0;
    touch-action: none;
    cursor: grab;
  }

  .panel-handle {
    width: 40px;
    height: 5px;
    background-color: rgba(var(--clr-text-rgb), 0.2);
    border-radius: 2.5px;
    margin: 0 auto 0.5rem;
  }
  .panel-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
  }

  .panel-content {
    padding: 0;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-height: 0;
    overflow: hidden;
  }

  .filter-tabs {
    display: flex;
    border-bottom: 1px solid var(--clr-bg-card);
    flex-shrink: 0;
    padding: 0 1rem;
  }

  .filter-tab {
    flex: 1;
    padding: 0.8rem 0.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--clr-text-sub);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
  }

  .filter-tab.active {
    color: var(--clr-text);
    border-bottom-color: var(--clr-text);
  }

  .tab-content-wrapper {
    flex-grow: 1;
    overflow-y: auto;
    min-height: 0;
  }

  .filter-tab-content {
    display: none;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
  }

  .filter-tab-content.active {
    display: flex;
  }

  .general-filters-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }

  .general-filters-grid .filter-group.full-width {
    grid-column: 1 / -1;
  }

  .panel-content .filter-group {
    gap: 0.5rem;
  }

  .mobile-filters-panel .custom-dropdown {
    position: relative;
  }

  .mobile-filters-panel .custom-dropdown-menu {
    background-color: var(--clr-bg-card);
    border-radius: 8px;
    margin-top: 0.5rem;
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out,
      opacity 0.3s ease-out;
    padding: 0;
    min-width: unset;
  }

  .mobile-filters-panel
    .custom-dropdown-toggle[aria-expanded="true"]
    + .custom-dropdown-menu {
    max-height: 500px;
    opacity: 1;
    padding: 0.5rem 0;
    border: 1px solid var(--border-color);
  }

  .mobile-filters-panel .custom-dropdown-option {
    padding: 0;
  }

  .mobile-filters-panel .custom-dropdown-option label {
    padding: 0.8rem 1rem;
    padding-left: 38px;
  }

  .mobile-filters-panel .custom-dropdown-option label::before {
    left: 1rem;
  }

  .panel-content .custom-dropdown-toggle {
    height: 48px;
  }

  .panel-footer {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
    border-top: 1px solid var(--clr-bg-card);
    flex-shrink: 0;
  }
  .panel-action-btn {
    flex: 1;
    padding: 0.8rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
  }
  .panel-action-btn.reset {
    background-color: var(--clr-bg-card);
    color: var(--clr-text);
  }
  .panel-action-btn.apply {
    background-color: var(--clr-bg-card-invert);
    color: var(--clr-text-invert);
  }

  /* Cacher les anciens boutons sur mobile */
  .results-toolbar .view-toggle-buttons {
    display: none;
  }

  /* Style du nouveau bouton unique sur mobile */
  #toggle-view-btn {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    justify-content: center;
    padding: 0;
    /* On hérite de la couleur de base et on active la couleur inversée au survol/actif */
    background-color: var(--clr-bg-card);
    color: var(--clr-text);
  }

  /* Logique d'affichage des icônes */
  #toggle-view-btn .view-icon {
    display: none; /* Cache les deux par défaut */
  }

  /* Si la vue actuelle est "grid", on montre l'icône "list" */
  #toggle-view-btn[data-current-view="detailed-grid"]
    .view-icon[data-view-icon="list"] {
    display: inline-block;
  }

  /* Si la vue actuelle est "list", on montre l'icône "grid" */
  #toggle-view-btn[data-current-view="list"]
    .view-icon[data-view-icon="detailed-grid"] {
    display: inline-block;
  }
}
