/* =============================================================================
   PREMIUM SIDEBAR NAVIGATION
   Inspired by Linear, Stripe, and Money Copilot
   Clean, refined, and professional aesthetics
   ============================================================================= */

/* CSS Custom Properties */
:root {
  --sidebar-width: 280px;
  --sidebar-collapsed-width: 64px;
  --sidebar-transition-duration: 0.25s;
  --sidebar-transition-timing: cubic-bezier(0.16, 1, 0.3, 1); /* Expo-out for smoothness */
  --sidebar-hover-timing: cubic-bezier(0.34, 1.56, 0.64, 1); /* Slight spring */

  /* Light Theme Colors */
  --sidebar-bg-light: #f5f6f8;
  --sidebar-bg-hover-light: #eeeff2;
  --sidebar-text-primary-light: #2a2f42;
  --sidebar-text-secondary-light: #384152;
  --sidebar-border-light: #e5e7eb;
  --sidebar-active-bg-light: rgba(139, 92, 246, 0.08);
  --sidebar-active-text-light: #8b5cf6;
  --sidebar-active-border-light: #8b5cf6;

  /* Dark Theme Colors */
  --sidebar-bg-dark: #15171c;
  --sidebar-bg-hover-dark: #1d1f26;
  --sidebar-text-primary-dark: #f0f2f5;
  --sidebar-text-secondary-dark: #c0c4ca;
  --sidebar-border-dark: #24262d;
  --sidebar-active-bg-dark: rgba(99, 102, 241, 0.15);
  --sidebar-active-text-dark: #818cf8;
  --sidebar-active-border-dark: #818cf8;
}

/* =============================================================================
   BASE SIDEBAR STYLES
   ============================================================================= */

.sidebar-nav {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: linear-gradient(180deg, #e8eaef 0%, #f8f9fb 100%);
  border-right: 1px solid var(--sidebar-border-light);
  box-shadow: none;
  z-index: 1030;
  transition: width var(--sidebar-transition-duration) var(--sidebar-transition-timing);
  display: flex;
  flex-direction: column;
}

.sidebar-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  position: relative;
}

/* Refined Scrollbar */
.sidebar-content::-webkit-scrollbar {
  width: 4px;
}

.sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 2px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.12);
}

/* =============================================================================
   LOGO SECTION
   ============================================================================= */

.sidebar-logo {
  padding: 0.5rem 1rem;
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-link {
  flex: 1;
  display: flex;
  justify-content: center;
  transition: all 0.25s var(--sidebar-transition-timing);
  filter: drop-shadow(0 0 0 transparent);
  margin-right: 3.5rem; /* Compensate for icon on left to keep logo visually centered */
}

.logo-link:hover {
  transform: scale(1.015) translateY(-1px);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.08));
}

.sidebar-logo-img {
  height: 26px;
  width: auto;
  display: block;
}

/* Theme-based Logo Visibility */
.sidebar-logo-img.logo-light {
  display: block;
}

.sidebar-logo-img.logo-dark {
  display: none;
}

[data-theme="light"] .sidebar-logo-img.logo-light,
[data-theme="corporate"] .sidebar-logo-img.logo-light {
  display: none;
}

[data-theme="light"] .sidebar-logo-img.logo-dark,
[data-theme="corporate"] .sidebar-logo-img.logo-dark {
  display: block;
}

[data-theme="dark"] .sidebar-logo-img.logo-light,
[data-theme="brand"] .sidebar-logo-img.logo-light {
  display: block;
}

[data-theme="dark"] .sidebar-logo-img.logo-dark,
[data-theme="brand"] .sidebar-logo-img.logo-dark {
  display: none;
}

/* Trenly theme: Show dark logo */
[data-theme="trenly"] .sidebar-logo-img.logo-light {
  display: none !important;
}

[data-theme="trenly"] .sidebar-logo-img.logo-dark {
  display: block !important;
}

/* =============================================================================
   NAVIGATION MENU
   ============================================================================= */

.sidebar-menu {
  flex: 1;
  padding: 0.75rem 0;
  overflow-y: auto;
}

/* Menu Items */
.sidebar-item {
  padding: 0 0.5rem;
  margin-bottom: 0.125rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.875rem;
  color: var(--sidebar-text-secondary-light);
  text-decoration: none;
  border-radius: 0.4375rem; /* 7px for softer corners */
  transition: all 0.22s var(--sidebar-transition-timing),
              transform 0.18s var(--sidebar-hover-timing);
  font-size: 0.9375rem;
  font-weight: 400;
  letter-spacing: 0.015em; /* Slightly more airy */
  position: relative;
}

.sidebar-link:hover {
  background: var(--sidebar-bg-hover-light);
  color: var(--sidebar-text-primary-light);
  transform: translateX(2px) scale(1.005);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.sidebar-link.active {
  background: var(--sidebar-active-bg-light);
  color: var(--sidebar-active-text-light);
  font-weight: 500;
  box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.12),
              0 1px 3px rgba(139, 92, 246, 0.08),
              0 0 0 0 transparent;
}

.sidebar-link.active:hover {
  background: rgba(139, 92, 246, 0.12);
  box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.18),
              0 2px 4px rgba(139, 92, 246, 0.12);
}

.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: linear-gradient(180deg, #a78bfa 0%, #8b5cf6 100%);
  border-radius: 0 2px 2px 0;
  box-shadow: 0 0 20px rgba(139, 92, 246, 0.8),
              0 0 8px rgba(139, 92, 246, 0.6),
              0 0 4px rgba(139, 92, 246, 0.4);
}

.sidebar-link.active::after {
  content: '';
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 32px;
  background: radial-gradient(ellipse at center, rgba(139, 92, 246, 0.35) 0%, transparent 65%);
  pointer-events: none;
}

.sidebar-icon {
  width: 20px;
  font-size: 1rem;
  text-align: center;
  opacity: 0.6;
}

.sidebar-link:hover .sidebar-icon,
.sidebar-link.active .sidebar-icon {
  opacity: 1;
}

.sidebar-text {
  flex: 1;
  transition: opacity 0.2s var(--sidebar-transition-timing);
  white-space: nowrap;
  overflow: hidden;
}

/* Refined Badge */
.sidebar-badge {
  background: rgba(139, 92, 246, 0.15);
  color: #7c3aed;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  min-width: 20px;
  text-align: center;
  border-radius: 10px;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.1);
}

.sidebar-badge:empty,
.sidebar-badge.hidden {
  display: none !important;
}

/* =============================================================================
   SECTION LABELS (Operations / Portfolio dividers)
   ============================================================================= */

.sidebar-section-label {
  padding: 1rem 1.25rem 0.5rem 1.25rem;
  margin-top: 0.5rem;
}

.sidebar-section-label:first-of-type {
  margin-top: 0.25rem;
}

.sidebar-section-label-text {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sidebar-text-secondary-light);
  opacity: 0.6;
}

/* Dark theme */
[data-theme="dark"] .sidebar-section-label-text,
[data-theme="trenly-dark"] .sidebar-section-label-text {
  color: var(--sidebar-text-secondary-dark);
  opacity: 0.5;
}

/* =============================================================================
   DISABLED MENU ITEMS (Coming Soon)
   ============================================================================= */

.sidebar-item-disabled {
  opacity: 0.5;
}

