/* ============================================
   SIDEBAR NAVIGATION
   ============================================ */

.app-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: 80px;
  background: linear-gradient(180deg, rgba(var(--da-royal-rgb), 0.25) 0%, rgba(var(--da-royal-rgb), 0.15) 50%, rgba(15, 12, 25, 0.98) 100%);
  backdrop-filter: blur(12px);
  border-right: 1px solid rgba(var(--da-royal-rgb), 0.25);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: width 0.3s ease, padding 0.3s ease;
  overflow: hidden;
  font-family: var(--font-heading);
}

.app-sidebar:hover {
  width: 260px;
}

.sidebar-header {
  padding: 1.5rem 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  border-bottom: 1px solid rgba(var(--da-royal-rgb), 0.2);
  min-height: 80px;
}

.app-sidebar:hover .sidebar-header {
  justify-content: flex-start;
  padding: 1.5rem 1rem;
  gap: 0.75rem;
}

.sidebar-logo {
  height: 40px;
  width: 40px;
  object-fit: contain;
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-extrabold);
  font-family: var(--font-heading);
  background: linear-gradient(135deg, var(--da-royal), var(--da-silver));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.app-sidebar:hover .sidebar-logo-text {
  opacity: 1;
}

.sidebar-nav {
  flex: 1;
  padding: 0.5rem 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.sidebar-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0.875rem;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: all 0.2s ease;
  position: relative;
  cursor: pointer;
  margin: 0.25rem 0.25rem;
  border-radius: 12px;
}

.app-sidebar:hover .sidebar-item {
  justify-content: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  margin: 0.25rem 0.75rem;
}

.sidebar-item:hover:not(.sidebar-item--disabled) {
  background: rgba(var(--da-royal-rgb), 0.3);
  color: #ffffff;
}

.sidebar-item--active {
  background: linear-gradient(135deg, rgba(var(--da-royal-rgb), 0.35), rgba(var(--da-royal-rgb), 0.2));
  color: #ffffff;
  border: 1px solid rgba(var(--da-royal-rgb), 0.35);
}

.sidebar-item--active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: linear-gradient(180deg, var(--da-royal), var(--da-silver));
  border-radius: 0 4px 4px 0;
  opacity: 0;
}

.app-sidebar:hover .sidebar-item--active::before {
  opacity: 1;
}

.sidebar-item--disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.sidebar-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-label {
  white-space: nowrap;
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  font-family: var(--font-heading);
  opacity: 0;
  width: 0;
  overflow: hidden;
  transition: opacity 0.2s ease, width 0s 0.2s;
}

.app-sidebar:hover .sidebar-label {
  opacity: 1;
  width: auto;
  transition: opacity 0.2s ease;
}

.sidebar-badge {
  align-items: center;
  background: var(--color-error);
  border: 1px solid rgba(var(--color-error-rgb), 0.35);
  border-radius: 999px;
  color: var(--color-text-primary);
  display: inline-flex;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  justify-content: center;
  margin-left: auto;
  min-height: 1.25rem;
  min-width: 1.25rem;
  padding: 0 0.35rem;
}

.sidebar-footer {
  border-top: 1px solid rgba(var(--da-royal-rgb), 0.2);
  padding: 1rem 0;
}

.sidebar-collapse-btn {
  display: none;
}

.sidebar-item--logout {
  color: rgba(239, 68, 68, 0.8);
}

