/* ============================================================================
   Unified Sidebar Component
   @countermeasure/web-components

   A modular sidebar component that provides shared structure across all apps
   while allowing app-specific customization via BEM modifiers.

   Usage:
   <aside class="sidebar sidebar--{app}" data-sidebar="{app}">
     <div class="sidebar__header">{% include "partials/app-switcher.html" %}</div>
     <div class="sidebar__body"><!-- app-specific content --></div>
     <div class="sidebar__footer">{% include "partials/sidebar/footer.html" %}</div>
   </aside>
   <div class="sidebar__backdrop" data-sidebar-backdrop="{app}"></div>
   ============================================================================ */

/* -----------------------------------------------------------------------------
   Base Sidebar Styles
   ----------------------------------------------------------------------------- */
.sidebar {
  --sidebar-collapse-edge-size: 1.5rem;
  --sidebar-collapse-edge-top: 1.75rem;
  --sidebar-collapsed-body-padding-top: 0.5rem;
  --sidebar-collapsed-header-min-height: auto;
  width: var(--sidebar-width);
  height: 100%;
  min-height: 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  position: relative;
  z-index: 100;
  isolation: isolate; /* Create stacking context for app-switcher */
}

.sidebar--app {
  width: var(--sidebar-width);
}

.sidebar--default {
  width: var(--sidebar-width);
}

/* Boost z-index when app-switcher is open so panel appears above everything */
.sidebar:has(.app-switcher--open) {
  z-index: 300;
}

/* -----------------------------------------------------------------------------
   Sidebar Sections
   ----------------------------------------------------------------------------- */
.sidebar__header {
  padding: 1rem;
  border-bottom: 1px solid var(--color-border);
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}

.sidebar__header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.sidebar__brand {
  display: inline-flex;
  min-width: 0;
  padding: 0;
  color: var(--color-text);
  text-decoration: none;
  background: transparent;
  border: 0;
}

button.sidebar__brand {
  cursor: pointer;
}

.sidebar__brand:focus-visible {
  outline: 2px solid var(--color-primary, hsl(var(--primary)));
  outline-offset: 4px;
  border-radius: 0.375rem;
}

/* Sidebar Collapse Button */
.sidebar__collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.sidebar__collapse-btn:hover {
  color: var(--color-text);
  background: var(--color-surface-hover);
  border-color: var(--color-border);
}

.sidebar__collapse-btn svg {
  width: 1rem;
  height: 1rem;
  flex: 0 0 auto;
}

.sidebar__collapse-btn--edge {
  position: absolute;
  top: var(--sidebar-collapse-edge-top);
  right: 0;
  z-index: 10;
  width: var(--sidebar-collapse-edge-size);
  height: var(--sidebar-collapse-edge-size);
  border-color: var(--color-border);
  border-radius: 9999px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  box-shadow: 0 1px 3px rgb(0 0 0 / 20%);
  opacity: 0;
  transform: translateX(50%);
  transition:
    opacity 0.2s,
    color 0.15s,
    background 0.15s,
    transform 0.2s;
}

.sidebar:hover .sidebar__collapse-btn--edge,
.sidebar__collapse-btn--edge:focus-visible,
.sidebar__collapse-btn--edge[data-visible='true'] {
  opacity: 1;
}

.sidebar__collapse-icon--expand {
  display: none;
}

.sidebar--collapsed .sidebar__collapse-icon--collapse {
  display: none;
}

.sidebar--collapsed .sidebar__collapse-icon--expand {
  display: block;
}

.sidebar__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

.sidebar--collapsed .sidebar__header {
  min-height: var(--sidebar-collapsed-header-min-height);
}

.sidebar--collapsed .sidebar__body {
  padding-top: var(--sidebar-collapsed-body-padding-top);
}

.sidebar__footer {
  padding: 0.75rem;
  border-top: 1px solid var(--color-border);
  margin-top: auto;
}

/* Footer bar: flat row with avatar+name left, icon buttons right */
.sidebar__footer-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar__footer-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.sidebar__footer-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--color-surface-hover);
  color: var(--color-text-muted);
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar__footer-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.sidebar__footer-avatar svg {
  width: 14px;
  height: 14px;
}

.sidebar__footer-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Icon button row */
.sidebar__footer-icons {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.sidebar__footer-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.375rem;
  border: none;
  background: none;
  color: var(--color-text-muted);
  cursor: pointer;
  text-decoration: none;
  transition:
    background 0.15s,
    color 0.15s;
  flex-shrink: 0;
}

.sidebar__footer-icon:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.sidebar__footer-icon--danger:hover {
  color: hsl(var(--danger));
  background: hsl(var(--danger) / 0.1);
}

.sidebar__footer-icon svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Legacy footer-row kept for backwards compat */
.sidebar__footer-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar__huddle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease;
}

.sidebar__huddle-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-alpha);
  box-shadow: 0 0 12px -4px var(--color-primary);
}

.sidebar__huddle-btn:active {
  transform: scale(0.95);
}

.sidebar__huddle-btn.is-active {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: hsl(var(--primary-foreground));
  box-shadow: 0 0 16px -4px var(--color-primary);
}

.sidebar__huddle-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--color-primary);
  color: hsl(var(--primary-foreground));
  font-size: 0.625rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* -----------------------------------------------------------------------------
   Navigation Elements
   ----------------------------------------------------------------------------- */
.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: var(--density-gap);
  padding: var(--density-section-gap);
}

.sidebar__nav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--density-gap);
  padding: var(--density-padding-y) var(--density-padding-x);
  border-radius: 0.75rem;
  color: var(--color-text-muted);
  font-size: var(--density-font);
  font-weight: 500;
  text-decoration: none;
  transition:
    background 0.2s,
    color 0.2s;
}

.sidebar__nav-link:hover {
  color: var(--color-text);
  background: var(--color-surface-hover);
  text-decoration: none;
}

.sidebar__nav-link--active {
  background: var(--color-primary-alpha);
  color: var(--color-primary);
}

.sidebar__nav-link--active .sidebar__nav-icon {
  color: var(--color-primary);
}

/* Navigation Groups */
.sidebar__nav-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.5rem;
}

.sidebar__nav-group:first-child {
  margin-top: 0;
}

