/* Sidebar navigation with fold/unfold */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--dur-slow) var(--ease-out), min-width var(--dur-slow) var(--ease-out);
  overflow: hidden;
  z-index: var(--z-sticky);
}

.sidebar.folded {
  width: var(--sidebar-w-folded);
  min-width: var(--sidebar-w-folded);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px;
  border-bottom: 1px solid var(--border);
  height: 56px;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
}

.sidebar-logo-icon { width: 24px; height: 24px; flex-shrink: 0; }
.sidebar-logo-text { white-space: nowrap; overflow: hidden; }
.sidebar.folded .sidebar-logo-text { display: none; }

/* Toggle button - outside sidebar, positioned on its right edge */
.sidebar-toggle {
  position: absolute;
  top: 44px;
  left: calc(var(--sidebar-w) - 12px);
  width: 24px;
  height: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left var(--dur-slow) var(--ease-out), color var(--dur-fast), background var(--dur-fast);
  z-index: calc(var(--z-sticky) + 1);
  box-shadow: var(--shadow-sm);
  opacity: 0;
}
.sidebar-toggle svg { width: 14px; height: 14px; }
.sidebar:hover ~ .sidebar-toggle,
.sidebar-toggle:hover,
.sidebar-toggle:focus-visible { opacity: 1; }
.sidebar-toggle:hover { color: var(--text); background: var(--bg-hover); }
.sidebar.folded ~ .sidebar-toggle {
  left: calc(var(--sidebar-w-folded) - 12px);
  opacity: 1;
}

/* Nav items */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--dur-fast) var(--ease-out);
  position: relative;
  white-space: nowrap;
  margin-bottom: 1px;
}

.sidebar-nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.sidebar-nav-item.active {
  background: var(--accent-subtle);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-nav-item .nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke-width: 1.75;
}

.sidebar-nav-item .nav-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
  transform: translateX(0);
  transition: opacity var(--dur-normal) var(--ease-out), transform var(--dur-normal) var(--ease-out);
}

.sidebar.folded .nav-label { opacity: 0; transform: translateX(-8px); width: 0; pointer-events: none; }

/* Tooltip on folded sidebar items */
.sidebar.folded .sidebar-nav-item::after {
  content: attr(data-tooltip);
  position: absolute; left: calc(100% + 8px); top: 50%; transform: translateY(-50%);
  background: var(--text); color: white; font-size: 12px; font-weight: 500;
  padding: 4px 10px; border-radius: var(--radius-sm); white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity var(--dur-fast);
  z-index: var(--z-dropdown);
  box-shadow: var(--shadow-md);
}
.sidebar.folded .sidebar-nav-item:hover::after { opacity: 1; }

/* Badges */
.nav-badges {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-left: auto;
  transition: opacity var(--dur-normal) var(--ease-out);
}
.sidebar.folded .nav-badges { opacity: 0; pointer-events: none; width: 0; overflow: hidden; }

.nav-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  line-height: 1.4;
}

/* Round badge for numeric counts */
.nav-badge.round {
  min-width: 20px;
  height: 20px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  text-align: center;
}

.nav-badge.primary { background: var(--accent); color: white; }
.nav-badge.danger { background: var(--danger); color: white; }
.nav-badge.secondary { background: var(--bg-hover); color: var(--text-secondary); font-weight: 500; }
.nav-badge.muted { color: var(--text-muted); font-weight: 400; }

/* Folded badge: show single badge next to icon */
.sidebar.folded .sidebar-nav-item .folded-badge {
  display: flex;
  position: absolute;
  top: 0;
  right: 0;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.sidebar:not(.folded) .sidebar-nav-item .folded-badge { display: none; }

/* Nav bottom links (above footer) */
.sidebar-nav-bottom {
  padding: 4px 8px;
  flex-shrink: 0;
}

/* Sidebar footer */
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 8px;
  flex-shrink: 0;
}

.sidebar-footer-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--dur-fast) var(--ease-out);
}
.sidebar-footer-link:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-footer-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-label { transition: opacity var(--dur-normal) var(--ease-out); }
.sidebar.folded .sidebar-label { opacity: 0; width: 0; pointer-events: none; }

/* Dev environment badge */
.sidebar-env-badge {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.5px;
  color: #f59e0b; background: rgba(245,158,11,0.12);
  border: 1px solid rgba(245,158,11,0.25); border-radius: 4px;
  padding: 3px 8px; cursor: pointer; margin: 4px 12px 0;
  transition: all var(--dur-fast) var(--ease-out);
}
.sidebar-env-badge:hover { background: rgba(245,158,11,0.2); }
.sidebar.folded .sidebar-env-badge { opacity: 0; pointer-events: none; }

/* Sidebar version */
.sidebar-version {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.5;
  text-align: center;
  padding: 2px 0 0;
  cursor: default;
  transition: opacity var(--dur-fast) var(--ease-out);
}
.sidebar-version:hover { opacity: 1; }
.sidebar.folded .sidebar-version { opacity: 0; pointer-events: none; }

