/* Professional Core Sidebar - No Overlay, Always Visible on Desktop */
:root{
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 0px;
}

/* Global: prevent any element from causing horizontal overflow */
*, *::before, *::after {
  box-sizing: border-box;
}

/* Prevent horizontal scroll on mobile */
@media (max-width: 767.98px) {
  :root {
    --sidebar-width: 0px;
  }
  html {
    overflow-x: hidden;
  }
  body {
    overflow-x: hidden;
    max-width: 100vw;
    width: 100%;
  }
  .app-layout {
    width: 100% !important;
    max-width: 100vw;
    overflow-x: hidden;
  }
}

/* Main Sidebar Container */
.core-sidebar{
  width: var(--sidebar-width);
  position: fixed;
  left: 0;
  top: var(--navbar-height, 60px);
  height: calc(100vh - var(--navbar-height, 60px));
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  color: var(--text-primary);
  z-index: 1040;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 200ms ease, width 200ms ease;
  padding: 1.5rem 1rem;
}

@media (min-width: 768px) {
  .core-sidebar{
    top: var(--navbar-height, 70px);
    height: calc(100vh - var(--navbar-height, 70px));
  }
}

/* Custom scrollbar */
.core-sidebar::-webkit-scrollbar {
  width: 6px;
}

.core-sidebar::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

.core-sidebar::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 3px;
}

.core-sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--accent-red);
}

/* Inner container */
.core-sidebar .core-sidebar-inner{
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 0.5rem;
}

/* Brand section */
.core-sidebar .core-sidebar-brand{
  padding: 0.75rem 0.5rem 1rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-logo{
  height: 40px;
  width: 40px;
  object-fit: contain;
  border-radius: 8px;
  background: var(--bg-elevated);
  padding: 6px;
  border: 1px solid var(--border-subtle);
}

.core-sidebar .brand-text strong{
  font-size: 1rem;
  letter-spacing: -0.01em;
  font-weight: 600;
  color: var(--text-primary);
}

.core-sidebar .brand-text small{
  color: var(--text-muted);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Collapse toggle button */
.collapse-toggle{
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.15s ease;
  cursor: pointer;
}

.collapse-toggle:hover{
  background: var(--bg-elevated);
  border-color: var(--border-medium);
  color: var(--text-primary);
}

/* Navigation section */
.core-sidebar-nav{
  margin-top: 0.5rem;
  flex: 1;
}

.core-sidebar-nav .nav-section-label{
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 8px 12px 6px;
  margin-bottom: 4px;
  margin-top: 0.5rem;
}

.core-sidebar-nav .nav-section-label:first-child{
  margin-top: 0;
}

.core-sidebar-nav .nav-item{
  margin-bottom: 2px;
}

.core-sidebar-nav .nav-link{
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: var(--text-secondary);
  background: transparent;
  border-radius: 6px;
  text-decoration: none;
  transition: all 0.15s ease;
  font-weight: 500;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.core-sidebar-nav .nav-link i{
  font-size: 1.1rem;
  color: var(--text-secondary);
  transition: color 0.15s ease;
  min-width: 18px;
  text-align: center;
}

.core-sidebar-nav .nav-link:hover{
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.core-sidebar-nav .nav-link:hover i{
  color: var(--accent-red);
}

.core-sidebar-nav .nav-link.active{
  background: rgba(220, 38, 38, 0.1);
  color: var(--text-primary);
  border-left: 2px solid var(--accent-red);
  padding-left: 10px;
}

.core-sidebar-nav .nav-link.active i{
  color: var(--accent-red);
}

/* Separator */
.sidebar-sep{
  border: 0;
  height: 1px;
  background: var(--border-subtle);
  margin: 1rem 0;
}

/* Footer section */
.core-sidebar-footer{
  padding: 1rem 0.5rem 0.5rem;
  margin-top: auto;
}

.footer-link{
  color: var(--text-primary);
  text-decoration: none;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  transition: all 0.15s ease;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
}

.footer-link:hover {
  background: var(--bg-primary);
  border-color: var(--border-medium);
}

.footer-avatar{
  height: 40px;
  width: 40px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}

.footer-avatar-initial{
  height: 40px;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(220, 38, 38, 0.1);
  color: var(--accent-red);
  font-weight: 700;
  font-size: 1.1rem;
  border: 1px solid rgba(220, 38, 38, 0.3);
}

.footer-text strong {
  display: block;
  font-size: 0.9rem;
  color: var(--text-primary);
  font-weight: 600;
}

.footer-text small {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.core-sidebar-footer .btn {
  margin-top: 0.75rem;
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.15s ease;
  font-size: 0.9rem;
}

.core-sidebar-footer .btn-outline-primary {
  color: var(--text-primary);
  border-color: var(--border-medium);
  background: transparent;
}

.core-sidebar-footer .btn-outline-primary:hover {
  background: var(--bg-elevated);
  border-color: var(--border-medium);
  color: var(--text-primary);
}

.core-sidebar-footer .btn-sm.btn-primary {
  background: var(--accent-red);
  border: none;
  color: white;
  font-weight: 500;
}

.core-sidebar-footer .btn-sm.btn-primary:hover {
  background: var(--accent-red-hover);
}

.core-sidebar-footer a.text-danger {
  font-size: 0.85rem;
  text-align: center;
  display: block;
  transition: color 0.15s ease;
}

.core-sidebar-footer a.text-danger:hover {
  color: var(--accent-red) !important;
}

/* Backdrop - Only for mobile */
.core-sidebar-backdrop{
  position: fixed;
  inset: var(--navbar-height, 60px) 0 0 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1044;
  display: none;
  transition: opacity 200ms ease;
}

@media (min-width: 768px) {
  .core-sidebar-backdrop{
    inset: var(--navbar-height, 70px) 0 0 0;
    z-index: 1035;
  }
}

/* Mobile behaviour - Overlay on small screens */
@media (max-width: 767.98px){
  .core-sidebar{
    transform: translateX(-110%);
    width: 85%;
    max-width: 300px;
    min-width: 0;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.8);
    padding: 1rem 0.75rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 1045;
    top: var(--navbar-height, 60px);
    height: calc(100vh - var(--navbar-height, 60px));
  }

  .core-sidebar .core-sidebar-inner{
    padding-bottom: 2rem;
  }

  body.core-sidebar-open .core-sidebar{
    transform: translateX(0);
  }

  body.core-sidebar-open #coreSidebarBackdrop{
    display: block;
  }

  /* Mobile: full width, no margin */
  .app-content {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden;
  }
}

/* Desktop - sidebar pushes content via margin */
@media (min-width: 768px){
  .app-content{
    margin-left: var(--sidebar-width);
    transition: margin-left 200ms ease;
    width: calc(100% - var(--sidebar-width));
  }

  /* Collapsed state: hide sidebar completely */
  body.core-sidebar-collapsed .core-sidebar{
    transform: translateX(-100%);
  }

  body.core-sidebar-collapsed .app-content{
    margin-left: 0;
    width: 100%;
  }
}

/* Accessibility focus */
.core-sidebar a:focus{
  outline: 2px solid var(--accent-red);
  outline-offset: 2px;
  border-radius: 6px;
}

.core-sidebar button:focus {
  outline: 2px solid var(--accent-red);
  outline-offset: 2px;
}

/* Smooth animations */
@media (prefers-reduced-motion: reduce) {
  .core-sidebar,
  .core-sidebar *,
  .app-content {
    transition: none !important;
  }
}
