/* ==========================================================
   Sidebar header
   ========================================================== */

.sidebar-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.sidebar-title {
  font-weight: 700;
}

.sidebar-actions {
  display: flex;
  gap: 0.5rem;
}

.tree-action {
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

/* ==========================================================
   Tree layout
   ========================================================== */

.tree {
  list-style: none;
  margin: 0;
  padding-left: 0;
}

/* Nested tree indentation */
.tree .tree {
  margin-top: 0.15rem;
  padding-left: 1rem;
}

.tree-row {
  display: flex;
  align-items: flex-start; /* supports multi-line link alignment */
  gap: 0.35rem;

  position: relative;
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  overflow: hidden; /* keeps ribbon edges clean */
}

/* Ensure contents sit above ribbon layers */
.tree-row > * {
  position: relative;
  z-index: 2;
}

.tree-link {
  display: block;
  flex: 1;
  min-width: 0;
  white-space: normal;
  word-break: break-word;

  color: rgba(242, 230, 210, 0.92);
  text-decoration: none;
}

.tree-row:hover {
  background: rgba(255, 255, 255, 0.05);
}

.tree-row:hover .tree-link {
  color: rgba(255, 245, 225, 0.98);
}

.tree-link,
.tree-link:visited,
.tree-link:active {
  display: block;
  flex: 1;
  min-width: 0;

  white-space: normal;
  word-break: break-word;

  color: rgba(242, 230, 210, 0.92);
  text-decoration: none;
}


/* ==========================================================
   Tree controls (toggle / spacer)
   ========================================================== */

.tree-toggle,
.tree-spacer {
  width: 1.25rem;
  height: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.tree-toggle {
  background: transparent;
  border: 0;
  padding: 2px 4px;
  border-radius: 4px;

  cursor: pointer;
  color: rgba(242, 230, 210, 0.7);

  transform: rotate(0deg);
  transition: transform 120ms ease, color 140ms ease, background 140ms ease;
}

.tree-toggle[aria-expanded="true"] {
  transform: rotate(90deg);
}

.tree-toggle:hover {
  color: rgba(255, 235, 200, 0.95);
  background: rgba(0, 0, 0, 0.06);
}

/* Remove default outline, keep accessible custom focus */
.tree-toggle:focus {
  outline: none;
}

.tree-toggle:focus-visible {
  outline: 2px solid rgba(255, 210, 120, 0.5);
  outline-offset: 2px;
}

.tree-spacer {
  border: 0;
  background: transparent;
  opacity: 0.35;
}

/* ==========================================================
   Ribbon band (full-width) with gold woven trim + triangle tail
   ========================================================== */

.tree-row::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 8px;

  --trim-inset: 4px;
  --trim-h: 3px;

  background:
    /* TOP trim */
    repeating-linear-gradient(
      90deg,
      rgba(255, 220, 140, 0.95) 0px,
      rgba(255, 220, 140, 0.95) 2px,
      rgba(120, 80, 25, 0.95) 2px,
      rgba(120, 80, 25, 0.95) 4px
    ) top var(--trim-inset) left / 100% var(--trim-h) no-repeat,

    /* BOTTOM trim */
    repeating-linear-gradient(
      90deg,
      rgba(255, 220, 140, 0.95) 0px,
      rgba(255, 220, 140, 0.95) 2px,
      rgba(120, 80, 25, 0.95) 2px,
      rgba(120, 80, 25, 0.95) 4px
    ) bottom var(--trim-inset) left / 100% var(--trim-h) no-repeat,

    /* gentle fabric sheen */
    linear-gradient(to bottom, rgba(255, 255, 255, 0.14), transparent 45%) 0 0 / 100% 100% no-repeat,

    /* ribbon base */
    linear-gradient(135deg, #a1121a, #5c0b10) 0 0 / 100% 100% no-repeat;

  clip-path: polygon(0% 0%, 86% 0%, 100% 50%, 86% 100%, 0% 100%);

  opacity: 0;
  transform: translateY(2px);
  transition: opacity 140ms ease, transform 140ms ease;
  z-index: 0;
}

/* Optional overlay layer reserved for future effects (kept but minimal) */
.tree-row::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;

  clip-path: polygon(0% 0%, 86% 0%, 100% 50%, 86% 100%, 0% 100%);

  opacity: 0;
  transition: opacity 140ms ease, transform 140ms ease;
  transform: translateY(2px);
  z-index: 1;
}

/* ==========================================================
   Ribbon behavior
   - Default: ribbon on current page
   - While hovering sidebar: ribbon follows hovered row
   - Uses :has() so "sidebar hover" alone doesn't hide the active ribbon
   ========================================================== */

.tree-item.is-active > .tree-row::before,
.tree-item.is-active > .tree-row::after {
  opacity: 1;
  transform: translateY(0);
}

/* Only switch away from active when a row is actually hovered */
.sidebar:has(.tree-row:hover) .tree-item.is-active > .tree-row::before,
.sidebar:has(.tree-row:hover) .tree-item.is-active > .tree-row::after {
  opacity: 0;
  transform: translateY(2px);
}

/* Ribbon follows hover */
.sidebar .tree-row:hover::before,
.sidebar .tree-row:hover::after {
  opacity: 1;
  transform: translateY(0);
}

/* If hovering the active row, keep it visible */
.sidebar:has(.tree-row:hover) .tree-item.is-active > .tree-row:hover::before,
.sidebar:has(.tree-row:hover) .tree-item.is-active > .tree-row:hover::after {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================
   States (ancestor / legacy cleanup)
   ========================================================== */

.tree-item.is-ancestor > .tree-row .tree-link {
  font-weight: 650;
  color: rgba(242, 230, 210, 0.82);
}

/* Ribbon replaces any legacy left-border markers */
.tree-item.is-active > .tree-row,
.tree-item.is-ancestor > .tree-row {
  border-left: 0;
}