.sidebar-link-disabled {
  width: calc(100% - 1rem);
  margin: 0 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.875rem;
  color: var(--sidebar-text-secondary-light);
  background: transparent;
  border-radius: 0.5rem;
  font-size: 0.9375rem;
  font-weight: 400;
  cursor: not-allowed;
}

.sidebar-link-disabled .sidebar-badge {
  margin-left: auto;
  font-size: 0.6rem;
  padding: 0.15rem 0.4rem;
  border-radius: 0.25rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.badge-neutral {
  background: rgba(100, 116, 139, 0.15);
  color: #64748b;
}

[data-theme="dark"] .badge-neutral,
[data-theme="trenly-dark"] .badge-neutral {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
}

/* =============================================================================
   SECTION HEADERS & SUBMENUS
   ============================================================================= */

.sidebar-section {
  margin-bottom: 0.125rem;
}

.sidebar-section-header {
  width: calc(100% - 1rem);
  margin: 0 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.875rem;
  color: var(--sidebar-text-secondary-light);
  background: transparent;
  border: none;
  border-radius: 0.5rem;
  transition: all 0.2s var(--sidebar-transition-timing);
  font-size: 0.9375rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  cursor: pointer;
  text-align: left;
}

.sidebar-section-header:hover {
  background: var(--sidebar-bg-hover-light);
  color: var(--sidebar-text-primary-light);
}

.sidebar-section-header.active {
  color: var(--sidebar-text-primary-light);
  position: relative;
}

.sidebar-section-header.active::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 110%;
  height: 120%;
  background: radial-gradient(ellipse at center, rgba(139, 92, 246, 0.18) 0%, rgba(139, 92, 246, 0.08) 40%, transparent 70%);
  border-radius: 0.5rem;
  z-index: -1;
  pointer-events: none;
}

.sidebar-chevron {
  margin-left: auto;
  font-size: 0.75rem;
  transition: transform 0.2s var(--sidebar-transition-timing);
  opacity: 0.5;
}

.sidebar-section-header.active .sidebar-chevron {
  transform: rotate(180deg);
}

/* Submenu Container */
.sidebar-submenu {
  display: none;
  padding: 0.25rem 0 0.5rem;
  max-height: none;
  overflow-y: visible;
}

.sidebar-submenu.show {
  display: block;
  /* animation: slideDown 0.2s ease; */ /* Temporarily disabled to debug jumping issue */
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Submenu Links */
.sidebar-sublink {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5625rem 0.875rem 0.5625rem 2.875rem;
  margin: 0 0.5rem;
  color: var(--sidebar-text-secondary-light);
  text-decoration: none;
  border-radius: 0;
  transition: all 0.2s var(--sidebar-transition-timing);
  font-size: 0.875rem;
  font-weight: 400;
  position: relative;
}

.sidebar-sublink:hover {
  background: var(--sidebar-bg-hover-light);
  color: var(--sidebar-text-primary-light);
  transform: translateX(1px);
}

.sidebar-sublink.active {
  color: var(--sidebar-active-text-light);
  background: var(--sidebar-active-bg-light);
  font-weight: 500;
  box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.08);
}

.sidebar-sublink i {
  width: 16px;
  font-size: 0.8125rem;
  text-align: center;
  flex-shrink: 0;
  opacity: 0.75;
}

.sidebar-sublink.active i {
  opacity: 1;
}

/* Submenu Tags */
.sublink-tag {
  margin-left: auto;
  background: rgba(37, 99, 235, 0.08);
  color: var(--sidebar-active-text-light);
  font-size: 0.625rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tag-new {
  background: rgba(16, 185, 129, 0.08);
  color: #059669;
}

/* Submenu Grouping */
.sidebar-subgroup {
  padding: 0.25rem 0;
}

.subgroup-title {
  padding: 0.75rem 0.875rem 0.375rem 2.625rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 0.5rem;
  opacity: 0.8;
}

.sidebar-divider {
  height: 1px;
  background: linear-gradient(to right,
    transparent 0%,
    rgba(0, 0, 0, 0.12) 15%,
    rgba(0, 0, 0, 0.35) 50%,
    rgba(0, 0, 0, 0.12) 85%,
    transparent 100%);
  margin: 0;
  padding: 0;
  position: relative;
}

.sidebar-divider::after {
  content: '';
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 50%;
  height: 5px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.2) 0%, transparent 65%);
  filter: blur(2px);
}

/* =============================================================================
   BOTTOM ACTIONS (Support)
   ============================================================================= */

.sidebar-bottom-actions {
  padding: 0.25rem 0.75rem;
  display: flex;
  gap: 0.25rem;
}

.sidebar-bottom-actions .sidebar-link {
  font-size: 0.875rem;
  flex: 1;
}

/* =============================================================================
   ASSISTANT EMAIL SECTION (Email Relay)
   ============================================================================= */

.sidebar-relay-email {
  padding: 0.5rem 0.75rem;
  margin: 0 0.5rem 0.5rem;
}

.relay-email-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--sidebar-text-secondary-light);
  margin-bottom: 0.375rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.relay-email-label i {
  font-size: 0.75rem;
  opacity: 0.7;
}

.assistant-contact-rows {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.relay-email-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.relay-row-icon {
  flex-shrink: 0;
  width: 16px;
  font-size: 0.625rem;
  color: var(--sidebar-text-secondary-light);
  opacity: 0.6;
  text-align: center;
}

.relay-email-input {
  flex: 1;
  min-width: 0;
  padding: 0.375rem 0.5rem;
  font-size: 0.6875rem;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, "Cascadia Mono", "Segoe UI Mono", "Roboto Mono", "Oxygen Mono", "Ubuntu Monospace", "Source Code Pro", "Fira Code", "Droid Sans Mono", "Courier New", monospace;
  background: var(--sidebar-bg-hover-light);
  border: 1px solid var(--sidebar-border-light);
  border-radius: 0.375rem;
  color: var(--sidebar-text-secondary-light);
  cursor: text;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.relay-email-input:focus {
  outline: none;
  border-color: oklch(34% 0.16 305);
}

.relay-email-copy-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-bg-hover-light);
  border: 1px solid var(--sidebar-border-light);
  border-radius: 0.375rem;
  color: var(--sidebar-text-secondary-light);
  cursor: pointer;
  transition: all 0.15s ease;
}

.relay-email-copy-btn:hover {
  background: oklch(94% 0 0);
  border-color: oklch(85% 0 0);
  color: oklch(34% 0.16 305);
}

.relay-email-copy-btn i {
  font-size: 0.75rem;
}

/* Dark theme */
[data-theme="dark"] .relay-email-label {
  color: var(--sidebar-text-secondary-dark);
}

[data-theme="dark"] .relay-email-input {
  background: var(--sidebar-bg-hover-dark);
  border-color: var(--sidebar-border-dark);
  color: var(--sidebar-text-secondary-dark);
}

[data-theme="dark"] .relay-email-copy-btn {
  background: var(--sidebar-bg-hover-dark);
  border-color: var(--sidebar-border-dark);
  color: var(--sidebar-text-secondary-dark);
}

[data-theme="dark"] .relay-row-icon {
  color: var(--sidebar-text-secondary-dark);
}

[data-theme="dark"] .relay-email-copy-btn:hover {
  background: #1c2128;
  color: var(--sidebar-active-text-dark);
}

