/* ============================================
   Compact Tree — Hierarchical Expandable View
   ============================================ */

.pivot-tree-container {
  max-width: 100%;
  margin: 20px 0;
  background: transparent !important;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  border: none !important;
}

/* Remove Bootstrap borders from all descendants */
.pivot-tree-container *,
.pivot-tree-container section,
.pivot-tree-container ul,
.pivot-tree-container ol,
.pivot-tree-container li,
.pivot-tree-container .tree-node,
.pivot-tree-container .tree-word,
.pivot-tree-container .tree-word-link,
.pivot-tree-container .tree-ending,
.pivot-tree-container .tree-ending-wrap,
.pivot-tree-container .tree-toggle,
.pivot-tree-container .tree-toggle-blank,
.pivot-tree-container .tree-arrow,
.pivot-tree-container .tree-translation {
  border: none !important;
  box-shadow: none !important;
}

/* Bootstrap overrides */
.pivot-tree-container ul,
.pivot-tree-container ol {
  margin: 0;
  padding: 0;
}

.pivot-tree-container h2 {
  margin: 0 0 12px 0;
  font-size: 1.3rem;
  color: #1e293b;
}

/* Controls */
.tree-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.btn-tree {
  padding: 6px 14px;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s;
}

.btn-tree:hover {
  background: #2563eb;
}

.btn-tree:active {
  transform: translateY(1px);
}

/* Tree list */
.tree-root {
  list-style: none;
  padding: 0;
  margin: 0;
}

.tree-node {
  list-style: none;
  padding: 0;
  margin: 0;
  line-height: 1.6;
  transition: background 0.15s;
  border-radius: 4px;
  background: transparent;
}

/* Hover effect — JS adds .hovered class for full-row coverage */
.tree-node.hovered {
  background: rgba(0, 0, 0, 0.04) !important;
}

.tree-node.active {
  background: #fef3c7 !important;
  border-radius: 4px;
}

.tree-node.hidden {
  display: none;
}

/* Toggle button */
.tree-toggle {
  display: inline-block;
  width: 18px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  background: #3b82f6;
  color: white;
  border-radius: 4px;
  font-size: 9px;
  margin-right: 6px;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s, transform 0.2s;
  vertical-align: middle;
  flex-shrink: 0;
}

.tree-toggle:hover {
  background: #2563eb;
}

.tree-toggle.expanded {
  transform: rotate(90deg);
  background: #2563eb;
  color: white;
}

/* Empty toggle placeholder — visible spacer to keep child alignment */
.tree-toggle-blank {
  display: inline-block !important;
  width: 18px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  background: #3b82f6;
  color: white;
  border-radius: 4px;
  font-size: 9px;
  margin-right: 6px;
  opacity: 0.3;
  cursor: default;
  user-select: none;
  flex-shrink: 0;
  vertical-align: middle;
}

/* Suffix link */
.tree-ending-link {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.tree-ending-link:hover .tree-ending {
  text-decoration: underline;
}

/* Word text */
.tree-word {
  font-weight: 500;
  color: #1e293b;
}

.tree-word-link {
  text-decoration: none;
  color: inherit;
}

.tree-word-link:hover .tree-word {
  text-decoration: underline;
}

/* Ending + arrow wrapper */
.tree-ending-wrap {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-right: 2px;
}

.tree-ending {
  font-weight: 600;
  color: #e11d48;
  font-size: 0.95em;
}

.tree-arrow {
  color: #64748b;
  font-weight: 700;
  font-size: 1.05em;
  user-select: none;
}

/* Translation */
.tree-translation {
  color: #64748b;
  font-style: italic;
  margin-left: 8px;
  font-size: 0.9em;
}

/* Type-based colors for root + endings (synced with constants.js) */
:root {
  --wc-noun: green;
  --wc-verb: red;
  --wc-adj: blue;
  --wc-adv: purple;
  --wc-num: navy;
  --wc-prep: brown;
  --wc-post: maroon;
  --wc-conj: teal;
  --wc-pron: olive;
  --wc-pref: black;
}

.term-noun { --word-color: var(--wc-noun); }
.term-verb { --word-color: var(--wc-verb); }
.term-adj { --word-color: var(--wc-adj); }
.term-adv { --word-color: var(--wc-adv); }
.term-num { --word-color: var(--wc-num); }
.term-prep { --word-color: var(--wc-prep); }
.term-post { --word-color: var(--wc-post); }
.term-conj { --word-color: var(--wc-conj); }
.term-pron { --word-color: var(--wc-pron); }
.term-pref { --word-color: var(--wc-pref); }
.term-noun .tree-word,
.term-noun .tree-ending { color: var(--wc-noun); }
.term-verb .tree-word,
.term-verb .tree-ending { color: var(--wc-verb); }
.term-adj .tree-word,
.term-adj .tree-ending { color: var(--wc-adj); }
.term-adv .tree-word,
.term-adv .tree-ending { color: var(--wc-adv); }
.term-num .tree-word,
.term-num .tree-ending { color: var(--wc-num); }
.term-prep .tree-word,
.term-prep .tree-ending { color: var(--wc-prep); }
.term-post .tree-word,
.term-post .tree-ending { color: var(--wc-post); }
.term-conj .tree-word,
.term-conj .tree-ending { color: var(--wc-conj); }
.term-pron .tree-word,
.term-pron .tree-ending { color: var(--wc-pron); }
.term-pref .tree-word,
.term-pref .tree-ending { color: var(--wc-pref); }

/* Nested indentation */
.tree-root .tree-root {
  padding-left: 20px;
  margin-top: 2px;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  .pivot-tree-container {
    background: transparent !important;
    box-shadow: none;
  }

  .pivot-tree-container h2 {
    color: #f1f5f9;
  }

  .tree-node:hover {
    background: rgba(255, 255, 255, 0.06);
  }

  .tree-node.active {
    background: #fef3c7 !important;
  }

  .tree-word {
    color: #f1f5f9;
  }

  .tree-toggle {
    background: #3b82f6;
  }

  .tree-toggle:hover {
    background: #2563eb;
  }

  .tree-toggle.expanded {
    background: #2563eb;
  }

  .tree-translation {
    color: #94a3b8;
  }
}
