/* Clients → Projects sidebar tree (FUN-015, CA-15..18).
   Dark UI: uses the shared design tokens from tokens.css. */

.clients-tree {
  padding: var(--space-2) 0 var(--space-3);
}

/* Section-level collapse control (FUN-015 CA-17). The "Clients" nav item and
   the chevron toggle are wrapped in a row; the button sits absolutely on the
   right of that row and toggles the whole tree below it. */
.sidebar-nav__row {
  position: relative;
}

.clients-tree-toggle {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.clients-tree-toggle:hover,
.clients-tree-toggle:focus-visible {
  color: var(--color-accent);
  outline: none;
}

.clients-tree-toggle i {
  font-size: 0.625rem;
  transition: transform var(--transition-fast);
}

.clients-tree.is-section-collapsed .clients-tree__list {
  display: none;
}

.clients-tree.is-section-collapsed .clients-tree-toggle i {
  transform: rotate(-90deg);
}

/* The toggle is only meaningful when the global sidebar is expanded. */
.app-sidebar.collapsed .clients-tree-toggle {
  display: none;
}

.clients-tree__header {
  padding: var(--space-2) var(--space-5);
  font-size: 0.6875rem;
  font-weight: var(--font-weight-subtitle);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

.clients-tree__list,
.clients-tree__projects {
  list-style: none;
  margin: 0;
  padding: 0;
}

.clients-tree__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.clients-tree__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: var(--space-4);
  padding: 0;
  background: transparent;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.clients-tree__toggle:hover,
.clients-tree__toggle:focus-visible {
  color: var(--color-accent);
  outline: none;
}

.clients-tree__toggle i {
  font-size: 0.625rem;
  transition: transform var(--transition-fast);
}

.clients-tree__client.is-open > .clients-tree__row .clients-tree__toggle i {
  transform: rotate(90deg);
}

.clients-tree__link {
  display: block;
  flex: 1;
  min-width: 0;
  padding: var(--space-2) var(--space-3) var(--space-2) 0;
  color: var(--color-text-secondary);
  font-size: 0.875rem;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 2px solid transparent;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.clients-tree__link:hover,
.clients-tree__link:focus-visible {
  color: var(--color-accent);
  outline: none;
}

.clients-tree__client.is-active > .clients-tree__row .clients-tree__link {
  color: var(--color-accent);
  font-weight: var(--font-weight-subtitle);
}

.clients-tree__projects {
  display: none;
  padding-left: var(--space-8);
}

.clients-tree__client.is-open > .clients-tree__projects {
  display: block;
}

.clients-tree__project-link {
  display: block;
  flex: 1;
  min-width: 0;
  padding: var(--space-1) var(--space-3) var(--space-1) var(--space-1);
  color: var(--color-text-secondary);
  font-size: 0.8125rem;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 2px solid var(--color-border);
  transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

.clients-tree__project-link:hover,
.clients-tree__project-link:focus-visible {
  color: var(--color-accent);
  border-left-color: var(--color-accent);
  outline: none;
}

.clients-tree__project.is-active > .clients-tree__project-row .clients-tree__project-link {
  color: var(--color-accent);
  border-left-color: var(--color-accent);
  font-weight: var(--font-weight-subtitle);
  background: rgba(255, 69, 0, 0.08);
}

/* ── Project subtrees (ADR-015, FUN-016/017) ─────────────────────────── */

.clients-tree__project-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.clients-tree__project-row .clients-tree__toggle {
  margin-left: 0;
}

.clients-tree__project.is-open > .clients-tree__project-row .clients-tree__toggle i {
  transform: rotate(90deg);
}

.clients-tree__subtree {
  display: none;
  padding-left: var(--space-6);
}

.clients-tree__project.is-open > .clients-tree__subtree {
  display: block;
}

.clients-tree__subtree-header {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: var(--space-1) var(--space-3) var(--space-1) var(--space-3);
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: 0.6875rem;
  font-weight: var(--font-weight-subtitle);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

.clients-tree__subtree-header:hover,
.clients-tree__subtree-header:focus-visible {
  color: var(--color-accent);
  outline: none;
}

.clients-tree__subtree-header i {
  font-size: 0.625rem;
  transition: transform var(--transition-fast);
}

.clients-tree__subtree-section.is-collapsed .clients-tree__subtree-header i {
  transform: rotate(-90deg);
}

.clients-tree__subtree-section.is-collapsed .clients-tree__subtree-body,
.clients-tree__subtree-section.is-collapsed .clients-tree__subtree-search {
  display: none;
}

.clients-tree__toggle-spacer {
  width: 18px;
  height: 18px;
  margin-left: var(--space-4);
  flex-shrink: 0;
}

.clients-tree__subtree-body {
  display: flex;
  flex-direction: column;
}

.clients-tree__subtree-folder {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2) var(--space-1) var(--space-2);
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  font-weight: var(--font-weight-subtitle);
}

.clients-tree__subtree-folder i {
  color: var(--color-warning);
  font-size: 0.6875rem;
}

.clients-tree__subtree-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2) var(--space-1) var(--space-5);
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 2px solid var(--color-border);
  transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

.clients-tree__subtree-link:hover,
.clients-tree__subtree-link:focus-visible {
  color: var(--color-accent);
  border-left-color: var(--color-accent);
  outline: none;
  background: rgba(255, 69, 0, 0.06);
}

.clients-tree__subtree-count {
  margin-left: auto;
  color: var(--color-text-secondary);
  font-size: 0.625rem;
  flex-shrink: 0;
}

.clients-tree__subtree-method {
  flex-shrink: 0;
  min-width: 32px;
  text-align: center;
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--color-accent);
}

.clients-tree__subtree-empty {
  padding: var(--space-1) var(--space-2) var(--space-1) var(--space-5);
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  font-style: italic;
}

.clients-tree__subtree-search {
  padding: var(--space-1) var(--space-2) var(--space-1) var(--space-3);
}

.clients-tree__subtree-search-input {
  width: 100%;
  min-height: 26px;
  padding: 2px 8px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  color: var(--color-text-primary);
  font: inherit;
  font-size: 0.75rem;
  outline: none;
}

.clients-tree__subtree-search-input:focus {
  border-color: var(--color-accent);
}

.clients-tree__subtree-search-input::placeholder {
  color: var(--color-text-secondary);
}

/* ── Managed project subtrees (dedicated pages, ADR-015) ─────────────── */

/* Toolbar (refresh + overflow menu) inside the Collections section header. */
.clients-tree__subtree-toolbar {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.clients-tree__subtree-toolbar .nav-refresh-btn,
.clients-tree__subtree-toolbar .nav-context-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 3px;
  border-radius: 4px;
  color: var(--color-text-secondary);
  font-size: 0.6875rem;
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast);
}

.clients-tree__subtree-toolbar .nav-refresh-btn:hover,
.clients-tree__subtree-toolbar .nav-refresh-btn:focus-visible,
.clients-tree__subtree-toolbar .nav-context-indicator:hover,
.clients-tree__subtree-toolbar .nav-context-indicator:focus-visible {
  color: var(--color-accent);
  background: rgba(255, 69, 0, 0.08);
  outline: none;
}

/* Management trees (endpoints/tasks) mounted inside the project subtree.
   Remove the extra outer left padding (the subtree already indents) and let the
   outer sidebar nav own the scroll instead of nesting a second scroll region. */
.clients-tree__subtree .endpoint-tree {
  padding-left: 0;
  max-height: none;
  overflow-y: visible;
  min-height: 0;
}

.clients-tree__subtree .tasks-folder-tree {
  /* Indent the folders inside the "Tasks" section so the tree hierarchy is
     visible relative to the section header. */
  padding-left: 14px;
  min-width: 0;
  overflow-x: hidden;
}

/* Hide the tree when the global sidebar is collapsed (consistent with the
   endpoint-tree and nav-item label rules in sidebar.css). */
.app-sidebar.collapsed .clients-tree {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .clients-tree__toggle i,
  .clients-tree__link,
  .clients-tree__project-link,
  .clients-tree__subtree-link,
  .clients-tree-toggle i {
    transition: none;
  }
}