/* Sidebar user auth */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-top: 4px;
  border-top: 1px solid var(--border-light);
}
.sidebar-user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.sidebar-user-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
}
.sidebar-user-role.role-admin { color: var(--accent); }
.sidebar-logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--dur-fast);
  flex-shrink: 0;
}
.sidebar-logout-btn:hover { background: var(--danger-bg); color: var(--danger); }
.sidebar-logout-btn svg { width: 16px; height: 16px; }
.sidebar.folded .sidebar-user-info { display: none; }

/* Nav separator */
.sidebar-sep {
  height: 1px;
  background: var(--border-light);
  margin: 6px 10px;
}

/* ── Sidebar collapsible sections ── */
.sidebar-section { margin-bottom: 2px; }

.sidebar-section-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 10px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-radius: var(--radius-sm);
  transition: all var(--dur-fast);
  text-align: left;
  font-family: var(--font);
}
.sidebar-section-toggle:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-section-toggle .nav-icon { width: 16px; height: 16px; flex-shrink: 0; stroke-width: 1.75; }
.sidebar-section-toggle .nav-label { flex: 1; }

.section-chevron {
  width: 14px; height: 14px; flex-shrink: 0;
  transition: transform var(--dur-normal) var(--ease-out);
  opacity: .5;
}
.sidebar-section.collapsed .section-chevron { transform: rotate(-90deg); }

.sidebar-section-body {
  padding: 4px 10px 8px;
  overflow: hidden;
  transition: max-height var(--dur-slow) var(--ease-out), opacity var(--dur-normal);
  max-height: 500px;
  opacity: 1;
}
.sidebar-section.collapsed .sidebar-section-body {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}

/* Hide sections when sidebar folded */
.sidebar.folded .sidebar-section-toggle .nav-label,
.sidebar.folded .sidebar-section-toggle .section-chevron,
.sidebar.folded .sidebar-section-toggle .nav-badges { display: none; }
.sidebar.folded .sidebar-section-body { display: none; }

/* Stats in sidebar */
.sidebar-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  transition: all var(--dur-fast);
}
.sidebar-stat:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-stat.active { background: var(--accent-subtle); color: var(--accent); font-weight: 600; }
.sidebar-stat-label { display: flex; align-items: center; gap: 6px; }
.sidebar-stat-value { font-weight: 600; font-family: var(--font-mono); font-size: 12px; }

/* Filter search in sidebar */
.sidebar-search {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  transition: all var(--dur-fast);
  margin-bottom: 6px;
}
.sidebar-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
  background: var(--bg-card);
}

/* Filter pills in sidebar */
.sidebar-filter-pills { display: flex; flex-direction: column; gap: 3px; margin-bottom: 6px; }
.sidebar-filter-pills:empty { display: none; }
.sidebar-filter-pills .filter-pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--accent-subtle);
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: background var(--dur-fast);
}
.sidebar-filter-pills .filter-pill:hover { background: var(--accent-light); }
.sidebar-filter-pills .pill-remove {
  background: none; border: none; color: inherit; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 0 2px; opacity: .6;
}
.sidebar-filter-pills .pill-remove:hover { opacity: 1; }

.sidebar-filter-actions { display: flex; gap: 6px; align-items: center; }

/* Views in sidebar */
.sidebar-view-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  transition: all var(--dur-fast);
}
.sidebar-view-item:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-view-item.active { background: var(--accent-subtle); color: var(--accent); font-weight: 600; }
.sidebar-view-item .default-star { color: var(--warning); font-size: 10px; margin-left: 4px; }
.sidebar-views-actions {
  display: flex; gap: 4px; margin-top: 6px; padding-top: 6px;
  border-top: 1px solid var(--border-light);
}

/* ── Compact header ── */
.compact-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-card);
  gap: 8px;
  flex-shrink: 0;
  min-height: 36px;
}
.compact-left {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  flex-wrap: wrap;
  min-width: 0;
}
.compact-count { font-weight: 700; color: var(--text); font-size: 13px; font-family: var(--font-mono); }
.compact-sep { color: var(--text-muted); opacity: .4; }
.compact-update { color: var(--text-muted); }
.compact-live { color: var(--success); font-size: 8px; animation: livePulse 2s infinite; }
@keyframes livePulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.compact-badge {
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  background: var(--bg-hover);
  color: var(--text-muted);
}
.compact-badge.credits { background: var(--accent-subtle); color: var(--accent); }

.compact-right { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.compact-btn {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border: none; background: none; border-radius: var(--radius-sm);
  color: var(--text-muted); cursor: pointer;
  transition: all var(--dur-fast);
  position: relative;
}
.compact-btn:hover { background: var(--bg-hover); color: var(--text); }
.compact-btn svg { width: 16px; height: 16px; }
.compact-btn.drafts-btn { color: var(--warning); }
.compact-btn.gamif-btn { color: #8b5cf6; }
.compact-badge-count {
  position: absolute; top: 2px; right: 2px;
  font-size: 9px; font-weight: 700;
  background: var(--warning); color: white;
  min-width: 14px; height: 14px;
  border-radius: 7px; display: flex;
  align-items: center; justify-content: center;
  padding: 0 3px;
}