/* Brand theme */
[data-theme="brand"] .relay-email-label {
  color: #a5a3b8;
}

[data-theme="brand"] .relay-email-input {
  background: rgba(139, 92, 246, 0.06);
  border-color: rgba(139, 92, 246, 0.15);
  color: #c4c2d8;
}

[data-theme="brand"] .relay-email-copy-btn {
  background: rgba(139, 92, 246, 0.06);
  border-color: rgba(139, 92, 246, 0.15);
  color: #a5a3b8;
}

[data-theme="brand"] .relay-row-icon {
  color: #a5a3b8;
}

[data-theme="brand"] .relay-email-copy-btn:hover {
  background: rgba(139, 92, 246, 0.12);
  border-color: rgba(139, 92, 246, 0.25);
  color: #c4b5fd;
}

/* Collapsed state - hide the entire section */
.sidebar-nav.collapsed .sidebar-relay-email {
  display: none;
}

/* =============================================================================
   VERTICAL DENSITY TIERS (short-screen support)
   Three sizes that progressively tighten the sidebar as viewport height shrinks.
   Only apply when sidebar is in normal full-width mode (above mobile breakpoint
   and not user-collapsed).
   ============================================================================= */

/* Tier 2 — Compact (≤ 850px tall): trim vertical padding across the menu. */
@media (min-width: 1025px) and (max-height: 850px) {
  .sidebar-nav:not(.collapsed) .sidebar-logo {
    padding-top: 0.375rem;
    padding-bottom: 0.375rem;
  }

  .sidebar-nav:not(.collapsed) .sidebar-link,
  .sidebar-nav:not(.collapsed) .sidebar-section-header {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .sidebar-nav:not(.collapsed) .sidebar-sublink {
    padding-top: 0.4375rem;
    padding-bottom: 0.4375rem;
  }

  .sidebar-nav:not(.collapsed) .sidebar-relay-email {
    padding: 0.375rem 0.75rem;
    margin-bottom: 0.25rem;
  }

  .sidebar-nav:not(.collapsed) .sidebar-relay-email .relay-email-label {
    margin-bottom: 0.25rem;
  }

  .sidebar-nav:not(.collapsed) .sidebar-bottom-actions {
    padding-top: 0.125rem;
    padding-bottom: 0.125rem;
  }

  .sidebar-nav:not(.collapsed) .sidebar-bottom-actions .sidebar-link {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .sidebar-nav:not(.collapsed) .sidebar-footer {
    padding: 0.5rem 0.75rem;
  }

  .sidebar-nav:not(.collapsed) .sidebar-user-button {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .sidebar-nav:not(.collapsed) .sidebar-user-avatar {
    width: 32px;
    height: 32px;
  }
}

/* Tier 3 — Cozy (≤ 720px tall): everything from compact, plus collapse the
   assistant block to a single "My Assistant" row with the email/phone shown
   in a hover flyout to the right of the sidebar. */
@media (min-width: 1025px) and (max-height: 720px) {
  .sidebar-nav:not(.collapsed) .sidebar-link,
  .sidebar-nav:not(.collapsed) .sidebar-section-header {
    padding-top: 0.4375rem;
    padding-bottom: 0.4375rem;
    font-size: 0.9rem;
  }

  .sidebar-nav:not(.collapsed) .sidebar-sublink {
    padding-top: 0.375rem;
    padding-bottom: 0.375rem;
    font-size: 0.84375rem;
  }

  .sidebar-nav:not(.collapsed) .sidebar-bottom-actions .sidebar-link {
    padding-top: 0.4375rem;
    padding-bottom: 0.4375rem;
    font-size: 0.84375rem;
  }

  /* Collapse the assistant block to its label row only */
  .sidebar-nav:not(.collapsed) .sidebar-relay-email {
    position: relative;
    padding: 0.25rem 0.75rem;
  }

  .sidebar-nav:not(.collapsed) .sidebar-relay-email .relay-email-label {
    margin-bottom: 0;
    cursor: default;
  }

  /* Subtle chevron-right cue on the label so the user knows there's more */
  .sidebar-nav:not(.collapsed) .sidebar-relay-email .relay-email-label::after {
    content: '\f105'; /* fa-chevron-right */
    font-family: "Font Awesome 7 Free", "Font Awesome 6 Free", "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 0.625rem;
    margin-left: 0.375rem;
    opacity: 0.45;
    transition: opacity 0.18s ease, transform 0.18s ease;
  }

  .sidebar-nav:not(.collapsed) .sidebar-relay-email:hover .relay-email-label::after,
  .sidebar-nav:not(.collapsed) .sidebar-relay-email:focus-within .relay-email-label::after {
    opacity: 0.85;
    transform: translateX(2px);
  }

  /* The contact rows become a flyout anchored to the right edge of the sidebar */
  .sidebar-nav:not(.collapsed) .sidebar-relay-email .assistant-contact-rows {
    position: absolute;
    bottom: 0;
    left: calc(100% + 6px);
    min-width: 240px;
    padding: 0.625rem 0.75rem;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px) saturate(140%);
    border: 1px solid var(--sidebar-border-light);
    border-radius: 0.75rem;
    box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.12),
                0 4px 12px -2px rgba(0, 0, 0, 0.08),
                0 0 0 1px rgba(139, 92, 246, 0.06);
    opacity: 0;
    pointer-events: none;
    transform: translateX(-6px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 1050;
  }

  /* Invisible bridge so cursor can travel from label to flyout without closing */
  .sidebar-nav:not(.collapsed) .sidebar-relay-email::after {
    content: '';
    position: absolute;
    top: 0;
    left: 100%;
    width: 12px;
    height: 100%;
    background: transparent;
    pointer-events: none;
  }

  .sidebar-nav:not(.collapsed) .sidebar-relay-email:hover::after,
  .sidebar-nav:not(.collapsed) .sidebar-relay-email:focus-within::after {
    pointer-events: auto;
  }

  .sidebar-nav:not(.collapsed) .sidebar-relay-email:hover .assistant-contact-rows,
  .sidebar-nav:not(.collapsed) .sidebar-relay-email:focus-within .assistant-contact-rows,
  .sidebar-nav:not(.collapsed) .sidebar-relay-email .assistant-contact-rows:hover {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
  }

  /* Dark-theme flyout surface */
  [data-theme="dark"] .sidebar-nav:not(.collapsed) .sidebar-relay-email .assistant-contact-rows,
  [data-theme="trenly-dark"] .sidebar-nav:not(.collapsed) .sidebar-relay-email .assistant-contact-rows {
    background: rgba(20, 22, 28, 0.98);
    border-color: var(--sidebar-border-dark);
    box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.4),
                0 4px 12px -2px rgba(0, 0, 0, 0.25);
  }

  [data-theme="brand"] .sidebar-nav:not(.collapsed) .sidebar-relay-email .assistant-contact-rows {
    background: rgba(28, 22, 44, 0.98);
    border-color: rgba(139, 92, 246, 0.2);
    box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.4),
                0 4px 12px -2px rgba(139, 92, 246, 0.18);
  }
}

/* =============================================================================
   USER FOOTER SECTION
   ============================================================================= */

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--sidebar-border-light);
  margin-top: auto;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  background: var(--sidebar-bg-light);
  backdrop-filter: blur(8px);
}

