/* ─── Sidebar ─── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border-light);
  box-shadow: var(--shadow-sidebar);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: width 0.3s ease;
}

.sidebar.collapsed,
html.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-height);
  padding: 0 16px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.sidebar-brand .brand-logo {
  width: 32px;
  height: var(--control-height);
  border-radius: var(--radius-row);
  flex-shrink: 0;
}

.sidebar-brand .brand-text {
  line-height: 1.2;
  overflow: hidden;
  white-space: nowrap;
  transition: opacity 0.2s;
}

.sidebar.collapsed .brand-text {
  opacity: 0;
  width: 0;
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-4) 12px;
  overflow-y: auto;
  position: relative;
}

.sidebar-nav-pill {
  position: absolute;
  left: 12px;
  right: 12px;
  border-radius: var(--radius-row);
  background: var(--primary-light);
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transition:
    top 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.2s ease;
}

.nav-section {
  margin-bottom: var(--space-6);
}

.nav-section-title {
  padding: 0 12px;
  margin-bottom: var(--space-2);
  font-size: var(--text-2xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .nav-section-title {
  opacity: 0;
  height: 0;
  margin: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 12px;
  border-radius: var(--radius-row);
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text-secondary);
  border-left: 3px solid transparent;
  transition: var(--transition);
  white-space: nowrap;
  position: relative;
  z-index: 1;
}

.nav-item:hover:not(.active) {
  background: var(--surface-raised);
  color: var(--text-primary);
}

.nav-item.active {
  color: var(--primary);
  border-left-color: var(--primary);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: var(--space-2);
}

.sidebar.collapsed .nav-item span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.nav-tooltip {
  position: fixed;
  padding: 6px 10px;
  background: var(--text-primary);
  color: var(--surface);
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius-row);
  white-space: nowrap;
  pointer-events: none;
  z-index: 200;
  box-shadow: var(--shadow-card);
  opacity: 0;
  transform: translateY(-50%);
  transition: opacity 0.15s ease;
  top: 0;
  left: 0;
}

.nav-tooltip.is-visible {
  opacity: 1;
}

/* User pill (merged: original .sidebar-preferences + duplicate block deleted) */
.sidebar-preferences {
  padding: var(--space-2) 12px 0 12px;
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: var(--control-height);
  border-radius: var(--radius-pill);
  background: var(--surface-raised);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  transition: var(--transition);
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.theme-icon { display: inline-flex; }
.theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-light { display: inline-flex; }
[data-theme="dark"] .theme-icon-dark { display: none; }

/* ─── Sidebar Theme Icon Crossfade ───
   Override the global ``.theme-icon-light { display: none }`` swap above
   so sun/moon ease between each other. Scoped to ``.sidebar .theme-toggle``
   so the login-card overrides in pages/login.css stay untouched. */
.sidebar .theme-toggle {
  position: relative;
  overflow: hidden;
}

.sidebar .theme-toggle .theme-icon {
  position: absolute;
  inset: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    opacity 400ms cubic-bezier(0.4, 0, 0.2, 1),
    transform 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar .theme-toggle .theme-icon-light,
.sidebar .theme-toggle .theme-icon-dark {
  display: inline-flex;
}

.sidebar .theme-toggle .theme-icon-light {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}
.sidebar .theme-toggle .theme-icon-dark {
  opacity: 0;
  transform: rotate(90deg) scale(0.6);
}

[data-theme="dark"] .sidebar .theme-toggle .theme-icon-light {
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}
[data-theme="dark"] .sidebar .theme-toggle .theme-icon-dark {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.sidebar-locale {
  padding: var(--space-3) 12px 16px 12px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.sidebar-locale .locale-switcher,
.sidebar-locale .tz-switcher,
.sidebar-locale .dropdown {
  width: 100%;
}

.sidebar-locale .locale-switcher-trigger,
.sidebar-locale .tz-switcher-trigger {
  justify-content: center;
}

.sidebar-locale .dropdown-menu {
  top: auto;
  bottom: calc(100% + 4px);
}

html.sidebar-collapsed .sidebar-locale .dropdown-menu,
.sidebar.collapsed .sidebar-locale .dropdown-menu {
  top: 50%;
  bottom: auto;
  right: auto;
  left: calc(100% + 8px);
  transform: translateY(-50%);
  min-width: 180px;
  animation-name: dropdown-menu-in-fade;
}

@keyframes dropdown-menu-in-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.sidebar-locale .tz-switcher-trigger {
  padding: 6px var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

html.sidebar-collapsed .sidebar-preferences,
.sidebar.collapsed .sidebar-preferences {
  justify-content: center;
}

html.sidebar-collapsed .sidebar-locale,
.sidebar.collapsed .sidebar-locale {
  align-items: stretch;
  padding: var(--space-2) 8px 12px 8px;
}

html.sidebar-collapsed .sidebar-locale .locale-switcher-trigger,
html.sidebar-collapsed .sidebar-locale .tz-switcher-trigger,
.sidebar.collapsed .sidebar-locale .locale-switcher-trigger,
.sidebar.collapsed .sidebar-locale .tz-switcher-trigger {
  padding: 6px 0;
  gap: 0;
}

html.sidebar-collapsed .sidebar-locale .dropdown-label,
html.sidebar-collapsed .sidebar-locale .dropdown-chevron,
.sidebar.collapsed .sidebar-locale .dropdown-label,
.sidebar.collapsed .sidebar-locale .dropdown-chevron {
  display: none;
}

html.sidebar-collapsed .sidebar-locale .dropdown-icon,
.sidebar.collapsed .sidebar-locale .dropdown-icon {
  margin: 0 auto;
}

.sidebar-user {
  padding: var(--space-4) 12px 12px 12px;
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}

/* Merged: original .sidebar-user-inner (447) + position: relative from duplicate (2195) */
.sidebar-user-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: var(--space-2);
  border-radius: var(--radius-row);
  background: var(--surface-raised);
  position: relative;
}

.sidebar-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-on-primary);
  font-size: var(--text-xs);
  font-weight: 600;
  flex-shrink: 0;
}

.sidebar-user-info {
  overflow: hidden;
  line-height: 1.3;
  transition: opacity 0.2s;
}

.sidebar.collapsed .sidebar-user-info {
  display: none;
}

/* Collapse toggle */
.sidebar-toggle {
  position: absolute;
  right: -12px;
  top: 80px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(var(--shadow-rgb), 0.08);
  z-index: 101;
  transition: color 0.15s ease, background 0.15s ease;
}

.sidebar-toggle:hover {
  color: var(--primary);
  background: var(--surface-raised);
}

.sidebar-toggle-icon-expand {
  display: none;
}

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

.sidebar.collapsed .sidebar-toggle-icon-expand {
  display: inline-flex;
}

/* ─── Sidebar Logout Button ─── */
.sidebar-logout-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-row);
  background: var(--danger-light);
  color: var(--danger);
  font-size: var(--text-xs);
  font-weight: 600;
  text-decoration: none;
  transition: var(--transition);
  flex-shrink: 0;
}

.sidebar-logout-btn:hover {
  background: var(--danger);
  color: var(--surface);
}

.sidebar.collapsed .sidebar-logout-btn {
  padding: 0;
  width: 32px;
  justify-content: center;
}

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

@media (prefers-reduced-motion: reduce) {
  .sidebar-nav-pill { transition: none; }
  .nav-item.active { background: var(--primary-light); }
  .sidebar .theme-toggle .theme-icon { transition-duration: 0ms; }
}
