.sidebar {
  width: 60px;
  transition: 0.3s ease;
  overflow-x: hidden;
  flex-direction: column;
  height: 100vh;
  background: var(--color-primary);
  position: fixed;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.2);
  z-index: 999;
}

.sidebar-menu-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  background: none;
  border: none;
  color: var(--color-white);
  padding: 0.5rem 1rem;
  cursor: pointer;
  text-align: left;
  position: relative;
  text-decoration: none;
  transition: opacity 0.3s ease, width 0.3s ease, margin 0.3s ease;
}

.sidebar-menu-button .label {
  opacity: 0;
  width: 0;
  overflow: hidden;
  transition: opacity 0.3s ease, width 0.3s ease, margin 0.3s ease;
  font-size: 1rem;
}

.sidebar-menu-button:hover {
  color: var(--color-text-hover);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 0.2rem;
}

.sidebar-brand {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--color-white);
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* Hover to expand on wider screens */
@media (min-width: 769px) {
  .sidebar:hover {
    width: 220px;
    opacity: 0.97;
  }

  .sidebar:hover .sidebar-brand {
    opacity: 1;
  }

  .sidebar:hover .sidebar-menu-button .label {
    opacity: 1;
    width: auto;
    margin-left: 0.5rem;
  }

  .mobile-menu-button, .mobile-menu-brand {
    display: none;
  }
}

/* Burger expand for narrower screens */
@media (max-width: 768px) {
  .sidebar-brand {
    display: none;
  }

  .mobile-menu-button {
    display: flex;
    position: fixed;
    left: 1rem;
    z-index: 997;
    border: none;
    background: var(--color-primary);
    color: white;
    padding: .5rem;
    border-radius: 4px;
    cursor: pointer;
  }

  .sidebar {
    width: 220px;
    margin-top: 35px;
    transform: translateX(-100%);
    transition: transform .3s;
  }

  .sidebar-logout-link {
    margin-bottom: 35px;
  }

  .mobile-menu-brand {
    color: var(--color-white);
    font-size: 1.0rem;
    font-weight: bold;
    text-decoration: none;
    transition: opacity 0.3s ease;
    text-align: right;
    margin-left: auto;
    padding: .5rem;
    padding-right: 2.5rem;
  }

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

  .sidebar-menu-button .label {
    opacity: 1;
    width: auto;
    margin-left: .5rem;
  }

  .sidebar-submenu.open {
    max-height: 500px;
  }

  .mobile-header {
    height: 35px;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    background: var(--color-primary);
    color: white;
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 999;
  }

  .mobile-menu-button {
    background: none;
    border: 0;
    color: white;
    margin-right: 1rem;
  }
}

.sidebar-menu-button .caret {
  margin-left: auto;
  transition: transform 0.3s ease;
}

.sidebar-menu-button .caret.rotate {
  transform: rotate(180deg);
}

.sidebar-submenu {
  display: flex;
  flex-direction: column;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.sidebar-submenu.open {
  max-height: 500px;
}

.sidebar-submenu a {
  color: var(--color-white);
  display: block;
  font-size: 0.9rem;
  font-weight: normal;
  padding: 0.25rem 0;
  padding-left: 2rem;
  text-decoration: none;
  transition: background 0.2s ease;
}

.sidebar-submenu a:hover {
  background: var(--color-primary-dark);
}

.sidebar:not(:hover) .sidebar-submenu {
  max-height: 0 !important;
  overflow: hidden;
}

.sidebar:hover .sidebar-submenu.open {
  max-height: 500px;
}

.sidebar-links {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.sidebar-logout-link {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  margin-top: auto;
  text-decoration: none;
  color: var(--color-white);
}

.sidebar:hover .sidebar-logout-link {
  justify-content: flex-start;
}

.sidebar-overlay {
    display: none;
}

.sidebar-overlay.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 998;
}