.sidebar-user {
  position: relative;
}

.sidebar-user-button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  background: var(--sidebar-bg-hover-light);
  border: 1px solid var(--sidebar-border-light);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s var(--sidebar-transition-timing);
}

.sidebar-user-button:hover {
  background: #f1f5f9;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.08),
              0 1px 3px rgba(0, 0, 0, 0.05);
  transform: translateY(-1px);
  border-color: rgba(139, 92, 246, 0.15);
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.15),
              0 2px 8px rgba(139, 92, 246, 0.2);
}

.sidebar-user-info {
  flex: 1;
  text-align: left;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--sidebar-text-primary-light);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  font-size: 0.8125rem;
  color: var(--sidebar-text-secondary-light);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-chevron {
  font-size: 0.7rem;
  color: var(--sidebar-text-secondary-light);
  transition: transform 0.2s var(--sidebar-transition-timing);
  flex-shrink: 0;
}

.sidebar-user-button[aria-expanded="true"] .sidebar-user-chevron {
  transform: rotate(180deg);
}

/* User Dropdown Menu */
.sidebar-user-menu {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(8px) saturate(120%);
  border: 1px solid rgba(139, 92, 246, 0.12);
  border-radius: 0.75rem;
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.12),
              0 0 0 1px rgba(139, 92, 246, 0.08);
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1050;
  will-change: transform, opacity;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.sidebar-user-menu.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.sidebar-user-menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.875rem;
  color: var(--sidebar-text-primary-light);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 400;
  transition: all 0.2s var(--sidebar-transition-timing);
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.sidebar-user-menu-item:hover {
  background: rgba(139, 92, 246, 0.08);
  color: var(--sidebar-active-text-light);
}

.sidebar-user-menu-item.logout {
  color: #dc2626;
}

.sidebar-user-menu-item.logout:hover {
  background: #fef2f2;
}

.sidebar-user-menu-item i {
  width: 16px;
  font-size: 0.875rem;
  text-align: center;
}

.sidebar-user-menu-divider {
  height: 1px;
  background: var(--sidebar-border-light);
  margin: 0.25rem 0;
}

/* =============================================================================
   COLLAPSE TOGGLE BUTTON (Claude-style panel icon)
   ============================================================================= */

.sidebar-collapse-btn {
  width: 2rem;
  height: 2rem;
  padding: 0.25rem;
  background: transparent;
  border: none;
  color: var(--sidebar-text-secondary-light);
  cursor: pointer;
  transition: all 0.2s var(--sidebar-transition-timing);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
  background: var(--sidebar-bg-hover-light);
  color: var(--sidebar-text-primary-light);
}

.sidebar-collapse-btn svg {
  transition: all 0.2s var(--sidebar-transition-timing);
}

.sidebar-nav.collapsed .sidebar-collapse-btn svg {
  transform: scaleX(-1);
}

.sidebar-collapse-btn {
  position: relative;
}

/* =============================================================================
   MOBILE STYLES
   ============================================================================= */

.mobile-close-btn {
  display: none !important;
  position: absolute;
  top: 0.3rem;
  right: 0.25rem;
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 0.5rem;
  color: var(--sidebar-text-secondary-light);
  font-size: 1rem;
  cursor: pointer;
  z-index: 10;
  padding: 0.5rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.mobile-close-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--sidebar-text-primary-light);
  transform: scale(1.05);
}

@media (max-width: 1024px) {
  .sidebar-nav {
    position: fixed;
    left: -280px;
    top: 0;
    height: 100vh;
    z-index: 1045;
    transition: left 0.3s ease-in-out;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
    width: var(--sidebar-width) !important;
    display: flex;
    flex-direction: column;
  }

  .sidebar-nav .sidebar-content {
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
  }

  .sidebar-nav .sidebar-menu {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
  }

  .sidebar-nav .sidebar-footer {
    position: relative;
    flex-shrink: 0;
    margin-top: auto;
    bottom: auto;
  }

  .sidebar-nav.mobile-open {
    left: 0 !important;
  }

  .sidebar-nav.mobile-open .mobile-close-btn {
    display: flex !important;
  }

  /* When mobile menu is open, always show full content (ignore collapsed state) */
  .sidebar-nav.mobile-open .sidebar-text,
  .sidebar-nav.mobile-open .sidebar-badge:not(.hidden):not(:empty),
  .sidebar-nav.mobile-open .sidebar-chevron,
  .sidebar-nav.mobile-open .sidebar-user-info,
  .sidebar-nav.mobile-open .sublink-tag,
  .sidebar-nav.mobile-open .sidebar-user-chevron,
  .sidebar-nav.mobile-open .logo-link {
    display: block !important;
  }

  /* Force expanded width on mobile (override collapsed state) */
  .sidebar-nav.collapsed {
    width: var(--sidebar-width) !important;
  }

  /* Show all elements on mobile (override collapsed state) */
  .sidebar-nav .sidebar-text,
  .sidebar-nav .sidebar-badge:not(.hidden):not(:empty),
  .sidebar-nav .sidebar-chevron,
  .sidebar-nav .sidebar-user-info,
  .sidebar-nav .sublink-tag,
  .sidebar-nav .sidebar-user-chevron,
  .sidebar-nav .logo-link {
    display: block !important;
  }

  /* Reset padding on mobile */
  .sidebar-nav.collapsed .sidebar-link,
  .sidebar-nav.collapsed .sidebar-section-header {
    padding: 0.75rem 0.875rem !important;
    justify-content: flex-start !important;
    margin: 0 !important;
  }

  .sidebar-nav.collapsed .sidebar-item {
    padding: 0 0.5rem !important;
  }

  /* Hide collapse toggle button on mobile */
  .sidebar-collapse-btn {
    display: none !important;
  }

  /* Remove all left margin on mobile */
  .main-content {
    margin-left: 0 !important;
  }
}

/* =============================================================================
   DARK THEME
   ============================================================================= */

[data-theme="dark"] .sidebar-nav {
  background: linear-gradient(180deg, #0f1218 0%, #1a1d24 100%);
  border-color: var(--sidebar-border-dark);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.05), 0 1px 2px rgba(0, 0, 0, 0.3);
}


[data-theme="dark"] .sidebar-link,
[data-theme="dark"] .sidebar-section-header {
  color: var(--sidebar-text-secondary-dark);
}

[data-theme="dark"] .sidebar-link:hover,
[data-theme="dark"] .sidebar-section-header:hover {
  background: var(--sidebar-bg-hover-dark);
  color: var(--sidebar-text-primary-dark);
}

[data-theme="dark"] .sidebar-section-header.active::before {
  background: radial-gradient(ellipse at center, rgba(99, 102, 241, 0.25) 0%, rgba(99, 102, 241, 0.12) 40%, transparent 70%);
}

[data-theme="dark"] .sidebar-link.active {
  background: var(--sidebar-active-bg-dark);
  color: var(--sidebar-active-text-dark);
}

[data-theme="dark"] .sidebar-link.active::before {
  background: var(--sidebar-active-border-dark);
}

[data-theme="dark"] .sidebar-icon {
  opacity: 0.6;
}

[data-theme="dark"] .sidebar-link:hover .sidebar-icon,
[data-theme="dark"] .sidebar-link.active .sidebar-icon {
  opacity: 1;
}

