/* sidebar.css — the menu inside the shared sidebar: sections, links, nested groups.
 *
 * Its own sheet (spec docs/specs/sidebar-tree-nav/, K13) so a host that renders the
 * sidebar inside its own layout loads it without the rest of shell.css. Tokens only.
 * The sidebar pane itself (.sidebar: scroll, width, resize handle) stays in shell.css.
 * Rail rules key off body[data-sidebar="collapsed"], the state the host's shell sets.
 */
.sidebar-nav { display: flex; flex-direction: column; }
/* The fold-all control above the menu (increment-fold-all, K17); the rail hides it with the titles. */
.sidebar-toolbar { display: flex; justify-content: flex-end; padding: 0 12px 4px; }
body[data-sidebar="collapsed"] .sidebar-toolbar { display: none; }
/* The typed filter (increment-filter, K18): the field takes the row, the fold-all button keeps its size. */
.sidebar-toolbar { align-items: center; gap: 6px; }
.sidebar-filter {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 2px 8px;
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--bg-input, var(--bg));
  color: var(--fg-muted);
}
.sidebar-filter:focus-within { border-color: var(--accent); }
.sidebar-filter-clear {
  display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 0;
  background: transparent; color: inherit; font: inherit; cursor: default;
}
.sidebar-filter-clear .ph-x, .sidebar-filter.is-filtering .sidebar-filter-clear .ph-magnifying-glass { display: none; }
.sidebar-filter.is-filtering .sidebar-filter-clear .ph-x { display: inline-block; }
.sidebar-filter.is-filtering .sidebar-filter-clear { cursor: pointer; }
.sidebar-filter.is-filtering .sidebar-filter-clear:hover, .sidebar-filter-clear:focus-visible { color: var(--fg); }
.sidebar-filter-input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--fg);
  font: inherit; font-size: var(--fs-sm, 0.85rem);
}
.sidebar-filter-empty { margin: 0; padding: 8px 16px; font-size: var(--fs-xs); color: var(--fg-muted); }
.sidebar-filter-empty[hidden] { display: none; }
.is-filtered-out { display: none !important; }
body[data-sidebar="collapsed"] .sidebar-filter, body[data-sidebar="collapsed"] .sidebar-filter-empty { display: none; }
.sidebar-section { margin-bottom: 16px; }
.sidebar-section-title {
  display: block; padding: 8px 16px 4px; font-size: var(--fs-xs);
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--fg-muted); font-weight: 600;
}
a.sidebar-section-link { text-decoration: none; cursor: pointer; transition: color var(--t-fast); }
a.sidebar-section-link:hover { color: var(--fg); }
a.sidebar-section-link.is-active { color: var(--accent); }
.sidebar-section-head { display: flex; align-items: center; cursor: pointer; user-select: none; }
.sidebar-section-head .sidebar-section-title { flex: 1; }
.sidebar-section-caret {
  font-size: 11px; color: var(--fg-muted); margin: 4px 14px 0 0;
  transition: transform var(--t-fast), color var(--t-fast);
}
.sidebar-section-head:hover .sidebar-section-title,
.sidebar-section-head:hover .sidebar-section-caret { color: var(--fg); }
.sidebar-section.collapsed .sidebar-section-caret { transform: rotate(-90deg); }
.sidebar-section.collapsed .sidebar-section-items { display: none; }
body[data-sidebar="collapsed"] .sidebar-section-caret { display: none; }
body[data-sidebar="collapsed"] .sidebar-section.collapsed .sidebar-section-items { display: block; }
.sidebar-link {
  display: flex; align-items: center; gap: 10px; padding: 7px 16px;
  color: var(--fg-subtle); font-size: var(--fs-md);
  border-left: 3px solid transparent;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.sidebar-link:hover { background: var(--bg-card); color: var(--fg); text-decoration: none; }
.sidebar-link.is-active { background: var(--bg-card); color: var(--fg); border-left-color: var(--accent); }
.sidebar-link.is-disabled { color: var(--fg-muted); cursor: default; opacity: 0.7; }
.sidebar-link .ph { font-size: 1.1em; flex-shrink: 0; }
.sidebar-link .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-link .count {
  font-size: var(--fs-xs); color: var(--fg-muted); font-variant-numeric: tabular-nums;
  margin-left: 8px; flex-shrink: 0;
}
body[data-sidebar="collapsed"] .sidebar-section-title,
body[data-sidebar="collapsed"] .sidebar-link .label,
body[data-sidebar="collapsed"] .sidebar-link .count { display: none; }
.sidebar-children {
  display: flex; flex-direction: column; padding-left: 18px;
  border-left: 1px solid var(--border); margin-left: 26px;
}
.sidebar-children .sidebar-link { padding-left: 12px; }

/* A nav item that owns children folds too — the section caret only reaches the
   top tier, so a deep branch (a wiki category's articles) had no way to close.
   The row is a flex pair: the link keeps navigating, the caret only folds. */
.sidebar-item-row { display: flex; align-items: center; }
.sidebar-item-row > .sidebar-link { flex: 1; min-width: 0; }
.sidebar-item-caret {
  font-size: 11px; color: var(--fg-muted); padding: 6px 14px 6px 4px; cursor: pointer;
  transition: transform var(--t-fast), color var(--t-fast);
}
.sidebar-item-caret:hover { color: var(--fg); }
.sidebar-item-caret:focus-visible { color: var(--accent); outline: none; }
.sidebar-item.collapsed > .sidebar-item-row .sidebar-item-caret { transform: rotate(-90deg); }
.sidebar-item.collapsed > .sidebar-children { display: none; }
body[data-sidebar="collapsed"] .sidebar-item-caret { display: none; }

/* A group with no page of its own: the whole row opens it (spec sidebar-tree-nav K12). */
.sidebar-group-label { cursor: pointer; user-select: none; }

/* ── Keyboard and depth (spec sidebar-tree-nav K1, K9, K12) ── */
/* One focus ring, drawn inside the row so the pane's edge never clips it. */
.sidebar-tree [role="treeitem"]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--r-sm);
}
/* Every nested level steps in from its parent. From the third level on the step is
   smaller, so a deep branch keeps room for its labels. */
.sidebar-children .sidebar-children { margin-left: 12px; padding-left: 8px; }
/* The rail is one icon wide: nesting cannot be shown by indent there, so every level
   lines up, and a group with no icon keeps its caret — otherwise its row is empty. */
body[data-sidebar="collapsed"] .sidebar-children { margin-left: 0; padding-left: 0; border-left: none; }
body[data-sidebar="collapsed"] .sidebar-children .sidebar-link { padding-left: 16px; }
body[data-sidebar="collapsed"] .sidebar-item-row:not(:has(> .sidebar-link > .ph)) > .sidebar-item-caret { display: inline-block; }