.sidebar__nav-label {
  padding: 0.5rem 0.75rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  opacity: 0.7;
}

/* Navigation Icons */
.sidebar__nav-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--color-text-muted);
  transition: color 0.2s;
}

.sidebar__nav-link:hover .sidebar__nav-icon {
  color: var(--color-text);
}

/* Collapsed state for nav groups and labels */
.sidebar--collapsed .sidebar__nav-group {
  margin-top: 0.25rem;
}

.sidebar--collapsed .sidebar__nav-label {
  display: none;
}

.sidebar--collapsed .sidebar__nav-link span:not(.sidebar__nav-icon) {
  display: none;
}

.sidebar--collapsed .sidebar__nav-icon {
  margin: 0;
}

/* -----------------------------------------------------------------------------
   Unified Nav Items
   ----------------------------------------------------------------------------- */
.sidebar__item {
  display: inline-flex;
  align-items: center;
  gap: var(--density-gap);
  padding: var(--density-padding-y) var(--density-padding-x);
  border-radius: 0.75rem;
  border-left: 3px solid transparent;
  color: var(--color-text-muted);
  font-size: var(--density-font);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  background: transparent;
  border-top: none;
  border-right: none;
  border-bottom: none;
  width: 100%;
  text-align: left;
  transition:
    background 0.2s,
    color 0.2s,
    border-color 0.2s;
  position: relative;
}

.sidebar__item:hover {
  color: var(--color-text);
  background: var(--color-surface-hover);
  text-decoration: none;
}

.sidebar__item--active {
  background: hsl(var(--primary) / 0.08);
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--primary) / 0.25);
  border-left: 3px solid hsl(var(--primary));
}

.sidebar__item--active .sidebar__item-icon {
  color: hsl(var(--primary));
}

.sidebar__item--active:hover {
  background: hsl(var(--primary) / 0.2);
}

.sidebar__item-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--color-text-muted);
  transition: color 0.2s;
}

.sidebar__item:hover .sidebar__item-icon {
  color: var(--color-text);
}

.sidebar__item--disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.sidebar__item--disabled:hover {
  background: transparent;
  color: var(--color-text-muted);
}

.sidebar__item-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-height: 1rem;
  padding: 0 0.4rem;
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  background: var(--color-surface-hover);
  color: var(--color-text-muted);
  font-size: 0.5625rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Unified Nav Sections */
.sidebar__section {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.5rem;
}

.sidebar__section:first-child {
  margin-top: 0;
}

.sidebar__section-label {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem 0.3125rem;
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  opacity: 0.5;
  white-space: nowrap;
}

.sidebar__section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--color-border, hsl(var(--border) / 0.5)), transparent);
}

.sidebar__section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.75rem;
}

.sidebar__section-header h3 {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  opacity: 0.7;
  margin: 0;
}

/* -----------------------------------------------------------------------------
   Collapsible Section / Accordion Group
   ----------------------------------------------------------------------------- */
.sidebar__group-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3125rem 0.75rem;
  border-radius: 0.375rem;
  color: var(--color-text);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition:
    background 0.15s,
    color 0.15s;
}

.sidebar__group-header:hover {
  background: var(--color-surface-hover);
}

.sidebar__group-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__group-chevron {
  flex-shrink: 0;
  color: var(--color-text-muted);
  transition: transform 0.2s ease;
}

.sidebar__section--expanded > .sidebar__group-header .sidebar__group-chevron {
  transform: rotate(0deg);
}

.sidebar__section--collapsible:not(.sidebar__section--expanded)
  > .sidebar__group-header
  .sidebar__group-chevron {
  transform: rotate(-90deg);
}

.sidebar__section--collapsible > .sidebar__items {
  max-height: 0;
  overflow: hidden;
  transition: max-height 250ms ease;
}

.sidebar__section--collapsible.sidebar__section--expanded > .sidebar__items {
  max-height: 2000px;
}

.sidebar--collapsed .sidebar__group-header {
  justify-content: center;
}

.sidebar--collapsed .sidebar__group-label,
.sidebar--collapsed .sidebar__group-chevron {
  display: none;
}

.sidebar--collapsed .sidebar__section--collapsible > .sidebar__items {
  display: none;
}

/* Badges */
.sidebar__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1;
  background: var(--color-surface-hover);
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.sidebar__badge--primary,
.sidebar__badge--default {
  background: var(--color-surface-hover);
  color: var(--color-text-muted);
}

.sidebar__badge--amber,
.sidebar__badge--warning {
  background: rgb(245 158 11 / 12%);
  color: #fbbf24;
  border-color: rgb(245 158 11 / 32%);
}

.sidebar__badge--cyan {
  background: rgb(34 211 238 / 12%);
  color: #67e8f9;
  border-color: rgb(34 211 238 / 32%);
}

.sidebar__badge--rose,
.sidebar__badge--error {
  background: rgb(244 63 94 / 12%);
  color: #fb7185;
  border-color: rgb(244 63 94 / 32%);
}

.sidebar__badge:empty {
  display: none;
}

.sidebar__badge--warning {
  background: hsl(var(--warning) / 0.15);
  color: hsl(var(--warning));
}

.sidebar__badge--error {
  background: hsl(var(--danger) / 0.15);
  color: hsl(var(--danger));
}

.sidebar__badge--primary {
  background: hsl(var(--primary) / 0.15);
  color: hsl(var(--primary));
}

/* -----------------------------------------------------------------------------
   Scope Selector (Z2)
   ----------------------------------------------------------------------------- */