[data-theme="dark"] .sidebar-sublink {
  color: var(--sidebar-text-secondary-dark);
}

[data-theme="dark"] .sidebar-sublink:hover {
  background: var(--sidebar-bg-hover-dark);
  color: var(--sidebar-text-primary-dark);
}

[data-theme="dark"] .sidebar-sublink.active {
  background: var(--sidebar-active-bg-dark);
  color: var(--sidebar-active-text-dark);
}

[data-theme="dark"] .subgroup-title {
  color: #6b7280;
  opacity: 0.7;
}

[data-theme="dark"] .sidebar-divider {
  background: linear-gradient(to right,
    transparent 0%,
    rgba(255, 255, 255, 0.15) 15%,
    rgba(255, 255, 255, 0.4) 50%,
    rgba(255, 255, 255, 0.15) 85%,
    transparent 100%);
}

[data-theme="dark"] .sidebar-divider::after {
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.25) 0%, transparent 65%);
}

[data-theme="dark"] .sidebar-footer {
  background: var(--sidebar-bg-dark);
  border-top-color: var(--sidebar-border-dark);
}

[data-theme="dark"] .sidebar-user-button {
  background: var(--sidebar-bg-hover-dark);
  border-color: var(--sidebar-border-dark);
}

[data-theme="dark"] .sidebar-user-button:hover {
  background: #1c2128;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .sidebar-user-name {
  color: var(--sidebar-text-primary-dark);
}

[data-theme="dark"] .sidebar-user-email {
  color: var(--sidebar-text-secondary-dark);
}

[data-theme="dark"] .sidebar-user-menu {
  background: #161b22;
  border-color: var(--sidebar-border-dark);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .sidebar-user-menu-item {
  color: var(--sidebar-text-primary-dark);
}

[data-theme="dark"] .sidebar-user-menu-item:hover {
  background: var(--sidebar-bg-hover-dark);
  color: var(--sidebar-active-text-dark);
}

[data-theme="dark"] .sidebar-collapse-btn {
  color: var(--sidebar-text-secondary-dark);
}

[data-theme="dark"] .sidebar-collapse-btn:hover {
  background: var(--sidebar-bg-hover-dark);
  color: var(--sidebar-text-primary-dark);
}

[data-theme="dark"] .sidebar-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .sidebar-content::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18);
}

[data-theme="dark"] .mobile-close-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--sidebar-text-primary-dark);
}

[data-theme="dark"] .mobile-close-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.15);
}

/* Collapsed flyout menus - Dark theme */
[data-theme="dark"] .sidebar-nav.collapsed .sidebar-section:hover .sidebar-submenu {
  background: rgba(22, 27, 34, 0.98);
  backdrop-filter: blur(12px) saturate(140%);
  border-color: var(--sidebar-border-dark);
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.5),
              0 4px 12px -2px rgba(0, 0, 0, 0.4),
              0 0 0 1px rgba(99, 102, 241, 0.15);
}

[data-theme="dark"] .sidebar-nav.collapsed .sidebar-section:hover .sidebar-submenu::before {
  color: var(--sidebar-text-secondary-dark);
  border-bottom-color: var(--sidebar-border-dark);
}

/* =============================================================================
   BRAND THEME (Bold Purple - Premium)
   ============================================================================= */

[data-theme="brand"] .sidebar-nav {
  background: linear-gradient(180deg, #120d20 0%, #2d2048 100%);
  border-right: 1px solid #1f1834;
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.08), 0 1px 3px rgba(0, 0, 0, 0.4);
}


[data-theme="brand"] .sidebar-link,
[data-theme="brand"] .sidebar-section-header {
  color: #d4d2e8;
}

[data-theme="brand"] .sidebar-link:hover,
[data-theme="brand"] .sidebar-section-header:hover {
  background: rgba(139, 92, 246, 0.08);
  color: #e5e3f0;
}

[data-theme="brand"] .sidebar-section-header.active::before {
  background: radial-gradient(ellipse at center, rgba(139, 92, 246, 0.30) 0%, rgba(139, 92, 246, 0.15) 40%, transparent 70%);
}

[data-theme="brand"] .sidebar-link.active {
  background: rgba(139, 92, 246, 0.15);
  color: #c4b5fd;
}

[data-theme="brand"] .sidebar-link.active::before {
  background: linear-gradient(180deg, #a78bfa 0%, #8b5cf6 100%);
  box-shadow: 0 0 8px rgba(167, 139, 250, 0.4);
}

[data-theme="brand"] .sidebar-icon {
  opacity: 0.65;
}

[data-theme="brand"] .sidebar-link:hover .sidebar-icon,
[data-theme="brand"] .sidebar-link.active .sidebar-icon {
  opacity: 1;
}

[data-theme="brand"] .sidebar-sublink {
  color: #c4c2d8;
}

[data-theme="brand"] .sidebar-sublink:hover {
  background: rgba(139, 92, 246, 0.06);
  color: #e5e3f0;
}

[data-theme="brand"] .sidebar-sublink.active {
  background: rgba(139, 92, 246, 0.12);
  color: #c4b5fd;
}

[data-theme="brand"] .subgroup-title {
  color: #7c7a8e;
  opacity: 1;
}

[data-theme="brand"] .sidebar-divider {
  background: linear-gradient(to right,
    transparent 0%,
    rgba(139, 92, 246, 0.25) 15%,
    rgba(139, 92, 246, 0.6) 50%,
    rgba(139, 92, 246, 0.25) 85%,
    transparent 100%);
}

[data-theme="brand"] .sidebar-divider::after {
  background: radial-gradient(ellipse at center, rgba(167, 139, 250, 0.4) 0%, transparent 65%);
}

[data-theme="brand"] .sidebar-footer {
  background: transparent;
  border-top: 1px solid rgba(139, 92, 246, 0.3);
  backdrop-filter: blur(12px);
}

[data-theme="brand"] .sidebar-user-avatar {
  background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 100%);
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2), 0 2px 8px rgba(139, 92, 246, 0.3);
}

[data-theme="brand"] .sidebar-user-button {
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.2);
}

[data-theme="brand"] .sidebar-user-button:hover {
  background: rgba(139, 92, 246, 0.12);
  border-color: rgba(139, 92, 246, 0.3);
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.15);
}

[data-theme="brand"] .sidebar-user-name {
  color: #e5e3f0;
}

[data-theme="brand"] .sidebar-user-email {
  color: #a5a3b8;
}

[data-theme="brand"] .sidebar-user-menu {
  background: rgba(15, 10, 31, 0.98);
  backdrop-filter: blur(8px) saturate(120%);
  border: 1px solid rgba(139, 92, 246, 0.25);
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(139, 92, 246, 0.1);
}

[data-theme="brand"] .sidebar-user-menu-item {
  color: #d4d2e0;
}

[data-theme="brand"] .sidebar-user-menu-item:hover {
  background: rgba(139, 92, 246, 0.15);
  color: #c4b5fd;
}

[data-theme="brand"] .sidebar-collapse-btn {
  color: rgba(255, 255, 255, 0.7);
}

[data-theme="brand"] .sidebar-collapse-btn:hover {
  background: rgba(139, 92, 246, 0.1);
  color: rgba(255, 255, 255, 0.95);
}

