/* public/css/advanced-search-tab.css */

/* Cache le panneau par défaut */
.advanced-search-tab-panel {
  display: none;
}

/* Affiche le panneau quand on est dans le bon mode */
.metabot-container.mode-advanced-search-tab .advanced-search-tab-panel {
  display: flex !important;
  flex-direction: column !important;
  flex: 1 1 auto !important;
  height: 100% !important;
  max-height: 100% !important;
  overflow: hidden !important;
}

/* En mode advanced-search-tab, on cache les autres panneaux */
.metabot-container.mode-advanced-search-tab .box-results,
.metabot-container.mode-advanced-search-tab #myVideosPanel,
.metabot-container.mode-advanced-search-tab #hybridBetaDebugPanel {
  display: none !important;
}

/* En mode advanced-search-tab, on force l'affichage du slot-br */
.metabot-container.mode-advanced-search-tab:not(.has-search-results):not(.mode-my-videos) .slot-br,
.metabot-container.mode-advanced-search-tab .slot-br {
  display: flex !important;
  flex-direction: column !important;
}

/* En mode advanced-search-tab, on cache le slot-tr (welcome) */
.metabot-container.mode-advanced-search-tab .slot-tr {
  display: none !important;
}

/* Structure interne du panneau */
.advanced-search-tab-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.advanced-search-tab-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--surface);
  border-radius: 8px;
}