.sidebar__scope {
  position: relative;
  padding: var(--density-padding-y) var(--density-padding-x);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar__scope-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

.sidebar__scope-select {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border-radius: 0.5rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.sidebar__scope-select:focus {
  outline: none;
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 2px hsl(var(--primary) / 0.15);
}

.sidebar__scope-trigger {
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
  gap: 0.5rem;
  padding: 0.45rem 0.625rem;
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  background: var(--color-surface);
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
}

.sidebar__scope-trigger:hover {
  border-color: var(--color-border-strong, var(--color-border));
  background: var(--color-surface-hover);
}

.sidebar__scope-icon,
.sidebar__scope-chevron {
  flex-shrink: 0;
  width: 0.875rem;
  height: 0.875rem;
  color: var(--color-text-muted);
}

.sidebar__scope-copy {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 0.125rem;
}

.sidebar__scope-current {
  overflow: hidden;
  color: var(--color-text);
  font-size: 0.75rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__scope-menu {
  position: absolute;
  z-index: 80;
  top: calc(100% + 0.25rem);
  right: var(--density-padding-x);
  left: var(--density-padding-x);
  overflow: hidden;
  padding: 0.25rem;
  border: 1px solid var(--color-border);
  border-radius: 0.625rem;
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
}

.sidebar__scope-menu[hidden] {
  display: none;
}

.sidebar__scope-option {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 0.5rem;
  padding: 0.45rem 0.5rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.75rem;
  text-align: left;
}

.sidebar__scope-option:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.sidebar__scope-option[aria-selected='true'] {
  color: hsl(var(--primary));
}

.sidebar__scope-option[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}

.sidebar__scope-option-label {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__scope-dot {
  width: 0.375rem;
  height: 0.375rem;
  flex-shrink: 0;
  border-radius: 9999px;
  background: var(--color-text-muted);
}

.sidebar__scope-dot--active {
  background: #34d399;
}

.sidebar__scope-dot--suspended,
.sidebar__scope-dot--warning {
  background: #fbbf24;
}

.sidebar__scope-dot--archived,
.sidebar__scope-dot--neutral {
  background: #94a3b8;
}

.sidebar__scope-dot--error {
  background: #fb7185;
}

.sidebar__scope-check {
  width: 0.75rem;
  height: 0.75rem;
  opacity: 0;
}

.sidebar__scope-option[aria-selected='true'] .sidebar__scope-check {
  opacity: 1;
}

/* -----------------------------------------------------------------------------
   Action Bar (Z3)
   ----------------------------------------------------------------------------- */
.sidebar__action-bar {
  padding: 0.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--density-gap);
  padding: var(--density-padding-y) var(--density-padding-x);
  border-radius: 0.75rem;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: var(--density-font);
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
}

.sidebar__cta:hover {
  background: hsl(var(--primary) / 0.85);
}

.sidebar__cta .icon {
  flex-shrink: 0;
}

.sidebar__search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  border-radius: 0.5rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  transition: border-color 0.15s;
}

.sidebar__search:focus-within {
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 2px hsl(var(--primary) / 0.15);
}

.sidebar__search-icon {
  flex-shrink: 0;
  color: var(--color-text-muted);
}

.sidebar__search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--color-text);
  font-size: 0.8125rem;
  min-width: 0;
}

.sidebar__search-input::placeholder {
  color: var(--color-text-muted);
}

.sidebar__search-hint {
  font-size: 0.6875rem;
  padding: 0.15rem 0.35rem;
  border-radius: 0.25rem;
  background: var(--color-surface-hover);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  font-family: inherit;
}

/* -----------------------------------------------------------------------------
   User Badge (Z5 footer)
   ----------------------------------------------------------------------------- */
.sidebar__user-badge {
  display: flex;
  flex-direction: column;
}

.sidebar__user-trigger {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.35rem;
  border-radius: 0.75rem;
  background: transparent;
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.15s;
  color: var(--color-text);
}

.sidebar__user-trigger:hover {
  background: var(--color-surface-hover);
}

.sidebar__avatar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--color-surface-hover);
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.sidebar__presence {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--color-surface);
  background: var(--color-text-muted);
  display: none;
}