[data-theme="brand"] .mobile-close-btn {
  background: rgba(139, 92, 246, 0.12);
  border-color: rgba(139, 92, 246, 0.25);
  color: #e5e3f0;
}

[data-theme="brand"] .mobile-close-btn:hover {
  background: rgba(139, 92, 246, 0.18);
  border-color: rgba(139, 92, 246, 0.35);
  color: #c4b5fd;
}

[data-theme="brand"] .sidebar-collapse-toggle {
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.25);
  color: #a5a3b8;
}

[data-theme="brand"] .sidebar-collapse-toggle:hover {
  background: rgba(139, 92, 246, 0.18);
  border-color: rgba(139, 92, 246, 0.35);
  color: #e5e3f0;
}

/* Collapsed flyout menus - Brand theme */
[data-theme="brand"] .sidebar-nav.collapsed .sidebar-section:hover .sidebar-submenu {
  background: rgba(15, 10, 31, 0.98);
  backdrop-filter: blur(12px) saturate(140%);
  border-color: rgba(139, 92, 246, 0.3);
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.6),
              0 4px 12px -2px rgba(0, 0, 0, 0.5),
              0 0 0 1px rgba(139, 92, 246, 0.2);
}

[data-theme="brand"] .sidebar-nav.collapsed .sidebar-section:hover .sidebar-submenu::before {
  color: #a5a3b8;
  border-bottom-color: rgba(139, 92, 246, 0.2);
}

/* =============================================================================
   COLLAPSED STATE
   ============================================================================= */

/* Initial collapsed state (applied before JS loads to prevent flash) */
html.sidebar-initially-collapsed .sidebar-nav {
  width: var(--sidebar-collapsed-width);
}

html.sidebar-initially-collapsed .main-content {
  margin-left: var(--sidebar-collapsed-width);
}

html.sidebar-initially-collapsed .sidebar-text,
html.sidebar-initially-collapsed .sidebar-badge,
html.sidebar-initially-collapsed .sidebar-chevron,
html.sidebar-initially-collapsed .sidebar-user-info,
html.sidebar-initially-collapsed .sublink-tag,
html.sidebar-initially-collapsed .sidebar-user-chevron {
  display: none;
}

html.sidebar-initially-collapsed .sidebar-submenu {
  display: none !important;
}

html.sidebar-initially-collapsed .sidebar-logo .logo-link {
  display: none;
}

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

.sidebar-nav.collapsed .sidebar-text,
.sidebar-nav.collapsed .sidebar-badge,
.sidebar-nav.collapsed .sidebar-chevron,
.sidebar-nav.collapsed .sidebar-user-info,
.sidebar-nav.collapsed .sublink-tag,
.sidebar-nav.collapsed .sidebar-user-chevron {
  display: none;
}

.sidebar-nav.collapsed .sidebar-footer {
  padding: 0.5rem;
}

.sidebar-nav.collapsed .sidebar-user-button {
  padding: 0.5rem;
  justify-content: center;
}

.sidebar-nav.collapsed .sidebar-item {
  padding: 0;
}

.sidebar-nav.collapsed .sidebar-link,
.sidebar-nav.collapsed .sidebar-section-header {
  padding: 0.75rem;
  justify-content: center;
  margin: 0 0.5rem;
}

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

.sidebar-nav.collapsed .sidebar-bottom-actions {
  flex-direction: column;
}

/* Collapsed Mode: Hover Flyout Menus */
.sidebar-nav.collapsed .sidebar-menu {
  overflow: visible;
}

.sidebar-nav.collapsed .sidebar-section {
  position: relative;
}

.sidebar-nav.collapsed .sidebar-submenu {
  display: none !important;
}

.sidebar-nav.collapsed .sidebar-section:hover .sidebar-submenu {
  display: block !important;
  position: fixed;
  left: calc(var(--sidebar-collapsed-width) - 2px);
  transform: translateY(-50%);
  min-width: 240px;
  max-width: 280px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(12px) saturate(140%);
  border: 1px solid var(--sidebar-border-light);
  border-radius: 0.75rem;
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.12),
              0 4px 12px -2px rgba(0, 0, 0, 0.08),
              0 0 0 1px rgba(139, 92, 246, 0.08);
  padding: 0.5rem;
  z-index: 1050;
  animation: flyoutSlideInCentered 0.2s ease;
}

/* Invisible L-shaped bridge to maintain hover state */
.sidebar-nav.collapsed .sidebar-section::after {
  content: '';
  position: absolute;
  left: 100%;
  top: 0;
  width: 240px;
  height: 100%;
  background: transparent;
  pointer-events: auto;
  z-index: 1049;
  display: none;
}

.sidebar-nav.collapsed .sidebar-section:hover::after {
  display: block;
}

@keyframes flyoutSlideIn {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes flyoutSlideInCentered {
  from {
    opacity: 0;
    transform: translateY(-50%) translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
  }
}

/* Collapsed flyout: reset padding for sublinks */
.sidebar-nav.collapsed .sidebar-section:hover .sidebar-sublink {
  padding: 0.5rem 0.75rem;
}

/* Add section title to flyout */
.sidebar-nav.collapsed .sidebar-section:hover .sidebar-submenu::before {
  content: attr(data-section-title);
  display: block;
  padding: 0.5rem 0.75rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--sidebar-text-secondary-light);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--sidebar-border-light);
  margin-bottom: 0.25rem;
}

.sidebar-nav.collapsed + .main-content {
  margin-left: var(--sidebar-collapsed-width);
}

.sidebar-nav.collapsed .sidebar-logo {
  padding: 1rem;
  justify-content: center;
}

.sidebar-nav.collapsed .sidebar-logo .logo-link {
  display: none;
}

.sidebar-nav.collapsed .sidebar-collapse-btn {
  margin: 0;
}

/* Collapsed mode: User menu as flyout */
.sidebar-nav.collapsed .sidebar-user {
  overflow: visible;
}

.sidebar-nav.collapsed .sidebar-user-menu.show {
  position: fixed;
  bottom: 1rem;
  left: calc(var(--sidebar-collapsed-width) - 2px);
  right: auto;
  top: auto;
  min-width: 200px;
}

/* =============================================================================
   NAVIGATION PROGRESS BAR
   ============================================================================= */

.nav-progress-bar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: 5px;
  background: transparent;
  z-index: 9999;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s ease, left 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Adjust position when sidebar is collapsed */
.sidebar-nav.collapsed ~ .nav-progress-bar {
  left: var(--sidebar-collapsed-width);
}

/* Mobile: full width */
@media (max-width: 1024px) {
  .nav-progress-bar {
    left: 0;
    top: 60px; /* Below mobile header */
  }
}

.nav-progress-bar.nav-loading {
  opacity: 1;
  background: linear-gradient(90deg, #6d28d9 0%, #6366f1 100%);
}

.nav-progress-bar.nav-loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: linear-gradient(90deg,
    transparent 0%,
    transparent 45%,
    #fbbf24 50%,
    transparent 55%,
    transparent 100%
  );
  animation: progressSlide 1.5s ease-in-out infinite;
  background-size: 200% 100%;
}