/* Nouveau Panneau de Recherche (Header) */
.ast-header-panel {
  display: flex;
  flex-direction: column;
  gap: 10px; /* Aligné avec l'espace de 10px de la colonne de gauche */
  padding: 0px 8px 12px 8px;
  /* Reduced top padding to align with left column */
  background: var(--surface);
  border-bottom: 1px solid var(--border-color, #334155);
}

/* Lignes du panneau */
.ast-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  /* Réduit */
  flex-wrap: nowrap;
  /* Force sur 1 ligne */
  overflow-x: auto;
  /* Sécurité: scroll plutôt que wrap */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.ast-header-row::-webkit-scrollbar {
  display: none;
}

/* Toolbar Supérieure */
.ast-top-toolbar {
  border-bottom: 1px solid var(--border-color, #334155);
  padding-bottom: 12px;
}

.ast-toolbar-left,
.ast-toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  /* Réduit de 12px à 6px */
  flex-shrink: 0;
}

/* Wrapper pour les boutons de vue et tri */
.ast-view-wrap,
.ast-sort-wrap {
  display: flex;
  background: var(--surface-hover);
  border-radius: 8px;
  padding: 4px;
  border: 1px solid var(--border-color, #334155);
}

.ast-sort-btn {
  background: transparent;
  border: none;
  height: 28px;
  padding: 0 8px;
  /* Réduit de 10px à 8px */
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
  /* Réduit de 6px à 4px */
  box-sizing: border-box;
}

.ast-sort-btn:hover {
  color: var(--text-primary);
}

.ast-sort-btn.active,
.ast-sort-btn.active:hover,
.ast-sort-btn.active:focus,
.ast-sort-btn.active:active {
  background: var(--primary-color, #3b82f6) !important;
  color: white !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Actions de Sélection & Reset (Toolbar Right) */
.ast-results-count {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0 8px;
  white-space: nowrap;
}

.ast-actions-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  /* Réduit de 6px à 4px */
  background: var(--surface-hover);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border-color, #334155);
}

.ast-icon-action-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.ast-icon-action-btn:hover {
  background: rgba(59, 130, 246, 0.15);
  color: var(--primary-color, #3b82f6);
}

.ast-divider {
  width: 1px;
  height: 18px;
  background: var(--border-color, #334155);
  margin: 0 2px;
}

.ast-reset-btn {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ast-reset-btn:hover,
.ast-reset-btn:active,
.ast-reset-btn:focus {
  background: rgba(239, 68, 68, 0.2) !important;
  color: #dc2626 !important;
}

/* Ligne des filtres (Scroll Horizontal Mobile) */
.ast-filters-row {
  align-items: stretch;
  flex-wrap: nowrap;
  /* Force 1 ligne */
  overflow-x: auto;
  /* Scroll horizontal si besoin */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  /* Cache la scrollbar (Firefox) */
}

.ast-filters-row::-webkit-scrollbar {
  display: none;
  /* Cache la scrollbar (Chrome/Safari) */
}

.ast-filter-group {
  display: flex;
  align-items: center;
  gap: 4px; /* Rendu plus compact pour éviter le débordement sur desktop */
  background: var(--surface-hover);
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-color, #334155);
  flex-wrap: nowrap;
  flex: 1; /* Permet de prendre exactement 50% de l'espace s'ils sont deux */
  min-width: 0; /* Permet au flex de rétrécir si besoin sans déborder */
}

.ast-filter-icon {
  color: var(--text-muted);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
}

/* Puces Date et Type */
.ast-chips-wrap {
  display: flex;
  gap: 4px;
}

.ast-chips-wrap .date-chip,
.ast-chips-wrap .type-chip {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  height: 28px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  /* Empêche le texte du bouton de se couper */
}

.ast-chips-wrap .date-chip:hover,
.ast-chips-wrap .type-chip:hover {
  background: rgba(59, 130, 246, 0.1);
  color: var(--text-primary);
}

.ast-chips-wrap .date-chip.active,
.ast-chips-wrap .date-chip.active:hover,
.ast-chips-wrap .type-chip.active,
.ast-chips-wrap .type-chip.active:hover {
  background: rgba(59, 130, 246, 0.15) !important;
  color: var(--primary-color, #3b82f6) !important;
  font-weight: 600 !important;
}

/* Plus besoin de forcer la largeur, car l'icône infini donne la même largeur naturelle aux deux boutons ! */

/* Calendrier */
.date-picker-input.compact {
  width: auto;
  /* Override width: 100% from advanced-search.css */
  min-width: 85px;
  height: 28px;
  margin: 0;
  padding: 0 4px;
  font-size: 0.75rem;
  border: 1px solid var(--border-color, #334155);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-primary);
  box-sizing: border-box;
  flex-shrink: 0;
  white-space: nowrap;
}

/* Liste de l'arbre */
#advancedSearchTabList {
  flex: 1;
  overflow-y: auto;
  padding: 16px 8px;
}

/* Styles pour l'arbre visuel (Style Bibliothèque) */
#advancedSearchTabList {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.ast-node {
  border-radius: var(--radius-lg);
  margin-bottom: 0;
  flex-shrink: 0;
}

.ast-node-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-lg);
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
}

.ast-node-header:hover {
  background: rgba(79, 141, 252, 0.08);
  z-index: 50;
}

.ast-toggle {
  width: 16px;
  text-align: center;
  color: #64748b;
  transition: transform 0.2s ease;
  flex-shrink: 0;
  font-size: 12px;
}

.ast-type-icon {
  font-size: 16px;
  color: #4f8dfc;
  flex-shrink: 0;
}

.ast-node.open>.ast-node-header .ast-toggle {
  transform: rotate(90deg);
}

.ast-checkbox {
  margin: 0;
  width: 16px;
  height: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.ast-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
}

.ast-count {
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 12px;
  margin-left: 8px;
}

.ast-children {
  display: none;
  padding: 8px 0 8px 12px;
  border-left: 1px dashed rgba(100, 116, 139, 0.3);
  margin-left: 8px;
  flex-direction: column;
  gap: 6px;
}

.ast-node.open>.ast-children {
  display: flex;
}

/* Types of nodes */
.ast-node-org>.ast-node-header {
  background: linear-gradient(135deg, #f0f4ff, #e8efff);
  border: 1px solid rgba(79, 141, 252, 0.2);
  font-weight: 600;
  font-size: 16px;
}

.ast-node-group>.ast-node-header {
  background: rgba(139, 92, 246, 0.06);
  border: 1px solid rgba(139, 92, 246, 0.15);
  font-weight: 600;
  font-size: 15px;
}

.ast-node-video {
  display: block;
}

/* =========================================================
   Correction de l'encadré blanc (.slot-br)
   ========================================================= */
/* Empêche l'apparition de l'encadré blanc (padding/background) 
   autour de la colonne de droite lorsqu'une vidéo est lancée,
   ce qui causait un décalage des boutons (saut vers la droite/haut) */
.metabot-container.mode-advanced-search-tab .slot-br {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  border-radius: 0 !important;
  margin-top: 0 !important;
  /* Empêche le -10px de margin-top de .has-search-results */
}

.ast-node-video>.ast-node-header {
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  padding: 6px 12px;
  font-size: 13px;
}

.ast-node-video:hover>.ast-node-header {
  background: rgba(79, 141, 252, 0.08);
  border-color: rgba(79, 141, 252, 0.3);
  transform: translateX(2px);
}

.ast-node-video .ast-label {
  font-weight: normal;
}

.ast-meta-date {
  font-size: 11px;
  color: #94a3b8;
  flex-shrink: 0;
  margin-left: auto;
}

/* IMPORTANT: Force parent container to show up */
.metabot-container.mode-advanced-search-tab .metabot-section[data-section="search"] .results-section {
  display: flex !important;
  flex-direction: column !important;
}

/* Vidéos - Hybrid mode */
.ast-play-btn {
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4f8dfc;
  font-size: 16px;
  flex-shrink: 0;
}

.ast-play-btn:hover {
  color: var(--primary-color, #3b82f6);
  transform: scale(1.1);
}

.ast-play-btn i {
  transition: color 0.2s ease;
}

.ast-node-video.active>.ast-node-header {
  background: linear-gradient(135deg, #4f8dfc, #3b82f6);
  border-color: #4f8dfc;
  color: #fff;
}

.ast-node-video.active>.ast-node-header .ast-label {
  color: #fff;
  font-weight: 600;
}

.ast-node-video.active>.ast-node-header .ast-play-btn {
  color: #fff;
}

.ast-node-video.active>.ast-node-header .ast-meta-date {
  color: rgba(255, 255, 255, 0.9);
}

/* Extension du layout en mode advanced-search-tab */
/* Chapitres */
.ast-chapter {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: #f8fafc;
  border-radius: 6px;
  margin-bottom: 4px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  font-size: 0.9rem;
  color: #334155;
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
}

.ast-chapter:hover {
  background: rgba(79, 141, 252, 0.08);
  border-color: rgba(79, 141, 252, 0.3);
  z-index: 50;
}

.ast-chapter-icon {
  margin-right: 8px;
  color: #4f8dfc;
  flex-shrink: 0;
}

.ast-chapter-label {
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #334155;
}

/* Infobulle pour les chapitres et titres tronqués */
.ast-chapter::after,
.ast-node-header::after {
  content: attr(data-full-title);
  position: absolute;
  bottom: calc(100% + 5px);
  left: 10px;
  background: rgba(15, 23, 42, 0.95);
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  white-space: normal;
  width: max-content;
  max-width: 300px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  z-index: 100;
  line-height: 1.4;
}

.ast-chapter::before,
.ast-node-header::before {
  content: "";
  position: absolute;
  bottom: calc(100% - 1px);
  left: 30px;
  border: 6px solid transparent;
  border-top-color: rgba(15, 23, 42, 0.95);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  z-index: 101;
}

.ast-chapter[data-full-title]:hover::after,
.ast-chapter[data-full-title]:hover::before,
.ast-node-header[data-full-title]:hover::after,
.ast-node-header[data-full-title]:hover::before {
  opacity: 1;
  visibility: visible;
}

.ast-chapter-meta {
  margin-left: 12px;
  font-size: 0.8rem;
  font-family: monospace;
  color: #94a3b8;
  flex-shrink: 0;
}

@media (min-width: 769px) {
  .metabot-container.mode-advanced-search-tab .metabot-section[data-section="search"] .content {
    grid-template-areas:
      "tl br"
      "bl br" !important;
  }

  .metabot-container.mode-advanced-search-tab .slot-tr {
    display: none !important;
  }
}

/* Hiding unnecessary panels in Advanced Search mode */
.metabot-container.mode-advanced-search-tab #videoResults,
.metabot-container.mode-advanced-search-tab #hybridBetaDebugPanel,
.metabot-container.mode-advanced-search-tab #myVideosPanel {
  display: none !important;
}

/* Mobile Layout pour le panneau de filtres */
@media (max-width: 768px) {

  /* Le parent a un gap de 12px par défaut, on l'annule pour égaliser l'espacement */
  .ast-header-panel {
    gap: 0px !important;
  }

  /* Forcer Ligne 1 sur une seule ligne hyper-compacte */
  .ast-header-row {
    flex-wrap: nowrap !important;
    overflow-x: visible !important;
    /* Permet à l'espace de s'étirer correctement */
    gap: 2px !important;
    width: 100% !important;
    justify-content: space-between !important;
  }

  /* Compression maximale de la Ligne 1 pour que tout rentre */
  .ast-top-toolbar {
    padding-bottom: 4px !important;
    /* 4px padding + 0px gap parent = 4px espace total avec Ligne 2 */
    border-bottom: 1px solid var(--border-color, #334155);
  }

  .ast-toolbar-left {
    flex: 1; /* Prend tout l'espace restant */
    gap: 2px !important;
  }

  /* Superposer les boutons d'action et le compteur dans le même encadré */
  .ast-toolbar-right {
    flex-shrink: 0; /* Ne pas écraser cette boîte */
  }

  .ast-view-wrap {
    flex: 2; /* Prend 2/3 de l'espace de gauche */
    padding: 4px !important; /* Identique à la ligne 2 */
    gap: 4px !important;
    height: 38px !important;
    box-sizing: border-box !important;
  }

  .ast-sort-wrap {
    flex: 1; /* Prend 1/3 de l'espace de gauche */
    padding: 4px !important; /* Identique à la ligne 2 */
    gap: 4px !important;
    height: 38px !important;
    box-sizing: border-box !important;
  }

  .ast-actions-wrap {
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0px 4px !important; /* Horizontal gap for buttons, 0 for vertical */
    background: var(--surface-hover);
    border-radius: 8px;
    border: 1px solid var(--border-color, #334155);
    padding: 2px 4px !important;
    min-height: 38px !important;
    box-sizing: border-box !important;
    width: 84px; /* Fixed width to fit exactly 3 buttons */
  }
  
  .ast-actions-wrap .ast-divider {
    display: none; /* Hide divider on mobile */
  }

  .ast-results-count {
    font-size: 0.65rem !important;
    padding: 0 !important;
    background: transparent !important;
    line-height: 1;
    width: 100%; /* Force to own line */
    text-align: center;
    order: 10; /* Make sure it's at the bottom */
  }
  
  .ast-sort-btn {
    flex: 1; /* Prend tout l'espace de sa boîte parent */
    justify-content: center; /* Centre le texte et l'icône */
    font-size: 0.75rem !important; /* On peut remettre une taille normale ! */
    padding: 0 4px !important;
    gap: 4px !important;
    height: 28px !important; /* Identique aux puces de la ligne 2 */
  }



  .ast-icon-action-btn,
  .ast-reset-btn {
    width: 20px !important;
    height: 20px !important;
    font-size: 0.8rem !important;
  }

  /* Ligne 2 et 3: Empiler les filtres */
  .ast-filters-row {
    flex-direction: column;
    align-items: stretch;
    gap: 4px !important;
    /* Espace entre Ligne 2 et Ligne 3 */
    margin-top: 0px !important;
    /* La ligne (border) et le padding de L1 feront l'espace */
    overflow-x: hidden;
  }

  .ast-filter-group {
    width: 100% !important;
    box-sizing: border-box !important;
    /* Essentiel pour aligner la bordure droite parfaitement ! */
    justify-content: flex-start;
    height: 38px !important;
  }

  /* Permettre le scroll sur les chips si ça déborde sur mobile */
  .ast-filter-group .ast-chips-wrap {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .ast-filter-group .ast-chips-wrap::-webkit-scrollbar {
    display: none;
  }
}
.ast-edition-box {
  width: 75px;
  flex-shrink: 1;
  font-size: 9px;
  line-height: 1.1;
  color: var(--text-secondary, #64748b);
  margin-left: 4px;
  margin-right: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
}

@media (max-width: 768px) {
  .ast-node-video > .ast-node-header {
    padding: 6px 4px !important;
    gap: 6px !important;
  }
  .ast-node-video .ast-toggle-chapter {
    margin-right: 0px !important;
    width: 20px !important;
    font-size: 14px;
    text-align: center;
  }
  .ast-node-video .ast-checkbox {
    width: 16px !important;
    height: 16px !important;
    margin: 0 !important;
  }
  .ast-node-video .ast-play-btn {
    font-size: 12px;
    margin: 0 !important;
  }
  .ast-edition-box {
    width: 45px;
    font-size: 8px;
    margin-left: 0px;
    margin-right: 2px;
    padding: 0;
  }
  .ast-node-video .ast-meta-date {
    font-size: 8px;
    margin-left: 0;
  }
  .ast-node-video .ast-label {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.1;
    font-size: 11px;
    flex: 1; /* Maximise l'espace pour le titre */
  }
}
