.secondary-sidebar {
  width: 220px;
  height: 100vh;
  background: #0d0d1f;
  border-right: 1px solid #1e1e3a;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.75rem;
  gap: 0.75rem;
  overflow: hidden;
  position: relative;
  // Pas de transition sur la largeur : sinon le drag de resize "traîne" derrière la souris.
  // L'animation d'expand/collapse est gérée uniquement par la classe .collapsed ci-dessous.

  &.collapsed {
    width: 44px !important;
    padding: 1.25rem 0.5rem;
    overflow: hidden;
    transition: width 0.25s ease;
  }
}

.resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
  background: transparent;
  transition: background 0.15s ease;

  &:hover,
  &:active { background: #6c63ff; }
}

.collapse-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  color: #6b7280;
  transition: color 0.2s, background 0.2s;
  flex-shrink: 0;

  &:hover { color: white; background: #1f2937; }
}

.btn-back {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: transparent;
  border: none;
  color: #6b7280;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  transition: color 0.2s;
  width: fit-content;

  &:hover { color: white; }
}

.sidebar-title {
  font-size: 1rem;
  font-weight: 700;
  color: white;
  padding: 0 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

// Variante cliquable : le titre devient un bouton "retour à l'accueil".
.sidebar-title--link {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  transition: background 0.15s;

  .sidebar-title-icon {
    flex-shrink: 0;
    color: #a78bfa;
  }

  .sidebar-title-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  &:hover { background: rgba(255, 255, 255, 0.07); }
  &.active { background: rgba(108, 99, 255, 0.18); }
}

.actions-row {
  display: flex;
  gap: 0.4rem;
}

.btn-pill {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.6rem;
  font-size: 0.82rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, filter 0.15s;

  &.primary   { background: #6c63ff; color: white; }
  &.primary:hover { background: #5a52e0; }
  &.secondary { background: #2a2a3d; color: #d1d5db; }
  &.secondary:hover { background: #363650; }
}

.tree {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow-y: auto;
  padding: 0.25rem 0;
}

// En-tête de section — groupe visuellement les nœuds racines (ex: Personnages / Narration).
// Un filet au-dessus crée la séparation ; pas de filet pour la première section
// (le titre suffit) — on cible ça via :not(:first-child).
.tree-section-header {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9ca3af;
  padding: 0.6rem 0.5rem 0.3rem;
}
.tree > .tree-section-header:not(:first-child) {
  border-top: 1px solid #374151;
  margin-top: 0.35rem;
  padding-top: 0.6rem;
}

.tree-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  background: transparent;
  border: none;
  color: #d1d5db;
  font-size: 0.82rem;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;

  &:hover { background: #1f2937; }
  &.action { color: #6b7280; font-style: italic; }
  &.action:hover { color: #a5b4fc; background: #1f2937; }

  // Dossier / page / scène actuellement affichée : surligné avec un accent
  // violet et une barre gauche pour repérer instantanément où on se trouve,
  // utile quand plusieurs entrées partagent le même label.
  &.active {
    background: #1e1b4b;
    color: white;
    font-weight: 500;
    box-shadow: inset 3px 0 0 #6c63ff;
  }
  &.active:hover { background: #2a2558; }

  .tree-item-meta {
    margin-left: auto;
    font-size: 0.72rem;
    color: #6b7280;
    flex-shrink: 0;
  }
}

.item-icon {
  display: inline-flex;
  align-items: center;
  color: #a5b4fc;
  flex-shrink: 0;
  margin-right: 0.1rem;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  width: 100%;
  position: relative;

  // Hover-reveal : les boutons d'action de creation n'apparaissent qu'au
  // survol de la ligne. Pattern Notion/VS Code.
  &:hover .node-actions { opacity: 1; pointer-events: auto; }
}

.node-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin-left: auto;
  flex-shrink: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  // Superpose les boutons d'action sur le .tree-item-meta eventuel
  // (compteur de pages) : au hover on affiche les actions, au repos le meta.
  position: absolute;
  right: 0.25rem;
  background: linear-gradient(to right, transparent, #1f2937 30%);
  padding-left: 1rem;
}

.node-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: rgba(55, 65, 81, 0.6);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: #d1d5db;
  padding: 0;
  transition: background 0.12s, color 0.12s;

  &:hover { background: #4338ca; color: #ffffff; }
}

.chevron-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background: transparent;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  color: #6b7280;
  padding: 0;

  &:hover { background: #374151; color: white; }
}

.chevron-spacer {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.tree-children {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}


/* --- Bottom panel (ex: Templates) ------------------------------------- */
.bottom-panel {
  border-top: 1px solid #1e1e3a;
  padding-top: 0.5rem;
  margin-top: auto; /* colle en bas de la sidebar flex */
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.panel-header-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.panel-header-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: rgba(108, 99, 255, 0.15);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: #c7d2fe;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;

  &:hover { background: #6c63ff; color: #ffffff; }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: #a5b4fc;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;

  &:hover { background: #1f2937; }

  .panel-title { letter-spacing: 0.02em; }
}

.panel-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.panel-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  border: none;
  color: #d1d5db;
  font-size: 0.82rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;

  &:hover { background: #1f2937; }

  &.action {
    color: #6b7280;
    font-style: italic;
  }
  &.action:hover { color: #a5b4fc; }

  .panel-item-meta {
    font-size: 0.72rem;
    color: #6b7280;
    flex-shrink: 0;
  }
}