@keyframes progressSlide {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

/* Dark theme progress bar */
[data-theme="dark"] .nav-progress-bar.nav-loading {
  background: linear-gradient(90deg, #7c3aed 0%, #818cf8 100%);
}

[data-theme="dark"] .nav-progress-bar.nav-loading::before {
  background: linear-gradient(90deg,
    transparent 0%,
    transparent 45%,
    #fcd34d 50%,
    transparent 55%,
    transparent 100%
  );
}

/* Brand theme progress bar */
[data-theme="brand"] .nav-progress-bar.nav-loading {
  background: linear-gradient(90deg, #7c3aed 0%, #818cf8 100%);
}

[data-theme="brand"] .nav-progress-bar.nav-loading::before {
  background: linear-gradient(90deg,
    transparent 0%,
    transparent 45%,
    #fbbf24 50%,
    transparent 55%,
    transparent 100%
  );
}

/* =============================================================================
   LOADING STATE
   ============================================================================= */

/* Aggressively hide ALL loading indicators on sidebar navigation */
.sidebar-nav a[aria-busy],
.sidebar-nav a[data-loading],
.sidebar-nav .sidebar-link[aria-busy],
.sidebar-nav .sidebar-sublink[aria-busy] {
  position: relative;
}

.sidebar-nav a[aria-busy]::before,
.sidebar-nav a[aria-busy]::after,
.sidebar-nav a[data-loading]::before,
.sidebar-nav a[data-loading]::after,
.sidebar-nav .sidebar-link[aria-busy]::before,
.sidebar-nav .sidebar-link[aria-busy]::after,
.sidebar-nav .sidebar-sublink[aria-busy]::before,
.sidebar-nav .sidebar-sublink[aria-busy]::after {
  content: none !important;
  display: none !important;
}

/* Hide any child spinners that might be injected */
.sidebar-nav a .loading,
.sidebar-nav a .loading-spinner,
.sidebar-nav a .spinner,
.sidebar-nav .sidebar-link .loading,
.sidebar-nav .sidebar-link .loading-spinner,
.sidebar-nav .sidebar-sublink .loading,
.sidebar-nav .sidebar-sublink .loading-spinner,
.sidebar-nav a span.loading,
.sidebar-nav a span.loading-spinner {
  display: none !important;
}

/* Icon pulse animation when loading - scoped to sidebar only */
.sidebar-nav .sidebar-link.nav-loading .sidebar-icon,
.sidebar-nav .sidebar-sublink.nav-loading i {
  animation: iconPulse 1s ease-in-out infinite;
}

@keyframes iconPulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.7;
  }
}

/* =============================================================================
   ACCESSIBILITY
   ============================================================================= */

.sidebar-link:focus-visible,
.sidebar-section-header:focus-visible,
.sidebar-sublink:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* =============================================================================
   SMOOTH TRANSITIONS
   ============================================================================= */

.sidebar-nav,
.main-content,
footer {
  transition: all var(--sidebar-transition-duration) var(--sidebar-transition-timing);
}

/* =============================================================================
   CONTENT AREA ADJUSTMENTS
   ============================================================================= */

.main-content {
  /* min-height removed - flex layout on body handles height */
}

.sidebar-layout .card {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  border: 1px solid rgba(0, 0, 0, 0.03);
}


/* =============================================================================
   PROPTRUST THEME (Stripe-inspired Grayscale)
   ============================================================================= */

[data-theme="trenly"] .sidebar-nav,
[data-theme="trenly-dark"] .sidebar-nav {
  /* Grayscale sidebar - no purple */
}

[data-theme="trenly"] .sidebar-link:hover,
[data-theme="trenly"] .sidebar-section-header:hover {
  background: var(--sidebar-bg-hover-light);
  color: var(--sidebar-text-primary-light);
}

[data-theme="trenly"] .sidebar-link.active {
  background: oklch(94% 0 0) !important;    /* Clean light gray background - Plaid style */
  color: oklch(34% 0.16 305) !important;    /* Deep purple text #401780 */
  font-weight: 500 !important;
  box-shadow: none !important;               /* No blur/shadow effects */
  border-radius: 6px;                        /* Subtle rounded corners like Plaid */
}

[data-theme="trenly"] .sidebar-link.active:hover {
  background: oklch(92% 0 0) !important;    /* Slightly darker on hover */
  box-shadow: none !important;
}

[data-theme="trenly"] .sidebar-link.active::before {
  background: oklch(34% 0.16 305) !important; /* Deep purple left border #401780 */
  box-shadow: none !important;               /* No glow effect */
  width: 3px;                                /* Slightly thicker for better visibility */
  left: 0;
  border-radius: 0 2px 2px 0;                /* Rounded right side */
}

[data-theme="trenly"] .sidebar-link.active::after {
  content: none !important;                  /* Remove blur effect completely */
  display: none !important;
  background: none !important;
}

[data-theme="trenly"] .sidebar-section-header.active {
  background: oklch(94% 0 0) !important;    /* Clean light gray - subtle highlight */
  color: oklch(34% 0.16 305) !important;    /* Deep purple text #401780 */
  font-weight: 500 !important;
  border-radius: 6px;                        /* Subtle rounded corners like Plaid */
}

[data-theme="trenly"] .sidebar-section-header.active::before {
  display: none !important;                  /* Remove blur effect */
}

[data-theme="trenly"] .sidebar-sublink.active {
  background: oklch(94% 0 0) !important;    /* Clean light gray - consistent with main links */
  color: oklch(34% 0.16 305) !important;    /* Deep purple text #401780 */
  box-shadow: none !important;               /* No blur effects */
  font-weight: 500 !important;
  border-radius: 6px;                        /* Subtle rounded corners like Plaid */
}

[data-theme="trenly"] .sidebar-user-button:hover {
  background: oklch(94% 0 0);               /* Clean gray hover */
  box-shadow: none;                          /* No blur */
  border-color: oklch(85% 0 0);
}

[data-theme="trenly"] .sidebar-user-avatar {
  background: oklch(50% 0 0);               /* Solid medium gray - no gradient */
  box-shadow: none;                          /* No blur/glow */
}

[data-theme="trenly"] .sidebar-user-menu {
  border-color: oklch(85% 0 0);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); /* Subtle shadow, minimal blur */
}

[data-theme="trenly"] .sidebar-user-menu-item:hover {
  background: rgba(0, 0, 0, 0.05);
  color: oklch(15% 0 0);
}

/* PropTrust theme: Sharp, crisp icon rendering like Plaid */
[data-theme="trenly"] .sidebar-icon,
[data-theme="trenly"] .sidebar-link i,
[data-theme="trenly"] .sidebar-sublink i,
[data-theme="trenly"] .sidebar-section-header i,
[data-theme="trenly"] .fa,
[data-theme="trenly"] .fas,
[data-theme="trenly"] .fa-solid,
[data-theme="trenly"] .far {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* DO NOT override font-weight - Font Awesome 7 needs 900 for solid icons */
  opacity: 0.85;                             /* Better contrast */
}

[data-theme="trenly"] .sidebar-link.active .sidebar-icon,
[data-theme="trenly"] .sidebar-link.active i,
[data-theme="trenly"] .sidebar-sublink.active i,
[data-theme="trenly"] .sidebar-section-header.active i {
  /* DO NOT override font-weight - Font Awesome 7 uses it to select font files */
  opacity: 1;
  color: oklch(34% 0.16 305);               /* Deep purple icons #401780 */
}