.sidebar__presence--online {
  display: block;
  background: var(--color-success, #22c55e);
}

.sidebar__presence--away {
  display: block;
  background: var(--color-warning, #f59e0b);
}

.sidebar__presence--busy,
.sidebar__presence--dnd {
  display: block;
  background: var(--color-error, #ef4444);
}

.sidebar__user-details {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.sidebar__user-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__user-status {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.sidebar__user-chevron {
  flex-shrink: 0;
  color: var(--color-text-muted);
}

/* -----------------------------------------------------------------------------
   Skeleton Loader
   ----------------------------------------------------------------------------- */
.sidebar__skeleton {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
}

.sidebar__skeleton-row {
  height: 2.25rem;
  border-radius: 0.5rem;
  background: var(--color-surface-hover);
  animation: sidebar-skeleton-pulse 1.5s ease-in-out infinite;
}

.sidebar__skeleton-row--short {
  width: 65%;
}

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

/* -----------------------------------------------------------------------------
   Empty State
   ----------------------------------------------------------------------------- */
.sidebar__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  gap: 0.5rem;
  text-align: center;
}

.sidebar__empty-icon {
  color: var(--color-text-muted);
  opacity: 0.5;
  margin-bottom: 0.25rem;
}

.sidebar__empty-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  margin: 0;
}

.sidebar__empty-description {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  opacity: 0.7;
  margin: 0;
}

/* -----------------------------------------------------------------------------
   Login Link (shown when unauthenticated)
   ----------------------------------------------------------------------------- */
.sidebar__login {
  display: block;
  text-align: center;
  color: var(--color-primary);
  text-decoration: none;
  padding: 0.5rem;
  border-radius: var(--radius-md);
}

.sidebar__login:hover {
  background: var(--color-bg-hover);
}

/* -----------------------------------------------------------------------------
   Sidebar Backdrop (mobile overlay)
   ----------------------------------------------------------------------------- */
.sidebar__backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5); /* TODO(phase-1): tokenize — backdrop overlay colour */
  z-index: 40;
  opacity: 0;
  transition: opacity var(--transition-slow) var(--ease-standard);
}

.sidebar__backdrop[data-visible="true"] {
  display: block;
  opacity: 1;
}

/* -----------------------------------------------------------------------------
   Desktop Collapsed State
   ----------------------------------------------------------------------------- */
.sidebar--collapsed {
  width: var(--sidebar-collapsed-width);
}

.sidebar--collapsed .sidebar__header {
  padding: 0.5rem;
}

.sidebar--collapsed .sidebar__body {
  padding: var(--sidebar-collapsed-body-padding-top) 0.5rem 0.5rem 0.5rem;
  overflow-x: visible;
  overflow-y: clip;
}

.sidebar--collapsed .sidebar__footer {
  padding: 0.5rem;
}

/* Collapsed footer: hide user info, stack icons vertically */
.sidebar--collapsed .sidebar__footer-user {
  display: none;
}

.sidebar--collapsed .sidebar__footer-bar {
  justify-content: center;
}

.sidebar--collapsed .sidebar__footer-icons {
  flex-direction: column;
  gap: 2px;
}

.sidebar--collapsed .sidebar__footer-icon {
  width: 2rem;
  height: 2rem;
}

/* Hide text in collapsed state */
.sidebar--collapsed .sidebar__nav-link span:not(.icon),
.sidebar--collapsed .sidebar__login,
.sidebar--collapsed .page__profile-details,
.sidebar--collapsed .page__profile-trigger svg:last-child,
.sidebar--collapsed .app-switcher__label,
.sidebar--collapsed .app-switcher__chevron {
  display: none;
}

/* Unified collapsed rules */
  .sidebar--collapsed .sidebar__item-label,
  .sidebar--collapsed .sidebar__badge,
  .sidebar--collapsed .sidebar__tag,
  .sidebar--collapsed .sidebar__section-label,
  .sidebar--collapsed .sidebar__scope,
  .sidebar--collapsed .sidebar__action-bar,
.sidebar--collapsed .sidebar__user-details,
.sidebar--collapsed .sidebar__user-chevron,
.sidebar--collapsed .sidebar__footer-action-label {
  display: none;
}

.sidebar--collapsed .sidebar__item {
  justify-content: center;
  padding: 0.5rem;
  border-left: none;
  width: auto;
  height: auto;
  border-radius: 0.375rem;
  margin: 0 auto;
}

.sidebar--collapsed .sidebar__item-icon {
  margin: 0;
}

/* ============================================================================
   TOUCH DEVICE ENHANCEMENTS (WCAG 2.5.5 - 44px minimum)
   Desktop keeps compact 32px collapsed items; touch devices get a 44px
   minimum tap target without altering the visual icon size.
   ============================================================================ */
@media (pointer: coarse) {
  .sidebar--collapsed .sidebar__item {
    min-width: var(--cmm-touch-target-min, 44px);
    min-height: var(--cmm-touch-target-min, 44px);
  }
}

.sidebar--collapsed .sidebar__section {
  margin-top: 0.25rem;
}

/* Tooltip for collapsed unified nav items */
.sidebar--collapsed .sidebar__item::after {
  content: attr(title);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 0.5rem;
  padding: 0.35rem 0.65rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 70;
  box-shadow: var(--shadow-md); /* TODO(phase-1): was rgba(0,0,0,0.15) elevation shadow */
}

.sidebar--collapsed .sidebar__item:hover::after {
  opacity: 1;
}

.sidebar--collapsed .sidebar__nav-link {
  justify-content: center;
  padding: 0.55rem;
}

.sidebar--collapsed .sidebar__nav-link .icon {
  margin: 0;
}

.sidebar--collapsed .sidebar__header-row {
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.sidebar--collapsed .cmm-brand-lockup {
  justify-content: center;
}

.sidebar--collapsed .cmm-brand-lockup__wordmark {
  display: none;
}

.sidebar--collapsed .sidebar__footer-action {
  justify-content: center;
  padding: 0.5rem;
}

.sidebar--collapsed .app-switcher--brand {
  width: auto;
}

.sidebar--collapsed .app-switcher__trigger--brand {
  width: auto;
  justify-content: center;
  padding: 0.375rem;
  position: relative;
}

/* Tooltip for trigger in collapsed state */
.sidebar--collapsed .app-switcher__trigger--brand::after {
  content: attr(title);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 0.5rem;
  padding: 0.35rem 0.65rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 70;
  box-shadow: var(--shadow-md); /* TODO(phase-1): was rgba(0,0,0,0.15) elevation shadow */
}

.sidebar--collapsed .app-switcher__trigger--brand:hover::after {
  opacity: 1;
}

/* Hide tooltip when app-switcher is open */
.sidebar--collapsed .app-switcher--open .app-switcher__trigger--brand::after {
  display: none;
}

/* Dropdown positioning in collapsed state */
.sidebar--collapsed .dropdown__content {
  left: 100%;
  right: auto;
  bottom: 0;
  top: auto;
  margin-left: 0.5rem;
  margin-bottom: 0;
}

/* Compact app-switcher in collapsed sidebar */
.sidebar--collapsed .app-switcher__panel {
  min-width: auto;
  width: auto;
}

.sidebar--collapsed .app-switcher__grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sidebar--collapsed .app-switcher__item {
  padding: 0.5rem;
  position: relative;
}

.sidebar--collapsed .app-switcher__content,
.sidebar--collapsed .app-switcher__badge {
  display: none;
}

.sidebar--collapsed .app-switcher__item .app-switcher__icon {
  width: 2.25rem;
  height: 2.25rem;
}

/* Tooltip for collapsed app switcher items */
.sidebar--collapsed .app-switcher__item::after {
  content: attr(title);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 0.5rem;
  padding: 0.35rem 0.65rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 70;
  box-shadow: var(--shadow-md); /* TODO(phase-1): was rgba(0,0,0,0.15) elevation shadow */
}

.sidebar--collapsed .app-switcher__item:hover::after {
  opacity: 1;
}

/* -----------------------------------------------------------------------------
   CounterMeasure Product Sidebar Variant
   ----------------------------------------------------------------------------- */
.sidebar--product,
.sidebar--analyst-console,
.sidebar--security,
.sidebar--admin {
  --cmm-sidebar-bg: var(--sidebar-bg, rgb(20 20 26 / 70%));
  --cmm-sidebar-border: var(--sidebar-border, rgb(255 255 255 / 6%));
  --cmm-sidebar-hover: var(--sidebar-hover, rgb(255 255 255 / 4%));
  --cmm-sidebar-active: var(--sidebar-active, rgb(255 255 255 / 6%));
  --cmm-sidebar-divider: var(--sidebar-divider, rgb(255 255 255 / 8%));
  --cmm-sidebar-divider-fade: var(--sidebar-divider-fade, rgb(255 255 255 / 2%));
  --cmm-sidebar-text: var(--color-foreground-secondary, rgb(255 255 255 / 70%));
  --cmm-sidebar-text-muted: var(--color-foreground-tertiary, rgb(255 255 255 / 50%));
  --cmm-sidebar-text-active: var(--color-foreground, var(--color-text));
  --cmm-sidebar-primary: var(--color-accent-primary, #ff7a00);
  --cmm-sidebar-primary-alpha: var(--color-primary-alpha, rgb(255 122 0 / 15%));
  --cmm-sidebar-primary-border: var(--color-primary-border, rgb(255 122 0 / 15%));
  --cmm-sidebar-shadow-glow: var(--shadow-glow, 0 0 12px rgb(255 122 0 / 15%));
  --cmm-sidebar-width: var(--spacing-sidebar, 264px);
  --cmm-sidebar-collapsed-width: var(--spacing-sidebar-collapsed, 64px);
  --sidebar-collapse-edge-size: 2rem;
  --sidebar-collapse-edge-top: 1.85rem;
  --sidebar-collapsed-body-padding-top: 0;
  --sidebar-collapsed-header-min-height: 4rem;
  width: var(--cmm-sidebar-width);
  background: var(--cmm-sidebar-bg);
  border-right-color: var(--cmm-sidebar-border);
  -webkit-backdrop-filter: blur(60px);
  backdrop-filter: blur(60px);
  overflow: visible;
}

.sidebar--product::before,
.sidebar--analyst-console::before,
.sidebar--security::before,
.sidebar--admin::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 8rem;
  pointer-events: none;
  background: linear-gradient(to bottom, rgb(255 122 0 / 3%), transparent);
  z-index: -1;
}

.sidebar--product .sidebar__header,
.sidebar--analyst-console .sidebar__header,
.sidebar--security .sidebar__header,
.sidebar--admin .sidebar__header {
  min-height: 3.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 0;
}

.sidebar--product .sidebar__header-row,
.sidebar--analyst-console .sidebar__header-row,
.sidebar--security .sidebar__header-row,
.sidebar--admin .sidebar__header-row {
  min-height: 2rem;
}

.sidebar--product .cmm-brand-lockup,
.sidebar--analyst-console .cmm-brand-lockup,
.sidebar--security .cmm-brand-lockup,
.sidebar--admin .cmm-brand-lockup {
  gap: 0.75rem;
}

.sidebar--product .cmm-brand-lockup__wordmark,
.sidebar--analyst-console .cmm-brand-lockup__wordmark,
.sidebar--security .cmm-brand-lockup__wordmark,
.sidebar--admin .cmm-brand-lockup__wordmark {
  font-size: 0.8125rem;
  letter-spacing: 0.1em;
}

.sidebar--product .sidebar__collapse-btn--edge,
.sidebar--analyst-console .sidebar__collapse-btn--edge,
.sidebar--security .sidebar__collapse-btn--edge,
.sidebar--admin .sidebar__collapse-btn--edge {
  top: var(--sidebar-collapse-edge-top);
  width: var(--sidebar-collapse-edge-size);
  height: var(--sidebar-collapse-edge-size);
  background: var(--cmm-sidebar-bg);
  border-color: var(--cmm-sidebar-border);
  color: var(--cmm-sidebar-text);
  box-shadow: 0 6px 18px rgb(0 0 0 / 30%);
}

.sidebar--product .sidebar__collapse-btn--edge:hover,
.sidebar--analyst-console .sidebar__collapse-btn--edge:hover,
.sidebar--security .sidebar__collapse-btn--edge:hover,
.sidebar--admin .sidebar__collapse-btn--edge:hover {
  color: var(--cmm-sidebar-text-active);
  background: var(--cmm-sidebar-hover);
}

.sidebar--product .sidebar__body,
.sidebar--analyst-console .sidebar__body,
.sidebar--security .sidebar__body,
.sidebar--admin .sidebar__body {
  gap: 1.25rem;
  padding: 0 0.75rem 0.75rem;
}

.sidebar--product .sidebar__section,
.sidebar--analyst-console .sidebar__section,
.sidebar--security .sidebar__section,
.sidebar--admin .sidebar__section {
  gap: 1px;
  margin-top: 0;
}

.sidebar--product .sidebar__section + .sidebar__section,
.sidebar--analyst-console .sidebar__section + .sidebar__section,
.sidebar--security .sidebar__section + .sidebar__section,
.sidebar--admin .sidebar__section + .sidebar__section {
  margin-top: 0;
}

.sidebar--product .sidebar__section-label,
.sidebar--analyst-console .sidebar__section-label,
.sidebar--security .sidebar__section-label,
.sidebar--admin .sidebar__section-label {
  gap: 0.625rem;
  margin-bottom: 0.375rem;
  padding: 0 0.75rem 0.375rem;
  color: var(--cmm-sidebar-text-muted);
  font-size: 0.625rem;
  letter-spacing: 0.32em;
  line-height: 1.25;
  opacity: 1;
}

.sidebar--product .sidebar__section-label::after,
.sidebar--analyst-console .sidebar__section-label::after,
.sidebar--security .sidebar__section-label::after,
.sidebar--admin .sidebar__section-label::after {
  background: linear-gradient(90deg, var(--cmm-sidebar-divider), var(--cmm-sidebar-divider-fade));
}

.sidebar--product .sidebar__item,
.sidebar--analyst-console .sidebar__item,
.sidebar--security .sidebar__item,
.sidebar--admin .sidebar__item {
  min-height: 2.5rem;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  color: var(--cmm-sidebar-text);
  font-size: 0.8125rem;
  line-height: 1;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
}

.sidebar--product .sidebar__item::before,
.sidebar--analyst-console .sidebar__item::before,
.sidebar--security .sidebar__item::before,
.sidebar--admin .sidebar__item::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  width: 2.5px;
  height: 0;
  transform: translateY(-50%);
  border-radius: 9999px;
  background: var(--cmm-sidebar-primary);
  transition:
    height 0.15s,
    box-shadow 0.15s;
}

.sidebar--product .sidebar__item:hover,
.sidebar--analyst-console .sidebar__item:hover,
.sidebar--security .sidebar__item:hover,
.sidebar--admin .sidebar__item:hover {
  color: var(--cmm-sidebar-text-active);
  background: var(--cmm-sidebar-hover);
}

.sidebar--product .sidebar__item--active,
.sidebar--analyst-console .sidebar__item--active,
.sidebar--security .sidebar__item--active,
.sidebar--admin .sidebar__item--active {
  color: var(--cmm-sidebar-text-active);
  background: var(--cmm-sidebar-active);
  border-color: var(--cmm-sidebar-primary-border);
}

.sidebar--product .sidebar__item--active::before,
.sidebar--analyst-console .sidebar__item--active::before,
.sidebar--security .sidebar__item--active::before,
.sidebar--admin .sidebar__item--active::before {
  height: 1rem;
  box-shadow: var(--cmm-sidebar-shadow-glow);
}

.sidebar--product .sidebar__item-icon,
.sidebar--analyst-console .sidebar__item-icon,
.sidebar--security .sidebar__item-icon,
.sidebar--admin .sidebar__item-icon {
  width: 0.9375rem;
  height: 0.9375rem;
  color: currentColor;
}

.sidebar--product .sidebar__item--active .sidebar__item-icon,
.sidebar--analyst-console .sidebar__item--active .sidebar__item-icon,
.sidebar--security .sidebar__item--active .sidebar__item-icon,
.sidebar--admin .sidebar__item--active .sidebar__item-icon {
  color: var(--cmm-sidebar-primary);
}

.sidebar--product .sidebar__item-label,
.sidebar--analyst-console .sidebar__item-label,
.sidebar--security .sidebar__item-label,
.sidebar--admin .sidebar__item-label {
  transition:
    color 0.15s,
    transform 0.15s;
}

.sidebar--product .sidebar__item:hover .sidebar__item-label,
.sidebar--analyst-console .sidebar__item:hover .sidebar__item-label,
.sidebar--security .sidebar__item:hover .sidebar__item-label,
.sidebar--admin .sidebar__item:hover .sidebar__item-label {
  transform: translateX(0.125rem);
}

.sidebar--product .sidebar__badge,
.sidebar--analyst-console .sidebar__badge,
.sidebar--security .sidebar__badge,
.sidebar--admin .sidebar__badge {
  min-width: 1.25rem;
  height: 1rem;
  padding: 0 0.375rem;
  border: 1px solid currentColor;
  border-radius: 0.25rem;
  font-size: 0.5625rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sidebar--product .sidebar__badge--primary,
.sidebar--analyst-console .sidebar__badge--primary,
.sidebar--security .sidebar__badge--primary,
.sidebar--admin .sidebar__badge--primary {
  background: rgb(255 122 0 / 12%);
  color: var(--cmm-sidebar-primary);
  border-color: var(--cmm-sidebar-primary-border);
}

.sidebar--product .sidebar__tag,
.sidebar--analyst-console .sidebar__tag,
.sidebar--security .sidebar__tag,
.sidebar--admin .sidebar__tag {
  border-color: var(--cmm-sidebar-border);
  background: var(--cmm-sidebar-hover);
  color: var(--cmm-sidebar-text-muted);
}

.sidebar--product .sidebar__scope,
.sidebar--analyst-console .sidebar__scope,
.sidebar--security .sidebar__scope,
.sidebar--admin .sidebar__scope {
  padding: 0 0.75rem 0.625rem;
}

.sidebar--product .sidebar__scope-trigger,
.sidebar--analyst-console .sidebar__scope-trigger,
.sidebar--security .sidebar__scope-trigger,
.sidebar--admin .sidebar__scope-trigger {
  min-height: 2rem;
  border-color: var(--cmm-sidebar-border);
  background: var(--cmm-sidebar-hover);
  color: var(--cmm-sidebar-text);
}

.sidebar--product .sidebar__scope-trigger:hover,
.sidebar--analyst-console .sidebar__scope-trigger:hover,
.sidebar--security .sidebar__scope-trigger:hover,
.sidebar--admin .sidebar__scope-trigger:hover,
.sidebar--product .sidebar__scope-trigger[aria-expanded='true'],
.sidebar--analyst-console .sidebar__scope-trigger[aria-expanded='true'],
.sidebar--security .sidebar__scope-trigger[aria-expanded='true'],
.sidebar--admin .sidebar__scope-trigger[aria-expanded='true'] {
  border-color: var(--cmm-sidebar-primary-border);
  background: var(--cmm-sidebar-active);
  color: var(--cmm-sidebar-text-active);
}

.sidebar--product .sidebar__scope-icon,
.sidebar--product .sidebar__scope-chevron,
.sidebar--analyst-console .sidebar__scope-icon,
.sidebar--analyst-console .sidebar__scope-chevron,
.sidebar--security .sidebar__scope-icon,
.sidebar--security .sidebar__scope-chevron,
.sidebar--admin .sidebar__scope-icon,
.sidebar--admin .sidebar__scope-chevron {
  color: var(--cmm-sidebar-text-muted);
}

.sidebar--product .sidebar__scope-label,
.sidebar--analyst-console .sidebar__scope-label,
.sidebar--security .sidebar__scope-label,
.sidebar--admin .sidebar__scope-label {
  color: var(--cmm-sidebar-text-muted);
  font-size: 0.5625rem;
  letter-spacing: 0.14em;
}

.sidebar--product .sidebar__scope-current,
.sidebar--analyst-console .sidebar__scope-current,
.sidebar--security .sidebar__scope-current,
.sidebar--admin .sidebar__scope-current {
  color: var(--cmm-sidebar-text);
}

.sidebar--product .sidebar__scope-menu,
.sidebar--analyst-console .sidebar__scope-menu,
.sidebar--security .sidebar__scope-menu,
.sidebar--admin .sidebar__scope-menu {
  border-color: var(--cmm-sidebar-border);
  background: var(--cmm-sidebar-bg);
  box-shadow: 0 16px 42px rgb(0 0 0 / 35%);
  -webkit-backdrop-filter: blur(40px);
  backdrop-filter: blur(40px);
}

.sidebar--product .sidebar__scope-option,
.sidebar--analyst-console .sidebar__scope-option,
.sidebar--security .sidebar__scope-option,
.sidebar--admin .sidebar__scope-option {
  color: var(--cmm-sidebar-text-muted);
}

.sidebar--product .sidebar__scope-option:hover,
.sidebar--analyst-console .sidebar__scope-option:hover,
.sidebar--security .sidebar__scope-option:hover,
.sidebar--admin .sidebar__scope-option:hover {
  background: var(--cmm-sidebar-hover);
  color: var(--cmm-sidebar-text-active);
}

.sidebar--product .sidebar__scope-option[aria-selected='true'],
.sidebar--analyst-console .sidebar__scope-option[aria-selected='true'],
.sidebar--security .sidebar__scope-option[aria-selected='true'],
.sidebar--admin .sidebar__scope-option[aria-selected='true'] {
  color: var(--cmm-sidebar-primary);
}

.sidebar--product .sidebar__footer,
.sidebar--analyst-console .sidebar__footer,
.sidebar--security .sidebar__footer,
.sidebar--admin .sidebar__footer {
  padding: 0.625rem 0.75rem 0.75rem;
  border-top-color: var(--cmm-sidebar-divider);
}

.sidebar--product .sidebar__footer-name,
.sidebar--analyst-console .sidebar__footer-name,
.sidebar--security .sidebar__footer-name,
.sidebar--admin .sidebar__footer-name {
  color: var(--cmm-sidebar-text);
}

.sidebar--product.sidebar--collapsed,
.sidebar--analyst-console.sidebar--collapsed,
.sidebar--security.sidebar--collapsed,
.sidebar--admin.sidebar--collapsed {
  width: var(--cmm-sidebar-collapsed-width);
  --sidebar-collapse-edge-top: 3rem;
}

.sidebar--product.sidebar--collapsed .sidebar__header,
.sidebar--analyst-console.sidebar--collapsed .sidebar__header,
.sidebar--security.sidebar--collapsed .sidebar__header,
.sidebar--admin.sidebar--collapsed .sidebar__header {
  padding: 0.75rem 0.5rem;
  min-height: var(--sidebar-collapsed-header-min-height);
}

.sidebar--product.sidebar--collapsed .sidebar__body,
.sidebar--analyst-console.sidebar--collapsed .sidebar__body,
.sidebar--security.sidebar--collapsed .sidebar__body,
.sidebar--admin.sidebar--collapsed .sidebar__body {
  gap: 0.5rem;
  padding: var(--sidebar-collapsed-body-padding-top) 0.5rem 0.5rem;
}

.sidebar--product.sidebar--collapsed .sidebar__section,
.sidebar--analyst-console.sidebar--collapsed .sidebar__section,
.sidebar--security.sidebar--collapsed .sidebar__section,
.sidebar--admin.sidebar--collapsed .sidebar__section {
  align-items: center;
  gap: 1px;
  margin-top: 0;
}

.sidebar--product.sidebar--collapsed .sidebar__item,
.sidebar--analyst-console.sidebar--collapsed .sidebar__item,
.sidebar--security.sidebar--collapsed .sidebar__item,
.sidebar--admin.sidebar--collapsed .sidebar__item {
  width: 2.5rem;
  height: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 9999px;
  margin: 0;
}

.sidebar--product.sidebar--collapsed .sidebar__item::before,
.sidebar--analyst-console.sidebar--collapsed .sidebar__item::before,
.sidebar--security.sidebar--collapsed .sidebar__item::before,
.sidebar--admin.sidebar--collapsed .sidebar__item::before {
  display: none;
}

.sidebar--product.sidebar--collapsed .sidebar__item[data-badge-visible='true']::before,
.sidebar--analyst-console.sidebar--collapsed .sidebar__item[data-badge-visible='true']::before,
.sidebar--security.sidebar--collapsed .sidebar__item[data-badge-visible='true']::before,
.sidebar--admin.sidebar--collapsed .sidebar__item[data-badge-visible='true']::before {
  display: block;
  content: '';
  position: absolute;
  top: 0.375rem;
  right: 0.375rem;
  left: auto;
  width: 0.375rem;
  height: 0.375rem;
  transform: none;
  border-radius: 9999px;
  background: var(--cmm-sidebar-primary);
  box-shadow: 0 0 0 1px var(--cmm-sidebar-bg);
}

.sidebar--product.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='amber']::before,
.sidebar--product.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='warning']::before,
.sidebar--analyst-console.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='amber']::before,
.sidebar--analyst-console.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='warning']::before,
.sidebar--security.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='amber']::before,
.sidebar--security.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='warning']::before,
.sidebar--admin.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='amber']::before,
.sidebar--admin.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='warning']::before {
  background: #fbbf24;
  box-shadow:
    0 0 0 1px var(--cmm-sidebar-bg),
    0 0 8px rgb(245 158 11 / 35%);
}

