/* ==========================================================================
   Tuimux — Sidebar Tree Styles
   ========================================================================== */

/* ---------- Tree Root ---------- */
.tree {
  padding: 4px 0;
  font-size: 13px;
  user-select: none;
}

/* ---------- Tree Node (details/summary pattern) ---------- */
.tree details {
  margin: 0;
}

.tree details > summary {
  list-style: none;
  cursor: pointer;
  outline: none;
}

.tree details > summary::-webkit-details-marker {
  display: none;
}

.tree details > summary::marker {
  display: none;
  content: '';
}

/* ---------- Tree Item (shared for folders + connections) ---------- */
.tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  min-height: 30px;
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
  border-left: 2px solid transparent;
}

.tree-item:hover {
  background: var(--bg-hover);
}

.tree-item.selected {
  background: var(--bg-active);
}

.tree-item.focused {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

/* Color-coded left border from connection.color */
.tree-item[data-color="red"]     { border-left-color: var(--error); }
.tree-item[data-color="green"]   { border-left-color: var(--success); }
.tree-item[data-color="blue"]    { border-left-color: var(--accent); }
.tree-item[data-color="yellow"]  { border-left-color: var(--warning); }
.tree-item[data-color="purple"]  { border-left-color: #bb9af7; }
.tree-item[data-color="cyan"]    { border-left-color: #7dcfff; }
.tree-item[data-color="orange"]  { border-left-color: #ff9e64; }
.tree-item[data-color="pink"]    { border-left-color: #f7768e; }
.tree-item[data-color="teal"]    { border-left-color: #73daca; }

/* Indent levels */
.tree-item[data-depth="0"] { padding-left: 12px; }
.tree-item[data-depth="1"] { padding-left: 28px; }
.tree-item[data-depth="2"] { padding-left: 44px; }
.tree-item[data-depth="3"] { padding-left: 60px; }
.tree-item[data-depth="4"] { padding-left: 76px; }

/* ---------- Chevron (expand / collapse) ---------- */
.tree-chevron {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.15s ease, color 0.1s;
  font-size: 12px;
}

/* Rotates when folder is open */
details[open] > summary .tree-chevron {
  transform: rotate(90deg);
}

.tree-item:hover .tree-chevron {
  color: var(--text-secondary);
}

/* Placeholder for leaf nodes (no chevron, but keep alignment) */
.tree-chevron-spacer {
  width: 16px;
  flex-shrink: 0;
}

/* ---------- Tree Icon ---------- */
.tree-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.tree-item.folder .tree-icon {
  color: var(--warning);
}

.tree-item.connection .tree-icon {
  color: var(--accent);
}

/* ---------- Tree Label ---------- */
.tree-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.4;
}

.tree-item.connection.disconnected .tree-label {
  color: var(--text-secondary);
}

/* ---------- Status Dot ---------- */
.tree-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tree-status.connected {
  background: var(--success);
  box-shadow: 0 0 4px rgba(158, 206, 106, 0.4);
}

.tree-status.disconnected {
  background: var(--text-muted);
}

.tree-status.error {
  background: var(--error);
  box-shadow: 0 0 4px rgba(247, 118, 142, 0.4);
}

.tree-status.hollow {
  background: transparent;
  border: 1.5px solid var(--text-muted);
}

/* ---------- Pulsing Activity Indicator ---------- */
.tree-activity {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: tree-pulse 1.5s ease-in-out infinite;
}

@keyframes tree-pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(0.8);
  }
}

/* Only show on hover or when active */
.tree-item .tree-activity {
  display: none;
}

.tree-item.has-activity .tree-activity {
  display: block;
}

/* ---------- Folder Badge (connected count) ---------- */
.tree-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-mono);
  flex-shrink: 0;
  background: rgba(158, 206, 106, 0.15);
  color: var(--success);
}

.tree-badge.empty {
  background: rgba(65, 72, 104, 0.3);
  color: var(--text-muted);
}

/* ---------- Right-side Actions (show on hover) ---------- */
.tree-actions {
  display: none;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  margin-left: auto;
}

.tree-item:hover .tree-actions {
  display: flex;
}

.tree-actions button {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 3px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  transition: background 0.1s, color 0.1s;
}

.tree-actions button:hover {
  background: var(--bg-active);
  color: var(--text-primary);
}

/* ---------- Drag and Drop ---------- */

/* Drop line indicator (between items) */
.tree-drop-line {
  height: 2px;
  background: var(--accent);
  margin: 0 12px;
  border-radius: 1px;
  pointer-events: none;
  animation: drop-line-pulse 0.6s ease-in-out infinite alternate;
}

@keyframes drop-line-pulse {
  from { opacity: 0.6; }
  to   { opacity: 1; }
}

/* Folder highlight (drop into folder) */
.tree-item.drop-target {
  background: rgba(122, 162, 247, 0.12);
  outline: 1px dashed var(--accent);
  outline-offset: -1px;
}

/* Dragging item ghost */
.tree-item.dragging {
  opacity: 0.4;
}

/* Drag preview */
.tree-drag-preview {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-primary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
}

/* ---------- Inline Rename ---------- */
.tree-rename-input {
  width: 100%;
  height: 22px;
  padding: 0 4px;
  background: var(--bg-primary);
  border: 1px solid var(--accent);
  border-radius: 3px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-sans);
  outline: none;
  box-shadow: 0 0 0 2px rgba(122, 162, 247, 0.2);
}

/* ---------- Filter Highlight ---------- */
.tree-label mark {
  background: rgba(224, 175, 104, 0.3);
  color: var(--warning);
  border-radius: 2px;
  padding: 0 1px;
}

/* ---------- Tree Group Header ---------- */
.tree-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.tree-group-header .tree-group-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------- Folder Children Container ---------- */
.tree details > .tree-children {
  /* Subtle left guide line */
  position: relative;
}

.tree details > .tree-children::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
  opacity: 0.4;
}

.tree-children[data-depth="0"]::before { left: 20px; }
.tree-children[data-depth="1"]::before { left: 36px; }
.tree-children[data-depth="2"]::before { left: 52px; }
.tree-children[data-depth="3"]::before { left: 68px; }

/* ---------- Empty Folder ---------- */
.tree-empty {
  padding: 8px 12px 8px 44px;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* ---------- Tree Animations ---------- */
details > .tree-children {
  animation: tree-expand 0.15s ease-out;
}

@keyframes tree-expand {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Keyboard Navigation Focus Ring ---------- */
.tree-item:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
  background: var(--bg-hover);
}

/* ---------- Tree Skeleton (Loading State) ---------- */
.tree-skeleton {
  padding: 4px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tree-skeleton-item {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 28px;
}

.tree-skeleton-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bg-hover);
  animation: skeleton-pulse 1.2s ease-in-out infinite;
}

.tree-skeleton-bar {
  height: 10px;
  border-radius: 4px;
  background: var(--bg-hover);
  animation: skeleton-pulse 1.2s ease-in-out infinite;
}

.tree-skeleton-bar.short  { width: 60%; }
.tree-skeleton-bar.medium { width: 80%; }
.tree-skeleton-bar.long   { width: 95%; }

@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 0.8; }
}