.sidebar-item--logout:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.sidebar-legal {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 0.5rem;
  font-size: var(--fs-2xs);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.app-sidebar:hover .sidebar-legal {
  opacity: 1;
}

.sidebar-legal a {
  color: rgba(255, 255, 255, 0.5);
  text-decoration: none;
  transition: color 0.2s ease;
}

.sidebar-legal a:hover {
  color: var(--da-gold);
  text-decoration: underline;
}

.sidebar-legal-divider {
  color: rgba(255, 255, 255, 0.3);
}

/* Page layout with sidebar */
.app-layout {
  display: flex;
  min-height: 100vh;
  margin: 0;
  padding: 0;
  border: none;
  font-family: var(--font-heading);
}

.app-main {
  flex: 1;
  margin-left: 80px;
  transition: margin-left 0.3s ease;
  background: transparent;
  min-height: 100vh;
  border: none;
  font-family: var(--font-heading);
}

/* Pages that deliberately hide the sidebar */
.app-layout.no-sidebar .app-main {
  margin-left: 0;
}

/* Responsive */
@media (max-width: 1024px) {
  .app-sidebar:hover {
    width: 220px;
  }
}

/* Mobile: Bottom Navigation Bar */
@media (max-width: 768px) {
  .app-sidebar {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid rgba(var(--da-royal-rgb), 0.25);
    padding: 0;
    z-index: 1000;
  }

  .app-sidebar:hover {
    width: 100%;
  }

  .sidebar-header {
    display: none;
  }

  .sidebar-nav {
    flex-direction: row;
    flex: 1;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    justify-content: space-around;
  }

  .sidebar-item {
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem 0.5rem;
    margin: 0;
    border-radius: 0;
    flex: 1;
    min-width: 60px;
    max-width: 100px;
    justify-content: center;
  }

  .app-sidebar:hover .sidebar-item {
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem 0.5rem;
    margin: 0;
  }

  .sidebar-icon {
    width: 20px;
    height: 20px;
  }

  .sidebar-label {
    opacity: 1;
    width: auto;
    font-size: var(--fs-2xs);
    text-align: center;
    transition: none;
  }

  .app-sidebar:hover .sidebar-label {
    opacity: 1;
  }

  .sidebar-logo-text {
    display: none;
  }

  .sidebar-item--active::before {
    display: none;
  }

  .sidebar-footer {
    border-top: none;
    border-left: 1px solid rgba(var(--da-royal-rgb), 0.2);
    padding: 0;
    display: flex;
    align-items: center;
  }

  .sidebar-footer .sidebar-item {
    border-radius: 0;
  }

  .sidebar-legal {
    display: none;
  }

  /* Adjust main content to account for bottom nav */
  .app-main {
    margin-left: 0;
    margin-bottom: 65px;
  }

  /* Pages without sidebar still need bottom padding if sidebar is visible */
  .app-layout.no-sidebar .app-main {
    margin-left: 0;
    margin-bottom: 0;
  }
}

/* Dormant items: de-emphasized until the owner has data for them.
   Still clickable — target pages have empty states. */
.sidebar-item--dormant {
  /* 0.65 keeps the label >= 4.5:1 contrast on the dark sidebar
     (0.45 measured ~2.8:1); hover/focus restore full opacity. */
  opacity: 0.65;
}

/* Expanded rail reveals labels next to full-strength siblings — lift the
   dormant items too so their text stays comfortably above 4.5:1. */
.app-sidebar:hover .sidebar-item--dormant {
  opacity: 0.8;
}

.sidebar-item--dormant:hover,
.sidebar-item--dormant:focus-visible,
.app-sidebar:hover .sidebar-item--dormant:hover,
.app-sidebar:hover .sidebar-item--dormant:focus-visible,
.sidebar-item--dormant.sidebar-item--active {
  opacity: 1;
}

/* Mobile bottom-nav: the 11px labels are always visible, so de-emphasis must
   come from color, never compounded opacity — rgba(255,255,255,.55) over the
   near-black bar stays >= 4.5:1 (AA for small text). */
@media (max-width: 768px) {
  .sidebar-item--dormant {
    opacity: 1;
    color: rgba(255, 255, 255, 0.55);
  }

  .sidebar-item--dormant:hover,
  .sidebar-item--dormant:focus-visible,
  .sidebar-item--dormant.sidebar-item--active {
    color: rgba(255, 255, 255, 0.95);
  }
}