.sidebar--product.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='cyan']::before,
.sidebar--analyst-console.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='cyan']::before,
.sidebar--security.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='cyan']::before,
.sidebar--admin.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='cyan']::before {
  background: #67e8f9;
  box-shadow:
    0 0 0 1px var(--cmm-sidebar-bg),
    0 0 8px rgb(34 211 238 / 35%);
}

.sidebar--product.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='rose']::before,
.sidebar--product.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='error']::before,
.sidebar--analyst-console.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='rose']::before,
.sidebar--analyst-console.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='error']::before,
.sidebar--security.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='rose']::before,
.sidebar--security.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='error']::before,
.sidebar--admin.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='rose']::before,
.sidebar--admin.sidebar--collapsed .sidebar__item[data-badge-visible='true'][data-badge-tone='error']::before {
  background: #fb7185;
  box-shadow:
    0 0 0 1px var(--cmm-sidebar-bg),
    0 0 8px rgb(244 63 94 / 35%);
}

.sidebar--product.sidebar--collapsed .sidebar__item--active,
.sidebar--analyst-console.sidebar--collapsed .sidebar__item--active,
.sidebar--security.sidebar--collapsed .sidebar__item--active,
.sidebar--admin.sidebar--collapsed .sidebar__item--active {
  color: var(--cmm-sidebar-primary);
  background: var(--cmm-sidebar-primary-alpha);
  border-color: transparent;
}