/* PropTrust theme: Clean divider without smudge/gradient effect (Plaid-style) */
[data-theme="trenly"] .sidebar-divider {
  background: oklch(92% 0.003 250);          /* Clean cool gray line */
  filter: none;
}

[data-theme="trenly"] .sidebar-divider::after {
  content: none;                             /* Remove blur/smudge effect */
  display: none;
}

[data-theme="trenly"] .mobile-close-btn {
  background: rgba(0, 0, 0, 0.03);
  border-color: oklch(85% 0 0);
  color: var(--sidebar-text-secondary-light);
}

[data-theme="trenly"] .mobile-close-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  border-color: oklch(80% 0 0);
  color: var(--sidebar-text-primary-light);
}

/* =============================================================================
   TRENLY DARK THEME - Sidebar User Section
   Grayscale aesthetic adapted for dark backgrounds
   ============================================================================= */

[data-theme="trenly-dark"] .sidebar-footer {
  background: oklch(17% 0.01 240);
  border-top-color: oklch(25% 0 0);
}

[data-theme="trenly-dark"] .sidebar-user-button {
  background: oklch(22% 0 0);
  border-color: oklch(28% 0 0);
}

[data-theme="trenly-dark"] .sidebar-user-button:hover {
  background: oklch(26% 0 0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  border-color: oklch(32% 0 0);
}

[data-theme="trenly-dark"] .sidebar-user-avatar {
  background: oklch(45% 0 0);               /* Solid medium gray - no gradient, grayscale */
  box-shadow: none;
}

[data-theme="trenly-dark"] .sidebar-user-name {
  color: oklch(90% 0 0);
}

[data-theme="trenly-dark"] .sidebar-user-email {
  color: oklch(65% 0 0);
}

[data-theme="trenly-dark"] .sidebar-user-chevron {
  color: oklch(55% 0 0);
}

[data-theme="trenly-dark"] .sidebar-user-menu {
  background: oklch(15% 0 0);
  border-color: oklch(25% 0 0);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
}

[data-theme="trenly-dark"] .sidebar-user-menu-item {
  color: oklch(85% 0 0);
}

[data-theme="trenly-dark"] .sidebar-user-menu-item:hover {
  background: oklch(22% 0 0);
  color: oklch(95% 0 0);
}

[data-theme="trenly-dark"] .sidebar-user-menu-item.logout:hover {
  background: rgba(220, 38, 38, 0.1);
}

[data-theme="trenly-dark"] .sidebar-user-menu-divider {
  background: oklch(25% 0 0);
}

[data-theme="trenly-dark"] .sidebar-divider {
  background: oklch(25% 0 0);
  filter: none;
}

[data-theme="trenly-dark"] .sidebar-divider::after {
  content: none;
  display: none;
}

[data-theme="trenly-dark"] .sidebar-link,
[data-theme="trenly-dark"] .sidebar-section-header {
  color: oklch(75% 0 0);
}

[data-theme="trenly-dark"] .sidebar-link:hover,
[data-theme="trenly-dark"] .sidebar-section-header:hover {
  background: oklch(22% 0 0);
  color: oklch(92% 0 0);
}

[data-theme="trenly-dark"] .sidebar-icon {
  opacity: 0.7;
}

[data-theme="trenly-dark"] .sidebar-link:hover .sidebar-icon,
[data-theme="trenly-dark"] .sidebar-link.active .sidebar-icon {
  opacity: 1;
}

[data-theme="trenly-dark"] .sidebar-sublink {
  color: oklch(65% 0 0);
}

[data-theme="trenly-dark"] .sidebar-sublink:hover {
  background: oklch(22% 0 0);
  color: oklch(88% 0 0);
}

[data-theme="trenly-dark"] .relay-email-label {
  color: oklch(55% 0 0);
}

[data-theme="trenly-dark"] .relay-email-input {
  background: oklch(20% 0 0);
  border-color: oklch(28% 0 0);
  color: oklch(70% 0 0);
}

[data-theme="trenly-dark"] .relay-email-copy-btn {
  background: oklch(20% 0 0);
  border-color: oklch(28% 0 0);
  color: oklch(55% 0 0);
}

[data-theme="trenly-dark"] .relay-row-icon {
  color: oklch(55% 0 0);
}

[data-theme="trenly-dark"] .relay-email-copy-btn:hover {
  background: oklch(26% 0 0);
  border-color: oklch(35% 0 0);
  color: oklch(80% 0 0);
}

[data-theme="trenly-dark"] .sidebar-collapse-btn {
  color: oklch(55% 0 0);
}

[data-theme="trenly-dark"] .sidebar-collapse-btn:hover {
  background: oklch(22% 0 0);
  color: oklch(80% 0 0);
}

/* =============================================================================
   PRINT STYLES
   ============================================================================= */

@media print {
  .sidebar-nav {
    display: none;
  }

  .main-content {
    margin-left: 0;
  }

  footer {
    margin-left: 0;
  }
}

/* =============================================================================
   ALWAYS-FLYOUT SECTION (bottom-actions Imports etc.)
   ============================================================================= */

/* This variant forces the submenu to render as a hover flyout regardless of
   sidebar collapsed/expanded state. Use for short navigation lists living in
   tight UI strips (bottom-actions) where inline expansion would push other
   items around. */

.sidebar-section--flyout-always {
  position: relative;
}

.sidebar-section--flyout-always > .sidebar-submenu {
  display: none !important;
  position: fixed;
  left: var(--sidebar-width);
  min-width: 220px;
  max-width: 280px;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(12px) saturate(140%);
  border: 1px solid var(--sidebar-border-light);
  border-radius: 0.75rem;
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.12),
              0 4px 12px -2px rgba(0, 0, 0, 0.08),
              0 0 0 1px rgba(139, 92, 246, 0.08);
  padding: 0.5rem;
  z-index: 1050;
  animation: flyoutSlideIn 0.18s ease;
  transform: translateY(-100%);
}

/* Collapsed sidebar — anchor to the collapsed width instead. */
.sidebar-nav.collapsed .sidebar-section--flyout-always > .sidebar-submenu {
  left: calc(var(--sidebar-collapsed-width) - 2px);
}

.sidebar-section--flyout-always:hover > .sidebar-submenu,
.sidebar-section--flyout-always:focus-within > .sidebar-submenu {
  display: block !important;
}

/* Invisible hover bridge so the cursor can travel from the section header
   into the flyout without the flyout closing mid-traversal. */
.sidebar-section--flyout-always::after {
  content: '';
  position: absolute;
  left: 100%;
  top: 0;
  width: 220px;
  height: 100%;
  background: transparent;
  pointer-events: none;
  z-index: 1049;
}
.sidebar-section--flyout-always:hover::after {
  pointer-events: auto;
}

/* Pretty sublink padding inside the flyout (matches collapsed-flyout) */
.sidebar-section--flyout-always > .sidebar-submenu .sidebar-sublink {
  padding: 0.5rem 0.75rem;
}

/* Section title chip at the top of the flyout */
.sidebar-section--flyout-always > .sidebar-submenu::before {
  content: attr(data-section-title);
  display: block;
  padding: 0.5rem 0.75rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--sidebar-text-secondary-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Suppress the inline chevron — this variant doesn't inline-expand. */
.sidebar-section--flyout-always > .sidebar-section-header > .sidebar-chevron {
  display: none;
}