.sidebar--product.sidebar--collapsed .sidebar__collapse-btn--edge,
.sidebar--analyst-console.sidebar--collapsed .sidebar__collapse-btn--edge,
.sidebar--security.sidebar--collapsed .sidebar__collapse-btn--edge,
.sidebar--admin.sidebar--collapsed .sidebar__collapse-btn--edge {
  top: var(--sidebar-collapse-edge-top);
}

.sidebar--product.sidebar--collapsed .sidebar__scope,
.sidebar--analyst-console.sidebar--collapsed .sidebar__scope,
.sidebar--security.sidebar--collapsed .sidebar__scope,
.sidebar--admin.sidebar--collapsed .sidebar__scope {
  display: flex;
  padding: 0 0.5rem 0.5rem;
}

.sidebar--product.sidebar--collapsed .sidebar__scope-trigger,
.sidebar--analyst-console.sidebar--collapsed .sidebar__scope-trigger,
.sidebar--security.sidebar--collapsed .sidebar__scope-trigger,
.sidebar--admin.sidebar--collapsed .sidebar__scope-trigger {
  justify-content: center;
  width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
  border-radius: 9999px;
}

.sidebar--product.sidebar--collapsed .sidebar__scope-copy,
.sidebar--product.sidebar--collapsed .sidebar__scope-chevron,
.sidebar--analyst-console.sidebar--collapsed .sidebar__scope-copy,
.sidebar--analyst-console.sidebar--collapsed .sidebar__scope-chevron,
.sidebar--security.sidebar--collapsed .sidebar__scope-copy,
.sidebar--security.sidebar--collapsed .sidebar__scope-chevron,
.sidebar--admin.sidebar--collapsed .sidebar__scope-copy,
.sidebar--admin.sidebar--collapsed .sidebar__scope-chevron {
  display: none;
}

.sidebar--product.sidebar--collapsed .sidebar__scope-menu,
.sidebar--analyst-console.sidebar--collapsed .sidebar__scope-menu,
.sidebar--security.sidebar--collapsed .sidebar__scope-menu,
.sidebar--admin.sidebar--collapsed .sidebar__scope-menu {
  top: 0;
  right: auto;
  left: calc(100% + 0.5rem);
  width: 14rem;
}

/* -----------------------------------------------------------------------------
   Mobile Responsive Styles
   ----------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    max-width: 85vw;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform var(--transition-slow) var(--ease-standard);
  }

  .sidebar[data-open="true"] {
    transform: translateX(0);
  }

  /* Reset collapsed state on mobile */
  .sidebar--collapsed {
    width: var(--sidebar-width);
  }

  .sidebar--collapsed .sidebar__header {
    padding: 1rem;
  }

  .sidebar--collapsed .sidebar__body {
    padding: 0;
    overflow-x: initial;
    overflow-y: auto;
  }

  .sidebar--collapsed .sidebar__footer {
    padding: 0.75rem;
  }

  /* Reset footer collapsed state on mobile — show full row */
  .sidebar--collapsed .sidebar__footer-user {
    display: flex;
  }

  .sidebar--collapsed .sidebar__footer-icons {
    flex-direction: row;
    gap: 2px;
  }

  .sidebar--collapsed .sidebar__footer-icon {
    width: 1.75rem;
    height: 1.75rem;
  }

  .sidebar--collapsed .sidebar__nav-link span:not(.icon),
  .sidebar--collapsed .sidebar__login,
  .sidebar--collapsed .page__profile-details,
  .sidebar--collapsed .page__profile-trigger svg:last-child,
  .sidebar--collapsed .app-switcher__label,
  .sidebar--collapsed .app-switcher__chevron {
    display: flex;
  }

  /* Reset unified collapsed rules on mobile */
  .sidebar--collapsed .sidebar__item-label,
  .sidebar--collapsed .sidebar__badge,
  .sidebar--collapsed .sidebar__section-label,
  .sidebar--collapsed .sidebar__user-details,
  .sidebar--collapsed .sidebar__user-chevron,
  .sidebar--collapsed .sidebar__footer-action-label {
    display: flex;
  }

  .sidebar--collapsed .sidebar__scope,
  .sidebar--collapsed .sidebar__action-bar {
    display: flex;
  }

  .sidebar--collapsed .sidebar__item {
    justify-content: flex-start;
    padding: 0.55rem 0.75rem;
    border-left: 3px solid transparent;
    width: 100%;
    height: auto;
    border-radius: 0.75rem;
    margin: 0;
  }

  .sidebar--collapsed .sidebar__item--active {
    border-left-color: hsl(var(--primary));
  }

  .sidebar--collapsed .sidebar__footer-action {
    justify-content: flex-start;
    padding: 0.5rem 0.75rem;
  }

  /* Hide collapsed tooltips on mobile */
  .sidebar--collapsed .sidebar__item::after {
    display: none;
  }

  /* Hide collapsed trigger tooltip on mobile */
  .sidebar--collapsed .app-switcher__trigger--brand::after {
    display: none;
  }

  .sidebar--collapsed .app-switcher__trigger--brand {
    width: 100%;
    padding: 0.5rem 0.25rem;
  }

  .sidebar--collapsed .sidebar__nav-link {
    justify-content: flex-start;
    padding: 0.55rem 0.75rem;
  }

  .sidebar--collapsed .dropdown__content {
    left: auto;
    right: 0;
    bottom: 100%;
    margin-left: 0;
    margin-bottom: 0.5rem;
  }

  /* Reset header-row to horizontal on mobile */
  .sidebar--collapsed .sidebar__header-row {
    flex-direction: row;
    align-items: center;
  }

  .sidebar--collapsed .cmm-brand-lockup {
    justify-content: flex-start;
  }

  .sidebar--collapsed .cmm-brand-lockup__wordmark {
    display: inline-flex;
  }

  /* Reset storage collapsed nav on mobile */
  .sidebar--storage.sidebar--collapsed .storage-sidebar__org {
    display: flex;
  }

  .sidebar--storage.sidebar--collapsed .storage-nav__item span {
    display: inline;
  }

  .sidebar--storage.sidebar--collapsed .storage-nav__item {
    justify-content: flex-start;
    padding: 0.6rem 0.85rem;
  }

  .sidebar--storage.sidebar--collapsed .storage-nav__item::after {
    display: none;
  }

  /* Hide sidebar toggle on mobile */
  .sidebar__toggle {
    display: none;
  }

  /* Hide inline sidebar collapse buttons on mobile; keep edge-docked affordances available. */
  .sidebar__collapse-btn:not(.sidebar__collapse-btn--edge) {
    display: none;
  }
}
